/* type-system.css — the shared type system. Products never edit this file. */
@layer reset, tokens, base, components, utilities;

/* One family, three weights. Self-hosted WOFF2 with a metric-matched fallback. */
@font-face {
  font-family: "System Sans";
  src: url("../../fonts/system-sans-var.woff2") format("woff2");  /* relative: works from any base path */
  font-weight: 400 600;
  font-display: swap;
}
@font-face {
  font-family: "System Sans Fallback";
  src: local("Arial");
  size-adjust: 107%;        /* PLACEHOLDER: generate per font (next/font, fontaine, Chrome calculator) */
  ascent-override: 90%;
  descent-override: 22%;
  line-gap-override: 0%;
}

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Family (fixed) */
    --font-sans: "System Sans", "System Sans Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

    /* Size ladder (fixed). Fluid steps are rem-dominant: max ≤ 2.5× min, rem term ≥ 60%. */
    --font-size-caption: 0.75rem;                              /* 12 */
    --font-size-small:   0.875rem;                             /* 14 */
    --font-size-body:    1rem;                                 /* 16 */
    --font-size-lead:    1.125rem;                             /* 18 */
    --font-size-sub:     1.25rem;                              /* 20 */
    --font-size-heading: 1.5rem;                               /* 24 */
    --font-size-title:   clamp(2rem, 1.75rem + 1vw, 2.5rem);   /* 32–40 */
    --font-size-display: clamp(2.75rem, 2.4rem + 1.4vw, 3.75rem); /* 44–60 */

    /* Weights (fixed) */
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;

    /* Line-height (fixed) */
    --leading-display: 1.05;
    --leading-title: 1.1;
    --leading-heading: 1.2;
    --leading-sub: 1.3;
    --leading-body: 1.55;
    --leading-small: 1.5;
    --leading-caption: 1.45;
    --leading-label: 1.3;

    /* Tracking (fixed) */
    --tracking-display: -0.02em;
    --tracking-title: -0.015em;
    --tracking-heading: -0.01em;
    --tracking-caps: 0.06em;

    /* Measure and spacing (fixed) */
    --measure: 65ch;
    --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
    --space-5: 1.5rem;  --space-6: 2rem;   --space-7: 3rem;    --space-8: 4rem;
    --space-9: 6rem;    --space-10: 8rem;
    --space-paragraph: 1em;
    --space-heading-above: 2.5em;
    --space-heading-below: 0.5em;
    --space-card: var(--space-5);
    --space-section-app: var(--space-7);
    --space-section: clamp(2.5rem, 8vw, 6rem);
    --gutter: clamp(1rem, 3.5vw, 2.5rem);

    /* Ink neutrals (fixed — they carry the contrast guarantee). Ratios on #FAFAFA, 2026-10-15. */
    --ink: #18181B;            /* 17.0:1 */
    --ink-muted: #595F69;      /* 6.2:1 — ≥16 px only */
    --ink-subtle: #6B7280;     /* 4.6:1 — ≥16 px, last resort */
    --ink-inverse: #EDEDEF;

    /* Semantic text colors: products do NOT override these. */
    --color-text: var(--ink);
    --color-text-muted: var(--ink-muted);
    --color-text-subtle: var(--ink-subtle);

    /* Product-owned tokens: DEFAULTS ONLY. product.css overrides these and nothing else. */
    --brand-hue: 250deg;
    --color-bg: #FAFAFA;
    --color-surface: #FFFFFF;
    --color-accent: oklch(52% 0.14 var(--brand-hue));    /* on-accent 5.3:1 at hue 250; reduce chroma until in sRGB gamut for other hues */
    --color-accent-hover: oklch(47% 0.13 var(--brand-hue));
    --color-on-accent: #FAFAFA;
    --color-link: oklch(45% 0.14 var(--brand-hue));      /* 7.1:1 on bg at hue 250; underlined always */
    --color-focus: var(--color-accent);
    --color-success-text: #14532D; --color-danger-text: #991B1B; --color-warning-text: #713F12;  /* 8.7 / 8.0 / 8.3:1 — safe at ≤14 px */
  }

  /* Dark set: emitted twice (system preference, explicit toggle) from one source. Ratios on #121214. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --ink: #EDEDEF;          /* 16.0:1 */
      --ink-muted: #A5A5AC;    /* 7.6:1 */
      --ink-subtle: #8A8A92;   /* 5.5:1 */
      --ink-inverse: #18181B;
      --color-bg: #121214;
      --color-surface: #1A1A1D;
      --color-accent: oklch(72% 0.11 var(--brand-hue));
      --color-accent-hover: oklch(78% 0.10 var(--brand-hue));
      --color-on-accent: #121214;
      --color-link: oklch(75% 0.12 var(--brand-hue));
      --color-success-text: #86EFAC; --color-danger-text: #FCA5A5; --color-warning-text: #FDE68A;
    }
  }
  :root[data-theme="dark"] {
    --ink: #EDEDEF; --ink-muted: #A5A5AC; --ink-subtle: #8A8A92; --ink-inverse: #18181B;
    --color-bg: #121214; --color-surface: #1A1A1D;
    --color-accent: oklch(72% 0.11 var(--brand-hue)); --color-accent-hover: oklch(78% 0.10 var(--brand-hue));
    --color-on-accent: #121214; --color-link: oklch(75% 0.12 var(--brand-hue));
    --color-success-text: #86EFAC; --color-danger-text: #FCA5A5; --color-warning-text: #FDE68A;
  }

  @media (prefers-contrast: more) {
    :root, :root:not([data-theme="light"]), :root[data-theme="dark"] {
      --color-text-muted: var(--ink);
      --color-text-subtle: var(--ink);
    }
  }
}

@layer base {
  html {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-synthesis: none;              /* no faux bold/italic (Baseline 2022) */
    font-optical-sizing: auto;         /* opsz axis thickens small text (Baseline 2020) */
    -webkit-text-size-adjust: 100%;    /* non-Baseline; keep 100%, never none */
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }
  body { font: var(--weight-regular) var(--font-size-body) / var(--leading-body) var(--font-sans); margin: 0; }
  :lang(ja), :lang(zh), :lang(ko) { line-height: 1.7; font-style: normal; }

  /* Roles via semantic elements */
  h1 { font-size: var(--font-size-title);   font-weight: var(--weight-semibold); line-height: var(--leading-title);   letter-spacing: var(--tracking-title);   text-wrap: balance; }
  h2 { font-size: var(--font-size-heading); font-weight: var(--weight-medium);   line-height: var(--leading-heading); letter-spacing: var(--tracking-heading); text-wrap: balance; }
  h3 { font-size: var(--font-size-sub);     font-weight: var(--weight-medium);   line-height: var(--leading-sub);     text-wrap: balance; }
  h4, h5, h6 { font-size: var(--font-size-body); font-weight: var(--weight-medium); line-height: var(--leading-body); }
  h1, h2, h3, h4 { margin-block: var(--space-heading-above) var(--space-heading-below); }
  h1 { margin-block-start: 0; }
  p, li { max-inline-size: var(--measure); text-wrap: pretty; }
  p + p { margin-block-start: var(--space-paragraph); }
  small { font-size: var(--font-size-caption); line-height: var(--leading-caption); color: var(--color-text); }
  strong, b { font-weight: var(--weight-medium); }          /* emphasis is a half-step, never 700 */
  em, i { font-style: italic; }                             /* use sparingly; never with strong */
  a { color: var(--color-link); text-decoration: underline; text-underline-offset: 0.15em; }
  code, kbd, pre { font-family: var(--font-mono); font-size: max(0.875em, 0.875rem); }
  pre { overflow-x: auto; max-inline-size: 100%; }
  td, th, [data-numeric] { font-variant-numeric: tabular-nums; }
  input, select, textarea, button { font: inherit; }
  input, select, textarea { font-size: max(var(--font-size-body), 100%); min-block-size: 2.5rem; }  /* ≥16 px: no iOS zoom */
  ::placeholder { color: var(--color-text-muted); opacity: 1; }
  :focus-visible { outline: none; box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 4px var(--color-focus); }
  @media (forced-colors: active) { :focus-visible { outline: 2px solid CanvasText; outline-offset: 2px; } }
}

@layer utilities {
  /* Role classes for places where the semantic element is not available */
  .t-display    { font-size: var(--font-size-display); font-weight: var(--weight-semibold); line-height: var(--leading-display); letter-spacing: var(--tracking-display); text-wrap: balance; }
  .t-title      { font-size: var(--font-size-title);   font-weight: var(--weight-semibold); line-height: var(--leading-title);   letter-spacing: var(--tracking-title); }
  .t-heading    { font-size: var(--font-size-heading); font-weight: var(--weight-medium);   line-height: var(--leading-heading); letter-spacing: var(--tracking-heading); }
  .t-subheading { font-size: var(--font-size-sub);     font-weight: var(--weight-medium);   line-height: var(--leading-sub); }
  .t-lead       { font-size: var(--font-size-lead);    font-weight: var(--weight-regular);  line-height: var(--leading-body); }
  .t-body       { font-size: var(--font-size-body);    font-weight: var(--weight-regular);  line-height: var(--leading-body); }
  .t-body-sm    { font-size: var(--font-size-small);   font-weight: var(--weight-regular);  line-height: var(--leading-small);   color: var(--color-text); }
  .t-label      { font-size: var(--font-size-small);   font-weight: var(--weight-medium);   line-height: var(--leading-label); }
  .t-overline   { font-size: var(--font-size-caption); font-weight: var(--weight-medium);   line-height: var(--leading-label);   letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text); }
  .t-caption    { font-size: var(--font-size-caption); font-weight: var(--weight-regular);  line-height: var(--leading-caption); color: var(--color-text); }
  .t-code       { font-family: var(--font-mono); font-size: max(0.875em, 0.875rem); }
  .t-muted      { color: var(--color-text-muted); }   /* ≥16 px text only */
  .t-subtle     { color: var(--color-text-subtle); }  /* ≥16 px text only */
  .t-numeric    { font-variant-numeric: tabular-nums; }

  /* Reading mode (docs, articles): body becomes Lead */
  .reading { font-size: var(--font-size-lead); }
  .reading h2 + p, .reading h3 + p { margin-block-start: 0; }

  /* Widget root: inherits everything, sizes by its container */
  .widget { container-type: inline-size; color: var(--color-text); background: var(--color-surface); padding: var(--space-card); }
  @container (max-width: 24rem) { .widget { padding: var(--space-4); } }
}
