/* Cabinhub News — accessibility layer. Owner: N3-DESIGN (a11y lane).
   NEW file, loaded last (after css/ops.css and before motion.css) so its
   overrides win without editing another owner's file.

   Scope: WCAG 2.2 AA. Rule numbers, measured contrast and the audit trail are
   in docs/bar/A11Y.md. Every colour below is a token from tokens.css; there is
   no new hex in this file.

     1. Focus            2.4.11 Focus Not Obscured · 2.4.13 Focus Appearance
     2. Target size      2.5.8 (24x24 AA) raised to the Ember 44px tap
     3. More contrast    prefers-contrast: more
     4. Forced colours   forced-colors: active (Windows high contrast)
     5. Text spacing     1.4.12 (no clipping at 1.5 line / 0.12em / 0.16em / 2em)
     6. Skip link + a non-colour cue for [aria-current="page"]
     7. Non-text contrast fixes 1.4.11 that belong to the shared tokens
   ====================================================================== */

/* ======================================================= 1. focus ======
   A 2px ring in --focus with a 2px offset. The offset IS the second,
   contrasting element of the pair: it leaves a 2px gap of the ground colour
   between the control and the ring, so the ring never sits directly on a
   same-coloured fill (accent button, pressed chip, white article sheet).
   Drawn with `outline`, not box-shadow, so it survives forced-colors.

   Measured (WCAG 2.x relative-luminance formula, see docs/bar/A11Y.md):
     light --focus #D64221  4.14:1 on --paper, 3.84:1 on --paper-2,
                            4.51:1 on --canvas (white)
     dark  --focus #FF9C6B  9.14:1 / 8.48:1 / 8.48:1
   Every ground clears the 3:1 that 2.4.13 requires between the focused and
   unfocused states. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
/* chrome.css fixes the search field at offset 1px (0,2,0); keep the system
   ring identical everywhere. */
.searchbar__input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
/* A pointer press is not keyboard focus: no ring, exactly as base.css says.
   Kept here so this file is self-contained if base.css is reordered. */
:focus:not(:focus-visible) { outline: none; }

/* 2.4.11: a focused item must not be hidden behind the sticky stack. The
   stack is the toolbar (60px once the 44px targets below are applied) plus the
   filters row (~55px); scroll-padding keeps the browser's focus scroll clear of
   both. base.css carries 44px, which is less than the stack and would let a
   focused card hide behind it. */
html { scroll-padding-top: calc(120px + env(safe-area-inset-top, 0px)); }

/* =================================================== 2. target size =====
   2.5.8 asks for 24x24 (AA). The Ember tap token is 44px, so every primary
   control takes the full token; inline text links keep the 24px hit height
   without changing their type size or line box. Sizes only: no text scaling. */
.theme-switch__btn { width: var(--tap); height: var(--tap); }
.locale-switch__btn { min-width: var(--tap); min-height: var(--tap); }
/* .mascot__trigger takes the same token, but its rule lives in css/mascot.css:
   that sheet is linked AFTER this one, so the 34px it sets would beat a rule
   here. See the measurement note there. */
.chip { min-height: var(--tap); min-width: var(--tap); }
/* min-width as well as min-height: a two-character label is a narrow box. The
   zh toolbar links measured 38x44 on a coarse pointer at 360/390/768, and the
   markets back link 42x44 — width under the token while height was over it
   (n3_tap tN38, 16 combos; the same numbers reproduce on main's tree, so this
   is the shell's own defect, not a regression). The token is square, so the
   guarantee is too. English labels were already wider than 44. */
.toolbar__link { min-height: var(--tap); min-width: var(--tap); }
.searchbar__input { min-height: var(--tap); }

/* Inline targets. 24px of vertical hit area, text size untouched. */
/* ================================= 9. footer links are real targets ====
   WCAG 2.5.8 (AA) is 24x24 and this product's own tap token is 44px. Measured
   2026-11-10 at 390 with a coarse pointer, every route's footer had two links
   at 62x24 and 87x24 — the only controls under the token left on the page.
   The fix grows the TARGET, not the painted text: the extra height comes from
   an ::after that overhangs the box symmetrically, so the type, the row height
   and the underline are what they were. `position: relative` is what lets a
   child pseudo-element use the link as its containing block. */
.colophon__link {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding-block: 0.1em;
  position: relative;
}
.colophon__link::after {
  content: "";
  position: absolute;
  /* Centred and at least as wide as the token: a short label ("编辑部", 39px)
     is a narrow target even when it is tall enough, and the box must not grow
     or the footer's separator shifts. */
  left: 50%;
  width: max(100%, 46px);
  transform: translateX(-50%);
  /* (box - 44)/2 is NEGATIVE for a 24px link, which is what makes the overhang
     reach above and below it. The subtraction the other way round pushed the
     target down past the link's own centre (measured 2026-11-10). */
  top: calc((100% - 46px) / 2);
  /* 44 plus one pixel each side: a finger or a probe exactly on the boundary is
     outside the element, and a target that touches the minimum only at its
     mathematical edge does not meet it. */
  height: 46px;
  min-height: 100%;
  background: transparent;
  /* Square corners: the link's own radius would clip the corner probes of the
     44x44 square (measured 2026-11-10: every probe missed on a radius box). */
  border-radius: 0;
}
.prose a, .related__reason a { padding-block: 0.12em; }

/* The 44px toolbar links make the sticky toolbar 60px tall. Keep the filters
   pinned to its real bottom edge, and stop pinning them while the toolbar can
   still wrap to two rows (it wraps below ~700px), or the two sticky bars
   overlap the focused item — a 2.4.11 failure. */
.filters { top: 60px; }
@media (max-width: 699px) {
  .filters { position: static; top: auto; }
}

/* ============================================== 3. prefers-contrast ======
   Raise the two weakest tokens toward the stronger values tokens.css already
   defines: hairlines become --rule-strong and the faintest ink becomes
   --ink-soft. No new colour is introduced. The selector repeats the shapes
   tokens.css uses (html[data-theme] and the OS-dark no-choice case) at equal
   specificity, and this file loads later, so it wins in both themes. */
@media (prefers-contrast: more) {
  html[data-theme],
  html:not([data-theme="light"]) {
    --rule: var(--rule-strong);
    --ink-faint: var(--ink-soft);
  }
  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline-width: 3px;
    outline-offset: 3px;
  }
  .searchbar__input { border-color: var(--ink-faint); }
}

/* ================================================ 4. forced-colors ======
   Windows high contrast discards author colours and paints the CSS system
   palette over them. Rules must therefore be written in system colours, and
   the borders some components set to 0 must come back or the control vanishes.

   Palette used: Canvas/CanvasText (page), ButtonFace/ButtonText/ButtonBorder
   (controls), Highlight/HighlightText (selection and checked state),
   LinkText/VisitedText (links), GrayText (disabled). */
@media (forced-colors: active) {
  html, body { background: Canvas; color: CanvasText; }

  /* Chrome that separated itself with --rule hairlines: keep a line. */
  .masthead, .rail, .toolbar, .filters, .colophon,
  .feed-head, .feed__side, .article--lead, .card, .digest-item,
  .detail__head, .panel, .related, .disclaimer { border-color: CanvasText; }

  /* Every rounded, filled or transparent control needs an edge and a face. */
  .theme-switch__btn,
  .locale-switch__btn,
  .chip,
  .toolbar__link,
  .searchbar__input,
  .button,
  .skip-link {
    border: 1px solid ButtonBorder;
    background: ButtonFace;
    color: ButtonText;
  }
  /* The icon button and the magnifier must not disappear into ButtonFace. */
  .theme-switch__btn { border-color: ButtonText; }
  .searchbar::before { background-color: CanvasText; }
  .button { border-color: ButtonText; }

  /* State is not colour-only and stays visible when fills are flattened. */
  .chip[aria-pressed="true"],
  .locale-switch__btn[aria-pressed="true"],
  .toolbar__link[aria-current="page"] {
    border: 2px solid Highlight;
    text-decoration: underline;
  }
  .dot { border: 1px solid CanvasText; }
  .dot[data-state="live"],
  .dot[data-state="fixture"],
  .dot[data-state="error"] { background: CanvasText; }

  a { color: LinkText; }
  a:visited { color: VisitedText; }

  /* 2.4.13 in high contrast: the system Highlight ring is the one colour the
     user chose to see. */
  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 2px;
  }
}

/* ================================================ 5. text spacing =======
   1.4.12: nothing may clip when the reader sets line-height 1.5, letter
   spacing 0.12em, word spacing 0.16em and paragraph spacing 2em. That means
   no fixed heights and no line clamping on any text container. Measured with
   those exact overrides injected; see docs/bar/A11Y.md for the run. */

/* feed.css clamps a card deck to two lines with overflow:hidden: that is a
   guaranteed text-spacing clip, so the clamp is released here. */
.card__deck {
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
}
/* A nowrap + ellipsis source label clips as soon as tracking widens. Let it
   wrap; the meta line already wraps. */
.card__source {
  max-width: none;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
/* The empty-plate band is the one fixed-height text box in the product. */
.plate .thumb__empty { height: auto; min-height: 2.25rem; }
/* No text container may carry a fixed height or a max-height. :where() keeps
   this at zero specificity so a future component rule can still win. */
:where(
  p, li, h1, h2, h3, h4, h5, h6, blockquote, dd, dt, figcaption,
  .article__title, .detail__title, .card__title, .card__deck, .article__deck,
  .digest__headline, .digest-item__title, .digest-item__summary,
  .article__bullets li, .prose, .prose p, .claim__text, .claim__span,
  .related__reason, .state__body, .state__detail, .colophon__note, .detail__deck
) {
  height: auto;
  max-height: none;
}
/* nowrap is safe only inside the chip scroller; anywhere else it can push a
   line past its container once tracking grows. */
.article__more { white-space: normal; }
/* The filter count is the exception, and it is a two-word label ("8 items" /
   "8 条"). a11y.css normalised it to `normal` so a widened line could not push
   past its box, but the box is itself the only free shrinkable item in
   .filters__inner, so between 560 and 899 the flex row squeezed it to 32-42px
   and the label broke into "8" over "items" — measured 2026-11-17 in the
   fixture feed at 600/768 (height 39px = two 20px lines; 42x20 at 900+). At
   >=900 the row has room and it sits on one line. Pin the label to one line and
   let the CHIP SCROLLER, which already scrolls and is the clipped element,
   surrender the space instead — `white-space: nowrap` can only overflow the
   count if the two words are wider than its own content, which they never are. */
.filters__count { white-space: nowrap; }

/* ============================================ 6. skip link + current ====
   The skip link is the first focusable thing on every page; make it a real
   target with a real ring on both grounds. */
.skip-link {
  top: -8rem;
  background: var(--canvas);
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}
.skip-link:focus,
.skip-link:focus-visible {
  top: max(0.75rem, env(safe-area-inset-top, 0px));
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

/* [aria-current="page"] is marked by a plate and a 600 weight in chrome.css.
   Add a non-colour cue that survives every theme: a 2px underline. */
[aria-current="page"] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.32em;
}

/* ============================================ 7. non-text contrast ======
   1.4.11 failures measured in the shared chrome (details in docs/bar/A11Y.md):
   - the search field's boundary was a transparent border on a 1.09:1 fill;
   - .colophon__link was identified only by a 1.46:1 --rule underline.
   Both are fixed with tokens that already exist; the files that own those
   declarations are not edited. --ink-faint is used for the field edge because
   --rule-strong measures 2.88:1 against the dark field fill (below 3:1). */
.searchbar__input { border-color: var(--ink-faint); }
.colophon__link { border-bottom-color: var(--rule-strong); }

/* ================================= 8. status messages on a phone =======
   WCAG 4.1.3 Status Messages (AA). `.filters__count` is the live region that
   announces how many stories the selected category holds ("50 items" /
   "10 items"), and responsive.css removes it with `display: none` below 600px.
   A display:none node is NOT in the accessibility tree, so on a phone the
   announcement does not exist at all: a reader picks "Commodities" and nothing
   says the edition became ten stories.

   It stays out of the phone's LAYOUT exactly as before — the visually-hidden
   recipe takes it out of flow at 1px — but it remains in the tree, so the
   polite announcement still fires. This file loads after responsive.css, so the
   override wins without editing the file that owns the breakpoint. */
@media (max-width: 599px) {
  .filters__count {
    display: block;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}
