/* mobile.css — Chronicle mobile-first / responsive layer (MOBILE_PWA_PLAN).
   ADDITIVE ONLY: everything here is behind `@media (max-width:900px)` or `(pointer:coarse)`, so the
   desktop layout in styles.css is never altered. Loaded AFTER styles.css.
   Breakpoint: ≤900px = phone/tablet-portrait shell (bottom tab bar). >900px = untouched desktop. */

/* These elements exist in the DOM for mobile but are hidden on desktop. */
.tabbar, .more-sheet, .topbar-brand, .topbar-search-btn { display: none; }

@media (max-width: 900px) {
  /* ---- shell: single column, topbar / main / bottom tab bar ---- */
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "topbar" "main" "tabbar";
    height: 100vh;            /* fallback */
    height: 100dvh;           /* fixes iOS Safari dynamic-toolbar clipping */
  }
  .sidebar { display: none; }
  .app > .main { grid-area: main; }

  /* ---- mobile topbar: brand · spacer · search · theme · settings ---- */
  .topbar { padding: 0 10px; gap: 6px; padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
  .topbar-feature, .topbar-links, .topbar-sep { display: none; }
  .topbar-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 700; }
  .topbar-brand .brand-mark { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
  .topbar-brand .tb-name { font-size: 16px; letter-spacing: -.01em; }
  .topbar-right { margin-left: auto; gap: 2px; }
  .topbar-search-btn { display: inline-flex; }

  /* ---- bottom tab bar ---- */
  .tabbar {
    grid-area: tabbar; display: flex; align-items: stretch; justify-content: space-around;
    background: var(--bg-panel); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom); z-index: 50;
  }
  .tab-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; background: none; border: 0; padding: 7px 2px 5px; min-height: 50px;
    color: var(--text-muted); font-size: 10.5px; font-weight: 600; cursor: pointer;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  .tab-item .tab-ico { font-size: 20px; line-height: 1; }
  .tab-item.on { color: var(--accent); }
  .tab-item.on .tab-ico { transform: translateY(-1px); }

  /* ---- readers/views: reclaim full width, keep centered columns centered ---- */
  .hadith-index, .hadith-lhead, .hadith-filters, .hadith-reader,
  .lib, .enc-article .answer, .enc-sources { max-width: 100%; }
  .seg-wrap.hub { padding: 0 14px 72px; }
  .seg-wrap.hub > * { max-width: 100%; }
  .seg-wrap.hadith .seg-body { padding: 0 12px 32px; }
  #view-learn > *:not(.vhead) { max-width: 100%; padding-left: 14px; padding-right: 14px; }
  #view-learn > .up-stepper, #view-learn > .up-stage, #view-learn > .up-footer { max-width: 100%; }
  .learn-hero { flex-wrap: wrap; }
  .learn-tabs, .lb-tabs, .q-seg { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .learn-tabs::-webkit-scrollbar, .q-seg::-webkit-scrollbar { display: none; }
  .lp-grid, .badge-grid, .insights-grid { grid-template-columns: 1fr; }
  .vhead { padding: 12px 14px; flex-wrap: wrap; }        /* let a header's controls (segs) wrap below the title */
  .vhead h2 { font-size: 17px; }
  .vhead > div:first-child { min-width: 0; flex: 1 1 100%; }
  .enc-wrap .vhead .q-seg, #encSeg { align-self: flex-start; }

  /* the unit-player sticky footer must clear the tab bar (it sits inside #view-learn which ends
     above the tab bar, so bottom:0 is already correct — just ensure comfortable spacing) */
  #view-learn { padding-bottom: 24px; }

  /* generic: no view may cause horizontal page scroll */
  .view { overflow-x: hidden; }
}

/* ---- More sheet (built by tabbar.js; shown via .open) ---- */
.more-sheet.open { display: block; position: fixed; inset: 0; z-index: 100; }
.more-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.more-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 82vh; overflow-y: auto;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0; padding: 6px 16px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,.28);
}
.more-sheet:not(.reduce) .more-panel { animation: moreUp .24s cubic-bezier(.2,.9,.3,1); }
@keyframes moreUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.more-handle { width: 40px; height: 4px; border-radius: 3px; background: var(--border); margin: 8px auto 12px; }
.more-group-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-dim); margin: 14px 4px 8px; }
.more-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.more-item { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  background: var(--bg-hover); border: 1px solid var(--border-subtle); border-radius: 12px;
  padding: 12px 6px; text-decoration: none; color: var(--text); font-size: 11.5px; font-weight: 600;
  min-height: 44px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.more-item:active { background: var(--accent-soft); }
.more-item.on { border-color: var(--accent); color: var(--accent); }
.more-item .more-ico { font-size: 22px; line-height: 1; }
.more-foot { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin: 18px 0 4px;
  padding-top: 14px; border-top: 1px solid var(--border-subtle); }
.more-foot a { color: var(--text-muted); font-size: 12.5px; text-decoration: none; }
.more-install { margin: 14px 0 4px; }

/* ---- touch affordances (any coarse pointer, any width) ---- */
@media (pointer: coarse) {
  .nav-item, .tab-item, .more-item, .btn, .icon-btn { touch-action: manipulation; }
}

/* ---- touch annotation: the selection toolbar becomes a fixed bottom action sheet (P1) ---- */
.annot-toolbar.annot-toolbar-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto;
  width: 100%; justify-content: center; gap: 14px; z-index: 300;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.24);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  animation: annotUp .18s ease-out;
}
:root[data-motion="reduce"] .annot-toolbar.annot-toolbar-sheet { animation: none; }
@keyframes annotUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.annot-toolbar-sheet .annot-dot { width: 34px; height: 34px; border-width: 3px; }
.annot-toolbar-sheet .annot-tool { font-size: 22px; padding: 8px 10px; min-width: 44px; min-height: 44px; }
.annot-toolbar-sheet .annot-sep { height: 28px; align-self: center; }
.annot-toolbar-sheet .annot-cta { font-size: 15px; padding: 12px 18px; min-height: 44px; }

/* ---- P2: dense-viz touch niceties ---- */
@media (pointer: coarse) {
  /* River: swap the desktop keyboard hint for a touch one (CSS-only text swap) */
  .river-scrollhint { font-size: 0; }
  .river-scrollhint::after { content: "Drag to pan · pinch to zoom · tap a state for its story"; font-size: 12px; }
  /* horizontal-pan viz stages scroll smoothly on touch */
  #view-river svg, .states-chart, .timeline-track, .matrix-mount, .genealogy-matrix {
    -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y;
  }
}
@media (max-width: 900px) {
  /* entity/River drawer → full-width bottom-ish sheet instead of a narrow side panel */
  .river-drawer, .drawer { width: 100% !important; max-width: 100%; }
  /* matrix/heatmap: let the chart use full width */
  .viz-chart.matrix-chart { max-width: 100%; }
}

/* ---- PWA install card (More sheet / Settings) ---- */
.install-card { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 14px; }
.install-txt { display: flex; flex-direction: column; gap: 2px; }
.install-txt strong { font-size: 14px; }
.install-txt span { font-size: 12.5px; color: var(--text-muted); }

/* ---- Encyclopedia ("Wiki"): mobile master-detail (list ↔ full-width article) ---- */
.enc-mobile-back { display: none; }              /* desktop: no back button (two-pane) */
@media (max-width: 900px) {
  .enc-body { grid-template-columns: 1fr; }      /* single column — no 300px tree stealing space */
  .enc-tree { border-right: 0; padding: 8px 8px 40px; }
  .enc-article { display: none; padding: 14px 14px 48px; }
  /* browse (list) mode = tree visible; detail mode = article full-width, tree hidden */
  .enc-mobile-detail .enc-tree { display: none; }
  .enc-mobile-detail .enc-article { display: block; }
  .enc-mobile-back {
    display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px;
    background: var(--bg-hover); border: 1px solid var(--border); border-radius: 999px;
    padding: 8px 16px; font-size: 13px; font-weight: 600; color: var(--text); cursor: pointer;
    min-height: 40px; -webkit-tap-highlight-color: transparent;
  }
  /* scroll the whole Wiki as ONE column so the tall title+blurb header scrolls AWAY (not pinned),
     instead of the tree scrolling inside a fixed region under a permanently-visible header */
  #view-encyclopedia { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .enc-wrap { height: auto; min-height: 100%; }
  .enc-body { display: block; min-height: 0; }
  .enc-tree, .enc-article { overflow: visible; }
  .enc-wrap .vhead { position: static; }
  .enc-node { padding: 11px 12px; font-size: 15px; }   /* bigger tap targets in the list */
  .enc-refgroup .enc-node { padding-left: 24px; }
  .enc-search { font-size: 16px; }                      /* ≥16px so iOS doesn't zoom on focus */
}
