/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  background: #46178f;
  color: #fff;
}

/* ── Landing ────────────────────────────────────────────────────────────────── */
.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
}

.logo {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  letter-spacing: -1px;
  text-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.tagline {
  font-size: 1.2rem;
  opacity: 0.85;
}

.landing-btns {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 1rem;
}

.btn-host, .btn-join {
  padding: 1rem 2.5rem;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
}
.btn-host:hover, .btn-join:hover { transform: scale(1.04); opacity: 0.93; }
.btn-host { background: #e21b3c; color: #fff; }
.btn-join { background: #1368ce; color: #fff; }

/* ── Common buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-block;
  padding: 0.85rem 2rem;
  background: #fff;
  color: #46178f;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  margin-top: 1.5rem;
}
.btn-primary:hover { transform: scale(1.04); opacity: 0.9; }

/* ── Host: Question-set picker ──────────────────────────────────────────────── */
.picker-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.picker-select {
  padding: 0.85rem 1.5rem;
  border-radius: 12px;
  border: none;
  font-size: 1.2rem;
  font-weight: 700;
  color: #333;
  background: #fff;
  cursor: pointer;
  min-width: 260px;
  text-align: center;
}

/* ── Host wrapper ───────────────────────────────────────────────────────────── */
.host-wrapper {
  min-height: 100vh;
  background: #46178f;
}

#host-main { min-height: 100vh; }

/* ── Host: Lobby ────────────────────────────────────────────────────────────── */
.host-lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 2rem;
  gap: 1.5rem;
  text-align: center;
  min-height: 100vh;
}

.host-lobby .logo { font-size: clamp(2rem, 5vw, 3.5rem); }

.code-box {
  background: rgba(255,255,255,0.15);
  border: 3px solid rgba(255,255,255,0.4);
  border-radius: 20px;
  padding: 1.5rem 3rem;
  text-align: center;
}

.code-label {
  font-size: 1rem;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 0.3rem;
}

.game-code {
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 900;
  letter-spacing: 8px;
  line-height: 1;
}

.set-name {
  font-size: 0.9rem;
  opacity: 0.7;
  letter-spacing: 1px;
  margin-top: 0.4rem;
  text-transform: uppercase;
}

.player-count { font-size: 1.2rem; opacity: 0.9; }

#player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  list-style: none;
  max-width: 800px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.2);
  padding: 0.4rem 0.6rem 0.4rem 1rem;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
}

.player-chip-name { flex: 1; }

.btn-kick {
  background: rgba(226, 27, 60, 0.5);
  border: 1px solid rgba(226, 27, 60, 0.7);
  border-radius: 50%;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.1s;
}
.btn-kick:hover { background: rgba(226, 27, 60, 0.85); }

/* ── Host: Question ─────────────────────────────────────────────────────────── */
.host-question {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  padding: 1.25rem 2rem 1rem;
  gap: 1rem;
  box-sizing: border-box;
}

.q-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.q-counter {
  background: rgba(255,255,255,0.18);
  padding: 0.35rem 0.9rem;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
}

.timer {
  font-size: 1.9rem;
  font-weight: 900;
  background: rgba(255,255,255,0.18);
  padding: 0.25rem 0.9rem;
  border-radius: 8px;
  min-width: 84px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.pts-badge {
  background: rgba(255,255,255,0.9);
  color: #46178f;
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
}

/* ── Fullscreen question display (reading buffer + fullscreen flag) ─────────── */
.host-question-fullscreen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 4rem 3rem 2rem;
  gap: 1.5rem;
  text-align: center;
  background: #0a0a0a;
  position: relative;
}

.question-text-full {
  font-family: "Barlow Condensed", "Impact", "Arial Narrow", sans-serif;
  font-size: clamp(2.5rem, 5.5vw, 4.5rem);
  font-weight: 800;
  text-align: center;
  line-height: 1.2;
  letter-spacing: 0.01em;
  color: #ffffff;
  max-width: 90%;
  -webkit-font-smoothing: antialiased;
}

.question-image-full {
  max-width: 70%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: 12px;
  border: 3px solid rgba(255,255,255,0.2);
}

.fs-answer-count {
  font-size: 0.85rem;
  opacity: 0.4;
  font-weight: 600;
  margin-top: 0.5rem;
}

/* Small fullscreen toggle next to timer */
.btn-fs-toggle {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.6);
  font-size: 0.7rem;
  font-weight: 900;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s, opacity 0.12s;
  opacity: 0.5;
}
.btn-fs-toggle:hover { opacity: 1; background: rgba(255,255,255,0.2); }

.host-question-fullscreen .q-header {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
}

.host-question-fullscreen .timer {
  background: rgba(255,255,255,0.1);
}

.host-question-fullscreen .q-counter {
  background: rgba(255,255,255,0.1);
}

/* ── Fixed-height question band (normal options view) ──────────────────────── */
.question-band {
  background: #0a0a0a;
  border-top: 5px solid #f5c400;
  border-bottom: 5px solid #f5c400;
  margin-left: -2rem;
  margin-right: -2rem;
  padding: 0.6rem 2rem;
  height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  /* Ensure band doesn't grow wider than viewport */
  max-width: 100vw;
  box-sizing: border-box;
}

.question-text-band {
  font-family: "Barlow Condensed", "Impact", "Arial Narrow", sans-serif;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 800;
  text-align: left;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: #ffffff;
  -webkit-font-smoothing: antialiased;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  min-width: 0;
}

/* ── Code block in fullscreen ──────────────────────────────────────────────── */
.question-code-full {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: clamp(1.6rem, 3.5vw, 2.5rem);
  font-weight: 600;
  color: #e6db74;
  background: #1a1a2e;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 1.5rem 2.5rem;
  text-align: left;
  max-width: 90%;
  line-height: 1.6;
}

/* Four options: equal-size 2×2 grid filling available height */
.options-host {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
  min-height: 0;   /* critical: lets grid cell shrink inside parent grid */
}

.option-host {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-radius: 16px;
  font-size: clamp(1rem, 2.2vw, 1.5rem);
  font-weight: 700;
  color: #fff;
  min-height: 0;   /* let grid control height, not content */
  overflow: hidden;
}

.opt-shape {
  font-size: 1.6rem;
  flex-shrink: 0;
  background: rgba(0,0,0,0.22);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.opt-text { flex: 1; }

/* ── Host: Bottom bar (progress + controls) ──────────────────────────────────── */
.host-bottom {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

/* Answer progress: thin bar that fills as students submit */
.answer-progress-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.answer-progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(255,255,255,0.12);
  border-radius: 3px;
  overflow: hidden;
}

.answer-progress-fill {
  height: 100%;
  background: rgba(255,255,255,0.6);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.answer-progress-label {
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.45;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Controls: compact, muted — visible but not distracting */
.host-controls {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.2s;
}
.host-controls:hover { opacity: 1; }

.btn-control {
  padding: 0.25rem 0.75rem;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.85);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  letter-spacing: 0.2px;
}
.btn-control:hover {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.6);
}

.btn-skip {
  border-color: rgba(226, 27, 60, 0.45);
  color: rgba(255,160,160,0.85);
}
.btn-skip:hover { background: rgba(226, 27, 60, 0.2); }

/* ── Host: Reveal ───────────────────────────────────────────────────────────── */
.host-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  gap: 1.5rem;
  min-height: 100vh;
  overflow: hidden;
}

.host-reveal .question-band {
  width: calc(100% + 4rem);
  margin-left: -2rem;
  margin-right: -2rem;
  flex-shrink: 0;
  min-width: 0;
}

.host-reveal .options-host {
  width: 100%;
}

.reveal-label {
  opacity: 0.8;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.wrong-opt { opacity: 0.18; }
.correct-opt { outline: 5px solid #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }

.opt-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bar-outer {
  display: flex;
  align-items: center;
  height: 48px;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  margin-top: 0.5rem;
  overflow: hidden;
  position: relative;
  min-width: 80px;
}

.bar-num {
  position: absolute;
  right: 10px;
  font-size: 1.1rem;
  font-weight: 800;
}

/* ── Host: Leaderboard ──────────────────────────────────────────────────────── */
.host-leaderboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 2rem;
  gap: 1.5rem;
  min-height: 100vh;
}

.lb-title {
  font-size: 2.5rem;
  font-weight: 900;
}

.leaderboard {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 65vh;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 0.75rem 1.25rem;
  font-size: 1.15rem;
}

.lb-rank {
  font-weight: 900;
  font-size: 1.2rem;
  min-width: 36px;
  opacity: 0.8;
}

.lb-delta {
  font-size: 0.8rem;
  font-weight: 800;
  min-width: 34px;
  text-align: center;
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}
.delta-up   { color: #7fff7f; background: rgba(38,137,12,0.35); }
.delta-down { color: #ffaaaa; background: rgba(226,27,60,0.3); }
.delta-none { color: rgba(255,255,255,0.35); background: transparent; }

.lb-name { flex: 1; font-weight: 700; }

.lb-score {
  font-weight: 900;
  font-size: 1.3rem;
  color: #ffd700;
}

.lb-unit {
  font-size: 0.85rem;
  opacity: 0.7;
  font-weight: 600;
  margin-left: -0.3rem;
}

/* ── Host: Final ────────────────────────────────────────────────────────────── */
.host-final {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 2rem;
  gap: 1.5rem;
  min-height: 100vh;
  text-align: center;
}

.final-title {
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 900;
  text-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.podium {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 650px;
  max-height: 60vh;
  overflow-y: auto;
}

.podium-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255,255,255,0.15);
  border-radius: 12px;
  padding: 0.9rem 1.25rem;
}

.medal { font-size: 2rem; flex-shrink: 0; }

.final-name { flex: 1; font-size: 1.3rem; font-weight: 700; }

.final-score {
  font-size: 1.2rem;
  font-weight: 900;
  color: #ffd700;
}

.btn-export {
  display: inline-block;
  padding: 0.65rem 1.5rem;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.45);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s;
  margin-top: 0.5rem;
}
.btn-export:hover { background: rgba(255,255,255,0.3); }

/* ── Join page ──────────────────────────────────────────────────────────────── */
.join-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1.2rem;
  padding: 2rem;
  text-align: center;
}

.join-page .logo { font-size: clamp(2rem, 6vw, 3rem); margin-bottom: 0.5rem; }

.join-page form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  width: 100%;
  max-width: 360px;
}

.input-code, .input-nick {
  padding: 1rem 1.25rem;
  border-radius: 12px;
  border: none;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  outline: none;
  color: #333;
}

.input-code { letter-spacing: 6px; }

.btn-join-submit {
  padding: 1rem;
  background: #e21b3c;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1.3rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s;
  margin-top: 0.25rem;
}
.btn-join-submit:hover { transform: scale(1.03); }

.error-msg {
  background: rgba(226,27,60,0.3);
  border: 2px solid #e21b3c;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-size: 1.1rem;
}

.btn-back {
  color: #fff;
  font-size: 1rem;
  opacity: 0.8;
}

/* ── Player wrapper ─────────────────────────────────────────────────────────── */
.player-wrapper {
  min-height: 100vh;
  background: #fff;
  color: #333;
}

#player-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Host: Read buffer timer variant ────────────────────────────────────────── */
.timer-reading {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.6);
  letter-spacing: 1px;
}

/* ── Player: Reading buffer screen ──────────────────────────────────────────── */
.player-reading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 2rem;
  text-align: center;
  gap: 1rem;
  background: #f5f5f5;
  color: #333;
}

.reading-icon {
  font-size: 4rem;
  line-height: 1;
}

.reading-prompt {
  font-size: 1.1rem;
  color: #888;
  font-weight: 500;
}

/* ── Player: Waiting / Lobby ────────────────────────────────────────────────── */
.player-waiting, .player-answered, .player-leaderboard, .player-final {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
  gap: 1rem;
  background: #fff;
  color: #333;
}

.player-in-title {
  font-size: 2.5rem;
  font-weight: 900;
  color: #46178f;
}

.player-nick-display {
  font-size: 1.8rem;
  font-weight: 800;
  color: #333;
  background: #f0e6ff;
  padding: 0.5rem 1.5rem;
  border-radius: 999px;
}

.waiting-msg {
  font-size: 1.1rem;
  color: #888;
}

/* ── Player: Question ───────────────────────────────────────────────────────── */
.player-question {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0.5rem;
  gap: 0.4rem;
  background: #f5f5f5;
  box-sizing: border-box;
}

.player-q-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.5rem 0;
}

.player-q-progress {
  font-size: 0.95rem;
  font-weight: 700;
  color: #46178f;
}

.player-q-points {
  font-size: 0.9rem;
  font-weight: 700;
  color: #888;
}

.tap-prompt {
  text-align: center;
  font-size: 0.9rem;
  color: #666;
  padding: 0.25rem 0.5rem;
}

/* ── Player: 2×2 answer grid ─────────────────────────────────────────────────── */
.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

.answer-grid form {
  margin: 0;
  display: contents;
}

.answer-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 16px;
  font-size: 3.5rem;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.1s, opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.answer-btn:active { transform: scale(0.94); opacity: 0.85; }

/* ── Player: Answered ───────────────────────────────────────────────────────── */
.locked-title {
  font-size: 2rem;
  font-weight: 900;
  color: #26890c;
}

/* ── Player: Reveal ─────────────────────────────────────────────────────────── */
.player-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
  gap: 1rem;
}

.player-reveal.correct { background: #26890c; color: #fff; }
.player-reveal.wrong   { background: #e21b3c; color: #fff; }
.player-reveal.timeout { background: #555; color: #fff; }

.result-icon {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
}

.correct-icon { text-shadow: 0 0 30px rgba(255,255,255,0.5); }
.wrong-icon   { text-shadow: 0 0 30px rgba(255,255,255,0.5); }

.points-earned {
  font-size: 2rem;
  font-weight: 900;
}

.correct-answer {
  font-size: 1.1rem;
  opacity: 0.9;
  font-style: italic;
}

.timeout-msg {
  font-size: 1.5rem;
  font-weight: 700;
}

.player-score-total {
  font-size: 1.2rem;
  opacity: 0.85;
}

/* ── Player: Leaderboard ────────────────────────────────────────────────────── */
.player-rank-big {
  font-size: 3rem;
  font-weight: 900;
  color: #46178f;
}

.rank-delta {
  font-size: 1rem;
  font-weight: 700;
}
.delta-up-text   { color: #26890c; }
.delta-down-text { color: #e21b3c; }
.delta-hold-text { color: #888; }

/* ── Player: Final ──────────────────────────────────────────────────────────── */
.player-final .final-title {
  font-size: 2.5rem;
  color: #46178f;
}

.player-medal {
  font-size: 5rem;
  line-height: 1;
}

.player-final .player-score-total {
  font-size: 1.5rem;
  font-weight: 800;
  color: #333;
}

/* ── Player: Kicked ──────────────────────────────────────────────────────────── */
.player-kicked {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  text-align: center;
  gap: 1rem;
  background: #e21b3c;
  color: #fff;
}

.kicked-title {
  font-size: 3rem;
  font-weight: 900;
}

.kicked-msg {
  font-size: 1.2rem;
  opacity: 0.9;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .options-host { grid-template-columns: 1fr; }
  .q-header { gap: 0.75rem; }
  .game-code { letter-spacing: 4px; }
  .host-controls { gap: 0.5rem; }
}
