/* base.css — @layer base. Reset, type, focus ring, skip link, .sr-only.
   The reduced-motion guard and the two [hidden] cascade defenses live
   UNLAYERED at the foot of this file: a cascade defense must out-rank the
   layered component/page skins that set display, and reduced-motion must
   beat every animation regardless of which layer declared it. */

@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    margin: 0;
    background: var(--paper);
    color: var(--on-surface);
    font: 400 var(--t-body)/1.6 var(--font-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Type floor — display voice for headings, text font for prose. Components
     (@layer components) and pages (@layer pages) override freely; these are
     only the resting defaults. */
  h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--s4);
    font-weight: 700;
    color: var(--on-surface);
    font-family: var(--font-display);
    line-height: 1.2;
  }
  h1 { font-size: var(--t-h1); letter-spacing: -0.02em; line-height: 1.05; }
  h2 { font-size: var(--t-h2); }
  h3 { font-size: var(--t-h3); }
  h4 { font-size: var(--t-lede); font-family: var(--font-text); font-weight: 500; line-height: 1.3; }
  h5, h6 { font-size: var(--t-body); }

  h1, h2, h3 { text-wrap: balance; }

  p { margin: 0 0 var(--s4); }
  p:last-child { margin-bottom: 0; }

  a { color: inherit; text-decoration: none; }

  img, svg, video { max-width: 100%; display: block; }

  ul, ol { margin: 0; padding: 0; }

  /* Form-control reset. `color: inherit` is scoped to fields and to theme
     buttons (`.btn` + our chrome/drawer/quicksearch buttons all set their own
     colour anyway) — NOT bare plugin buttons. A plugin banner that paints its
     own dark button background must keep its own label colour; the old blanket
     `button { color: inherit }` forced such a label to the inherited page ink,
     rendering it ink-on-ink (M2, the consent "Accept all" CTA). */
  button, input, select, textarea { font: inherit; }
  input, select, textarea { color: inherit; }
  button { cursor: pointer; background: none; border: 0; }

  /* Plugin palette bridge (M2). Cross-theme plugins (e.g. the consent banner)
     are authored against the dot_books token names --paper-2/--rule/etc. Those
     names don't exist verbatim in this theme, so aliasing them to Quiet
     Neutral tokens makes such plugin chrome render legibly in this theme
     without editing any plugin markup. --paper itself is already a native
     token (tokens.css) and must not be re-aliased here. */
  :root {
    --paper-2: var(--surface-well);
    --rule: var(--hairline);
    --muted: var(--ink-muted);
    --serif: var(--font-text);
    --sans: var(--font-form);
  }

  strong, b { font-weight: 600; }

  /* All numerals are mono, always — price rows self-align (§2.2). */
  ::selection { background: var(--ink); color: var(--paper); }

  /* Universal focus ring (§2.4) — every interactive element, no exceptions. */
  :focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
    border-radius: var(--r-sm);
  }

  /* Skip-to-content — off-screen until focused (§2.4, release-blocking). */
  .skip-link {
    position: fixed;
    top: var(--s2);
    left: var(--s2);
    z-index: var(--z-overlay);
    transform: translateY(-150%);
    background: var(--accent);
    color: var(--paper);
    padding: var(--s2) var(--s4);
    border-radius: var(--r-sm);
    font: 500 var(--t-label)/1 var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: transform var(--dur-fast) var(--ease);
  }
  .skip-link:focus { transform: translateY(0); }

  /* Visually-hidden but available to assistive tech. */
  .sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  /* Native lazy-load fade — JS adds .ko-fade-img then .is-loaded; without JS
     the class is never added, so images are never hidden (§7 hook). */
  .ko-fade-img { opacity: 0; transition: opacity var(--dur) var(--ease); }
  .ko-fade-img.is-loaded { opacity: 1; }
}

/* Cross-document View Transitions for PLP→PDP cover morph (§7 view-transition
   wiring). At-rule, layer-agnostic. The base.html handler names the cover. */
@view-transition { navigation: auto; }

/* ── UNLAYERED cascade defenses (must beat all @layer skins) ──────────── */

/* Global reduced-motion guard (§2.5) — ported verbatim. Unlayered + !important
   so it wins over any animation/transition declared in components or pages. */
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (prefers-reduced-motion: reduce) { ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; } }

/* Critical: the components-layer .quicksearch{display:flex} rule would
   override the [hidden] attribute's default display:none — and because it
   lives in a higher cascade layer it beats a layered defense on specificity-
   agnostic grounds. Kept UNLAYERED here so the JS-toggled hidden attribute
   always wins and the toggle button can dismiss the panel. */
#quicksearch-panel[hidden] { display: none; }

/* Same defense for the PDP sticky add-to-cart bar: the pages-layer
   .sticky-atc{display:flex} would otherwise render it even while the hidden
   attribute is set (before the IntersectionObserver runs). Unlayered so the
   JS-toggled attribute always wins. */
#sticky-atc[hidden] { display: none; }
