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

:root {
  --bg:       #0d0d1a;
  --surface:  #16213e;
  --card:     #1a1a2e;
  --border:   #2a2a4a;
  --primary:  #6c63ff;
  --primary-h:#8b85ff;
  --accent:   #00d4aa;
  --danger:   #ff4757;
  --warning:  #ffa502;
  --text:     #e8e8f0;
  --muted:    #8888aa;
  --radius:   12px;
  --shadow:   0 4px 24px rgba(0,0,0,.4);
}

html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────── */
.container { max-width: 860px; margin: 0 auto; padding: 0 16px; }

/* ── Navbar ──────────────────────────────────────────────── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.navbar .logo { font-size: 1.4rem; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.navbar .logo span { color: var(--accent); }
.nav-link { color: var(--muted); text-decoration: none; font-size: .9rem; transition: color .2s; }
.nav-link:hover { color: var(--text); }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 11px 22px; border-radius: 8px;
  border: none; cursor: pointer; font-size: .95rem; font-weight: 600;
  transition: transform .1s, filter .15s; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); }
.btn-accent  { background: var(--accent);  color: #0d0d1a; }
.btn-accent:hover  { filter: brightness(1.1); }
.btn-outline {
  background: transparent; color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-lg      { padding: 14px 32px; font-size: 1.05rem; border-radius: 10px; }
.btn-full    { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Inputs ──────────────────────────────────────────────── */
.input {
  width: 100%; padding: 11px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem;
  transition: border-color .2s;
}
.input:focus { outline: none; border-color: var(--primary); }
.input::placeholder { color: var(--muted); }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 6px; }
.form-group { margin-bottom: 16px; }

/* ── Badge ───────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
}
.badge-easy   { background: #00d4aa22; color: var(--accent); }
.badge-medium { background: #ffa50222; color: var(--warning); }
.badge-hard   { background: #ff475722; color: var(--danger); }
.badge-primary { background: var(--primary); color: #fff; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 18px; font-size: .9rem;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none;
  transition: opacity .3s; z-index: 999;
}
#toast.show { opacity: 1; pointer-events: auto; }

/* ── Game answer buttons ─────────────────────────────────── */
.answer-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-top: 24px;
}
.answer-btn {
  padding: 18px 16px; border-radius: 10px; border: 2px solid var(--border);
  background: var(--surface); color: var(--text); font-size: .95rem;
  cursor: pointer; text-align: left; transition: border-color .15s, background .15s;
  line-height: 1.4;
}
.answer-btn:hover:not(:disabled) { border-color: var(--primary); background: #6c63ff18; }
.answer-btn.correct  { border-color: var(--accent) !important; background: #00d4aa22 !important; color: var(--accent); }
.answer-btn.wrong    { border-color: var(--danger) !important; background: #ff475722 !important; color: var(--danger); }
.answer-btn:disabled { cursor: default; }
.answer-letter {
  display: inline-block; width: 26px; height: 26px; border-radius: 50%;
  background: var(--border); text-align: center; line-height: 26px;
  font-size: .8rem; font-weight: 700; margin-right: 10px; flex-shrink: 0;
}

/* ── Timer bar ───────────────────────────────────────────── */
.timer-bar-wrap { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.timer-bar { height: 100%; background: var(--accent); border-radius: 99px; transition: width .1s linear, background .3s; }
.timer-bar.danger { background: var(--danger); }

/* ── Score pill ──────────────────────────────────────────── */
.hud {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  padding: 12px 0; margin-bottom: 8px;
}
.hud-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.hud-value { font-size: 1.2rem; font-weight: 800; }

/* ── Leaderboard table ───────────────────────────────────── */
.lb-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.lb-table th { color: var(--muted); font-weight: 600; text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.lb-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: var(--surface); }
.rank-1 { color: #ffd700; font-weight: 800; }
.rank-2 { color: #c0c0c0; font-weight: 700; }
.rank-3 { color: #cd7f32; font-weight: 700; }

/* ── Result page ─────────────────────────────────────────── */
.result-players { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 24px 0; }
.result-player { text-align: center; padding: 24px 16px; border-radius: var(--radius); border: 2px solid var(--border); }
.result-player.winner { border-color: var(--accent); background: #00d4aa0d; }
.result-player.loser  { opacity: .7; }
.result-crown { font-size: 2rem; }
.result-username { font-size: 1.2rem; font-weight: 800; margin: 8px 0; }
.result-score-big { font-size: 3rem; font-weight: 900; color: var(--primary); line-height: 1; }
.result-stat { font-size: .8rem; color: var(--muted); margin-top: 12px; line-height: 1.8; }

/* ── Hero ────────────────────────────────────────────────── */
.hero { text-align: center; padding: 48px 16px 32px; }
.hero h1 { font-size: 2.8rem; font-weight: 900; letter-spacing: -1px; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); margin-top: 10px; font-size: 1.05rem; }
.hero-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; flex-wrap: wrap; }

/* ── Index grid ──────────────────────────────────────────── */
.index-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 0 0 32px; }
@media (max-width: 600px) {
  .index-grid, .answer-grid, .result-players { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
}

/* ── Session code display ────────────────────────────────── */
.code-display {
  font-size: 2.2rem; font-weight: 900; letter-spacing: 6px;
  color: var(--accent); text-align: center; padding: 16px;
  background: var(--surface); border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; user-select: all; transition: border-color .2s;
}
.code-display:hover { border-color: var(--accent); }
.code-hint { text-align: center; font-size: .8rem; color: var(--muted); margin-top: 6px; }

/* ── Word question ───────────────────────────────────────── */
.question-word {
  font-size: 2rem; font-weight: 900; text-align: center;
  color: var(--text); margin: 16px 0 4px; letter-spacing: -0.5px;
}
.question-label { text-align: center; color: var(--muted); font-size: .85rem; }

/* ── Waiting overlay ─────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(13,13,26,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; z-index: 50;
}
.spinner {
  width: 48px; height: 48px; border: 4px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ───────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--muted); }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
