/* FYI Design — Universal Semantic Tokens */

:root {
  /* Background */
  --fyi-bg-primary: #ffffff;
  --fyi-bg-secondary: #f8fafc;
  --fyi-bg-tertiary: #f1f5f9;

  /* Text */
  --fyi-text-primary: #0f172a;
  --fyi-text-secondary: #475569;
  --fyi-text-muted: #94a3b8;

  /* Border */
  --fyi-border: #e2e8f0;
  --fyi-border-light: #f1f5f9;

  /* Shadows */
  --fyi-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --fyi-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

  /* Radius */
  --fyi-radius-sm: 0.375rem;
  --fyi-radius-md: 0.5rem;
  --fyi-radius-lg: 0.75rem;
}

.dark {
  --fyi-bg-primary: #0f172a;
  --fyi-bg-secondary: #1e293b;
  --fyi-bg-tertiary: #334155;
  --fyi-text-primary: #f1f5f9;
  --fyi-text-secondary: #94a3b8;
  --fyi-text-muted: #64748b;
  --fyi-border: #334155;
  --fyi-border-light: #1e293b;
  --fyi-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --fyi-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
}

/* ==========================================================================
   Frontend Gold Standard primitives (v0.3.0) — ADDITIVE.
   Every rule below is scoped to a new `.fyi-*` class that no existing template
   uses, so sites that do not adopt the new tags render unchanged. See
   frontend-gold-standard.md §1–§2. No bare element selectors here on purpose.
   ========================================================================== */

/* Perf/mobile baseline (§2): guarantee these components inherit a ≥16px base
   so prose never renders below body size; no post-load injection = zero CLS. */
.fyi-toc,
.fyi-faq,
.fyi-references {
  font-size: 1rem;
}

/* --- {% fyi_toc %} : mobile collapsible <details>, sticky + always-open at lg+ */
.fyi-toc__summary {
  min-height: 48px; /* ≥48px tap target (§2) */
}
.fyi-toc[open] .fyi-toc__caret {
  transform: rotate(180deg);
}
@media (min-width: 1024px) {
  .fyi-toc {
    position: sticky;
    top: 5rem;
  }
}
/* Reveal the outline on desktop without JS in browsers that support the
   ::details-content pseudo (Baseline 2026). Where unsupported, the <details>
   degrades to a normal collapsible everywhere — links stay in the HTML either
   way, so SSR/crawlability is never affected. */
@supports selector(::details-content) {
  @media (min-width: 1024px) {
    .fyi-toc > summary {
      display: none;
    }
    .fyi-toc::details-content {
      content-visibility: visible;
      display: block;
    }
  }
}

/* --- {% fyi_faq %} : accordion summaries are ≥48px tap targets (§2) */
.fyi-faq__q {
  min-height: 48px;
}

/* --- .fyi-table-scroll : reusable wide-table overflow-x wrapper (§2).
   Wrap any wide <table> so the page body never scrolls horizontally. */
.fyi-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.fyi-table-scroll > table {
  min-width: 100%;
}

/* ==========================================================================
   FYI Screen Rules v1 (FS-01 … FS-12) — fleet-wide reading/tapping baseline.
   Spec + audit: seo-ops .claude/rules/screen-rules.md · scripts/audit/screen_rules_audit.py
   Loading: this file is already linked by every site that links tokens.css,
   so the rules reach a site with a package bump — no template change.

   Cascade contract
   - Defaults live in `@layer base`: Tailwind v4 utilities (layer `utilities`)
     always win over them, so a site can still restyle anything.
   - Guards that must hold whatever a template says (motion, tap size, overflow)
     are unlayered and use :where() so they add no specificity.
   ========================================================================== */

:root {
  --fyi-neg: #b91c1c;          /* negative numbers (FS-03) — 5.9:1 on white */
  --fyi-pos: #15803d;
  --fyi-focus: #2563eb;        /* focus ring (FS-08) */
  --fyi-tap: 24px;             /* minimum control size, fine pointer (WCAG 2.5.8) */
}
.dark {
  --fyi-neg: #f87171;
  --fyi-pos: #4ade80;
  --fyi-focus: #93c5fd;
}
/* Touch screens, and any phone-width window (some browsers misreport `pointer`,
   and a width test is what the audit can reproduce in a headless browser). */
@media (pointer: coarse), (max-width: 40rem) {
  :root { --fyi-tap: 44px; }   /* WCAG 2.5.5; the audit fails below 40px */
}

@layer base {
  /* FS-02 numbers line up: equal-width digits wherever values are compared. */
  :where(table, dl, output, time, input[type="number"], .fyi-num, [data-fyi-num]) {
    font-variant-numeric: tabular-nums lining-nums;
  }
  /* FS-04 text left, numbers right, never centred. */
  :where(th) { text-align: start; }
  :where(td.fyi-num, th.fyi-num, [data-fyi-num]) { text-align: end; white-space: nowrap; }
  /* FS-09 headings do not leave one-word last lines; prose avoids orphans. */
  :where(h1, h2, h3) { text-wrap: balance; }
  :where(main p, main li, main dd, main figcaption) { text-wrap: pretty; }
  /* FS-01 long tokens (URLs, code points, hex strings) wrap instead of pushing the page wide. */
  :where(main p, main li, main dd, main dt, main h1, main h2, main h3, main figcaption) {
    overflow-wrap: break-word;
  }
  :where(pre) { overflow-x: auto; max-inline-size: 100%; }
  :where(iframe, video, canvas, embed, object) { max-inline-size: 100%; }
}

/* FS-03 negative values: colour AND a real minus sign (the sign is content, set by
   fyiNumber()/ux.js — colour alone never carries the meaning). Zero stays neutral. */
/* Colour is opt-in: `.fyi-neg` / `.fyi-pos` on the value, or `data-fyi-signed` on a
   container whose negatives are deficits or losses (balances, changes, deltas). A
   measurement that merely sits below zero (−183 °C, −4.2 magnitude, −420 m) keeps the
   text colour — the minus sign already says it, and red would read as "bad". */
:where(.fyi-neg, [data-fyi-signed] [data-fyi-sign="-"]) { color: var(--fyi-neg); }
:where(.fyi-pos, [data-fyi-signed] [data-fyi-sign="+"]) { color: var(--fyi-pos); }

/* FS-05 wide tables scroll inside their own box; the page never scrolls sideways.
   ux.js wraps any table wider than its column in .fyi-table-scroll. */
.fyi-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-inline-size: 100%;
  overscroll-behavior-inline: contain;
}
.fyi-table-scroll:focus-visible { outline: 2px solid var(--fyi-focus); outline-offset: 2px; }
.fyi-table-scroll > table { min-inline-size: 100%; }
/* first column keeps its place while the rest scrolls (only inside the wrapper) */
.fyi-table-scroll[data-fyi-sticky] > table :where(tbody th:first-child, tbody td:first-child) {
  position: sticky;
  inset-inline-start: 0;
  background: var(--fyi-bg-primary);
  z-index: 1;
}

/* FS-06 controls are big enough to hit. Links inside sentences are exempt (WCAG). */
:where(button, [role="button"], select, summary,
       input:not([type="checkbox"], [type="radio"], [type="range"], [type="hidden"], [type="color"]),
       .fyi-tap) {
  min-block-size: var(--fyi-tap);
}
:where(button, [role="button"], .fyi-tap) { min-inline-size: var(--fyi-tap); }
/* icon-only links (search, theme, social) are as narrow as their icon otherwise */
:where(header a:has(> svg:only-child), footer a:has(> svg:only-child), main a:has(> svg:only-child)) {
  min-inline-size: var(--fyi-tap);
}
/* links that are already boxes (logo, nav rows, cards) get the same minimum height;
   `display` is never set here — an unlayered display would un-hide `.hidden` links. */
:where(header a, footer a, nav a) { min-block-size: var(--fyi-tap); }
/* row and card links in lists ("Tokyo → 9,560 km") are boxes too */
:where(main a.flex, main a.inline-flex, main a.block, main a.grid) { min-block-size: var(--fyi-tap); }
/* a link that is the whole content of a value cell ("Block: Gurmukhi") */
:where(main dd > a:only-child, main td > a:only-child) { min-block-size: var(--fyi-tap); }
/* a link laid out as a flex item (chips, meta rows, jump lists) is a box, not running
   text. `align-content` centres its label without touching `display`, so a card link
   with block children keeps its layout. */
:where(main .flex > a, main .inline-flex > a) { min-block-size: var(--fyi-tap); align-content: center; }
@layer base {
  @media (pointer: coarse), (max-width: 40rem) {
    /* stand-alone inline links in footers / breadcrumbs / outlines become finger-sized
       rows. In `base` so a template's own display/padding utilities still win. */
    /* `main nav` covers breadcrumbs, outlines and pagers whatever their (translated or
       missing) aria-label says. */
    :where(footer a, main nav a, nav[aria-label="Breadcrumb" i] a, .fyi-toc a,
           main dd > a:only-child, main td > a:only-child) {
      display: inline-flex;
      align-items: center;
    }
  }
}
@media (pointer: coarse), (max-width: 40rem) {
  /* iOS zooms the page when a focused field is under 16px */
  :where(input, select, textarea) { font-size: max(16px, 1em); }
}

/* FS-07 a disabled control looks disabled and says why (reason text: title or
   aria-describedby — checked by the audit, not by CSS). */
:where(button:disabled, [aria-disabled="true"], input:disabled, select:disabled) {
  cursor: not-allowed;
}
[data-fyi-reason]:where(:disabled, [aria-disabled="true"])::after {
  content: " — " attr(data-fyi-reason);
  font-weight: 400;
}

/* FS-08 keyboard focus is always visible. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--fyi-focus);
  outline-offset: 2px;
}

/* FS-10 motion follows the visitor's setting. Handled case by case, never by a
   global `animation-duration: 0.01ms` (that makes some animations more jarring and
   breaks code waiting on animationend). */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  :where(.animate-ping, .animate-bounce, .animate-pulse) { animation: none !important; }
  :where(.animate-spin) { animation-duration: 2.5s !important; }   /* busy state stays visible */
  :where([class*="hover:scale-"], [class*="hover:-translate-"], [class*="hover:translate-"]) {
    transition-property: color, background-color, border-color, opacity, box-shadow !important;
    transform: none !important;
    translate: none !important;
    scale: none !important;
  }
}

/* FS-11 source line: where the data came from and as-of when, next to the data. */
.fyi-source {
  margin-block-start: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--fyi-text-secondary);
}
.fyi-source :where(a) { text-decoration: underline; text-underline-offset: 2px; }

/* FS-12 answer block: the page's answer in the first screen, quotable on its own. */
.fyi-answer {
  font-size: 1.0625rem;
  line-height: 1.6;
  max-inline-size: 70ch;
}

/* print: values and sources survive, chrome does not */
@media print {
  :where(header nav, footer nav, .fyi-no-print, [x-data*="toast"]) { display: none !important; }
  .fyi-table-scroll { overflow: visible; }
}
