/* =====================================================================
   mobile.css — phone-first layer for the Anwar archive.
   Load AFTER style.css and responsive.css. Works with mobile.js.

   What it does on phones (≤700px, or short coarse-pointer landscape):
   • Compact header: title + search button only
   • Bottom tab bar (Tree · Photos · History · Map · More)
   • "More" sheet with the other tabs + Surprise / What's new / Theme / Language
   • Search results as a full-width list under the header
   • Tree toolbar tightened, clock + legend moved out of the way
   • Larger tap targets, comfortable reading sizes, no sideways overflow
   ===================================================================== */

/* Hidden everywhere by default; shown only in the mobile query below */
#bnav, #msheet, #msheet-bg, #sbtn { display: none; }

@media (max-width: 700px), (max-height: 520px) and (pointer: coarse) {

  :root {
    --bnav-h: 58px;
    --tap: 44px;
  }

  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }

  /* ---------- Header ---------- */
  header {
    flex-wrap: wrap;
    gap: 0 8px;
    min-height: 0;
    padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 6px max(14px, env(safe-area-inset-left));
    box-shadow: none;
  }
  header h1 {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 21px;
    line-height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  header nav { display: none; }              /* replaced by the bottom bar */

  #sbtn {
    display: grid;
    place-items: center;
    flex: none;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
  }
  header.search-open #sbtn { border-color: var(--acc); color: var(--acc); }

  .sw {
    display: none;
    flex: 1 0 100%;
    order: 5;
    width: 100%;
    margin: 6px 0 2px;
  }
  header.search-open .sw { display: block; }
  #q {
    width: 100%;
    max-width: none;
    height: 46px;
    padding: 0 16px;
    border-radius: 12px;
  }

  /* Results: full-width list hanging under the header */
  #sr {
    position: fixed;
    top: var(--hdr-b, 112px);
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    min-width: 0;
    max-width: none;
    max-height: calc(100dvh - var(--hdr-b, 112px) - var(--bnav-h) - 20px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
    z-index: 60;
  }
  #sr div { min-height: 48px; padding: 12px 16px; line-height: 1.35; }
  #sr div + div { border-top: 1px solid var(--line); }

  /* ---------- Bottom tab bar ---------- */
  #bnav {
    display: flex;
    flex: none;
    position: relative;
    z-index: 40;
    align-items: stretch;
    height: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left));
    background: var(--card);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, .12);
  }
  #bnav button {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px 4px;
    border: 0;
    background: none;
    color: var(--mut);
    font: 600 10.5px/1.1 var(--font-sans);
    letter-spacing: .01em;
    cursor: pointer;
    position: relative;
    transition: color .15s;
  }
  #bnav button span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #bnav svg {
    width: 23px;
    height: 23px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .18s;
  }
  #bnav button.on { color: var(--acc); }
  #bnav button.on svg { transform: translateY(-1px) scale(1.06); }
  #bnav button.on::before {
    content: "";
    position: absolute;
    top: 0;
    left: 28%;
    right: 28%;
    height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--acc);
  }
  #bnav button:active { background: var(--soft); }

  /* ---------- More sheet ---------- */
  #msheet-bg {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(0, 0, 0, .5);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
  }
  #msheet-bg.on { opacity: 1; pointer-events: auto; }

  #msheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 71;
    max-height: 86dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 10px 16px max(20px, env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--line);
    border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform .3s cubic-bezier(.3, 1, .4, 1), visibility 0s linear .3s;
  }
  #msheet.on { transform: none; visibility: visible; transition-delay: 0s; }
  #msheet .grab {
    width: 40px; height: 4px; margin: 0 auto 14px;
    border-radius: 2px; background: var(--line);
  }
  #msheet h4 {
    margin: 6px 2px 10px;
    font: 600 11px var(--font-sans);
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--mut);
  }
  .ms-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .ms-grid button {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 60px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--soft);
    color: var(--text);
    font: 600 14px var(--font-sans);
    text-align: start;
    cursor: pointer;
  }
  .ms-grid button svg {
    flex: none; width: 22px; height: 22px;
    fill: none; stroke: var(--acc); stroke-width: 1.7;
    stroke-linecap: round; stroke-linejoin: round;
  }
  .ms-grid button.on { border-color: var(--acc); color: var(--acc); }
  .ms-grid button:active { transform: scale(.98); }

  .ms-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: stretch;
  }
  .ms-tools > .btn,
  .ms-tools .lang-btn {
    width: 100%;
    min-height: 50px;
    justify-content: center;
    font-size: 14px;
    border-radius: 14px;
  }
  .ms-tools .lang-switch { position: relative; }
  .ms-tools .lang-btn { display: flex; align-items: center; gap: 8px; padding: 0 14px; }
  .ms-tools .lang-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    top: auto;
    inset-inline: 0;
    min-width: 0;
    max-height: 50dvh;
    overflow-y: auto;
  }
  .ms-tools .lang-menu li { min-height: 46px; display: flex; align-items: center; padding: 0 16px; font-size: 15px; }

  /* ---------- Tree view ---------- */
  .tb {
    top: 0; left: 0; right: 0;
    max-width: none;
    gap: 6px;
    padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  .tb .btn {
    flex: 1 1 auto;
    min-height: 40px;
    padding-inline: 10px;
    font-size: 12.5px;
    border-radius: 10px;
  }
  #print-tree { display: none; }               /* printing from a phone is rare; frees the row */

  /* clock sits under the toolbar, out of the way */
  .wc { top: 58px; right: max(10px, env(safe-area-inset-right)); }
  .wc-btn { min-height: 34px; }
  .wc-menu { right: 0; max-width: calc(100vw - 20px); }
  #tree:has(.alive-bar.on) .wc { display: none; }

  .alive-bar { left: 8px; right: 8px; width: auto; margin-top: 6px; }
  .alive-top .btn { min-height: 40px; min-width: 40px; }

  .zc { left: max(10px, env(safe-area-inset-left)); bottom: 12px; gap: 6px; }
  .zc .btn { width: 46px; height: 46px; padding: 0; border-radius: 14px; box-shadow: var(--shadow); }
  .lg { bottom: 12px; right: max(10px, env(safe-area-inset-right)); opacity: .92; padding: 6px 10px; }

  /* ---------- Profile sheet sits above the tab bar (it lives inside <main>) ---------- */
  #pn { max-height: 100%; height: min(82%, 740px); }
  #pn .pf-bar { cursor: grab; touch-action: none; }

  /* ---------- Reading pages ---------- */
  .pg { padding: 16px max(16px, env(safe-area-inset-left)) 40px max(16px, env(safe-area-inset-right)); }
  .pg h2 { font-size: 28px; }
  .pg > p, .map-intro, .gallery-intro, .archive-intro { font-size: 15px; line-height: 1.6; }
  .editorial-view .pg { padding-top: 22px; }
  .history-copy { font-size: 16.5px; line-height: 1.75; }

  .two { grid-template-columns: 1fr; gap: 22px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

  .gallery-filters { flex-wrap: nowrap; overflow-x: auto; margin-inline: -16px; padding: 2px 16px 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .gallery-filters::-webkit-scrollbar { display: none; }
  .gallery-filters > * { flex: none; min-height: 40px; }
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

  .cn { gap: 12px; }
  .cn select, .cn .cn-q { min-height: 48px; font-size: 16px; }

  .map-mode .btn, .mig-chip { min-height: 44px; }
  #map-canvas { height: clamp(300px, 52dvh, 520px); border-radius: 14px; }
  .mig-play .btn { min-height: 44px; }

  .fold > summary { min-height: 56px; }
  .archive-index-link { min-height: 60px; }
  .arc-table-wrap, .tl { -webkit-overflow-scrolling: touch; }

  /* floating buttons (back-to-top / records) clear the tab bar since <main> ends above it */
  .float-ui { right: max(12px, env(safe-area-inset-right)); bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px) + 12px); }
  .float-btn { min-height: 44px; padding-inline: 16px; }
  #toast { bottom: calc(var(--bnav-h) + env(safe-area-inset-bottom, 0px) + 14px); max-width: calc(100vw - 32px); text-align: center; }

  /* full-screen overlays */
  #wn .wn-card, #credits .credits-card { max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #gate form { width: 100%; }

  button, .tab, .btn, .chip, .n { -webkit-tap-highlight-color: rgba(232, 161, 95, .18); }
}

/* Short landscape phones: slim tab bar, icons only */
@media (max-height: 520px) and (pointer: coarse) {
  :root { --bnav-h: 44px; }
  #bnav button { flex-direction: row; gap: 6px; font-size: 11px; }
  #bnav svg { width: 19px; height: 19px; }
  header h1 { font-size: 18px; line-height: 34px; }
  #sbtn { width: 38px; height: 38px; }
  #msheet { max-height: 94dvh; }
}

/* Very narrow phones */
@media (max-width: 360px) {
  #bnav button { font-size: 9.5px; }
  .ms-grid, .ms-tools { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .tb .btn { padding-inline: 7px; font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  #msheet, #msheet-bg, #bnav svg { transition: none; }
}

@media print { #bnav, #msheet, #msheet-bg, #sbtn { display: none !important; } }
