/* ============================================================================
 * OAW Projects Hub v1.0 — Quiet UI Layered Token & Reset Architecture
 * Cascade Order: reset -> tokens -> shell -> archetypes -> evidence -> views -> utilities
 * ============================================================================ */

@layer reset, tokens, shell, archetypes, evidence, views, utilities;

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

  html {
    scroll-padding-top: 64px;
    -webkit-text-size-adjust: 100%;
  }

  body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-sans);
    font-size: var(--prose-size);
    line-height: 1.65;
    color: var(--ink-primary);
    background: var(--bg-canvas);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  h1,
  h2,
  h3,
  h4,
  p,
  figure,
  blockquote {
    margin-top: 0;
  }

  img {
    max-width: 100%;
    height: auto;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
    border-radius: var(--radius-ui);
  }

  a {
    color: var(--accent-link);
  }

  :focus-visible {
    outline: 2px solid var(--accent-link);
    outline-offset: 2px;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      scroll-behavior: auto;
      transition-duration: 0.01ms;
      animation-duration: 0.01ms;
    }
  }
}

@layer tokens {
  :root {
    color-scheme: light dark;
    &:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
    &:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }

    /* Typography */
    --font-serif: 'Newsreader', 'Source Serif 4', 'Charter', Georgia, serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Default D2 Balanced Workspace Density */
    --prose-size: 1.05rem;
    --prose-lh: 1.70;
    --section-pad-y: 26px;
    --figure-pad: 16px;
    --breakout-pad: 14px 18px;
    --table-cell-pad: 8px 12px;

    /* Parametric Corner Radii */
    --radius-ui: 8px;
    --radius-card: 12px;
    --radius-pill: 999px;

    /* Masthead Swatch Dot Tokens */
    --swatch-dot-white: #ffffff;
    --swatch-dot-paper: #f2e8d4;
    --swatch-dot-dark-paper: #3c342b;
    --swatch-dot-dark: #0f172a;

    /* Contrast Text on Accent Fill */
    --text-on-accent: #ffffff;

    /* Code Sidecar Tokens */
    --bg-code-drawer: #0b0f17;
    --ink-code-drawer: #f1f5f9;
    --border-code-drawer: #1e293b;
  }

  [data-corners="soft"] {
    --radius-ui: 8px;
    --radius-card: 12px;
  }

  [data-corners="crisp"] {
    --radius-ui: 0px;
    --radius-card: 0px;
  }

  [data-density="D1"] {
    --prose-size: 1.14rem;
    --prose-lh: 1.82;
    --section-pad-y: 36px;
    --figure-pad: 22px;
    --breakout-pad: 18px 24px;
    --table-cell-pad: 11px 14px;
  }

  [data-density="D2"] {
    --prose-size: 1.05rem;
    --prose-lh: 1.70;
    --section-pad-y: 26px;
    --figure-pad: 16px;
    --breakout-pad: 14px 18px;
    --table-cell-pad: 8px 12px;
  }

  [data-density="D3"] {
    --prose-size: 0.96rem;
    --prose-lh: 1.56;
    --section-pad-y: 16px;
    --figure-pad: 10px;
    --breakout-pad: 10px 14px;
    --table-cell-pad: 5px 9px;
  }

  /* 4-Theme Surface Polarity Tokens (Default: S1 Pure White) */
  :root,
  [data-theme="white"] {
    --bg-canvas: #ffffff;
    --bg-elevated: #f8fafc;
    --bg-recessed: #f1f5f9;
    --ink-primary: #0f172a;
    --ink-secondary: #334155;
    --ink-muted: #64748b;
    --border-strong: #0f172a;
    --border-grid: #e2e8f0;
    --border-hairline: #f1f5f9;
    --accent-link: #1d4ed8;
    --sig-bg: #eff6ff;
    --sig-border: #1d4ed8;
    --warn-bg: #fef2f2;
    --warn-border: #b91c1c;
    --ok-bg: #f0fdf4;
    --ok-border: #15803d;
    --tint-indigo-bg: rgba(37, 99, 235, 0.08);
    --tint-emerald-bg: rgba(5, 150, 105, 0.08);
    --tint-amber-bg: rgba(217, 119, 6, 0.08);
    --tint-violet-bg: rgba(124, 58, 237, 0.08);
    --shadow-popover: 0 12px 28px rgba(15, 23, 42, 0.14);
    --shadow-card: 0 2px 8px rgba(15, 23, 42, 0.06);
    --trace-msg: #15803d;
    --trace-carrier: #6d28d9;
    --trace-quad: #0f766e;
    --trace-rf: #1d4ed8;
    --trace-demod: #b45309;
    --trace-err: #b91c1c;
  }

  [data-theme="paper"] {
    color-scheme: light;
    --bg-canvas: #fbf9f5;
    --bg-elevated: #f3efe6;
    --bg-recessed: #eae4d7;
    --ink-primary: #1c1917;
    --ink-secondary: #44403c;
    --ink-muted: #78716c;
    --border-strong: #1c1917;
    --border-grid: #d6d0c4;
    --border-hairline: #e5e0d5;
    --accent-link: #1e40af;
    --sig-bg: #f0ebe1;
    --sig-border: #1e3a8a;
    --warn-bg: #f9ebe8;
    --warn-border: #991b1b;
    --ok-bg: #ecfdf5;
    --ok-border: #15803d;
    --tint-indigo-bg: rgba(30, 64, 175, 0.08);
    --tint-emerald-bg: rgba(5, 150, 105, 0.08);
    --tint-amber-bg: rgba(217, 119, 6, 0.08);
    --tint-violet-bg: rgba(124, 58, 237, 0.08);
    --shadow-popover: 0 12px 28px rgba(28, 25, 23, 0.14);
    --shadow-card: 0 2px 8px rgba(28, 25, 23, 0.06);
    --trace-msg: #15803d;
    --trace-carrier: #6d28d9;
    --trace-quad: #0f766e;
    --trace-rf: #1d4ed8;
    --trace-demod: #b45309;
    --trace-err: #b91c1c;
  }

  [data-theme="dark-paper"] {
    color-scheme: dark;
    --bg-canvas: #181614;
    --bg-elevated: #211e1b;
    --bg-recessed: #12100e;
    --ink-primary: #ece7df;
    --ink-secondary: #b8b0a4;
    --ink-muted: #857d72;
    --border-strong: #d6cfc2;
    --border-grid: #332e29;
    --border-hairline: #26221e;
    --accent-link: #93c5fd;
    --text-on-accent: #0f172a;
    --sig-bg: #1e242b;
    --sig-border: #60a5fa;
    --warn-bg: #2b1d1d;
    --warn-border: #f87171;
    --ok-bg: #13261c;
    --ok-border: #4ade80;
    --tint-indigo-bg: rgba(96, 165, 250, 0.15);
    --tint-emerald-bg: rgba(74, 222, 128, 0.15);
    --tint-amber-bg: rgba(251, 191, 36, 0.15);
    --tint-violet-bg: rgba(192, 132, 252, 0.15);
    --shadow-popover: 0 14px 32px rgba(0, 0, 0, 0.45);
    --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.30);
    --trace-msg: #4ade80;
    --trace-carrier: #c084fc;
    --trace-quad: #2dd4bf;
    --trace-rf: #60a5fa;
    --trace-demod: #fbbf24;
    --trace-err: #f87171;
  }

  [data-theme="dark"] {
    color-scheme: dark;
    --bg-canvas: #0b0f17;
    --bg-elevated: #111827;
    --bg-recessed: #06090f;
    --ink-primary: #f1f5f9;
    --ink-secondary: #cbd5e1;
    --ink-muted: #64748b;
    --border-strong: #e2e8f0;
    --border-grid: #1e293b;
    --border-hairline: #172033;
    --accent-link: #60a5fa;
    --text-on-accent: #0b0f17;
    --sig-bg: #111c2d;
    --sig-border: #3b82f6;
    --warn-bg: #281419;
    --warn-border: #ef4444;
    --ok-bg: #0f291e;
    --ok-border: #34d399;
    --tint-indigo-bg: rgba(96, 165, 250, 0.15);
    --tint-emerald-bg: rgba(52, 211, 153, 0.15);
    --tint-amber-bg: rgba(251, 191, 36, 0.15);
    --tint-violet-bg: rgba(192, 132, 252, 0.15);
    --shadow-popover: 0 14px 32px rgba(2, 6, 23, 0.55);
    --shadow-card: 0 2px 10px rgba(2, 6, 23, 0.35);
    --trace-msg: #4ade80;
    --trace-carrier: #c084fc;
    --trace-quad: #2dd4bf;
    --trace-rf: #60a5fa;
    --trace-demod: #fbbf24;
    --trace-err: #f87171;
  }

  /* Semantic & Legacy Variable Bridges */
  :root,
  [data-theme] {
    --bg-primary: var(--bg-canvas);
    --bg-surface: var(--bg-elevated);
    --bg-subtle: var(--bg-recessed);
    --text-primary: var(--ink-primary);
    --text-secondary: var(--ink-secondary);
    --text-muted: var(--ink-muted);
    --border-subtle: var(--border-grid);
    --accent-primary: var(--accent-link);
    --accent-cyan: var(--sig-border);
    --accent-blue: var(--accent-link);
  }
}

@layer utilities {
  .tabular-readout {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .hidden,
  [hidden]:not([hidden="until-found"]) {
    display: none;
  }
}
