/* =====================================================================
   SyntaxMonkey  -  theme.css   (shared by index.html and practice.html)

   1. Theme tokens   - every colour lives here, once per theme
   2. Base           - tiny resets both pages need
   3. Shared pieces  - brand mark, language icon, name pop-up, buttons

   HOW THEMING WORKS
   - The <html> element carries data-theme="dark" or data-theme="light".
   - A 3-line script in the <head> of both pages sets it BEFORE the first
     paint, from localStorage ("sm_theme") or, if nothing is saved, from the
     visitor's system setting. That is why switching pages never flashes.
   - Page CSS (home.css / app.css) only uses var(--token). Never hard-code a
     colour there; add a token below, for both themes, instead.

   TOKEN NAMES
   Typing screen : --bg --side --line --fg --dim --ok --bad --badbg --acc --grn --glow
   Home page     : --bg-gradient --nav-bg --card-bg --text-main --text-muted
                   --accent-blue --accent-fill --on-accent --accent-red --border-color
   ===================================================================== */

/* ---------- 1. Theme tokens ---------- */

/* Non-colour tokens (identical in both themes) */
:root {
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark is also the fallback when no data-theme attribute is present (no JavaScript) */
:root:not([data-theme]),
[data-theme="dark"] {
  color-scheme: dark;

  /* typing screen */
  --bg: #0c111b;
  --side: #131a28;
  --line: #232c3f;
  --fg: #dbe3f2;
  --dim: #8d99b0;
  --ok: #eef3ff;
  --bad: #ff6b7a;
  --badbg: rgba(255, 93, 108, 0.18);
  --acc: #2b6be8;
  --grn: #4ade80;
  --glow: rgba(43, 107, 232, 0.55);

  /* home page */
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
  --nav-bg: rgba(15, 23, 42, 0.85);
  --card-bg: rgba(30, 41, 59, 0.7);
  --text-main: #f8fafc;
  --text-muted: #a3b1c6;
  --accent-blue: #60a5fa; /* blue text / links / icons on the page background */
  --accent-fill: #2563eb; /* blue button background */
  --on-accent: #ffffff; /* text on --accent-fill */
  --accent-rgb: 96, 165, 250; /* for tinted washes: rgba(var(--accent-rgb), .12) */
  --accent-red: #f87171;
  --red-rgb: 248, 113, 113;
  --border-color: rgba(255, 255, 255, 0.12);
  --row-hover: rgba(255, 255, 255, 0.04);
  --scrim: rgba(2, 6, 23, 0.82);
  --heading-from: #ffffff; /* gradient headings */
  --heading-to: #b4c0d4;
  --rank-1: #facc15;
  --rank-2: #e2e8f0;
  --rank-3: #fb923c;
  --mk-border: #596490;
  --wm-from: #f6a15a;
  --wm-to: #7aa7ff;
  --wpm-color: #9bbcff; /* big WPM number on the typing screen */
  --danger-fill: #c62828; /* "Go to Levels" button */

  /* "main.py" preview card on the home page */
  --bubble-bg: #000000;
  --bubble-fg: #ffffff;
  --editor-bg: #1e1e1e;
  --editor-head: #2d2d2d;
  --editor-line: #404040;
  --editor-fg: #d4d4d4;
  --editor-muted: #a6a6a6;
  --editor-kw: #c586c0;
  --editor-fn: #dcdcaa;
  --editor-cm: #6a9955;
  --editor-strip: #0063a5;
  --editor-strip-fg: #ffffff;
  --editor-strip-muted: #d6e8f7;
}

[data-theme="light"] {
  color-scheme: light;

  /* typing screen */
  --bg: #eef2f9;
  --side: #ffffff;
  --line: #d9e0ee;
  --fg: #1d2638;
  --dim: #5a6479;
  --ok: #0f172a;
  --bad: #b91c1c;
  --badbg: rgba(220, 38, 38, 0.12);
  --acc: #2563eb;
  --grn: #15803d;
  --glow: rgba(37, 99, 235, 0.35);

  /* home page */
  --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%);
  --nav-bg: rgba(248, 250, 252, 0.9);
  --card-bg: rgba(255, 255, 255, 0.92);
  --text-main: #0f172a;
  --text-muted: #475569;
  --accent-blue: #1d4ed8;
  --accent-fill: #2563eb;
  --on-accent: #ffffff;
  --accent-rgb: 37, 99, 235;
  --accent-red: #991b1b;
  --red-rgb: 153, 27, 27;
  --border-color: rgba(15, 23, 42, 0.14);
  --row-hover: rgba(15, 23, 42, 0.04);
  --scrim: rgba(15, 23, 42, 0.55);
  --heading-from: #0f172a;
  --heading-to: #475569;
  --rank-1: #854d0e;
  --rank-2: #475569;
  --rank-3: #c2410c;
  --mk-border: #8a94b8;
  --wm-from: #c2570c;
  --wm-to: #2f5fd0;
  --wpm-color: #1d4ed8;
  --danger-fill: #c62828;

  /* "main.py" preview card on the home page */
  --bubble-bg: #ffffff;
  --bubble-fg: #0f172a;
  --editor-bg: #ffffff;
  --editor-head: #eef2f7;
  --editor-line: #d6dce6;
  --editor-fg: #1f2937;
  --editor-muted: #5b6575;
  --editor-kw: #8f2fa0;
  --editor-fn: #7a5a14;
  --editor-cm: #3f7a2a;
  --editor-strip: #0b5cab;
  --editor-strip-fg: #ffffff;
  --editor-strip-muted: #d6e8f7;
}

/* ---------- 2. Base ---------- */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
button,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
button:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 2px;
}

/* Visually hidden but still read by screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 3. Shared pieces ---------- */

/* Logo in the top bar of both pages */
.mk {
  width: 43px;
  height: 43px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--side);
  border: 2px solid var(--mk-border);
  font-size: 22px;
}

/* Light / dark switch, same markup on both pages: a round button with a sun (shown in dark
   mode, click for light) and a moon (shown in light mode, click for dark). */
.tg {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--side);
  border: 1px solid var(--line);
  color: var(--fg);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.tg:hover {
  border-color: var(--acc);
}
.tg svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tg .i-moon {
  display: none;
}
[data-theme="light"] .tg .i-sun {
  display: none;
}
[data-theme="light"] .tg .i-moon {
  display: block;
}

/* Small language icon (Py, JS, C++ ...). Colours are set per language. */
.ic {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: inline-grid;
  place-items: center;
  font: 700 10px var(--ui);
  font-style: normal;
  flex: none;
}

/* Small pill label ("Live Rankings", "One-Time Setup") */
.sm-lb-badge {
  display: inline-block;
  margin-bottom: 0.5rem;
  padding: 0.22rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-blue);
  background: rgba(var(--accent-rgb), 0.12);
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  border-radius: 6px;
}

/* Name pop-up ("Enter Your Coder Tag"), built by leaderboard.js on either page, and the buttons it shares with the feedback form */
.sm-name-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--scrim);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sm-name-modal.open {
  display: flex;
}

.sm-name-card {
  width: min(420px, 100%);
  padding: 1.75rem;
  background: var(--editor-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  text-align: left;
}

.sm-name-card h3 {
  margin: 0 0 0.45rem;
  font-size: 1.25rem;
  color: var(--text-main);
}

.sm-name-card p {
  margin: 0 0 1.2rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.sm-input-group {
  display: flex;
  align-items: center;
  background: var(--nav-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0 0.8rem;
  transition: border-color 0.15s ease;
}

.sm-input-group:focus-within {
  border-color: var(--accent-blue);
}

.sm-input-prefix {
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.95rem;
  margin-right: 0.35rem;
}

.sm-input-group input {
  width: 100%;
  padding: 0.72rem 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: var(--mono);
  font-size: 1rem;
}

.sm-name-error {
  display: block;
  min-height: 1.15rem;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--accent-red);
}

.sm-name-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.sm-btn-ghost,
.sm-btn-primary {
  padding: 0.55rem 1.05rem;
  border-radius: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.sm-btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.sm-btn-ghost:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

.sm-btn-primary {
  background: var(--accent-fill);
  color: var(--on-accent);
  border: 1px solid var(--accent-fill);
}

.sm-btn-primary:hover {
  opacity: 0.92;
}

.sm-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.sm-btn-ghost:focus-visible,
.sm-btn-primary:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}
