/* ==========================================================
   TypeRush — design tokens
   Palette: ink charcoal + warm keycap amber + muted teal
   Type: Inter (UI) / IBM Plex Mono (typing text, data)
   Signature: the "keycap" caret around the active character
   ========================================================== */

:root {
  --bg: #16171a;
  --bg-elevated: #1d1f24;
  --bg-card: #202226;
  --border: #2b2e34;
  --text: #ece9e2;
  --text-muted: #83868d;
  --text-faint: #4a4d54;
  --accent: #e3a346;
  --accent-ink: #16171a;
  --accent-soft: rgba(227, 163, 70, 0.14);
  --accent-2: #5fb8a8;
  --error: #e2574c;
  --error-soft: rgba(226, 87, 76, 0.14);
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 10px;
  --shadow-key: 0 2px 0 rgba(0,0,0,0.35), 0 6px 16px rgba(0,0,0,0.25);
}

html[data-theme="light"] {
  --bg: #f5f3ee;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e2dfd6;
  --text: #232420;
  --text-muted: #8b8a82;
  --text-faint: #c7c4b8;
  --accent: #c8791f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(200, 121, 31, 0.12);
  --accent-2: #2f8f7e;
  --shadow-key: 0 2px 0 rgba(0,0,0,0.08), 0 6px 16px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .25s ease, color .25s ease;
}

a { color: inherit; text-decoration: none; }
kbd {
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---------- top bar ---------- */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.topbar__inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.logo__mark {
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 6px;
}
.tagline { margin: 0 0 0 4px; color: var(--text-muted); font-size: 0.85rem; flex: 1; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- ad slots ---------- */
.ad-slot { max-width: 1040px; margin: 16px auto; text-align: center; min-height: 0; }
.sidebar-ad { display: none; }
@media (min-width: 1280px) {
  .sidebar-ad {
    display: block;
    position: fixed;
    right: 16px;
    top: 120px;
    width: 200px;
  }
}

/* ---------- layout ---------- */
.app {
  flex: 1;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* ---------- controls ---------- */
.controls { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pillgroup {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.pill {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.pill:hover { color: var(--text); }
.pill.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- live stats ---------- */
.stats-live { font-family: var(--font-mono); color: var(--accent); font-size: 1.6rem; min-height: 2rem; opacity: 0; transition: opacity .2s; }
.stats-live.is-visible { opacity: 1; }

/* ---------- typing stage ---------- */
.type-stage { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.type-card {
  position: relative;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  cursor: text;
}
.words {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  line-height: 2.2rem;
  letter-spacing: 0.2px;
  color: var(--text-faint);
  max-height: 6.6rem;
  overflow: hidden auto;
  outline: none;
}
.words--zen { color: var(--text); white-space: pre-wrap; }
.words.is-blurred { filter: blur(4px); opacity: .5; }
.hidden-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  height: 1px; width: 1px;
}
.hint { color: var(--text-muted); font-size: 0.8rem; margin: 0; }

.char { position: relative; }
.char--typed-correct { color: var(--text); }
.char--typed-incorrect { color: var(--error); background: var(--error-soft); border-radius: 2px; }
.char--extra { color: var(--error); text-decoration: underline; }
.word { display: inline-block; margin-right: 0.5em; }

/* the keycap caret — signature element */
.char--current {
  border-radius: 3px;
  box-shadow:
    inset 0 -2px 0 var(--accent),
    var(--shadow-key);
  background: var(--accent-soft);
}
.char--current::before {
  content: "";
  position: absolute;
  left: -1px; top: -2px; bottom: -2px;
  width: 2px;
  background: var(--accent);
  animation: caretBlink 1s step-end infinite;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* ---------- results ---------- */
.results { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.results__grid {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}
.results__primary { display: flex; gap: 40px; }
.results__block { display: flex; flex-direction: column; }
.results__secondary { display: flex; gap: 28px; flex-wrap: wrap; }
.results__secondary > div { display: flex; flex-direction: column; }
.results__label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 4px; }
.results__value { font-family: var(--font-mono); font-size: 3rem; font-weight: 600; color: var(--accent); line-height: 1; }
.results__value--sm { font-size: 1.15rem; color: var(--text); font-weight: 500; }
#resultAcc { color: var(--accent-2); }

.btn-restart {
  font-family: var(--font-mono);
  display: flex; align-items: center; gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}
.btn-restart svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-restart:hover { filter: brightness(1.08); }

/* ---------- footer ---------- */
.sitefoot { text-align: center; color: var(--text-muted); font-size: 0.78rem; padding: 20px; border-top: 1px solid var(--border); }

/* ---------- popup ---------- */
.popup-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 999;
}
.popup-box {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; max-width: 480px; width: 92%;
  box-shadow: var(--shadow-key);
}
.popup-close {
  position: absolute; top: 10px; right: 14px; background: none; border: none;
  color: var(--text-muted); font-size: 1.4rem; cursor: pointer;
}

@media (max-width: 640px) {
  .words { font-size: 1.15rem; line-height: 1.9rem; }
  .results__value { font-size: 2.1rem; }
  .results__primary { gap: 24px; }
}
