/* qsolve.css – Chalk & Sunlight */
@import url('../fonts/fonts.css');
:root {
  --bg:          #faf7f0;
  --bg-card:     #ffffff;
  --bg-warm:     #fdf8ef;
  --bg-elevated: #f5f0e6;
  --text-primary:  #1a1a1a;
  --text-secondary:#8a7f6a;
  --border:      #e8e0d0;
  --border-dark: #d4c9b4;
  --accent:      #f59e0b;
  --accent-dark: #d97706;
  --accent-bg:   #fdf3dc;
  --correct:     #2d7a4f;
  --correct-bg:  #edf7f2;
  --correct-border:#a3d9b8;
  --wrong:       #b83232;
  --wrong-bg:    #fdf2f2;
  --answer-a:    #c2410c;
  --answer-a-bg: #fde8d8;
  --answer-a-border:#f5b89a;
  --answer-b:    #78350f;
  --answer-b-bg: #fef3c7;
  --answer-b-border:#f5d98a;
  --answer-c:    #1a5c35;
  --answer-c-bg: #dcf5e8;
  --answer-c-border:#86d9a8;
  --answer-d:    #1e3a8a;
  --answer-d-bg: #dbeafe;
  --answer-d-border:#93c5fd;
  --radius:      14px;
  --radius-sm:   9px;
  --shadow:      0 2px 8px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.05);
  --shadow-md:   0 6px 24px rgba(0,0,0,.1);
  --font-display:'Syne', sans-serif;
  --font-body:   'Nunito', sans-serif;
  --font-mono:   'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle warm grain texture via CSS */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 15% 40%, rgba(245,158,11,.06) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 70%, rgba(45,122,79,.04) 0%, transparent 55%);
  z-index: 0;
  pointer-events: none;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  position: relative;
  z-index: 1;
}

/* ====== LOBBY ====== */
.lobby-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
}

.game-logo {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .4rem;
  letter-spacing: -.03em;
}
.game-logo span { color: var(--accent); }

.game-logo-sub {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 2rem;
}

.game-code-display {
  font-family: var(--font-mono);
  font-size: clamp(2.8rem, 10vw, 5.5rem);
  font-weight: 700;
  letter-spacing: .25em;
  color: var(--text-primary);
  background: var(--bg-card);
  border: 2px solid var(--border-dark);
  border-radius: var(--radius);
  padding: 1rem 2.5rem;
  margin: 1.5rem 0;
  box-shadow: var(--shadow);
  position: relative;
}
.game-code-display::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.join-url {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}
.join-url strong { color: var(--accent-dark); font-weight: 700; }

.players-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  justify-content: center;
  max-width: 800px;
  margin: 1.5rem auto;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 50px;
  padding: .4rem .9rem .4rem .4rem;
  font-weight: 700;
  font-size: .9rem;
  color: var(--text-primary);
  animation: pop-in .35s cubic-bezier(.34,1.56,.64,1) both;
  box-shadow: var(--shadow);
}
.player-chip .avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .8rem; color: #fff;
}

@keyframes pop-in {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.btn-start {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  background: var(--text-primary);
  border: none;
  border-radius: 60px;
  padding: .9rem 3rem;
  cursor: pointer;
  letter-spacing: .01em;
  transition: .2s;
  margin-top: 1.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}
.btn-start::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
.btn-start:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.btn-start:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ====== JOIN SCREEN (Player) ====== */
.join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: var(--bg);
}

.join-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  border: 1.5px solid var(--border);
  position: relative;
}
.join-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.join-card h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.7rem;
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.form-group       { margin-bottom: 1.2rem; }
.form-group label {
  display: block;
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .45rem;
}

.form-input {
  width: 100%;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
  font-size: 1rem;
  font-family: var(--font-body);
  color: var(--text-primary);
  outline: none;
  transition: .18s;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,158,11,.15);
  background: #fffdf7;
}
.form-input::placeholder { color: var(--border-dark); }
.form-input.code-input {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: .3em;
}

.btn-join {
  width: 100%;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--text-primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: .85rem;
  cursor: pointer;
  letter-spacing: .01em;
  transition: .18s;
  margin-top: .5rem;
  position: relative;
  overflow: hidden;
}
.btn-join::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}
.btn-join:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

.waiting-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  padding: 2rem;
  background: var(--bg);
}

.waiting-spinner {
  width: 52px; height: 52px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ====== QUESTION SCREEN ====== */
.question-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: var(--bg);
}

.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}

.question-counter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: .25rem .85rem;
}

.timer-ring {
  position: relative;
  width: 68px; height: 68px;
}
.timer-ring svg {
  transform: rotate(-90deg);
  width: 68px; height: 68px;
}
.timer-ring circle { fill: none; stroke-width: 5; }
.timer-ring .timer-bg { stroke: var(--border); }
.timer-ring .timer-fg {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset .3s linear, stroke .3s;
}
.timer-ring .timer-fg.urgent { stroke: var(--wrong); }

.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.answer-progress {
  font-size: .88rem;
  color: var(--text-secondary);
  text-align: right;
}
.answer-progress strong { color: var(--text-primary); font-weight: 700; }

/* Question text box */
.question-text-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  padding: 2rem 2.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  position: relative;
}
.question-text-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.question-text {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 3.5vw, 2.4rem);
  font-weight: 700;
  line-height: 1.35;
  color: var(--text-primary);
}

.question-meta {
  color: var(--text-secondary);
  font-size: .82rem;
  margin-top: .75rem;
}

/* Answer buttons */
.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .85rem;
  flex: 1;
}

.answer-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 1.2rem 1.4rem;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: clamp(.95rem, 2vw, 1.2rem);
  font-weight: 600;
  font-family: var(--font-body);
  color: var(--text-primary);
  cursor: pointer;
  transition: .2s;
  text-align: left;
  overflow: hidden;
  min-height: 75px;
  box-shadow: var(--shadow);
}

.answer-btn .answer-label {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px;
}

.answer-btn.a { background: var(--answer-a-bg); border-color: var(--answer-a-border); }
.answer-btn.b { background: var(--answer-b-bg); border-color: var(--answer-b-border); }
.answer-btn.c { background: var(--answer-c-bg); border-color: var(--answer-c-border); }
.answer-btn.d { background: var(--answer-d-bg); border-color: var(--answer-d-border); }

.answer-btn.a .answer-label { background: rgba(194,65,12,.15); color: var(--answer-a); }
.answer-btn.b .answer-label { background: rgba(120,53,15,.15); color: var(--answer-b); }
.answer-btn.c .answer-label { background: rgba(26,92,53,.15);  color: var(--answer-c); }
.answer-btn.d .answer-label { background: rgba(30,58,138,.15); color: var(--answer-d); }

.answer-btn.a:hover, .answer-btn.a.selected {
  background: #fbd4be; border-color: var(--answer-a);
  box-shadow: 0 4px 16px rgba(194,65,12,.15);
}
.answer-btn.b:hover, .answer-btn.b.selected {
  background: #fde68a; border-color: var(--answer-b);
  box-shadow: 0 4px 16px rgba(120,53,15,.15);
}
.answer-btn.c:hover, .answer-btn.c.selected {
  background: #a7f3c8; border-color: var(--answer-c);
  box-shadow: 0 4px 16px rgba(26,92,53,.15);
}
.answer-btn.d:hover, .answer-btn.d.selected {
  background: #bfdbfe; border-color: var(--answer-d);
  box-shadow: 0 4px 16px rgba(30,58,138,.15);
}

.answer-btn.correct-reveal {
  border-color: var(--correct) !important;
  background: var(--correct-bg) !important;
  box-shadow: 0 4px 16px rgba(45,122,79,.2) !important;
}
.answer-btn.wrong-reveal {
  opacity: .45;
  filter: grayscale(.4);
}
.answer-btn.disabled { pointer-events: none; opacity: .75; }
.answer-btn.answered { pointer-events: none; }

/* Player mobile */
.player-view .answers-grid { grid-template-columns: 1fr; }
.player-view .answer-btn   { min-height: 65px; font-size: 1.1rem; }

/* ====== SCOREBOARD ====== */
.scoreboard-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  background: var(--bg);
}

.scoreboard-title {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 700;
  margin-bottom: .4rem;
  text-align: center;
  color: var(--text-primary);
}
.scoreboard-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  text-align: center;
}

.correct-answer-box {
  background: var(--correct-bg);
  border: 2px solid var(--correct-border);
  border-radius: var(--radius);
  padding: 1.1rem 2rem;
  text-align: center;
  margin-bottom: 2rem;
  max-width: 700px;
  width: 100%;
  box-shadow: var(--shadow);
}
.correct-answer-box .label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--correct);
  margin-bottom: .3rem;
}

/* Leaderboard */
.leaderboard {
  width: 100%;
  max-width: 700px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: .8rem 1.2rem;
  margin-bottom: .45rem;
  border: 1.5px solid var(--border);
  transition: .2s;
  animation: slide-in .35s cubic-bezier(.34,1.56,.64,1) both;
  box-shadow: var(--shadow);
}
.leaderboard-row:nth-child(1) {
  background: var(--accent-bg);
  border-color: var(--answer-b-border);
}
.leaderboard-row:nth-child(2) {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.leaderboard-row:nth-child(3) {
  background: #fde8d8;
  border-color: var(--answer-a-border);
}

@keyframes slide-in {
  from { transform: translateX(-24px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.lb-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.1rem;
  width: 32px;
  text-align: center;
  color: var(--text-secondary);
}
.leaderboard-row:nth-child(1) .lb-rank { color: var(--accent-dark); font-size: 1.3rem; }

.lb-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: .85rem; color: #fff;
  flex-shrink: 0;
}
.lb-name  { flex: 1; font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.lb-points-change {
  font-size: .82rem; font-weight: 700;
  color: var(--correct); min-width: 56px; text-align: right;
}
.lb-points-change.zero { color: var(--wrong); }
.lb-score {
  font-family: var(--font-mono);
  font-weight: 700; font-size: 1.05rem;
  min-width: 64px; text-align: right;
  color: var(--text-primary);
}
.lb-streak { font-size: .8rem; color: var(--accent-dark); }

/* ====== WINNER SCREEN ====== */
.winner-screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
  background: var(--bg);
}

.trophy-icon {
  font-size: 4.5rem;
  margin-bottom: 1rem;
  animation: bounce 1.2s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-14px); }
}

.winner-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3.3rem);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: .5rem;
}
.winner-title span { color: var(--accent-dark); }

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 1rem;
  margin: 2.5rem 0;
  width: 100%;
  max-width: 560px;
}
.podium-place {
  display: flex; flex-direction: column;
  align-items: center; flex: 1; max-width: 170px;
}
.podium-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.25rem; color: #fff;
  margin-bottom: .65rem;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
}
.podium-place:nth-child(2) .podium-avatar {
  width: 74px; height: 74px; font-size: 1.5rem;
  border-color: var(--accent);
}
.podium-name  { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; color: var(--text-primary); }
.podium-score { font-family: var(--font-mono); font-weight: 700; color: var(--accent-dark); font-size: .9rem; }
.podium-bar {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-top: .7rem;
  border: 1.5px solid var(--border);
  border-bottom: none;
}
.podium-place:nth-child(1) .podium-bar { background: #f3f4f6; height: 90px; }
.podium-place:nth-child(2) .podium-bar { background: var(--accent-bg); height: 130px; border-color: var(--answer-b-border); }
.podium-place:nth-child(3) .podium-bar { background: #fde8d8; height: 68px; border-color: var(--answer-a-border); }

/* Confetti */
.confetti-container { position: fixed; inset: 0; pointer-events: none; z-index: 999; overflow: hidden; }
.confetti {
  position: absolute; width: 9px; height: 9px;
  top: -10px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ====== TEACHER CONTROLS ====== */
.teacher-controls {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1.5px solid var(--border);
  padding: .85rem 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

.btn-control {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: .95rem;
  padding: .65rem 1.75rem;
  border: 1.5px solid var(--border);
  border-radius: 50px;
  cursor: pointer;
  transition: .18s;
  background: var(--bg-card);
  color: var(--text-primary);
}
.btn-control:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn-next {
  background: var(--text-primary);
  color: #fff;
  border-color: var(--text-primary);
  position: relative;
  overflow: hidden;
}
.btn-next::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}
.btn-next:hover { box-shadow: 0 4px 16px rgba(0,0,0,.2); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-dark);
}

.btn-danger {
  background: var(--wrong-bg);
  color: var(--wrong);
  border-color: #f5b3b3;
}

/* Sound toggle */
.sound-toggle {
  position: fixed;
  top: 1rem; right: 1rem;
  z-index: 200;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: .18s;
  color: var(--text-primary);
  box-shadow: var(--shadow);
}
.sound-toggle:hover { background: var(--bg-elevated); }

/* Fullscreen button */
.btn-fullscreen {
  font-family: var(--font-body);
  font-size: .78rem;
  font-weight: 600;
  padding: .3rem .7rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: .18s;
}
.btn-fullscreen:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* Alerts */
.alert {
  padding: .9rem 1.1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-weight: 600;
  border-left: 3px solid;
}
.alert-error   { background: var(--wrong-bg);   color: var(--wrong);   border-color: var(--wrong); }
.alert-success { background: var(--correct-bg); color: var(--correct); border-color: var(--correct); }

/* Streak badge */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .78rem;
  font-weight: 700;
  color: var(--accent-dark);
  background: var(--accent-bg);
  border: 1px solid var(--answer-b-border);
  padding: .18rem .55rem;
  border-radius: 20px;
}

/* Music visualizer */
.music-bars {
  display: flex; align-items: flex-end;
  gap: 2px; height: 18px; margin-left: .5rem;
}
.music-bars span {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: bar-dance 1s ease-in-out infinite;
}
.music-bars span:nth-child(1) { animation-delay: 0s;   height: 30%; }
.music-bars span:nth-child(2) { animation-delay: .15s; height: 60%; }
.music-bars span:nth-child(3) { animation-delay: .3s;  height: 40%; }
.music-bars span:nth-child(4) { animation-delay: .45s; height: 80%; }
@keyframes bar-dance {
  0%, 100% { transform: scaleY(1); }
  50%       { transform: scaleY(.35); }
}
.music-bars.paused span { animation-play-state: paused; }

/* Source reveal */
.source-reveal {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-top: .5rem;
  font-style: italic;
}
.source-reveal strong { color: var(--accent-dark); font-style: normal; font-weight: 700; }

/* Responsive */
@media (max-width: 640px) {
  .answers-grid          { grid-template-columns: 1fr; }
  .answer-btn            { padding: 1rem; min-height: 58px; }
  .question-text-box     { padding: 1.25rem; }
  .podium                { gap: .5rem; }
  .teacher-controls      { padding: .65rem 1rem; gap: .5rem; }
  .btn-control           { padding: .55rem 1.1rem; font-size: .82rem; }
}

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