/* Mobile: the game is landscape-only on phones. Loaded last, after trail-ledger.css.
   - Never narrower than 640px: below that the page scrolls sideways instead of shrinking the layout.
   - Phones held upright get a "turn your phone" gate and nothing else.
   - Landscape phones (short, wide viewports) get a compact shell that clears the notch and home bar. */

:root {
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html { min-width: 640px; overflow-x: auto; }
body { min-width: 640px; }
body.ledger .ledger-shell { min-width: 640px; }

/* ── Phones: below an iPad mini (744 × 1133) the game is not offered; point at the apps instead. ── */
.app-gate { display: none; }
@media (pointer: coarse) and (orientation: portrait) and (max-width: 743px),
       (pointer: coarse) and (orientation: landscape) and (max-height: 743px) and (max-width: 1100px) {
  html, body, body.ledger { min-width: 0; overflow: hidden; }
  body.ledger .ledger-shell { display: none; }
  .app-gate {
    position: fixed; inset: 0; z-index: 1000; box-sizing: border-box;
    display: flex; flex-direction: column; justify-content: center; gap: 28px;
    padding: calc(24px + var(--safe-t)) calc(28px + var(--safe-r)) calc(24px + var(--safe-b)) calc(28px + var(--safe-l));
    background: var(--tl-walnut); color: var(--tl-parchment); font-family: var(--tl-sans); overflow-y: auto;
  }
  .app-gate-copy { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
  .app-gate-pill { font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--tl-gold); border: 1.5px solid var(--tl-gold); border-radius: 999px; padding: 4px 12px; }
  .app-gate h1 { margin: 0; font-family: var(--tl-display); font-weight: 400; font-size: 34px; line-height: 1.05; }
  .app-gate p { margin: 0; font-size: 20px; line-height: 1.35; color: var(--tl-light-2); }
  .app-gate-stores { display: flex; flex-direction: column; gap: 12px; }
  .app-gate-stores > p { font-size: 15px; opacity: .8; }
  .app-gate-btn { display: flex; align-items: center; gap: 12px; min-height: 56px; box-sizing: border-box; padding: 0 20px; border-radius: 12px; background: #F4EAD3; color: #2B1D12; text-decoration: none; }
  .app-gate-btn:focus-visible { outline: 3px solid var(--tl-gold); outline-offset: 2px; }
  .app-gate-btn span { display: flex; flex-direction: column; line-height: 1.1; }
  .app-gate-btn small { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #6A5640; }
  .app-gate-btn b { font-size: 20px; font-weight: 800; }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 743px) and (max-width: 1100px) {
  .app-gate { flex-direction: row; align-items: center; gap: 40px; }
  .app-gate-copy { flex: 1; }
  .app-gate-stores { width: 300px; flex: none; }
}

/* ── Landscape phones. ── */
@media (orientation: landscape) and (max-height: 540px) {
  .ledger-shell { height: 100dvh; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; padding-bottom: var(--safe-b); background: var(--tl-walnut); }
  .ledger-shell > .screen { height: auto; min-height: 0; }
  .ledger-footer { height: 20px; padding: 0 max(12px, var(--safe-r)) 0 max(12px, var(--safe-l)); font-size: 11px; }
  .ledger-shell:not(:has(.tl-title)) { grid-template-rows: minmax(0, 1fr); padding-bottom: var(--safe-b); }

  /* Compact bar: 44px, 40px round buttons, insets on both sides. */
  .tl-screen { grid-template-rows: 44px minmax(0, 1fr); }
  .tl-bar { gap: 10px; padding: 0 max(10px, var(--safe-r)) 0 max(10px, var(--safe-l)); }
  .tl-bar-title { font-size: 21px; }
  .tl-bar-sub { display: block; font-size: 14px; }
  .tl-bar .tl-round, .tl-title-audio .tl-round { width: 40px; height: 40px; }
  .tl-records .tl-pill { height: 36px; }

  /* Title: art on the left, a compact walnut card on the right, clear of the notch. */
  .tl-title-audio { top: 8px; right: max(12px, var(--safe-r)); }
  .tl-title-card {
    right: max(12px, var(--safe-r)); top: 56px; bottom: 10px; transform: none;
    width: min(340px, 46%); max-height: none; padding: 16px 18px; gap: 10px; justify-content: space-between;
  }
  .tl-title-head { gap: 5px; }
  .tl-title-kicker { font-size: 11px; }
  .tl-title h1 { font-size: 40px; }
  .tl-title-blurb { font-size: 15px; line-height: 1.3; }
  .tl-title-blurb { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .tl-title-actions { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .tl-title-actions > * { flex: 1 1 auto; }
  .tl-title-actions .tl-button.is-outline { height: 44px; font-size: 15px; flex: 0 0 auto; padding: 0 14px; }
  .tl-title-begin { height: 48px; font-size: 18px; }
  .tl-title-continue { min-height: 52px; }
  .tl-title-continue strong { font-size: 17px; }
  .tl-title-pair { gap: 8px; }
  .title-account { padding: 6px 6px 6px 10px; gap: 8px; }
  .title-account-text span { font-size: 12px; }

  /* Trail map: map left, stop panel in a scrolling rail on the right. */
  .tl-map-body { grid-template-rows: none; grid-template-columns: minmax(0, 1fr) clamp(220px, 32%, 280px); }
  .tl-map-body > .tl-stop { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 10px 12px max(10px, var(--safe-r)) 12px; padding-right: max(12px, var(--safe-r)); border-top: 0; border-left: 2px solid var(--tl-line); overflow-y: auto; }
  .tl-map-frame { padding-left: var(--safe-l); }
  .tl-hunt-here { min-height: 54px; font-size: 21px; }

  .tl-stop h2 { font-size: 21px; }
  .tl-stop-land { font-size: 14px; }
  .tl-stop-kicker { font-size: 11px; }
  .tl-tile-sprite { width: 56px; height: 36px; }

  /* Hunt: the field fills the height; the HUD is clear of the notch. */
  .hunt-screen { padding-left: var(--safe-l); padding-right: var(--safe-r); }
  .hunt-screen .hunt-stage { box-shadow: none; }
  .tl-hud-btn { min-height: 44px; }

  /* Results: two columns, the rest scrolls. */
  .tl-res-main { grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: 12px; padding: 10px max(12px, var(--safe-r)) 10px max(12px, var(--safe-l)); }
  .tl-res-bag { grid-column: 1 / -1; }
  .tl-res-rating { padding: 12px; gap: 4px; }
  .tl-res-stars span { font-size: 52px; }
  .tl-res-score span { font-size: 52px; }
  .tl-res-calc h2, .tl-res-bag h2 { margin-bottom: 8px; font-size: 19px; }
  .tl-calc-row, .tl-calc-final { padding: 5px 0; gap: 10px; }
  .tl-calc-label { font-size: 16px; }
  .tl-result-stars { margin-top: 4px; padding-top: 8px; }
  .tl-res-calc, .tl-res-bag { padding: 12px 16px; }
  .tl-res-again { height: 48px; }
  .tl-res-foot { padding: 4px max(12px, var(--safe-r)) 4px max(12px, var(--safe-l)); }

  /* Everything else scrolls inside its own panel rather than past the notch. */
  .tl-body { padding-left: 0; }
  .tl-record-body, .screen-panel:not(.hunt-screen) { padding-left: max(10px, var(--safe-l)); padding-right: max(10px, var(--safe-r)); }
}

/* Narrow landscape phones (small iPhones, 640-760px): one more notch of compaction. */
@media (orientation: landscape) and (max-height: 540px) and (max-width: 760px) {
  .tl-bar-sub { display: none; }
  .tl-bar-title { font-size: 19px; }
  .tl-records { margin-right: 0; gap: 4px; }
  .tl-records .tl-pill { padding: 0 8px; font-size: 13px; }
  .tl-account-chip > span:last-child { display: none; }
  .tl-account-chip { padding: 0 6px; }
  .tl-title-blurb { display: none; }
  .tl-title-card { width: min(320px, 50%); }
}
