/* ============================================================
   ATMOS//NET — the phone layout
   ------------------------------------------------------------
   The console was built as a desktop kiosk: a fixed shell whose
   top bar needs ~810px and whose scrubber needs ~508px, with a
   single breakpoint at 1250px that only ever reduces the views
   to two columns. On a 390px phone that left content 983px wide
   inside a `body { overflow: hidden }` — so the clock and all
   four icon buttons (alerts, audio, briefing, settings) were not
   merely cramped, they were off-screen with no scroll to reach
   them, and every label/value row showed the label and clipped
   the number.

   This file is the second form factor. It changes layout only —
   no view loses a panel, no readout is dropped. Everything below
   is inside one media query so the desktop console is untouched.
   ============================================================ */

@media (max-width: 700px) {

  :root {
    --gap: 9px;
    --bar: 58px;              /* was 46 — room for 44px targets   */
    --scrub: auto;            /* the scrubber stacks and grows    */
    --navh: 54px;             /* the new bottom tab bar           */
    --tap: 44px;              /* Apple's minimum touch target     */
    /*
     * Eleven caption sizes are set inline in the view JS, where CSS cannot
     * reach them. Each is written max(<original>, var(--fs-floor, 0px)), so
     * on desktop the floor is unset, resolves to 0px, and the original wins
     * exactly. Here it lifts them all at once.
     */
    --fs-floor: 12.5px;
  }

  /*
   * 15px root with 57 of 66 sizes in rem means this one number
   * rescales essentially the whole type system. The console runs
   * from 7px to 12px, which is a kiosk viewed at arm's length,
   * not a phone held at 30cm.
   */
  html, body { font-size: 17px; }

  /* --- shell ------------------------------------------------ */

  #app {
    grid-template-rows: auto 1fr auto;
    /*
     * An implicit grid column is `auto`, which sizes to max-content — so an
     * overflowing top bar silently widened the ENTIRE shell and every view
     * with it. The deployed copy has one more top-bar child than the source
     * (scripts/inject-backlink.py adds a back link), which is exactly how that
     * went unnoticed locally. The shell can never be wider than the viewport.
     */
    grid-template-columns: minmax(0, 100%);
    max-width: 100vw;
    /* Reserve the bottom tab bar, which is fixed and out of flow. */
    padding-bottom: calc(var(--navh) + env(safe-area-inset-bottom));
  }

  /* --- top bar ---------------------------------------------- */

  #topbar {
    /* Wrap rather than overflow. How many children this bar has is not fully
       under this file's control, so it must fold gracefully. */
    flex-wrap: wrap;
    align-content: center;
    gap: 5px;
    padding: 5px 10px;
    padding-top: calc(env(safe-area-inset-top) + 5px);
    height: auto;
    min-height: var(--bar);
  }

  /* The wordmark costs ~84px that the location name needs more.
     The LED stays: it is the connection state. */
  .brand span, .brand b, .brand i { display: none; }
  .brand { gap: 0; }

  /* The scrubber readout below shows the time far more legibly. */
  .clock { display: none; }

  .loc {
    flex: 1 1 90px; min-width: 0; min-height: var(--tap);
    overflow: hidden;
    padding-inline: 6px; gap: 5px;
  }
  .bar-tools { gap: 4px; flex: 0 0 auto; }
  /*
   * The spacer and the location are both flexible, so they split the slack
   * in the bar between them. On a phone there is no slack to spare.
   */
  #topbar .spacer { flex: 0 0 0; }
  /* The bar is tight enough that a long place name has to truncate; do it
     with an ellipsis rather than a hard cut mid-word. */
  .loc .name, .loc .sub {
    display: block; max-width: 100%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  /*
   * ...and that only works if the wrapper between them and .loc can shrink.
   * A flex item does not go below its content width unless told to, so the
   * unnamed span sized itself to its widest line ("California - US", 118px),
   * `max-width: 100%` on the children measured against THAT rather than the
   * 92px actually on offer, and .loc hard-clipped the result. "Los Angeles /
   * California - US" reached a phone as "Los Ang / CALIFORNI", cut mid-word
   * with no ellipsis anywhere -- and no overflow, so nothing caught it.
   */
  .loc > span:not(.pin) { min-width: 0; }
  /* The desktop size. Bumping it here only bought a shorter name before the
     ellipsis: at 390px the bar has room for about twelve characters. */
  .loc .name { font-size: .78rem; }
  .loc .sub { font-size: .62rem; }

  .iconbtn {
    width: var(--tap); height: var(--tap);
    font-size: 1.05rem;
  }

  /* --- nav becomes a bottom tab bar -------------------------- */

  /*
   * Out of the top bar entirely and into the thumb zone. The five
   * tabs are already role="tab" buttons, so this is presentation
   * only — no markup change, no script change.
   */
  nav {
    position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 20;
    gap: 0;
    background: linear-gradient(0deg, color-mix(in srgb, var(--panel-solid) 97%, transparent), rgba(22,33,47,.92));
    border-top: 1px solid color-mix(in srgb, var(--cy) 22%, transparent);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  nav button {
    flex: 1 1 0;
    min-height: var(--navh);
    padding: 6px 2px;
    font-size: .58rem;
    letter-spacing: .1em;
    justify-content: center;
    clip-path: none;
    border-top: 2px solid transparent;
  }

  nav button[aria-selected="true"] { border-top-color: var(--cy); }

  /* The keyboard badges are meaningless without a keyboard. */
  nav button kbd { display: none; }

  /* --- scrubber --------------------------------------------- */

  /*
   * Was `auto auto 1fr` in 508px of minimum content, which
   * collapsed the canvas track — the primary interaction of the
   * whole app — to nothing. Now the strip is the full width and
   * the controls sit under it.
   */
  #scrub {
    grid-template-columns: 1fr;
    grid-template-areas: "strip" "row";
    height: auto;
    gap: 6px;
    padding: 8px 10px 10px;
  }

  .tl-canvas {
    grid-area: strip;
    width: 100%;
    height: 54px;
    /*
     * Without this iOS treats the first touch as a possible scroll
     * or back-swipe: it fires pointerdown, then pointercancel the
     * moment the finger moves. Tap-to-jump worked; dragging never
     * did.
     */
    touch-action: none;
  }

  #scrub .tl-readout { display: none; }

  .tl-controls {
    grid-area: row;
    justify-content: space-between;
    gap: 4px;
  }

  .tl-btn { min-width: var(--tap); min-height: var(--tap); font-size: .66rem; }
  .tl-btn.sm { min-width: var(--tap); min-height: var(--tap); font-size: .62rem; padding: 4px 6px; }
  .tl-rate { margin-left: 0; gap: 4px; }
  .tl-rate .lbl { display: none; }

  /* --- every view: one column -------------------------------- */

  /*
   * A stack, not a grid.
   *
   * Overriding the grid templates was not enough: an `auto` track sizes from
   * the item's intrinsic contribution, and these panels are nested flex
   * columns whose contribution resolved to 61px against content needing 418.
   * The panels then overflowed their own tracks and drew on top of each other.
   * A flex column has none of that ambiguity - each panel is simply as tall as
   * it needs to be, and the view scrolls.
   */
  .deck, .airview, .dataview, .skyview, .radar-wrap, .oh-wrap {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    gap: var(--gap);
  }

  .deck > *, .airview > *, .dataview > *, .skyview > *, .radar-wrap > *, .oh-wrap > * {
    flex: 0 0 auto !important;
    grid-area: auto !important;
    width: auto !important;
    min-height: 0;
  }

  /*
   * .side is a nested flex COLUMN wrapper holding three panels.
   * Left alone it stacks them inside one narrow grid cell;
   * display:contents dissolves it so its children join the parent
   * flow as siblings.
   */
  .deck > .side { display: contents; }

  /* Panels that force a horizontal body must stop. */
  .sunmoon-body, .moon-body, .aqi-body {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .sunmoon-body canvas, .moon-body canvas {
    width: 100% !important;
    flex: 0 0 auto !important;
    height: 120px;
    align-self: center;
    max-width: 180px;
  }
  .aqi-body canvas { flex: 0 0 auto !important; min-width: 0 !important; height: 170px; }

  /* Six gauges at 56px each were illegible; two rows of three. */
  .gauge .body {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .gauge-cell { min-width: 0; }
  /*
   * A third of a phone is ~109px, and four of the six notes were wider:
   * "LIGHT AIR · FROM SSE" ran into "NOTICEABLE HUMIDITY" and off the panel.
   * They wrap inside their cell here rather than lose their ends to an
   * ellipsis, since the note is the half of the gauge that is in words.
   */
  .gauge-note { white-space: normal; line-height: 1.25; }

  /*
   * Sixteen day columns in 114px is 7.6px per day. Give them a
   * real width and let the strip scroll sideways instead.
   */
  .tenday .body { overflow-x: auto !important; overscroll-behavior-x: contain; }
  .tenday-grid { grid-auto-columns: 62px !important; min-width: max-content; }
  .tenday-col { min-height: var(--tap); }

  /*
   * Panels size to their content and the VIEW scrolls, rather than each panel
   * being a little scroll box of its own - which on a phone means a nested
   * scroll you cannot discover and a body clipped mid-sentence.
   */
  .panel { height: auto; min-height: min-content; }

  /*
   * The body is `flex: 1 1 auto; min-height: 0` so it can be squeezed inside a
   * fixed-height kiosk panel. On a phone the panel follows the body, not the
   * other way round.
   */
  .body { flex: 0 0 auto !important; min-height: auto !important; }

  /* Full-bleed chart panels have no intrinsic height at all - the deck's
     meteogram measured 0px - so they need one stated. */
  .panel.bare { min-height: 220px; }
  .panel.bare > canvas, .meteo canvas { height: 100%; min-height: 200px; }
  /* Only the vertical axis: `overflow: visible` also cancelled the ten-day
     strip's deliberate sideways scroll. */
  .panel .body, .act .body { overflow-y: visible !important; }
  .view { padding: var(--gap); }

  /* The hero temperature's clamp floor is 4.6rem — desktop-calibrated. */
  .hero-temp { font-size: clamp(3rem, 16vw, 4.4rem) !important; }

  /* --- radar ------------------------------------------------- */

  /* The map is `.panel bare radar-main`; the generic .panel.bare rule below
     would otherwise cap it at 220px, which is not a map. */
  .radar-main { min-height: 52dvh !important; flex: 0 0 auto !important; }
  .radar-main > canvas.fill { height: 100%; }
  .radar-side { flex-direction: column !important; }
  /* `1 1 auto` let the rail divide a 122px row between three panels needing
     457px; on a phone they take their content and the view scrolls. */
  .radar-side > *, .radar-side > .grow { flex: 0 0 auto !important; }

  /* Six swatches on one nowrap line measured ~426px. Wrapped to 70vw over the
     map they took three rows at 390x844 and hid Lancaster, Palmdale and
     Santa Clarita. On a phone the legend is a strip under the map instead:
     the map is the grid's first row, and the canvas, stamp, tools and frames
     are positioned against that row (an absolute child of a grid takes its
     grid area as containing block), so none of them sit on the legend.
     The row's floor keeps the six 44px tools above the frame strip: at
     320x700 a plain 1fr row left 260px and the tools ran onto the strip. */
  .radar .radar-main { display: grid; grid-template-rows: minmax(calc(6 * var(--tap) + 104px), 1fr) auto; }
  .radar .radar-main > canvas.fill, .radar .radar-tools, .radar .radar-frames,
  .radar .radar-stamp { grid-row: 1 / 2; grid-column: 1; }   /* `1` alone ends at the padding edge */
  .radar .radar-hud { display: contents; }
  .radar .radar-stamp {
    position: absolute; top: 10px; left: 12px; z-index: 3;
    pointer-events: none; max-width: calc(100% - 90px);
  }
  .radar-legend {
    grid-row: 2; grid-column: 1; pointer-events: none;
    flex-wrap: wrap !important; justify-content: center; row-gap: 4px;
    background: var(--panel-solid); border-top: 1px solid rgba(255,255,255,.08);
  }
  .radar-tools .tl-btn { min-width: var(--tap); min-height: var(--tap); }
  .radar-frames canvas { height: 34px; touch-action: none; }

  /* --- sky ---------------------------------------------------- */

  /*
   * On a phone the observing panel comes first. It is the answer somebody
   * arrives for -- the landing page links straight here with "find out if
   * tonight is worth going outside" -- and it was four panels down a
   * scrolling column, behind the dome, the moon and the solar day. The
   * desktop grid places by area and is unaffected.
   */
  .skyview > .panel:nth-of-type(5) { order: -1; }

  /* --- overhead ---------------------------------------------- */

  /* Same reasoning as the radar: .panel.bare would cap the map at 220px. */
  .oh-main { min-height: 52dvh !important; flex: 0 0 auto !important; }
  .oh-main > canvas.fill { height: 100%; }
  .oh-side { flex-direction: column !important; }
  .oh-side > *, .oh-side > .grow { flex: 0 0 auto !important; }
  .oh-row { min-height: var(--tap); }
  .st-row { min-height: var(--tap); }
  .st-transport .tl-btn { min-width: var(--tap); min-height: var(--tap); }
  .st-transport input[type=range] { min-height: var(--tap); }
  .oh-chip { min-height: var(--tap); }
  /* Six tabs instead of five: the label has to survive 320/6 = 53px. */
  nav button { font-size: .54rem; letter-spacing: .06em; }


  /* --- the small end of the type scale ----------------------- *
   *
   * The console's labels run from 0.46rem to 0.62rem, which is a
   * kiosk read at arm's length. Raising the root alone cannot fix
   * it: the scale spans 2.5x, so a root large enough to lift the
   * captions past 12px would make the hero temperature absurd.
   * The floor is applied to the small end only, and this list is
   * derived from every rule in core.css and views.css declaring a
   * size under 0.72rem rather than guessed at.
   */
  .act-name,
  .act-when,
  .act-unit,
  .act-why,
  .act-note,
  .alert-item b,
  .alert-item span,
  .alertbtn[data-n]:not([data-n="0"])::after,
  .aqi-note,
  .burngrid b,
  .clock small,
  .gauge-note,
  .hd .val,
  .hero-obs,
  .keyhelp div,
  .keyhelp kbd,
  .kv dt,
  .loc .sub,
  .modal h3,
  .nowcast-scale,
  .pollen-fc b,
  .pollen-fc span,
  .radar-legend b, .radar-legend .lg-title,
  .radar-stamp span,
  .res-item .coord,
  .res-item span,
  .seg button,
  .setrow .hint,
  .stat .c,
  .td-date,
  .td-day,
  .td-lo,
  .td-pop,
  .tl-btn,
  .tl-btn.sm,
  .tl-delta,
  .tl-rate .lbl,
  .tl-when span,
  /* ============================================================ Type ============================================================ */ .lbl,
  /* Empty / error state inside a panel. */ .nodata,
  /* Panel heading: tiny caps label + rule + optional right-hand value. */ .hd,
  /* Status chip. */ .chip,
  nav button,
  nav button kbd {
    font-size: max(.72rem, 12.5px);
    letter-spacing: .08em;
  }

  /* Two exceptions: badges and keyboard help, which should stay small. */
  .alertbtn[data-n]:not([data-n="0"])::after { font-size: .5rem; }
  .keyhelp div, .keyhelp kbd { font-size: .68rem; }

  /* --- touch targets everywhere else ------------------------- */

  .seg button { min-height: var(--tap); }
  .res-item { min-height: var(--tap); }
  .res-item .rm { min-width: var(--tap); min-height: var(--tap); }
  .site-back { width: var(--tap) !important; height: var(--tap) !important; }

  /* --- cost ---------------------------------------------------
     A phone GPU is already carrying the sky shader; six to eight
     blurred compositing layers and three animated full-screen
     overlays on top of it is what turns warm into throttled. */

  #fx .grain, #fx .sweep, #fx .scan { display: none; }
  .panel, #topbar, #scrub, .modal-card, .radar-hud, .radar-legend, .radar-frames {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
  #topbar { background: color-mix(in srgb, var(--panel-solid) 96%, transparent); }
  #scrub { background: color-mix(in srgb, var(--panel-solid) 96%, transparent); }
}

/* Landscape on a phone: the bottom bar eats too much of a short
   viewport, so the tabs go back inline and the scrubber shrinks. */
@media (max-width: 900px) and (max-height: 480px) {
  nav { position: static; padding-bottom: 0; border-top: 0; background: none; }
  nav button { min-height: 40px; }
  #app { padding-bottom: env(safe-area-inset-bottom); }
  .tl-canvas { height: 38px; }
}

/*
 * The narrowest phones still in use are 320px wide.
 *
 * Seven playback controls at 44px each need 341px, so on an iPhone SE the
 * two faster rates sat off the right edge -- invisibly, because `body` is
 * `overflow: hidden` and nothing could scroll to reach them. Playback still
 * runs at 1x, and dragging the timeline is the primary way through the
 * forecast in any case.
 */
@media (max-width: 359px) {
  .tl-rate { display: none; }
}
