:root {
  --bg: #f5eef9;
  --bg-soft: #ece0f5;
  --surface: #ffffff;
  --surface-alt: #f8f2fc;
  --ink: #241b2e;
  --ink-soft: #756c85;
  --muted: #9d93ad;
  --border: #e8ddf2;
  --coral: #d6336c;
  --coral-dark: #b02358;
  --teal: #7048e8;
  --teal-dark: #5f3dc4;
  --gold: #f59f00;
  --gold-dark: #d88600;
  --green: #37b24d;
  --red: #ef4444;
  --white: #ffffff;
  --text: var(--ink);
  --card: var(--surface);
  --shadow: 0 10px 30px -16px rgba(36,27,46,0.22);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding: 1.5rem 1rem 4rem;
}
.container { max-width: 1200px; margin: 0 auto; }
h1, h2, h3 { font-weight: 800; }
h1 { font-size: 2rem; letter-spacing: -0.01em; }
h1 .boom { color: var(--coral); }
a { color: inherit; }

header.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.back-link { text-decoration: none; color: var(--ink-soft); font-weight: 700; font-size: 0.9rem; }
.back-link:hover { color: var(--ink); }

.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1.25rem; }
.card h2 {
  font-size: 1.15rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  color: var(--ink);
}

label { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); display: block; margin-bottom: 0.35rem; }
input[type=text], input[type=number], select, textarea {
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.95rem;
  width: 100%;
  background: var(--surface-alt);
  color: var(--ink);
}
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--coral);
  box-shadow: 0 0 0 3px rgba(214,51,108,0.15);
}
input[type=range] { width: 100%; accent-color: var(--coral); }

button {
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  transition: transform 0.1s, background 0.2s, opacity 0.2s, border-color 0.2s;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--coral); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--coral-dark); }
button.secondary { background: var(--surface-alt); color: var(--ink); border: 1.5px solid var(--border); }
button.secondary:hover:not(:disabled) { border-color: var(--coral); color: var(--coral); }
button.pink { background: var(--teal); color: #fff; }
button.pink:hover:not(:disabled) { background: var(--teal-dark); }
button.danger { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
button.danger:hover:not(:disabled) { background: var(--red); color: #fff; }
button.ghost { background: transparent; color: var(--ink-soft); font-weight: 700; }
button.ghost:hover:not(:disabled) { color: var(--ink); }
button.big { padding: 1rem 2.2rem; font-size: 1.1rem; }

/* avatar */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-alt);
  border: 3px solid var(--border);
  flex-shrink: 0;
}
.avatar.sm { width: 32px; height: 32px; }
.avatar.md { width: 48px; height: 48px; }
.avatar.lg { width: 84px; height: 84px; }

/* player chips / rows */
.player-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.player-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.85rem 0.5rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  cursor: pointer;
  user-select: none;
}
.player-chip.selected { border-color: var(--coral); background: rgba(214,51,108,0.08); }
.player-chip input[type=checkbox] { accent-color: var(--coral); width: 16px; height: 16px; }
.player-name { font-weight: 700; }

.player-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  background: var(--surface-alt);
}
.player-row + .player-row { margin-top: 0.5rem; }
.player-row .grow { flex: 1; min-width: 0; }

.empty-state { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

.status-toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.85rem 1.5rem;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 10px 25px -8px rgba(36,27,46,0.4);
  transform: translateY(150%);
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1);
  z-index: 500;
}
.status-toast.show { transform: translateY(0); }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab-btn { background: var(--surface); border: 1.5px solid var(--border); color: var(--ink-soft); border-radius: 999px; padding: 0.5rem 1.2rem; }
.tab-btn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ==================== SETUP ==================== */
.lobby-hero { text-align: center; margin-bottom: 1.5rem; }
.lobby-title {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--coral), var(--teal), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lobby-tagline { color: var(--ink-soft); font-weight: 700; margin-top: 0.25rem; }
.round-count-badge { font-size: 0.8rem; color: var(--muted); font-weight: 700; }

/* ==================== MAIN GAME SCREEN ==================== */
.game-header { text-align: center; margin-bottom: 1.25rem; }
.game-header .title-text { font-size: 1.6rem; font-weight: 900; letter-spacing: -0.01em; }
.game-header .title-text .boom { color: var(--coral); }
.game-header .round-num { font-size: 1.05rem; font-weight: 700; color: var(--ink-soft); margin-top: 0.2rem; }
.status-pill {
  display: inline-block;
  margin-top: 0.6rem;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
}

/* ---------------- Question + hue grid ---------------- */
.question-panel {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.4;
  padding: 0.9rem;
  margin-bottom: 1rem;
  border-radius: 16px;
  background: var(--surface-alt);
  border: 1.5px dashed var(--coral);
  color: var(--ink);
}
.question-panel #revealAnswerBtn { margin-top: 0.75rem; }
.question-panel .answer-reveal {
  margin-top: 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gold-dark);
}
.question-panel .answer-reveal b { color: var(--coral); }

.hue-grid-wrap { background: var(--surface); border: 1.5px solid var(--border); border-radius: 24px; padding: 1.1rem; box-shadow: var(--shadow); }
.hue-grid {
  display: grid;
  grid-template-columns: 34px repeat(6, 1fr);
  gap: 6px;
}
.hg-head {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.hue-cell {
  border-radius: 10px;
  aspect-ratio: 5 / 4;
  min-height: 46px;
  border: 1.5px solid rgba(36,27,46,0.08);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hue-cell.correct {
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 4px rgba(245,159,0,0.3), 0 10px 22px -10px rgba(245,159,0,0.6);
}
.hue-cell.correct::after {
  content: '\2713';
  font-weight: 900;
  font-size: 1.3rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.hue-cell.pick-target { cursor: pointer; }
.hue-cell.pick-target:hover { transform: scale(1.05); box-shadow: 0 0 0 3px rgba(112,72,232,0.5); }
.hue-cell.wrong { opacity: 0.32; filter: grayscale(0.7); cursor: default; }
.hue-cell.wrong::after {
  content: '\2715';
  font-weight: 900;
  font-size: 1.2rem;
  color: rgba(0,0,0,0.6);
}

@media (max-width: 700px) {
  .hue-grid { grid-template-columns: 24px repeat(6, 1fr); gap: 4px; }
  .hue-cell { min-height: 34px; border-radius: 8px; }
}

/* ---------------- Game Controls ---------------- */
.game-controls {
  margin-top: 1.25rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.controls-row { display: flex; gap: 0.75rem; justify-content: center; flex-wrap: wrap; }
.primary-action-hint { text-align: center; color: var(--ink-soft); font-weight: 700; margin-bottom: 0.75rem; font-size: 0.95rem; }
.round-summary-box {
  text-align: center;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 16px;
  background: var(--surface-alt);
  border: 1.5px solid var(--gold);
}
.round-summary-box .rs-line { display: flex; justify-content: space-between; max-width: 260px; margin: 0.2rem auto; font-weight: 700; color: var(--ink); }
.round-summary-box .rs-total { color: var(--coral); font-size: 1.2rem; }

/* ---------------- Scoreboard ---------------- */
.scoreboard {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.scoreboard h2 { text-align: center; margin-bottom: 0.9rem; font-size: 1.1rem; letter-spacing: 0.02em; border: none; padding: 0; color: var(--ink); }
.score-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 14px;
  margin-bottom: 0.4rem;
  background: var(--surface-alt);
  border: 1.5px solid var(--border);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
.score-row .rank { width: 1.6rem; text-align: center; font-weight: 900; color: var(--ink-soft); }
.score-row .s-name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.score-row .s-score {
  font-weight: 800;
  color: var(--ink);
  background: var(--gold);
  font-size: 0.9rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  transition: background 0.3s, color 0.3s;
}
.score-row .s-score.bump { background: var(--coral); color: #fff; }
.score-row.top1 { border-color: var(--gold); background: rgba(245,159,0,0.12); }
.score-row.answerable { cursor: pointer; }
.score-row.answerable:hover { border-color: var(--coral); transform: translateX(3px); box-shadow: 0 10px 22px -14px rgba(214,51,108,0.5); }
.score-row.winner-row { border-color: var(--green); background: rgba(55,178,77,0.12); }

/* ==================== FINAL RESULTS ==================== */
.champion-banner {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border-radius: 28px;
  background: var(--surface);
  border: 1.5px solid var(--gold);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.champion-banner .trophy { font-size: 3.5rem; }
.champion-banner .cb-title { color: var(--coral); font-size: 1rem; letter-spacing: 0.12em; font-weight: 800; margin-top: 0.5rem; text-transform: uppercase; }
.champion-banner .cb-name { font-size: 2.4rem; font-weight: 900; margin: 0.35rem 0; color: var(--ink); }
.champion-banner .cb-score { font-size: 1.3rem; color: var(--ink-soft); font-weight: 700; }
.leaderboard-final .lf-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0.9rem; border-radius: 14px; margin-bottom: 0.5rem;
  background: var(--surface-alt); border: 1.5px solid var(--border);
}
.leaderboard-final .lf-row.top1 { border-color: var(--gold); background: rgba(245,159,0,0.12); }
.leaderboard-final .lf-rank { width: 1.8rem; font-weight: 900; color: var(--ink-soft); }
.leaderboard-final .lf-name { flex: 1; font-weight: 700; color: var(--ink); }
.leaderboard-final .lf-score { font-weight: 800; color: var(--ink); background: var(--gold); font-size: 0.9rem; padding: 0.2rem 0.65rem; border-radius: 999px; }

/* ---------------- confetti ---------------- */
#confettiCanvas { position: fixed; inset: 0; pointer-events: none; z-index: 400; }

/* ==================== ADMIN: Questions ==================== */
.question-list-item { border: 1.5px solid var(--border); border-radius: 16px; padding: 0.9rem 1rem; background: var(--surface-alt); }
.question-list-item + .question-list-item { margin-top: 0.6rem; }
.question-list-item .ql-swatch { display: inline-block; width: 1rem; height: 1rem; border-radius: 4px; margin-right: 0.4rem; vertical-align: middle; border: 1.5px solid rgba(36,27,46,0.15); }
.question-list-item .ql-q { font-weight: 800; font-size: 1.02rem; color: var(--ink); }
.question-list-item .ql-answer { color: var(--ink-soft); font-size: 0.85rem; margin: 0.3rem 0; }
.question-list-item .ql-cell { font-size: 0.8rem; font-weight: 700; color: var(--teal-dark); }
.question-list-item .ql-actions { margin-top: 0.65rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.hue-form-row { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.hue-form-row > div { flex: 1; min-width: 220px; }
.hue-slider-readout { display: flex; align-items: center; gap: 0.6rem; }
.hue-slider-readout .swatch-lg { width: 2.2rem; height: 2.2rem; border-radius: 8px; border: 1.5px solid var(--border); flex-shrink: 0; }
.hue-slider-readout input[type=color] {
  width: 2.6rem;
  height: 2.6rem;
  padding: 2px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  cursor: pointer;
  flex-shrink: 0;
}
.hue-slider-readout input[type=text] { width: auto; }
.pick-hint { text-align: center; font-size: 0.85rem; font-weight: 700; color: var(--coral); margin-top: 0.6rem; }
.pick-hint.ok { color: var(--green); }
