/* Breakpoints 360-1440, sticky offsets, and reduced motion.
   Only overrides live here; every component's base rules are in its own file.
   Part of the Cabinhub News newsroom stylesheet set.

   The sticky stack is two bars: .toolbar at top:0 (52px) and .filters at
   top:52px. Under 600px the toolbar wraps to two rows, so the filters stop
   being sticky rather than overlapping it. */

/* ============================================================ motion ===
   One entrance: a 250ms rise, staggered 30ms, capped so a long feed does not
   read as a cascade. motion.css takes this over when motion.js is present;
   this is the no-JS and motion.js-failed path. */

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.feed.is-revealed .card,
.feed.is-revealed .article {
  animation: rise var(--dur-2) var(--ease) both;
  /* --i is a unitless integer app.js sets per item (1, 2, 3... up to the 50-item
     feed). It has to become a time here, and it has to be capped, or a long feed
     turns into a 1.5s cascade. `clamp()` keeps it integer-valued, so the multiply
     stays a valid <time> calculation. */
  animation-delay: calc(clamp(0, var(--i, 0), 6) * 30ms);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .dot[data-state="loading"],
  .skeleton__block,
  .skeleton__line,
  .boot__line { animation: none !important; }
}

/* ========================================================= responsive == */

/* ---- the rail is a system readout: it stays folded through the tablet band
   MEASURED 2026-11-16 (tools/n3_tablet.mjs): the connection dot + UTC clock
   strip is `display:none` <=599 (see the phone block below) and reappears at
   exactly 600, adding ~36px of a system readout above the lead on every
   tablet until the desktop layout at 900. The phone block's own reasoning --
   "system readout, not reader content; failures still reach the reader through
   the offline strip and the route's own state panel" -- holds identically at
   600-899: nothing in that strip is actionable at a tablet width, and it is
   36px of the first screen. Keep it folded until the desktop band. */
@media (min-width: 600px) and (max-width: 899px) {
  .rail { display: none; }
}

/* ---- tablet toolbar: the destinations and the search door share one row --
   MEASURED 2026-11-16 (tools/n3_tablet_detail.mjs, chromium 149, fixture feed):
   the toolbar was 63px on a <=599 phone, 119px at 600 and 700 (EN), and 65px
   from 768 up. The 54px difference is not padding: .toolbar__inner is
   `flex-wrap: wrap`, and its two items declare a flex-basis that sums past the
   content box until 768 (nav 329 + 16 gap + searchbar 320 = 665 against a
   561-655px box at 600-700). With wrap on, a sum that does not fit becomes a
   SECOND ROW instead of a shrunken field, so a 600-715 tablet paid a doubled
   sticky bar -- two thirds of a phone's entire toolbar -- for a search field
   that only needed to be narrower.

   `nowrap` makes the shrink honest: the searchbar already declares
   `flex: 0 1 20rem; min-width: 0` and its input `min-width: 0`, so it yields
   down to its 8rem floor and the row stays one bar. The nav never yields
   (its links are nowrap and it holds four destinations), which is the same
   "controls do not shrink, the flexible thing does" rule the masthead states
   above. 600 is the first width where nav + an 8rem field fit (329 + 16 + 128
   = 473 inside a 561px box), so the band can go no lower. */
@media (min-width: 600px) and (max-width: 899px) {
  .toolbar__inner { flex-wrap: nowrap; }
  /* The nav must not be the thing that yields: it is four destination links the
     reader needs, and `.toolbar__nav` is itself `flex-wrap: wrap`, so a shrunk
     nav silently becomes two rows of links inside the row it was meant to keep
     to one line — measured as a 111px bar in the first pass of this fix. */
  .toolbar__nav { flex-shrink: 0; flex-wrap: nowrap; }
  .searchbar--palette { min-width: 8rem; }
}

/* ---- tablet: one column, the rail drops below the feed --------------- */
@media (max-width: 899px) {
  .feed__side {
    border-left: 0;
    border-top: 1px solid var(--rule);
    padding-left: 0;
    padding-top: var(--sp-4);
  }
  .detail__aside { display: grid; gap: var(--sp-5); }
  .detail__aside > .panel + .panel { margin-top: 0; }
}

/* ---- the masthead's one row, from the phone up to the wide desktop -----
   MEASURED 2026-11-14 (hk2x, chromium-1254, live API, tools/n3_masthead.mjs):
   the row was ONE line at 390 (79.4px masthead) and at 599 (80.3px), then TWO
   lines for every width from 600 to at least 899 (195.5 / 164.0 / 166.6 /
   172.1 / 172.2px), and one line again at 1100 (140.0px). The kicker is the
   reason: it is hidden only by the phone block below, so at 600 it returns and
   the row must fit 25.6px gutter + 244.7px mark + 24px gap + 426.8px kicker +
   16px gap + 48px controls + 25.6px gutter = 810.7px inside an 800px box. It
   wraps, the side group takes its own 48px line, and the masthead doubles —
   on a tablet, where the reader has the least screen to spare.

   The kicker yields; the controls and the wordmark never do. It returns at
   1000px, where the same content fits one row with slack (measured: 1100 is
   one row with the kicker drawn). Declaring `nowrap` here is what makes the
   yield honest: if a future label outgrows the row, the row must not silently
   grow a second line — the kicker is the only flexible item and it is already
   gone. */
@media (max-width: 999px) {
  .masthead__inner { flex-wrap: nowrap; }
  .masthead__kicker { display: none; }
}

/* ---- phone: two stacked toolbars, one column everywhere -------------- */
@media (max-width: 599px) {
  .toolbar__inner { padding-top: 0.4rem; padding-bottom: 0.5rem; flex-wrap: nowrap; }
  .toolbar__nav { order: 1; }

  /* The destinations are ONE line, for the same reason the masthead is: a nav
     pod that wraps doubles the bar above the feed, and the phone reader pays
     for it in lead headline. The compaction below already shrinks the labels;
     this only stops the group from silently growing a second line, following
     the same rule the masthead states above.
     MEASURED 2026-11-15 on hk3g (chromium, tools/n3_masthead.mjs, static
     frontend at e73aaff): with the 0.42rem/12.5px compaction in place, at
     320/en the four destinations measured Latest 57 + Today 49 + About the
     desk 108 + Topics 51 = 265 in a 272px pod; beside the 16px column gap and
     the 44px search door that row needs 332px in a 288px box, so `Topics`
     still dropped to a second line -- the toolbar went 62px -> 108px and the
     pod ran 30px under the door. 390/en and 320/zh were one row (62px) and
     stay untouched; the extra step for <=359 is at the end of this file. */
  .toolbar__nav { flex-wrap: nowrap; }

  /* One search door on a phone: the palette, reached by the magnifier the
     toolbar row carries beside the destinations.
     NOT `display: none` on .searchbar. js/palette.js mounts that trigger
     INSIDE [data-search-form] (palette.js "if (form) { ... form.appendChild(
     trigger) }"), so hiding the form hid the ONLY search control with it:
     measured 2026-11-10 on the merged tree, 360/390 x en/zh showed
     searchbar=hidden trigger=hidden and ZERO visible search doors, while the
     360-light feed frame showed a masthead with no magnifier and no field.
     The field is what must go — it cost a 52px row before the lead — so hide
     its own parts and keep the form as a 0-width box for the trigger. */
  .searchbar__input,
  .searchbar__btn,
  .searchbar::before { display: none; }
  /* `order: 2` puts the door AFTER the destinations, the way the desktop row
     reads (nav left, search right). Without it the form — which precedes the
     nav only because the markup puts the field last — takes order 0 and the
     magnifier floats alone at the far left of the phone row. */
  .searchbar { order: 2; flex: 0 0 auto; margin-left: auto; }
  .cbn-palette-trigger--inline {
    position: static;
    transform: none;
    min-width: var(--tap);
    min-height: var(--tap);
    padding: 0;
    background: var(--paper-2);
    border: 1px solid var(--rule-strong);
    color: var(--ink-soft);
  }
  /* The glyph is the door: no chord exists on touch, and palette.css hides the
     keycap there. Restated here so the phone rule does not depend on a media
     feature the harness cannot set. */
  .cbn-palette-trigger--inline > svg { display: block; }
  .cbn-palette-trigger__kbd { display: none; }
  /* Five destinations must still be ONE row on a phone: wrapped, the group read as two
     unrelated strips and the fifth link sat alone under it (measured 2026-11-10 at 390:
     413px of labels in a 358px row). Compacting the padding and the type, not dropping a
     destination, keeps the desk's page and the topic hubs reachable at the phone width. */
  .toolbar__link { padding: 0 0.42rem; font-size: 12.5px; }
  /* Two wrapped sticky bars would eat a third of the screen, so the category
     strip scrolls with the page instead of pinning. */
  .filters { position: static; top: auto; }

  /* The rail is a dot and a UTC clock: system readout, not reader content,
     and it held a 34px band above the lead on every phone screen. Failures
     still reach the reader through the offline strip and the route's own
     state panel. */
  .rail { display: none; }

  /* One line, always. The row at 360 is 328px inside the gutters: lockup 173,
     theme 44, language 94, gaps 16. It fits — but only after two fixes the
     127px-tall masthead taught us. (a) The desktop 1.5rem column gap alone
     overflowed it and flex-wrap turned the overflow into a second row with
     both controls parked left, under the wordmark. (b) The zh lockup used to
     measure 201px because it inherited Songti from --font-display; the
     wordmark now letters in --font-brand in both editions, which is the
     brand-fidelity fix and the layout fix at once. */
  .masthead__inner {
    padding-top: var(--sp-4);
    padding-bottom: var(--sp-3);
    column-gap: 0.5rem;
    flex-wrap: nowrap;
  }
  /* No shrink on the mark: a squeezed serif wordmark reads as a mistake. */
  .masthead__mark { flex: none; }
  /* The side group must never shrink below its controls, or `justify-content:
     flex-end` spills the overflow LEFTWARD and the sun lands on the wordmark.
     Measured at zh-360 before the brand face: mark ended at 217, the theme
     button was painted at 200 — a 17px overlap no overflow probe can see,
     because the text itself never overflows.

     The guard above was `flex: 0 1 auto`, which still let the group shrink to
     its longest WORD once the row no longer fit: the mascot control (added to
     .masthead__controls after this rule was written) makes the controls measure
     185px against 173 for the lockup, and 185 + 173 + 8 gap = 366 > the 328px
     row at 360. So at 360 the group collapsed and was painted 30px over the
     "News" of the wordmark — measured 2026-11-17 on the fixture feed at 360 in
     both editions, 0px overlap at 390+. The fix is in the `<=389px` block
     below: where the row cannot hold both, the controls take their own line
     instead of painting over the logo. It cannot be a shrink guard here,
     because the row is `flex-wrap: nowrap` on every phone and a guard with no
     room to wrap would simply overflow the page horizontally by the same 38px.
     At 390-599 the group still shrinks the 8px into the column gap, which was
     measured as 0px overlap and 0px page overflow. */
  .masthead__side { flex: 0 1 auto; }
  .masthead__kicker { display: none; }
  .filters__count { display: none; }

  /* Defect 7: a lead headline must not read as five lines on a phone. The
     size comes from tokens.css (28px at 390); the measure is released so it
     fills the column, and leading is tightened. Never clamp a headline: a
     clipped headline is worse than a wrapped one. */
  .article__title,
  .detail__title {
    max-width: none;
    line-height: 1.14;
    letter-spacing: -0.02em;
  }
  .detail__head { margin-bottom: var(--sp-5); }
}

/* ---- small phone: nothing may overflow 360 -------------------------- */
@media (max-width: 379px) {
  .masthead__link { letter-spacing: -0.032em; }
  .chip { padding: 0 0.55rem; }
  .shell { padding-left: var(--pad-l); padding-right: var(--pad-r); }
}

/* ---- below 390 the masthead is two rows, not paint-on-paint ----------
   The phone block above pins the masthead to ONE line, and that was measured
   when the controls held only the theme switch and the language pair:
   173 lockup + 44 theme + 94 language + 16 gaps = 327, under the 328px row at
   360. The Ember mascot was added to `.masthead__controls` afterwards (34px),
   so the row now needs 366px and cannot fit. With `flex-wrap: nowrap` and a
   shrinkable side group, the browser painted the right-aligned controls 30px
   over the "News" of the wordmark at 360 (measured to the pixel in both
   editions). This block is the honest degradation: below the width where both
   fit, the controls take their own line and stay right-aligned, instead of the
   row overflowing sideways or the mascot sitting on the logo. At 390 and up the
   single line is unchanged (measured 0px overlap, 0px page overflow). */
@media (max-width: 389px) {
  .masthead__inner { flex-wrap: wrap; }
  .masthead__side { flex: 0 0 auto; margin-left: auto; }
}

/* ---- wide desktop: keep the measure, never stretch it --------------- */
@media (min-width: 1200px) {
  .article__deck, .detail__deck { max-width: var(--measure-deck); }
}

/* A landscape phone has no vertical room for the bullet list. */
@media (max-height: 460px) and (orientation: landscape) {
  .article__bullets { display: none; }
}

/* ---- the narrowest phones: the destinations keep one line ------------
   MEASURED 2026-11-15 (hk3g, chromium-1254, tools/n3_masthead.mjs) on the
   static frontend, base vs fix, same browser:
     base 320/en  nav 272px  toolbar 108px  pod 30px under the door
     fix  320/en  nav 242px  toolbar  62px  flush with the door, no overlap
     390/en, 320/zh, 390/zh, 599  unchanged at 62px on both trees.
   The row has 288px inside the gutters; the door is a 44px tap target pinned
   right at x=258, so the destinations own 16..258. The type is already at the
   12px floor the type law sets (the link is 12.5px from the phone block above)
   so no further step is legal there: the space comes out of the pod's own air,
   which is what the phone block already chose to trade (its comment: "compacting
   the padding and the type, not dropping a destination"). The result sits
   flush against the door at 320/en -- the physical limit of four full
   destination labels plus a 44px door at this width -- so the nav is `nowrap`
   above and an overlong future label overflows visibly instead of silently
   becoming a second row. Scoped to <=359 so 390 keeps its measured 62px row. */
@media (max-width: 359px) {
  .toolbar__link { padding: 0 0.1rem; }
  .toolbar__inner { column-gap: 0.5rem; }
}
