@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Mono:ital,wght@0,300;0,400;0,500;1,400&display=swap');

:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #1a1a1a;
  --border: #222222;
  --red: #e63946;
  --red-dim: rgba(230, 57, 70, 0.12);
  --green: #00ff15;
  --green-dim: rgba(6, 214, 160, 0.12);
  --text: #f0ede8;
  --text-dim: #888888;
  --text-muted: #444444;
  --font-body: 'DM Mono', monospace;
  --font-display: 'Syne', sans-serif;
  --radius: 6px;
  --radius-lg: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: 0.4;
}

/* ── Typography ──────────────────────────────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

a { color: inherit; text-decoration: none; }

/* ── Logo ──────────────────────────────────────────────────────────────── */

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.04em;
  position: relative;
  display: inline-block;
  color: var(--text);
}

.logo span {
  color: var(--red);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--red);
}

/* ── Nav ───────────────────────────────────────────────────────────────── */

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 40px;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-actions { display: flex; gap: 10px; align-items: center; }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.btn-primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn-primary:hover { background: #c62d3a; border-color: #c62d3a; transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover { border-color: var(--text-dim); background: var(--surface); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }

.btn-green {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  font-weight: 600;
}
.btn-green:hover { background: #04b388; transform: translateY(-1px); }

.btn-lg {
  padding: 14px 32px;
  font-size: 15px;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* ── Hero ───────────────────────────────────────────────────────────────── */

.hero {
  padding: 120px 40px 80px;
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
  animation: fadeUp 0.6s ease both;
}

.hero-eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--red);
  border: 1px solid var(--red-dim);
  background: var(--red-dim);
  padding: 4px 12px;
  border-radius: 99px;
  margin-bottom: 28px;
}

.hero h1 {
  font-size: clamp(3rem, 8vw, 6.5rem);
  color: var(--text);
  margin-bottom: 24px;
}

.hero h1 .strike {
  color: var(--red);
  text-decoration: line-through;
  text-decoration-thickness: 4px;
}

.hero h1 .correct {
  color: var(--green);
}

.hero-sub {
  font-size: 16px;
  color: var(--text-dim);
  max-width: 520px;
  margin: 0 auto 40px;
  line-height: 1.7;
}

.hero-cta { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ── Game Configurator ─────────────────────────────────────────────────── */

.configurator {
  max-width: 680px;
  margin: 0 auto 80px;
  padding: 0 40px;
  animation: fadeUp 0.6s 0.1s ease both;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.config-section { margin-bottom: 28px; }
.config-label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* Difficulty toggle */
.difficulty-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.diff-btn {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  color: var(--text);
  font-family: var(--font-body);
}

.diff-btn .diff-name {
  font-size: 13px;
  font-weight: 500;
  display: block;
  margin-bottom: 4px;
}

.diff-btn .diff-desc {
  font-size: 11px;
  color: var(--text-dim);
  display: block;
}

.diff-btn.active { border-color: var(--red); background: var(--red-dim); color: var(--text); }
.diff-btn:hover:not(.active) { border-color: var(--text-muted); }

/* Error types */
.error-types { display: flex; flex-wrap: wrap; gap: 8px; }

.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text-dim);
  transition: all 0.15s;
  user-select: none;
}

.type-chip input { display: none; }
.type-chip.active { border-color: var(--green); background: var(--green-dim); color: var(--text); }
.type-chip:hover:not(.active) { border-color: var(--text-muted); color: var(--text); }

/* Source toggle */
.source-toggle { display: flex; gap: 8px; }

.source-btn {
  flex: 1;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s;
}
.source-btn.active { border-color: var(--text-dim); color: var(--text); background: var(--surface); }

.config-actions { display: flex; gap: 10px; margin-top: 28px; }
.config-actions .btn { flex: 1; justify-content: center; }

/* ── Leaderboard ──────────────────────────────────────────────────────── */

.leaderboard-section {
  max-width: 780px;
  margin: 0 auto 100px;
  padding: 0 40px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
}

.filter-tabs { display: flex; gap: 4px; }
.filter-tab {
  padding: 6px 14px;
  border-radius: 99px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-body);
  transition: all 0.15s;
}
.filter-tab.active { background: var(--surface-2); border-color: var(--text-muted); color: var(--text); }

.leaderboard-table { width: 100%; border-collapse: collapse; }
.leaderboard-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.lb-rank {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-muted);
  width: 40px;
}

.lb-rank.top-1 { color: #FFD700; }
.lb-rank.top-2 { color: #C0C0C0; }
.lb-rank.top-3 { color: #CD7F32; }

.lb-user { display: flex; align-items: center; gap: 12px; }
.lb-avatar { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); }
.lb-username { font-size: 14px; font-weight: 500; }
.lb-score { font-family: var(--font-display); font-size: 1.3rem; font-weight: 800; color: var(--green); }
.lb-games { color: var(--text-dim); font-size: 13px; }

.leaderboard-table tr:hover td { background: var(--surface); }

/* ── Footer ─────────────────────────────────────────────────────────────── */

footer {
  border-top: 1px solid var(--border);
  padding: 24px 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.05em;
}

/* ── Game Page ──────────────────────────────────────────────────────────── */

.game-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

@media (max-width: 768px) {
  .game-layout { grid-template-columns: 1fr; }
}

.game-main { min-width: 0; }
.game-sidebar { position: sticky; top: 80px; height: fit-content; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.game-title {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
}

.progress-bar-wrap {
  background: var(--surface-2);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--green));
  border-radius: 99px;
  transition: width 0.3s ease;
}

.progress-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

/* Text display */
.text-display {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.9;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
}

.error-word {
  color: var(--red);
  text-decoration: underline wavy var(--red);
  text-decoration-thickness: 1.5px;
  cursor: pointer;
  border-radius: 3px;
  padding: 0 2px;
  transition: background 0.15s;
  position: relative;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}

.error-word:hover {
  background: var(--red-dim);
  animation: shake 0.3s ease;
}

.error-word.corrected {
  color: var(--green);
  text-decoration: underline var(--green);
  text-decoration-thickness: 1.5px;
}

.error-word.corrected:hover { background: var(--green-dim); animation: none; }

.word-selectable.corrected {
  color: var(--text-dim);
  text-decoration: none;
}
.word-selectable.corrected:hover { background: var(--surface); }

/* Correction popup */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

.popup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 380px;
  max-width: 90vw;
  animation: popIn 0.2s ease;
}

.popup-label { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; letter-spacing: 0.05em; }
.popup-word {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--red);
  margin-bottom: 20px;
}

.popup-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 12px 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.popup-input:focus { border-color: var(--green); }
.popup-actions { display: flex; gap: 8px; }
.popup-actions .btn { flex: 1; }

/* Sidebar stats */
.sidebar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}

.stat-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.stat-label { font-size: 12px; color: var(--text-dim); }
.stat-value { font-family: var(--font-display); font-size: 1.4rem; font-weight: 800; }
.stat-value.red { color: var(--red); }
.stat-value.green { color: var(--green); }

/* Timer */
.timer {
  text-align: center;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}

.timer-value {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  transition: color 0.3s;
}

.timer-value.urgent { color: var(--red); }
.timer-label { font-size: 11px; color: var(--text-muted); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 4px; }

/* Results */
.results {
  max-width: 780px;
  margin: 0 auto;
  padding: 40px 24px;
}

.score-display {
  text-align: center;
  margin-bottom: 48px;
}

.score-big {
  font-family: var(--font-display);
  font-size: 7rem;
  font-weight: 800;
  line-height: 1;
  background: linear-gradient(135deg, var(--green), var(--red));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-label { font-size: 14px; color: var(--text-dim); margin-top: 8px; }

.results-table { width: 100%; border-collapse: collapse; }
.results-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.results-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.result-correct { color: var(--green); }
.result-wrong { color: var(--red); }
.result-explanation { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ── VS Page ────────────────────────────────────────────────────────────── */

.vs-setup {
  max-width: 600px;
  margin: 80px auto;
  padding: 0 24px;
  text-align: center;
}

.vs-title {
  font-family: var(--font-display);
  font-size: 3rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.vs-sep {
  color: var(--red);
  font-weight: 800;
}

.vs-options { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 40px; }

@media (max-width: 500px) { .vs-options { grid-template-columns: 1fr; } }

.room-code-display {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--green);
  padding: 20px;
  border: 1px dashed var(--green);
  border-radius: var(--radius-lg);
  margin: 20px 0;
}

.vs-game {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  padding: 16px;
  gap: 16px;
}

.vs-scores {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
}

.vs-player {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.vs-player.me { border-color: var(--green); }
.vs-player.opponent { border-color: var(--text-muted); }
.vs-player-name { font-size: 13px; color: var(--text-dim); flex: 1; }
.vs-player-score {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
}
.vs-player.me .vs-player-score { color: var(--green); }

.vs-center { text-align: center; }

.vs-finish-screen {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.95);
  backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 24px;
}

.winner-label {
  font-size: 13px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.winner-name {
  font-family: var(--font-display);
  font-size: 5rem;
  font-weight: 800;
  color: var(--green);
  line-height: 1;
}

/* ── Profile Page ───────────────────────────────────────────────────────── */

.profile-layout {
  max-width: 1000px;
  margin: 0 auto;
  padding: 40px 24px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 40px;
}

.profile-avatar { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--green); }
.profile-name { font-family: var(--font-display); font-size: 2rem; font-weight: 800; }
.profile-since { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-card-value { font-family: var(--font-display); font-size: 2.5rem; font-weight: 800; color: var(--text); }
.stat-card-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 32px;
  height: 280px;
}

.history-table { width: 100%; border-collapse: collapse; }
.history-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.history-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}
.badge-easy { background: rgba(6,214,160,0.15); color: var(--green); }
.badge-medium { background: rgba(255,165,0,0.15); color: #FFA500; }
.badge-hard { background: var(--red-dim); color: var(--red); }

/* ── Modal ──────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 420px;
  max-width: 90vw;
  animation: popIn 0.2s ease;
}

.modal-title { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; margin-bottom: 24px; }
.modal-close { float: right; cursor: pointer; color: var(--text-dim); font-size: 20px; line-height: 1; margin-top: -4px; }

.form-group { margin-bottom: 16px; }
.form-label { font-size: 12px; color: var(--text-dim); letter-spacing: 0.05em; margin-bottom: 6px; display: block; }
.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--green); }
.form-error { font-size: 12px; color: var(--red); margin-top: 8px; }

/* ── Notifications ─────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-size: 13px;
  z-index: 9000;
  animation: toastIn 0.3s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ── Animations ─────────────────────────────────────────────────────────── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Loading ────────────────────────────────────────────────────────────── */

.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  z-index: 9998;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { font-size: 13px; color: var(--text-dim); }

/* ── Responsive tweaks ──────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .nav { padding: 12px 16px; }
  .hero { padding: 60px 16px 48px; }
  .configurator, .leaderboard-section { padding: 0 16px; }
  .difficulty-group { grid-template-columns: 1fr; }
  .game-layout { padding: 16px; }
}

/* ── Hidden util ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
