/* ==========================================================================
   tokens.css — Single source of truth for design tokens.
   Nothing outside this file may hardcode colors, spacing or radii.
   Themes are switched by setting [data-theme] on <html>.
   ========================================================================== */

:root {
  /* ---- Typography ------------------------------------------------------ */
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Home keycap wordmark & labels (ported from home.html). */
  --font-display: "Saira Stencil One", Impact, "Arial Narrow", sans-serif;
  --font-mono-home: "IBM Plex Mono", var(--font-mono);

  /* Fluid type scale */
  --fs-xs: 0.75rem;
  --fs-sm: 0.85rem;
  --fs-md: 1rem;
  --fs-lg: 1.15rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;
  --fs-3xl: 2.75rem;

  /* Arena is driven by a token so Settings can scale it at runtime. */
  --arena-font-size: 1.6rem;
  --arena-line-height: 1.6;
  --arena-lines-visible: 3;

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* ---- Spacing scale --------------------------------------------------- */
  --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;

  /* ---- Radii ----------------------------------------------------------- */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* ---- Motion ---------------------------------------------------------- */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 90ms;
  --dur-med: 160ms;
  --dur-slow: 260ms;

  /* ---- Elevation / depth ---------------------------------------------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.42);

  /* ---- Layout ---------------------------------------------------------- */
  --content-max: 1060px;
  --card-radius: var(--radius-lg);

  /* ---- Element rank accents (shared across all themes) ----------------- */
  --el-iron: #8d9099;
  --el-bronze: #b87333;
  --el-silver: #9fb0c0;
  --el-gold: #ddb14a;
  --el-platinum: #6fd6c4;
  --el-titanium: #7c8cf8;
  --el-obsidian: #a06bff;

  /* Runtime-updated caret coordinates (set from JS as custom props). */
  --caret-x: 0px;
  --caret-y: 0px;
  --caret-h: 1.2em;
  --opp-caret-x: 0px;
  --opp-caret-y: 0px;
  --opp-caret-h: 1.2em;

  /* Opponent identification accent & caret */
  --opp-accent: #fb7185;
  --opp-caret: #38bdf8;

  /* Avatar badge foreground (on top of the per-user hue). */
  --avatar-fg: #ffffff;

  /* ---- Home keycaps (tactile mechanical keys, ported from home.html) --- */
  --key-bg: #2b2d30;
  --key-border: #101113;
  --key-face-top: #41454a;
  --key-face-bottom: #383b40;
  --key-lip: rgba(226, 183, 20, 0.45);
  --key-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
  --key-shadow-active: 0 1px 3px rgba(0, 0, 0, 0.4);
  --key-primary-bg: #8a6a14;
  --key-primary-fg: #2a2410;
  --key-primary-face-top: #eac02a;
  --key-primary-face-bottom: #e2b714;
  --key-primary-lip: #f1cd62;
  --key-primary-kbd: #3d300a;

  /* ---- Home keyboard backdrop (SVG faces) ----------------------------- */
  --kb-deep: #1b1c1e;
  --kb-deep-edge: #111214;
  --kb-face: #2c2d30;
  --kb-face-edge: #151618;
  --kb-lip: rgba(226, 183, 20, 0.55);
  --kb-top: #393a3d;
  --kb-top-edge: #46474a;
  --kb-label: rgba(226, 183, 20, 0.45);
}

/* ==========================================================================
   Theme: dark-minimal  (DEFAULT)
   Matte, tactile, low-glare surfaces inspired by Monkeytype's dark theme.
   ========================================================================== */
[data-theme="dark-minimal"] {
  --bg: #323437;
  --bg-elevated: #2b2d30;
  --surface: #2c2e31;
  --surface-2: #363a3d;
  --surface-3: #414449;
  --border: #414449;
  --border-strong: #4d5155;

  --text: #d1d0c5;
  --text-muted: #8f9193;
  --text-dim: #646669;

  --accent: #e2b714;
  --accent-hover: #f0c520;
  --accent-soft: rgba(226, 183, 20, 0.14);
  --on-accent: #2c2e31;

  --correct: #d1d0c5;
  --incorrect: #ca4754;
  --incorrect-soft: rgba(202, 71, 84, 0.22);
  --caret: #e2b714;

  --btn-bg: var(--surface-2);
  --btn-bg-hover: var(--surface-3);
  --btn-border: var(--border);
  --overlay: rgba(20, 21, 23, 0.72);

  /* ---- Phase 2: matchmaking, status, glow, outcome ------------------- */
  --badge-started-bg: rgba(143, 145, 147, 0.18);
  --badge-started-fg: #b6b7b1;
  --badge-mid-bg: rgba(111, 214, 196, 0.16);
  --badge-mid-fg: #6fd6c4;
  --badge-final-bg: rgba(226, 183, 20, 0.22);
  --badge-final-fg: #f0c520;
  --flow-glow: 0 0 0 2px rgba(111, 214, 196, 0.7),
    0 0 16px rgba(111, 214, 196, 0.55);
  --color-victory: #6fd6c4;
  --color-victory-soft: rgba(111, 214, 196, 0.16);
  --color-defeat: #ca4754;
  --color-defeat-soft: rgba(202, 71, 84, 0.18);
  --queue-dash: rgba(143, 145, 147, 0.5);
  --modal-overlay: rgba(14, 15, 17, 0.82);

  --auth-badge-bg: rgba(226, 183, 20, 0.12);
  --auth-badge-fg: #e2b714;
  --auth-badge-border: rgba(226, 183, 20, 0.28);
  --auth-connected-bg: rgba(111, 214, 196, 0.14);
  --auth-connected-fg: #6fd6c4;
  --auth-notice-bg: #363a3d;
  --auth-notice-border: #4d5155;
  --auth-overlay: rgba(14, 15, 17, 0.82);
}

/* ==========================================================================
   Theme: light-tactile
   Warm paper background, crisp white cards, ink text.
   ========================================================================== */
[data-theme="light-tactile"] {
  --bg: #f1eee8;
  --bg-elevated: #e9e5dd;
  --surface: #ffffff;
  --surface-2: #f6f4ef;
  --surface-3: #ebe7df;
  --border: #ded8cd;
  --border-strong: #c9c1b3;

  --text: #26251f;
  --text-muted: #6f6a5d;
  --text-dim: #a49d8f;

  --accent: #2563eb;
  --accent-hover: #1d4fd8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --on-accent: #ffffff;

  --correct: #26251f;
  --incorrect: #d5384a;
  --incorrect-soft: rgba(213, 56, 74, 0.14);
  --caret: #2563eb;

  --btn-bg: var(--surface);
  --btn-bg-hover: var(--surface-3);
  --btn-border: var(--border);
  --overlay: rgba(40, 38, 32, 0.34);
  --shadow-sm: 0 1px 2px rgba(60, 55, 45, 0.1);
  --shadow-md: 0 6px 18px rgba(60, 55, 45, 0.14);
  --shadow-lg: 0 18px 44px rgba(60, 55, 45, 0.2);

  /* ---- Phase 2: matchmaking, status, glow, outcome ------------------- */
  --badge-started-bg: rgba(111, 106, 93, 0.14);
  --badge-started-fg: #6f6a5d;
  --badge-mid-bg: rgba(22, 130, 100, 0.14);
  --badge-mid-fg: #168264;
  --badge-final-bg: rgba(37, 99, 235, 0.14);
  --badge-final-fg: #1d4fd8;
  --flow-glow: 0 0 0 2px rgba(22, 163, 120, 0.55),
    0 0 16px rgba(22, 163, 120, 0.35);
  --color-victory: #16a378;
  --color-victory-soft: rgba(22, 163, 120, 0.14);
  --color-defeat: #d5384a;
  --color-defeat-soft: rgba(213, 56, 74, 0.14);
  --queue-dash: rgba(111, 106, 93, 0.4);
  --modal-overlay: rgba(28, 26, 22, 0.5);

  --auth-badge-bg: rgba(37, 99, 235, 0.1);
  --auth-badge-fg: #1d4fd8;
  --auth-badge-border: rgba(37, 99, 235, 0.24);
  --auth-connected-bg: rgba(22, 130, 100, 0.12);
  --auth-connected-fg: #168264;
  --auth-notice-bg: #f6f4ef;
  --auth-notice-border: #c9c1b3;
  --auth-overlay: rgba(28, 26, 22, 0.5);
}

/* ==========================================================================
   Theme: midnight-slate
   Deep blue-slate surfaces with a soft periwinkle accent.
   ========================================================================== */
[data-theme="midnight-slate"] {
  --bg: #141821;
  --bg-elevated: #11151d;
  --surface: #1b202b;
  --surface-2: #222836;
  --surface-3: #2b3242;
  --border: #29303f;
  --border-strong: #384053;

  --text: #c9d1e0;
  --text-muted: #8089a0;
  --text-dim: #545d73;

  --accent: #7aa2f7;
  --accent-hover: #93b4ff;
  --accent-soft: rgba(122, 162, 247, 0.14);
  --on-accent: #10141c;

  --correct: #c9d1e0;
  --incorrect: #f7768e;
  --incorrect-soft: rgba(247, 118, 142, 0.2);
  --caret: #7aa2f7;

  --btn-bg: var(--surface-2);
  --btn-bg-hover: var(--surface-3);
  --btn-border: var(--border);
  --overlay: rgba(8, 10, 15, 0.7);

  /* ---- Phase 2: matchmaking, status, glow, outcome ------------------- */
  --badge-started-bg: rgba(128, 137, 160, 0.16);
  --badge-started-fg: #9aa3b8;
  --badge-mid-bg: rgba(122, 162, 247, 0.16);
  --badge-mid-fg: #93b4ff;
  --badge-final-bg: rgba(181, 130, 255, 0.22);
  --badge-final-fg: #c9a6ff;
  --flow-glow: 0 0 0 2px rgba(122, 162, 247, 0.7),
    0 0 18px rgba(122, 162, 247, 0.5);
  --color-victory: #93b4ff;
  --color-victory-soft: rgba(122, 162, 247, 0.16);
  --color-defeat: #f7768e;
  --color-defeat-soft: rgba(247, 118, 142, 0.18);
  --queue-dash: rgba(128, 137, 160, 0.45);
  --modal-overlay: rgba(6, 8, 13, 0.82);

  --auth-badge-bg: rgba(122, 162, 247, 0.12);
  --auth-badge-fg: #93b4ff;
  --auth-badge-border: rgba(122, 162, 247, 0.28);
  --auth-connected-bg: rgba(122, 162, 247, 0.14);
  --auth-connected-fg: #93b4ff;
  --auth-notice-bg: #222836;
  --auth-notice-border: #384053;
  --auth-overlay: rgba(6, 8, 13, 0.82);
}

/* ==========================================================================
   Theme: extreme-bw
   Pure #000000 void black & #ffffff crisp high-contrast monochrome.
   ========================================================================== */
[data-theme="extreme-bw"] {
  --bg: #000000;
  --bg-elevated: #050505;
  --surface: #0a0a0a;
  --surface-2: #141414;
  --surface-3: #242424;
  --border: #2c2c2c;
  --border-strong: #ffffff;

  --text: #ffffff;
  --text-muted: #a3a3a3;
  --text-dim: #666666;

  --accent: #ffffff;
  --accent-hover: #e5e5e5;
  --accent-soft: rgba(255, 255, 255, 0.14);
  --on-accent: #000000;

  --correct: #ffffff;
  --incorrect: #ff4d4d;
  --incorrect-soft: rgba(255, 77, 77, 0.22);
  --caret: #ffffff;
  --opp-accent: #a3a3a3;
  --opp-caret: #a3a3a3;

  --btn-bg: #121212;
  --btn-bg-hover: #202020;
  --btn-border: #333333;
  --overlay: rgba(0, 0, 0, 0.85);

  --badge-started-bg: rgba(255, 255, 255, 0.14);
  --badge-started-fg: #ffffff;
  --badge-mid-bg: rgba(163, 163, 163, 0.16);
  --badge-mid-fg: #a3a3a3;
  --badge-final-bg: rgba(255, 255, 255, 0.22);
  --badge-final-fg: #ffffff;
  --flow-glow: 0 0 0 2px rgba(255, 255, 255, 0.8),
    0 0 16px rgba(255, 255, 255, 0.45);
  --color-victory: #ffffff;
  --color-victory-soft: rgba(255, 255, 255, 0.16);
  --color-defeat: #ff4d4d;
  --color-defeat-soft: rgba(255, 77, 77, 0.18);
  --queue-dash: rgba(255, 255, 255, 0.45);
  --modal-overlay: rgba(0, 0, 0, 0.88);

  --auth-badge-bg: rgba(255, 255, 255, 0.1);
  --auth-badge-fg: #ffffff;
  --auth-badge-border: rgba(255, 255, 255, 0.35);
  --auth-connected-bg: rgba(255, 255, 255, 0.18);
  --auth-connected-fg: #ffffff;
  --auth-notice-bg: #121212;
  --auth-notice-border: #333333;
  --auth-overlay: rgba(0, 0, 0, 0.88);

  /* Monochrome home keycaps & keyboard backdrop */
  --key-bg: #080808;
  --key-border: #2a2a2a;
  --key-face-top: #181818;
  --key-face-bottom: #0d0d0d;
  --key-lip: rgba(255, 255, 255, 0.4);
  --key-primary-bg: #737373;
  --key-primary-fg: #000000;
  --key-primary-face-top: #ffffff;
  --key-primary-face-bottom: #e5e5e5;
  --key-primary-lip: #ffffff;
  --key-primary-kbd: #000000;

  --kb-deep: #000000;
  --kb-deep-edge: #111111;
  --kb-face: #0a0a0a;
  --kb-face-edge: #1c1c1c;
  --kb-lip: rgba(255, 255, 255, 0.4);
  --kb-top: #141414;
  --kb-top-edge: #2c2c2c;
  --kb-label: rgba(255, 255, 255, 0.45);
}

/* ==========================================================================
   Component primitives (tokens only — layout lives in main.css)
   ========================================================================== */

/* ---- Card surface ------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow-sm);
}

/* ---- Button system ----------------------------------------------------- */
.btn {
  --btn-pad-y: 0.7rem;
  --btn-pad-x: 1.25rem;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  line-height: 1;
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}

.btn:active {
  transform: translateY(1px);
}

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

/* Primary — accent filled */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Secondary — solid surface */
.btn-secondary {
  background: var(--btn-bg);
  border-color: var(--btn-border);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--btn-bg-hover);
}

/* Ghost — borderless, subtle hover */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* Size modifier used by compact controls */
.btn-sm {
  --btn-pad-y: 0.45rem;
  --btn-pad-x: 0.8rem;
  font-size: var(--fs-sm);
}
