/* ==========================================================================
   Quiz Live — design tokens
   Palette:  ink (bg) / paper (text) / violet+magenta (signature gradient)
   Options:  ruby / amber / teal / indigo — one color+shape per answer
   Type:     Space Grotesk (display) + Inter (body)
   Signature element: the countdown ring that appears on every question
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #12122a;
  --ink-soft: #1b1c3d;
  --ink-softer: #262860;
  --paper: #f5f3ee;
  --muted: #a9a6cf;

  --violet: #7c5cff;
  --magenta: #ff5ca8;
  --gradient: linear-gradient(135deg, var(--violet), var(--magenta));

  --ruby: #ff4b5c;
  --amber: #ffc93c;
  --teal: #17c3b2;
  --indigo: #5b6ef5;

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;

  --radius: 20px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--paper);
  background: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Ambient background: soft gradient blobs, fixed so screens can scroll */
body::before,
body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  z-index: 0;
  opacity: 0.35;
  pointer-events: none;
}
body::before {
  width: 480px;
  height: 480px;
  top: -160px;
  left: -120px;
  background: var(--violet);
}
body::after {
  width: 420px;
  height: 420px;
  bottom: -140px;
  right: -100px;
  background: var(--magenta);
}

h1, h2, h3 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

a {
  color: inherit;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--magenta);
  outline-offset: 2px;
}

/* ---------- layout shell ---------- */

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--gradient);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
}

.pill-link {
  font-size: 0.85rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 999px;
  transition: border-color 0.2s, color 0.2s;
}
.pill-link:hover {
  border-color: var(--magenta);
  color: var(--paper);
}

/* ---------- cards & forms ---------- */

.card {
  position: relative;
  z-index: 1;
  background: var(--ink-soft);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.card-wide {
  max-width: 720px;
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--magenta);
  font-weight: 600;
  margin-bottom: 8px;
  display: block;
}

.field {
  margin-top: 20px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.05em;
}

.field input::placeholder {
  color: #55578c;
  font-weight: 400;
}

.field input#pin,
.field input.pin-input {
  text-align: center;
  font-size: 2rem;
  letter-spacing: 0.3em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  padding: 14px 24px;
  font-weight: 700;
  font-size: 1rem;
  font-family: var(--font-display);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--gradient);
  color: #16122e;
  width: 100%;
  margin-top: 24px;
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.35);
}

.btn-secondary {
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--paper);
}

.error-text {
  color: var(--ruby);
  font-size: 0.85rem;
  margin-top: 14px;
  min-height: 1.2em;
}

/* ---------- lobby ---------- */

.pin-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 3.2rem;
  letter-spacing: 0.12em;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
  margin: 10px 0 4px;
}

.player-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
  min-height: 46px;
}

.player-chip {
  background: var(--ink-softer);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  animation: pop-in 0.25s ease;
}

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

.player-count {
  font-family: var(--font-display);
  font-size: 1rem;
  color: var(--muted);
}

/* ---------- question stage ---------- */

.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 12px 20px 40px;
}

.progress-tag {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.08em;
}

.question-text {
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  text-align: center;
  max-width: 760px;
}

/* Countdown ring — the signature element */
.timer-ring-wrap {
  position: relative;
  width: 108px;
  height: 108px;
}
.timer-ring-wrap svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}
.timer-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 8;
}
.timer-ring-fg {
  fill: none;
  stroke: url(#ringGradient);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear, stroke 0.25s linear;
}
.timer-ring-wrap.urgent .timer-ring-fg {
  stroke: var(--ruby);
}
.timer-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
}

@media (max-width: 560px) {
  .options-grid {
    grid-template-columns: 1fr;
  }
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 20px;
  border-radius: 16px;
  border: none;
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-body);
  text-align: left;
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.2s ease;
  min-height: 76px;
}
.option-btn:hover {
  filter: brightness(1.08);
}
.option-btn:active {
  transform: scale(0.98);
}
.option-btn:disabled {
  opacity: 0.55;
}
.option-btn .shape {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}
.option-ruby { background: var(--ruby); }
.option-amber { background: var(--amber); color: #2a1e00; }
.option-teal { background: var(--teal); }
.option-indigo { background: var(--indigo); }

.option-btn.correct {
  outline: 3px solid #3ddc84;
  outline-offset: 3px;
}
.option-btn.incorrect {
  outline: 3px solid rgba(255, 255, 255, 0.5);
  outline-offset: 3px;
}
.option-btn.dim {
  opacity: 0.35;
}

/* ---------- feedback / waiting states ---------- */

.status-card {
  text-align: center;
}
.status-emoji {
  font-size: 3rem;
  margin-bottom: 10px;
}
.points-badge {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  margin: 6px 0;
}
.points-badge.positive { color: var(--teal); }
.points-badge.zero { color: var(--muted); }

.pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--magenta);
  margin-right: 8px;
  animation: pulse 1.2s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* ---------- leaderboard ---------- */

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink-softer);
  border-radius: 12px;
  padding: 14px 18px;
  animation: slide-in 0.3s ease backwards;
}
.leaderboard-row:nth-child(1) { animation-delay: 0.05s; }
.leaderboard-row:nth-child(2) { animation-delay: 0.1s; }
.leaderboard-row:nth-child(3) { animation-delay: 0.15s; }
.leaderboard-row:nth-child(4) { animation-delay: 0.2s; }
.leaderboard-row:nth-child(5) { animation-delay: 0.25s; }

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

.rank-badge {
  font-family: var(--font-display);
  font-weight: 700;
  width: 30px;
  text-align: center;
  color: var(--muted);
}
.leaderboard-row:nth-child(1) .rank-badge { color: #ffd35c; }
.leaderboard-row:nth-child(2) .rank-badge { color: #d7d7e6; }
.leaderboard-row:nth-child(3) .rank-badge { color: #e2a26a; }

.leaderboard-name {
  flex: 1;
  font-weight: 600;
}
.leaderboard-score {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--paper);
}

/* ---------- winner podium ---------- */

.podium-title {
  text-align: center;
}
.winner-banner {
  text-align: center;
  margin: 18px 0 6px;
}
.winner-crown {
  font-size: 2.6rem;
}
.winner-name {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  background: var(--gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- utility ---------- */

.center-text { text-align: center; }
.mt-24 { margin-top: 24px; }
.hidden { display: none !important; }
.small-muted {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 18px;
}

/* ==========================================================================
   Extras: music controls, QR join, confetti, typewriter, feedback animation
   ========================================================================== */

/* ---------- audio control widget ---------- */
.audio-control {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink-soft);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.audio-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--paper);
  padding: 0;
  line-height: 1;
}
#volume-slider {
  width: 80px;
  accent-color: var(--magenta);
}

/* ---------- QR join code ---------- */
.qr-wrap {
  background: #ffffff;
  padding: 14px;
  border-radius: 16px;
  display: inline-block;
  margin: 18px auto 6px;
}
.qr-wrap img {
  display: block;
  width: 160px;
  height: 160px;
}
.join-url {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
  margin-top: 4px;
}

/* ---------- typewriter cursor ---------- */
.question-text.typing::after {
  content: '|';
  margin-left: 3px;
  color: var(--magenta);
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink {
  50% { opacity: 0; }
}

/* ---------- answer selection feedback ---------- */
@keyframes select-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.option-btn.selected {
  animation: select-pulse 0.3s ease;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.55);
}

/* ---------- correct / incorrect result feedback ---------- */
@keyframes pop-bounce {
  0% { transform: scale(0); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.status-emoji.pop-in { animation: pop-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.status-emoji.shake { animation: shake 0.45s ease; }

#result-card, .status-card {
  position: relative;
  overflow: visible;
}

@keyframes flash-green {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.55); }
  100% { box-shadow: 0 0 0 34px rgba(61, 220, 132, 0); }
}
.status-card.flash-correct { animation: flash-green 0.7s ease; }

@keyframes bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.bump-once { animation: bump 0.25s ease; }

/* ---------- reveal grid: staggered flip-in + correct glow ---------- */
@keyframes flip-in {
  from { opacity: 0; transform: rotateX(-40deg) translateY(10px); }
  to { opacity: 1; transform: rotateX(0) translateY(0); }
}
#reveal-grid .option-btn {
  animation: flip-in 0.4s ease backwards;
}
#reveal-grid .option-btn:nth-child(1) { animation-delay: 0.05s; }
#reveal-grid .option-btn:nth-child(2) { animation-delay: 0.15s; }
#reveal-grid .option-btn:nth-child(3) { animation-delay: 0.25s; }
#reveal-grid .option-btn:nth-child(4) { animation-delay: 0.35s; }

@keyframes correct-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.5); }
  50% { box-shadow: 0 0 26px 8px rgba(61, 220, 132, 0.55); }
}
#reveal-grid .option-btn.correct {
  animation: flip-in 0.4s ease backwards, correct-glow 1.3s ease-in-out 0.4s infinite;
}

/* ---------- confetti ---------- */
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall 1.4s ease-in forwards;
  pointer-events: none;
}
@keyframes confetti-fall {
  to { transform: translateY(340px) rotate(400deg); opacity: 0; }
}
.confetti-piece.confetti-full {
  animation-name: confetti-fall-full;
  animation-duration: 2.2s;
}
@keyframes confetti-fall-full {
  to { transform: translateY(100vh) rotate(600deg); opacity: 0; }
}
.confetti-fullscreen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 999;
}

/* ---------- champion highlight ---------- */
@keyframes winner-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.winner-name.you-won { animation: winner-pulse 1s ease-in-out infinite; }

/* ---------- emoji avatar picker ---------- */
.emoji-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.emoji-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: var(--ink);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.emoji-btn:hover { transform: scale(1.08); }
.emoji-btn.selected {
  border-color: var(--magenta);
  background: var(--ink-softer);
  transform: scale(1.1);
}
.big-emoji { font-size: 4rem; }

/* ---------- reactions (Google Meet–style floating emoji) ---------- */
.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}
.reaction-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--ink-softer);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.reaction-btn:hover { transform: scale(1.15); }
.reaction-btn:active { transform: scale(0.9); }

.reaction-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 500;
  overflow: hidden;
}
.reaction-bubble {
  position: absolute;
  bottom: -40px;
  font-size: 2.2rem;
  text-align: center;
  animation: reaction-float 2.2s ease-in forwards;
}
.reaction-bubble .reaction-name {
  display: block;
  font-size: 0.65rem;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  padding: 1px 6px;
  margin-top: 2px;
}
@keyframes reaction-float {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  12% { opacity: 1; transform: translateY(-30px) scale(1.15); }
  25% { transform: translateY(-70px) scale(1); }
  100% { transform: translateY(-75vh) translateX(var(--drift, 0px)) scale(1); opacity: 0; }
}
