/* Cartigma — smartphone investigation layout.
   Desktop retains the existing two-column presentation.
   Portrait phones: a 1:1 interactive map above one continuous, readable case scroller. */
@media (max-width:760px),
       (max-height:540px) and (pointer:coarse) {
  html,body{
    height:100%;
    width:100%;
    overflow:hidden;
  }
  .app{
    height:100dvh;
    min-height:0;
    max-height:100dvh;
    overflow:hidden;
  }
  main{
    display:flex;
    flex:1 1 0;
    flex-direction:column;
    min-height:0;
    overflow:hidden;
  }
  .toolbar{
    flex:0 0 auto;
    min-height:46px;
    height:46px;
    padding-inline:10px;
    gap:6px;
  }
  .mode-tabs{gap:4px;min-width:0}
  .mode-tab{min-height:36px;padding:7px 11px;font-size:12px}
  .toolbar select{
    height:36px;
    min-width:90px;
    width:auto;
    font-size:12px;
    padding-inline:8px;
  }
  .game-grid{
    display:flex;
    flex:1 1 0;
    flex-direction:column;
    grid-template-columns:none;
    min-height:0;
    min-width:0;
    overflow:hidden;
  }
  .map-card{
    position:relative;
    flex:0 0 auto;
    width:100%;
    min-width:0;
    min-height:0;
    height:auto;
    overflow:hidden;
    border-right:0;
    border-bottom:1px solid var(--border-strong);
  }
  .map-toolbar{
    height:36px;
    min-height:36px;
    padding-inline:11px;
  }
  #map{
    display:block;
    flex:0 0 auto;
    width:100%;
    height:auto!important;
    aspect-ratio:1 / 1;
    min-width:0;
    min-height:0;
    margin:0;
  }
  .map-bottom{
    min-height:35px;
    height:35px;
    padding-inline:9px;
    font-size:10px;
    gap:6px;
  }
  #coordinates{
    min-width:0;
    max-width:41%;
    font-size:10px;
  }
  .map-style-button{
    min-height:29px;
    padding:6px 9px;
    font-size:10px;
  }
  .compass-rose{
    right:7px;
    bottom:64px;
    width:65px;
    height:65px;
  }
  .compass-rose .compass-art{
    left:13px;
    top:13px;
    width:38px;
    height:38px;
  }
  .compass-rose>span{font-size:9px}
  .maplibregl-ctrl-group button{width:35px!important;height:35px!important}
  .case-card{
    display:flex;
    flex:1 1 0;
    flex-direction:column;
    width:100%;
    min-width:0;
    min-height:0;
    height:auto;
    overflow-y:auto;
    overflow-x:hidden;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
    touch-action:pan-y;
    scroll-behavior:smooth;
    scrollbar-width:thin;
    scrollbar-color:var(--border-strong) transparent;
    background:var(--surface);
  }
  .case-header{
    display:flex;
    flex:0 0 auto;
    position:sticky;
    top:0;
    z-index:7;
    gap:10px;
    min-height:62px;
    padding:10px 14px;
    background:var(--surface);
    border-bottom:1px solid var(--border-strong);
  }
  .case-header .case-title h1{
    font-size:17px;
    line-height:1.25;
  }
  .case-kicker{font-size:10px}
  .case-status{display:inline-flex;font-size:10px;padding:5px 7px}
  .attempts{width:98px;gap:5px}
  .attempts .label-muted{font-size:10px}
  .attempts strong{font-size:11px}
  .case-columns{
    display:flex;
    flex:0 0 auto;
    flex-direction:column;
    width:100%;
    height:auto;
    min-height:0;
    grid-template-columns:none;
    grid-template-rows:none;
    overflow:visible;
    direction:ltr;
  }
  .case-columns>.clue-panel,.case-columns>.guess-panel{
    display:flex;
    flex:0 0 auto;
    flex-direction:column;
    min-width:0;
    width:100%;
    height:auto;
    min-height:0;
    padding:16px 16px 17px;
    overflow:visible;
    border-right:0;
  }
  .case-columns>.clue-panel{
    border-bottom:1px solid var(--border-strong);
  }
  .section-heading{
    min-height:34px;
    gap:9px;
    padding-bottom:8px;
    margin-bottom:10px;
  }
  .section-heading h2{font-size:14px}
  .section-heading>span{font-size:11px}
  .section-index{
    min-width:23px;
    height:23px;
    font-size:11px;
    margin-right:5px;
  }
  .case-columns .clue-list{
    display:flex;
    flex:0 0 auto;
    flex-direction:column;
    height:auto;
    min-height:0;
    max-height:none;
    overflow:visible!important;
    padding:0;
    gap:0;
  }
  .clue{
    display:grid;
    flex:0 0 auto;
    grid-template-columns:24px minmax(0,1fr);
    gap:10px;
    padding:12px 10px;
    min-height:59px;
  }
  .clue-index{font-size:11px}
  .clue-category{font-size:10px;letter-spacing:.55px}
  .clue-text{
    display:block;
    overflow:visible;
    font-size:13px;
    line-height:1.5;
    -webkit-line-clamp:unset;
  }
  .reveal-btn{
    margin-top:12px;
    min-height:43px;
    padding:11px 12px;
    font-size:13px;
  }
  .reveal-btn small{font-size:12px}
  .search-label{font-size:12px;margin:3px 0 9px}
  .search-wrap input{
    height:46px;
    padding-left:36px;
    font-size:16px; /* avoids Safari focus zoom */
  }
  .search-icon{left:11px;top:5px}
  .suggestions{
    top:47px;
    max-height:min(240px,40dvh);
    overflow:auto;
    z-index:20;
  }
  .suggestion{min-height:44px;padding:10px 12px;font-size:13px}
  .suggestion small{font-size:11px}
  .selection{min-height:39px;font-size:12px;gap:9px}
  .primary-btn,.secondary-btn{
    min-height:45px;
    padding:9px 12px;
    font-size:13px;
  }
  .feedback{font-size:12px;line-height:1.5;padding:10px 12px;margin-top:9px}
  .history-heading{margin-top:23px;padding-bottom:9px}
  .history-heading h3{font-size:13px}
  .history-heading span{font-size:11px}
  .case-columns .guess-history{
    flex:0 0 auto;
    min-height:0;
    height:auto;
    max-height:none;
    overflow:visible!important;
    padding-bottom:9px;
  }
  .history-item{min-height:42px;padding:10px 3px;font-size:12px;line-height:1.4}
  .history-item strong{font-size:11px}
  .empty-history{font-size:12px;padding:14px 3px}
  .result-card{
    position:relative;
    inset:auto;
    flex:0 0 auto;
    width:100%;
    margin-top:14px;
    padding:15px;
    overflow:visible;
    justify-content:flex-start;
    border-radius:4px;
  }
  .result-card h3{font-size:19px}
  .result-card p{font-size:12px}
  .result-actions{gap:9px}
  .result-actions button{min-height:44px}
  .status-bar{display:none}

  /* Non-modal completed-case dossier follows the investigation in the
     same lower scroll surface. It must never cover the square map. */
  dialog.case-report,dialog.case-report[open]{
    position:relative;
    inset:auto;
    display:flex;
    flex:0 0 auto;
    width:calc(100% - 24px);
    max-width:none;
    height:auto;
    min-height:0;
    max-height:none;
    margin:15px 12px 22px;
    overflow:visible;
    border:1px solid var(--border-strong);
    border-top:2px solid var(--accent);
    border-radius:4px;
    box-shadow:none;
    scroll-margin-top:75px;
    z-index:1;
  }
  dialog.case-report:not([open]){display:none!important}
  dialog.case-report .report-body{
    flex:0 0 auto;
    height:auto;
    max-height:none;
    min-height:0;
    overflow:visible;
    padding:12px 14px;
  }
  dialog.case-report .report-heading{padding:13px 14px}
  dialog.case-report .report-heading h2{font-size:20px}
  dialog.case-report .report-topbar{padding-inline:12px}
  dialog.case-report .report-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
  dialog.case-report .report-footer{
    grid-template-columns:repeat(2,minmax(0,1fr));
    gap:7px;
    padding:12px;
  }
  dialog.case-report .report-footer button{min-height:42px;font-size:12px}
  dialog.case-report #reportNextBtn{grid-column:1/-1}
  .report-log-row{overflow-wrap:anywhere}
  [dir="rtl"] .case-columns{direction:ltr}
  [dir="rtl"] .clue-body,[dir="rtl"] .guess-panel{direction:rtl}
}

/* Narrow phones: keep controls tappable rather than shrinking text to 9px. */
@media(max-width:390px){
  .toolbar{padding-inline:7px}
  .mode-tab{font-size:11px;padding-inline:8px}
  .toolbar select{min-width:75px;font-size:11px}
  .case-header{padding:9px 11px}
  .case-status{display:none}
  .case-columns>.clue-panel,.case-columns>.guess-panel{padding-inline:12px}
  .map-style-button{font-size:9px;padding-inline:6px}
  .map-bottom #coordinates{font-size:9px}
}

/* Short-height phones and landscape: let the entire page scroll.
   This prevents a square map from reducing the lower panel to a sliver. */
@media(max-width:760px) and (max-height:730px),
       (max-width:760px) and (min-aspect-ratio:11/20),
       (max-height:540px) and (pointer:coarse){
  html,body{
    height:auto;
    min-height:100%;
    overflow-x:hidden;
    overflow-y:auto;
    overscroll-behavior-y:auto;
  }
  .app{
    height:auto;
    min-height:100dvh;
    max-height:none;
    overflow:visible;
  }
  main{
    flex:0 0 auto;
    height:auto;
    overflow:visible;
  }
  .game-grid{
    flex:0 0 auto;
    height:auto;
    overflow:visible;
  }
  .case-card{
    flex:0 0 auto;
    height:auto;
    overflow:visible;
  }
  .case-header{position:relative;top:auto}
  dialog.case-report,dialog.case-report[open]{scroll-margin-top:18px}
}


/* Landscape phones get the same scrollable layout without an 850px-tall map. */
@media (max-height:540px) and (pointer:coarse) and (orientation:landscape){
  .map-card{align-items:stretch}
  #map{width:min(100%,540px);align-self:center}
}


/* Smartphone language selector: a centered, large, accessible dialog. */
.language-backdrop,.language-close{display:none}
@media (max-width:760px), (max-height:540px) and (pointer:coarse){
  html.language-modal-open,
  html.language-modal-open body{
    overflow:hidden!important;
  }
  .language-picker .language-backdrop:not(.hidden){
    position:fixed;
    display:block;
    inset:0;
    z-index:1240;
    background:rgba(4,9,20,.78);
    backdrop-filter:blur(3px);
    -webkit-backdrop-filter:blur(3px);
    touch-action:none;
  }
  .language-picker .language-menu:not(.hidden){
    position:fixed;
    inset:50% auto auto 50%;
    top:50%;
    right:auto;
    bottom:auto;
    left:50%;
    z-index:1250;
    display:flex;
    flex-direction:column;
    transform:translate(-50%,-50%);
    width:min(92vw,450px);
    height:min(78dvh,660px);
    max-width:calc(100vw - 20px);
    max-height:calc(100dvh - 24px);
    overflow:hidden;
    border:1px solid var(--border-strong);
    border-radius:12px;
    background:var(--surface);
    color:var(--text);
    box-shadow:0 28px 75px #0009;
  }
  .language-menu .language-menu-heading{
    min-height:58px;
    flex:0 0 auto;
    display:flex;
    align-items:center;
    gap:10px;
    padding:12px 16px;
    border-bottom:1px solid var(--border);
    color:var(--text);
    font:700 13px var(--mono);
    letter-spacing:.6px;
  }
  .language-menu .language-count{margin-left:auto;font-size:12px}
  .language-menu .language-close{
    display:grid;
    place-items:center;
    width:40px;
    height:40px;
    flex:0 0 40px;
    padding:0;
    border:1px solid var(--border);
    border-radius:7px;
    background:var(--surface2);
    color:var(--text);
  }
  .language-menu .language-close:hover,
  .language-menu .language-close:focus-visible{
    border-color:var(--accent);
    color:var(--accent);
  }
  .language-menu .language-search-wrap{
    min-height:48px;
    height:48px;
    flex:0 0 48px;
    margin:14px 14px 8px;
    padding:0 13px;
    background:var(--input-bg);
    border-color:var(--border-strong);
    border-radius:7px;
  }
  .language-menu .language-search-wrap input{
    min-height:44px;
    height:44px;
    font-size:16px;
  }
  .language-menu .language-options{
    min-height:0;
    flex:1 1 auto;
    overflow-y:auto;
    overflow-x:hidden;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    touch-action:pan-y;
    padding:3px 12px 14px;
    scrollbar-width:thin;
    scrollbar-color:var(--border-strong) transparent;
  }
  .language-menu .language-option{
    min-height:52px;
    gap:12px;
    padding:10px 12px;
    border-radius:6px;
    border-bottom:1px solid var(--border);
    font-size:14px;
  }
  .language-menu .language-option-name{font-size:14px}
  .language-menu .language-option-code{font-size:11px}
  .language-menu .language-option-flag{
    width:29px;
    height:21px;
  }
  .language-menu .language-option-emoji{
    min-width:29px;
    flex-basis:29px;
    height:21px;
    font-size:20px;
  }
}
@media (max-width:760px) and (max-height:540px),
       (max-height:540px) and (pointer:coarse){
  .language-picker .language-menu:not(.hidden){
    height:min(86dvh,500px);
    max-height:calc(100dvh - 16px);
  }
  .language-menu .language-menu-heading{min-height:46px;padding:6px 12px}
  .language-menu .language-search-wrap{margin:6px 12px;height:44px;min-height:44px;flex-basis:44px}
}
