/* ============================================================
   SCOTUS SIMULATOR — Design Tokens (v2 · dual-look redesign)
   colors_and_type.css  — single source of truth.

   TWO coordinated looks, mapped to screens:
     • "The Writ"      — editorial / engraved. Ink on laid paper,
                          guilloché, wax seals, engine-turned rules.
                          (Landing chrome, Docket, Summary, Court,
                           Achievements, Leaderboard, Settings, …)
     • "Lapis & Stone" — neoclassical marble chamber. Carved Roman
                          caps, lapis + gold. (The Argument / bench)
                          Scoped under `.stone`.

   Both ship light + dark via [data-theme] on <html>. Default light.

   Fonts: Fraunces (display / titling) · Source Serif 4 (body);
          Archivo (UI labels) · IBM Plex Mono (data).
   ============================================================ */

/* Google Fonts moved to <link> tags in index.html — an @import here
   hides the font CSS from the preload scanner and serializes discovery. */

/* ============================================================
   LOOK A — "THE WRIT"  (default · light)
   ============================================================ */
:root {
  /* ---- Type families ---- */
  --font-display:     'Fraunces', Georgia, serif;         /* headlines, case names (italic) */
  --font-body:        'Source Serif 4', Georgia, serif;   /* reading copy, opinions */
  --font-inscription: 'Fraunces', Georgia, serif;         /* tracked titling caps */
  --font-ui:          'Archivo', system-ui, sans-serif;   /* tracked uppercase labels */
  --font-mono:        'IBM Plex Mono', ui-monospace, monospace; /* ledger / data labels */

  /* ---- Writ palette ---- */
  --paper:        #F0E9D7;   /* laid paper          */
  --paper-2:      #F8F3E6;
  --paper-sunk:   #E6DCC5;
  --ink:          #1B1914;   /* intaglio ink (text) */
  --ink-2:        #4C473C;
  --ink-3:        #6F6857;   /* muted label — darkened to clear WCAG AA (4.5:1) on --paper */
  --wax:          #AE3528;   /* sealing-wax — PRIMARY accent */
  --wax-2:        #C8462F;
  --wax-tint:     rgba(174,53,40,.10);
  --ledger:       #1E5A4B;   /* promissory green — affirm/secondary */
  --ledger-2:     #2C7A64;
  --gold:         #9A7B33;   /* engraver's gold */
  --gold-2:       #BD9A45;
  --gold-3:       #E7CE8C;
  --line:         rgba(27,25,20,.14);
  --line-strong:  rgba(27,25,20,.30);
  --rule:         rgba(27,25,20,.5);
  --card:         rgba(248,243,230,.78);
  --guilloche:    rgba(27,25,20,.5);
  --wave:         rgba(27,25,20,.5);
  --shadow:       0 1px 2px rgba(60,45,20,.05), 0 14px 36px rgba(70,50,20,.1);
  --shadow-lift:  0 4px 10px rgba(60,45,20,.1), 0 26px 60px rgba(70,50,20,.2);

  /* difficulty ramp + ideology */
  --beginner:#2C7A56; --intermediate:#BD9A45; --advanced:#C2632B; --expert:#AE3528;
  --liberal:#3b5b7f; --center:#8a6e4e; --conservative:#9E2025;

  /* Semantic verdict colors — hoisted from the .stone chamber so screens
     OUTSIDE it (Summary verdict cards, Settings "Reset account") still
     resolve them. The .stone block overrides these within the chamber. */
  --affirm:#2C7A56; --oxblood:#7C2230; --lapis:#214A93;

  /* ---- Radii · motion (shared) ---- */
  --r-none:0; --r-sm:3px; --r-md:6px; --r-lg:8px; --r-xl:14px; --r-pill:999px;
  --dur-fast:150ms; --dur-med:300ms; --dur-slow:600ms; --dur-ceremonial:800ms;
  --ease-gavel:  cubic-bezier(.2,.8,.2,1);
  --ease-robe:   cubic-bezier(.4,0,.2,1);
  --ease-bench:  cubic-bezier(.34,.02,.18,1);
  --ease-pure-s: cubic-bezier(.45,0,.55,1);

  /* ============================================================
     LEGACY ALIASES — old token names mapped onto the new palette
     so existing inline styles reflow into the redesign. Prefer the
     names above in new code; these keep the long tail coherent.
     ============================================================ */
  --parchment:     var(--ink);
  --parchment-50:  var(--ink);
  --parchment-100: var(--ink);
  --parchment-200: var(--ink-2);
  --parchment-300: var(--ink-2);
  --parchment-400: var(--ink-3);
  --crimson:       var(--wax);
  --crimson-50:    var(--wax-tint);
  --crimson-100:   rgba(174,53,40,.2);
  --crimson-400:   var(--wax-2);
  --crimson-500:   var(--wax);
  --crimson-600:   #8A1C20;
  --crimson-700:   #6e1d14;
  --crimson-900:   #2E0608;
  --walnut-200:    var(--ink-3);
  --walnut-500:    #6A4423;
  --midnight-400:  var(--ledger);
  --midnight-500:  var(--ink-2);

  --bg:            var(--paper);
  --bg-elevated:   var(--card);
  --bg-sunken:     var(--paper-sunk);
  --fg1:           var(--ink);
  --fg2:           var(--ink-2);
  --fg3:           var(--ink-3);
  --fg-on-dark:    var(--ink);
  --fg-link:       var(--wax);
  --fg-link-hover: var(--wax-2);
  --accent:        var(--wax);
  --accent-hover:  var(--wax-2);
  --status-affirm: var(--ledger);
  --status-dissent:var(--wax);
  --status-pending:var(--gold);
  --border-hairline: var(--line);
  --border-soft:     var(--line);
  --border-strong:   var(--line-strong);
  --border-brass:    var(--gold);

  /* type sizes (kept for any class-based callers) */
  --fs-display-1:72px; --fs-display-2:56px; --fs-h1:42px; --fs-h2:32px;
  --fs-h3:24px; --fs-h4:19px; --fs-body:17px; --fs-body-sm:15px;
  --fs-caption:13px; --fs-micro:11px;
  --lh-body:1.6; --lh-h1:1.12;
  --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px; --sp-5:24px;
  --sp-6:32px; --sp-7:48px; --sp-8:64px;
  --shadow-1: var(--shadow); --shadow-2: var(--shadow); --shadow-3: var(--shadow-lift);

  --bp-mobile:768px; --bp-narrow:480px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

/* ---- THE WRIT · dark ---- */
[data-theme="dark"] {
  --paper:#10120E; --paper-2:#171A14; --paper-sunk:#0B0C09;
  --ink:#ECE6D4; --ink-2:#ABA48E; --ink-3:#8E8872;   /* lightened to clear WCAG AA on dark --paper */
  --wax:#E0654F; --wax-2:#EE7B61; --wax-tint:rgba(224,101,79,.12);
  --ledger:#57B193; --ledger-2:#6FC7A8; --gold:#C9A24E; --gold-2:#E0BC6A; --gold-3:#F3DEA0;
  --line:rgba(236,230,212,.12); --line-strong:rgba(236,230,212,.26); --rule:rgba(236,230,212,.4);
  --card:rgba(23,26,20,.66); --guilloche:rgba(201,162,78,.42); --wave:rgba(201,162,78,.4);
  --shadow:0 1px 2px rgba(0,0,0,.4), 0 16px 40px rgba(0,0,0,.5);
  --shadow-lift:0 6px 14px rgba(0,0,0,.45), 0 30px 70px rgba(0,0,0,.6);
  --beginner:#5FC093; --intermediate:#E0BC6A; --advanced:#E08A4F; --expert:#E0654F;
  --liberal:#6E9BE8; --center:#C7A24E; --conservative:#E0654F;
  --crimson-600:#EE7B61; --crimson-700:#C8462F; --walnut-500:#A68A6B;
  /* Semantic verdict colors (dark) — hoisted so Summary/Settings resolve them
     outside .stone; the dark .stone block overrides within the chamber. */
  --affirm:#5FC093; --oxblood:#C8576A; --lapis:#6E9BE8;
}

/* ============================================================
   LOOK B — "LAPIS & STONE"  (scoped: wrap a subtree in .stone)
   ============================================================ */
.stone {
  --paper:#E7E0CF; --paper-2:#F2ECDE; --stone-deep:#C6BAA0; --paper-sunk:#D8CDB2;
  --ink:#232026; --ink-2:#565062; --ink-3:#8A8270;
  --lapis:#214A93; --lapis-2:#2E63C2; --lapis-tint:rgba(33,74,147,.12);
  --oxblood:#7C2230; --gold:#9C7B2C; --gold-2:#C8A648; --gold-3:#E7CE8C;
  --line:rgba(35,32,38,.15); --line-strong:rgba(35,32,38,.3);
  --card:rgba(243,238,225,.82); --marble:url("/assets/marble-light.webp");
  --affirm:#2C7A56; --shadow:0 1px 2px rgba(40,30,15,.06), 0 16px 40px rgba(50,40,20,.14);
  --scrim:rgba(231,224,207,.5);
  /* aliases inside the chamber */
  --wax:var(--oxblood); --wax-2:var(--oxblood); --wax-tint:var(--lapis-tint);
  --parchment-50:var(--ink); --parchment-100:var(--ink); --parchment-200:var(--ink-2);
  --parchment-300:var(--ink-2); --parchment-400:var(--ink-3);
  --crimson-500:var(--oxblood); --accent:var(--lapis); --ledger:var(--affirm);
  /* Fonts inside the chamber inherit the root families (Fraunces + Source
     Serif 4) — no Cormorant override, keeping the type cohesive site-wide. */
}
[data-theme="dark"] .stone {
  --paper:#15151B; --paper-2:#1D1D25; --stone-deep:#2C2C37; --paper-sunk:#101015;
  --ink:#ECE6D6; --ink-2:#A8A192; --ink-3:#797262;
  --lapis:#6E9BE8; --lapis-2:#8FB4F2; --lapis-tint:rgba(110,155,232,.16);
  --oxblood:#C8576A; --gold:#C9A24E; --gold-2:#E0BC6A; --gold-3:#F3DEA0;
  --line:rgba(236,230,214,.12); --line-strong:rgba(236,230,214,.24);
  --card:rgba(29,29,37,.78); --marble:url("/assets/marble-dark.webp");
  --affirm:#5FC093; --shadow:0 1px 2px rgba(0,0,0,.4), 0 18px 44px rgba(0,0,0,.55);
  --scrim:rgba(21,21,27,.46);
}

/* ============================================================
   BASE
   ============================================================ */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100vh;
  overscroll-behavior-y: contain;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px; line-height: 1.6;
  font-feature-settings: "onum" 1, "liga" 1, "kern" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--dur-slow), color var(--dur-slow);
}
#root { min-height: 100vh; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

h1, .h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(30px,4vw,46px); line-height: 1.05; letter-spacing: -.01em; color: var(--ink); margin: 0; }
h2, .h2 { font-family: var(--font-display); font-weight: 700; font-size: 32px; line-height: 1.1; margin: 0; }
h3, .h3 { font-family: var(--font-display); font-weight: 700; font-size: 24px; line-height: 1.25; margin: 0; }
h4, .h4 { font-family: var(--font-display); font-weight: 600; font-size: 19px; line-height: 1.35; margin: 0; }
p  { text-wrap: pretty; }
code, pre, .mono { font-family: var(--font-mono); font-size: .92em; }

blockquote {
  font-family: var(--font-display); font-style: italic; font-size: 1.2em; line-height: 1.45;
  border-left: 2px solid var(--wax); padding: 8px 24px; color: var(--ink-2); margin: 24px 0;
}
a { color: var(--wax); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--wax-2); }

/* Ceremonial eyebrow — mono micro-label */
.eyebrow {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  letter-spacing: .26em; text-transform: uppercase; color: var(--gold);
}
.citation { font-variant: small-caps; letter-spacing: .04em; font-style: italic; }

/* Engine-turned wavy rule (letterhead divider) */
.wave {
  height: 16px; background: var(--wave);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='22' viewBox='0 0 120 22'><g fill='none' stroke='black' stroke-width='1.3'><path d='M0 11 C15 2 25 2 40 11 C55 20 65 20 80 11 C95 2 105 2 120 11'/><path d='M0 11 C15 20 25 20 40 11 C55 2 65 2 80 11 C95 20 105 20 120 11'/></g></svg>") repeat-x left center / 120px 16px;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='22' viewBox='0 0 120 22'><g fill='none' stroke='black' stroke-width='1.3'><path d='M0 11 C15 2 25 2 40 11 C55 20 65 20 80 11 C95 2 105 2 120 11'/><path d='M0 11 C15 20 25 20 40 11 C55 2 65 2 80 11 C95 20 105 20 120 11'/></g></svg>") repeat-x left center / 120px 16px;
}
.rule-brass { height: 5px; border-top: 1px solid var(--gold); border-bottom: 1px solid var(--gold); opacity: .55; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes riseIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes breath { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.035); } }
@keyframes ping { 0% { transform: scale(.6); opacity: .7; } 100% { transform: scale(1.9); opacity: 0; } }

/* Route content rises in on navigation (the curtain-lift cadence). */
.route-rise { animation: riseIn 460ms var(--ease-bench) both; }
/* A slower idle breath for ceremonial marks (the seal). */
.breath { animation: breath 6s var(--ease-pure-s) infinite; transform-origin: center; }

/* Buttons physically lift on hover, depress on press against their shadow. */
.btn:hover:not(:active):not(:disabled) { transform: translateY(-1px); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 0 #6e1d14, 0 12px 28px var(--wax-tint); }
.stone .btn-primary:hover:not(:disabled) { box-shadow: 0 4px 0 #122a55, 0 12px 28px var(--lapis-tint); }

@media (prefers-reduced-motion: reduce) {
  .route-rise, .breath { animation: none !important; }
  * { scroll-behavior: auto !important; }
}

/* ---- The Writ page background (laid paper + grain) ---- */
.writ-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; background: var(--paper); }
.writ-bg .laid { position: absolute; inset: 0; opacity: .5; mix-blend-mode: multiply; background-image: repeating-linear-gradient(0deg,transparent 0 3px,rgba(27,25,20,.02) 3px 4px); }
[data-theme="dark"] .writ-bg .laid { mix-blend-mode: screen; opacity: .3; background-image: repeating-linear-gradient(0deg,transparent 0 3px,rgba(236,230,212,.016) 3px 4px); }
.writ-bg .grain { position: absolute; inset: 0; opacity: .05; mix-blend-mode: multiply; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='150' height='150'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>"); }
[data-theme="dark"] .writ-bg .grain { mix-blend-mode: overlay; opacity: .08; }
.writ-bg canvas { position: absolute; left: -160px; top: 90px; opacity: .3; }

/* ---- The marble chamber background (Argument) ---- */
.stone-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; background: var(--paper); }
.stone-bg .m { position: absolute; inset: 0; background-image: var(--marble); background-size: cover; background-position: center; }
.stone-bg .scrim { position: absolute; inset: 0; background: radial-gradient(150% 90% at 50% 40%, var(--scrim) 0%, transparent 70%), linear-gradient(180deg, transparent 40%, var(--scrim)); }

/* ============================================================
   COMPONENT CLASSES (theme-aware; primitives wrap these)
   ============================================================ */
.btn {
  font-family: var(--font-mono); font-weight: 600; font-size: 11px;
  letter-spacing: .14em; text-transform: uppercase; cursor: pointer;
  border-radius: var(--r-pill); padding: 13px 22px; display: inline-flex;
  align-items: center; justify-content: center; gap: 9px; border: 1px solid transparent;
  text-decoration: none; transition: transform .12s, box-shadow .3s, background .3s, border-color .3s, color .3s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Keyboard focus rings — restored for controls that suppress the native
   outline. Shown only for keyboard nav (:focus-visible), gold per the Writ;
   inside .stone the gold token already resolves to the marble trim. */
.btn:focus-visible,
.sort-btn:focus-visible,
.leaderboard-tab:focus-visible,
.select-trigger:focus-visible,
.opinion-accordion-btn:focus-visible,
[role="switch"]:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn-primary { color: var(--paper-2); background: var(--wax); border-color: var(--wax-2); box-shadow: 0 2px 0 #6e1d14, 0 8px 20px var(--wax-tint); }
[data-theme="dark"] .btn-primary { color: #1b0e0a; }
.btn-primary:hover { background: var(--wax-2); }
.btn-secondary { color: var(--ink); border-color: var(--line-strong); background: transparent; }
.btn-secondary:hover { border-color: var(--ink); }
.btn-ghost { color: var(--ink-2); background: transparent; border-color: transparent; }
.btn-ghost:hover { color: var(--wax); background: var(--wax-tint); }
/* In the marble chamber, the primary action is lapis, not wax. */
.stone .btn-primary { background: linear-gradient(180deg,var(--lapis-2),var(--lapis)); border-color: var(--lapis-2); color: var(--gold-3); box-shadow: 0 2px 0 #122a55, 0 8px 20px var(--lapis-tint); }
[data-theme="dark"] .stone .btn-primary { color: #0e1b34; }
.stone .btn-primary:hover { background: var(--lapis-2); }

/* Paper panel / card — no backdrop-blur (frosted glass reads as generic;
   the laid-paper material is honestly opaque-tinted). */
.panel, .ds-card {
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--r-xl);
  box-shadow: var(--shadow);
}

/* Badges / tiers */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono);
  font-size: 10px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase;
  padding: 5px 10px; border-radius: var(--r-pill); border: 1px solid;
}
.tier {
  display: inline-flex; align-items: center; font-family: var(--font-mono); font-weight: 600;
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase; padding: 6px 13px;
  border-radius: var(--r-pill); background: color-mix(in srgb, var(--ink) 5%, transparent); border: 1px solid;
}

/* ============================================================
   MOBILE
   ============================================================ */
@media (max-width: 768px) {
  body { font-size: 15px; }
  h1, .h1 { font-size: clamp(26px,7vw,34px); }
  h2, .h2 { font-size: 22px; }
}
