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

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --primary: #6c63ff;
  --primary-dark: #5a52d5;
  --secondary: #ff6584;
  --accent: #43e97b;
  --text: #e8e8f0;
  --text-muted: #8888aa;
  --border: #2a2a45;
  --correct: #43e97b;
  --wrong: #ff4757;
  --warn: #ffa502;
}

/* ===== Themes ===== */
[data-theme="theme_sunset"] {
  --bg: #1a0a00;
  --card: #2d1500;
  --primary: #ff7b25;
  --primary-dark: #e06010;
  --secondary: #ff4500;
  --accent: #ffcc00;
  --text: #f0e8d8;
  --text-muted: #aa8855;
  --border: #4a2500;
  --correct: #ffcc00;
  --wrong: #ff2200;
  --warn: #ff9900;
}

[data-theme="theme_ocean"] {
  --bg: #001828;
  --card: #002a42;
  --primary: #0099cc;
  --primary-dark: #0077aa;
  --secondary: #00d4ff;
  --accent: #00ffcc;
  --text: #d0f0ff;
  --text-muted: #5599bb;
  --border: #003d5c;
  --correct: #00ffcc;
  --wrong: #ff4477;
  --warn: #ffbb00;
}

[data-theme="theme_neon"] {
  --bg: #080010;
  --card: #130020;
  --primary: #cc00ff;
  --primary-dark: #aa00dd;
  --secondary: #ff0080;
  --accent: #00ffaa;
  --text: #f0d0ff;
  --text-muted: #8844aa;
  --border: #2a0050;
  --correct: #00ffaa;
  --wrong: #ff0055;
  --warn: #ffcc00;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  height: 100%;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px 16px;
  gap: 16px;
  animation: fadeIn .25s ease;
  overflow-y: auto;
}

.screen.active { display: flex; }

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

.logo { font-size: 64px; line-height: 1; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
h2 { font-size: 22px; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 15px; }

/* Buttons */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, opacity .1s;
  letter-spacing: 0.2px;
}
.btn:active { transform: scale(.96); }

.btn-primary  { background: var(--primary);   color: #fff; }
.btn-secondary{ background: var(--secondary); color: #fff; }
.btn-accent   { background: var(--accent);    color: #111; }
.btn-outline  { background: transparent; color: var(--text); border: 2px solid var(--border); }

.back-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 15px; cursor: pointer; align-self: flex-start;
  padding: 4px 0; margin-bottom: 4px;
}

/* Join input */
.join-input {
  width: 100%;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  outline: none;
}
.join-input:focus { border-color: var(--primary); }

/* Spinner */
.spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Code display */
.code-display {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--accent);
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 14px 24px;
}
.hint { color: var(--text-muted); font-size: 13px; }

/* Game header */
.game-header { width: 100%; padding: 0 4px; }

.progress-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  margin-bottom: 8px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width .4s ease;
  width: 0%;
}

.game-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#timer-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 100%;
  transition: width linear;
}

/* Opponent info */
.opponent-info {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  width: 100%;
  text-align: center;
  color: var(--text-muted);
}
.opponent-info span { color: var(--text); font-weight: 600; }

/* Question */
.question-box {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  text-align: center;
  border: 1px solid var(--border);
}
#question-text {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}

/* Hint bar */
.hint-bar {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
}
.hint-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.hint-btn:active { transform: scale(.95); }
.hint-btn:hover  { border-color: var(--primary); }
.hint-btn.used   { opacity: .35; cursor: default; pointer-events: none; }
.hint-btn.locked { opacity: .25; cursor: default; pointer-events: none; filter: grayscale(1); }

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.option-btn {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  text-align: center;
  line-height: 1.3;
}
.option-btn:active { transform: scale(.96); }
.option-btn:hover  { border-color: var(--primary); }

.option-btn.selected { border-color: var(--primary); background: rgba(108,99,255,.2); }
.option-btn.correct  { border-color: var(--correct); background: rgba(67,233,123,.2); color: var(--correct); }
.option-btn.wrong    { border-color: var(--wrong);   background: rgba(255,71,87,.15); color: var(--wrong); }
.option-btn.disabled { cursor: default; pointer-events: none; opacity: .7; }

/* Result */
.result-icon { font-size: 72px; line-height: 1; }
.result-body {
  background: var(--card);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.result-row:last-child { border-bottom: none; }
.result-row .val { font-weight: 700; color: var(--accent); }

.versus-result {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.player-result {
  flex: 1;
  background: var(--bg);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  border: 2px solid var(--border);
}
.player-result.winner { border-color: var(--accent); }
.player-result .p-name  { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.player-result .p-score { font-size: 28px; font-weight: 900; color: var(--accent); }

/* Leaderboard */
.leaderboard-list { width: 100%; max-width: 380px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-radius: 14px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.lb-rank {
  font-size: 18px;
  font-weight: 900;
  width: 28px;
  text-align: center;
  color: var(--text-muted);
}
.lb-rank.top1 { color: #ffd700; }
.lb-rank.top2 { color: #c0c0c0; }
.lb-rank.top3 { color: #cd7f32; }
.lb-name  { flex: 1; font-weight: 600; }
.lb-score { font-weight: 700; color: var(--accent); }

/* User stats */
.user-stats {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* Shop */
.shop-balance {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 16px;
  width: 100%;
  max-width: 380px;
}
.balance-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.balance-label { font-size: 12px; color: var(--text-muted); }
.balance-val   { font-size: 18px; font-weight: 900; color: var(--accent); }
.balance-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
  margin: 0 12px;
}

.shop-list { width: 100%; max-width: 380px; }

.shop-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin: 14px 0 8px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 12px;
  margin-bottom: 8px;
}
.shop-item-icon { font-size: 26px; flex-shrink: 0; }
.shop-item-info { flex: 1; min-width: 0; }
.shop-item-name { font-size: 14px; font-weight: 700; }
.shop-item-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }

.shop-item-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.owned-tag { font-size: 11px; color: var(--text-muted); }

.qty-control {
  display: flex;
  align-items: center;
  gap: 6px;
}
.qty-btn {
  background: var(--border);
  border: none;
  border-radius: 6px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  width: 26px;
  height: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-btn:active { opacity: .7; }
.qty-val { font-size: 14px; font-weight: 700; min-width: 18px; text-align: center; }

.shop-btn {
  font-size: 11px;
  padding: 7px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hidden { display: none !important; }

/* Screen-specific */
#screen-game {
  justify-content: flex-start;
  padding-top: 16px;
  gap: 12px;
}
