:root {
  --bg: #1a1a2e;
  --bg-2: #16213e;
  --fg: #fff;
  --muted: #b8b8d4;
  --accent: #f5c518;
  --c1: #e21b3c; /* red    */
  --c2: #1368ce; /* blue   */
  --c3: #d89e00; /* yellow */
  --c4: #26890c; /* green  */
  --good: #26890c;
  --bad: #e21b3c;
  --card: #222845;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; max-width: 100%; overflow-x: hidden; }
img, svg { max-width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 50%, #2a1640 100%);
  background-size: 200% 200%;
  animation: bg-drift 18s ease-in-out infinite alternate;
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@keyframes bg-drift {
  0%   { background-position: 0% 0%; }
  100% { background-position: 100% 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

a { color: var(--accent); }

.wrap {
  margin: 0 auto;
  padding: 24px;
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.wrap > section { margin-bottom: 0; }

/* Question + reveal screens fill the available viewport, options grow into the space. */
#question, #reveal {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* Host: image grows, options stay compact. Player: options fill (no image/text on phone). */
#question > .options-grid,
#reveal > .options-grid {
  flex: 0 0 auto;
  height: clamp(150px, 24vh, 280px);
}
#question > .player-options {
  flex: 1;
  min-height: 220px;
}
#question .option,
#reveal .option {
  height: 100%;
  min-height: 0;
}
.question-image {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  height: auto;
  align-self: center;
  object-fit: contain;
}

/* Player option SVGs scale with the button — height-based so they fit a tall card. */
.player-options .option svg {
  width: 60%;
  height: 60%;
  max-width: 14rem;
  max-height: 14rem;
  min-width: 3.5rem;
  min-height: 3.5rem;
}

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: 2.4rem; }
.muted { color: var(--muted); }

button, .btn {
  background: var(--accent);
  color: #111;
  border: 0;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s;
}
button:hover { opacity: 0.92; }
button:active { transform: translateY(1px); }
button[disabled] { opacity: 0.4; cursor: not-allowed; }

.btn-secondary { background: #333a5c; color: #fff; }

input[type=text], input[type=number], select {
  background: #fff;
  color: #111;
  border: 0;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  width: 100%;
  margin-bottom: 12px;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
  animation: card-in 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

button, .btn { transition: transform 0.08s ease, opacity 0.15s, box-shadow 0.2s; }
button:hover { box-shadow: 0 4px 14px rgba(245, 197, 24, 0.3); }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---- Landing ---- */

.landing {
  display: flex; flex-direction: column; gap: 16px; align-items: center;
  text-align: center; padding-top: 60px;
}
.landing h1 { font-size: 3rem; }
.code-input {
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.4rem;
  font-weight: 700;
  max-width: 320px;
}

/* ---- Host ---- */

.code-display {
  font-size: 5rem;
  letter-spacing: 0.4rem;
  font-weight: 800;
  text-align: center;
  color: var(--accent);
  background: #0e1230;
  padding: 24px;
  border-radius: 16px;
  margin: 16px 0;
  animation: code-glow 2.4s ease-in-out infinite alternate;
}
@keyframes code-glow {
  from { box-shadow: 0 0 0 rgba(245,197,24,0); text-shadow: 0 0 0 transparent; }
  to   { box-shadow: 0 0 36px rgba(245,197,24,0.35); text-shadow: 0 0 24px rgba(245,197,24,0.5); }
}

.player-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.player-chip {
  background: var(--bg-2); padding: 8px 14px; border-radius: 999px;
  font-weight: 600; font-size: 1rem;
  animation: chip-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes chip-pop {
  0%   { opacity: 0; transform: scale(0.4); }
  60%  { opacity: 1; transform: scale(1.12); }
  100% { transform: scale(1); }
}
.player-chip.offline { opacity: 0.4; animation: none; }

/* ---- Question (host) ---- */

.question-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.timer {
  font-size: 2rem; font-weight: 800; color: var(--accent);
  background: #0e1230; padding: 8px 18px; border-radius: 12px; min-width: 80px; text-align: center;
}
.timer { transition: color 0.2s; }
.timer.urgent { color: var(--bad); animation: pulse 0.6s infinite alternate; }
@keyframes pulse {
  from { transform: scale(1); box-shadow: 0 0 0 rgba(226,27,60,0); }
  to   { transform: scale(1.12); box-shadow: 0 0 24px rgba(226,27,60,0.55); }
}

.question-text {
  font-size: 2rem;
  font-weight: 700;
  background: #fff; color: #111;
  border-radius: 12px;
  padding: 24px; margin-bottom: 16px;
  text-align: center;
  animation: drop-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.question-image {
  display: block; max-width: 100%; max-height: 300px;
  margin: 0 auto 16px;
  border-radius: 12px;
  animation: drop-in 0.45s 0.05s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes drop-in {
  from { opacity: 0; transform: translateY(-18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.options-grid, .player-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}
.option {
  border: 0; color: #fff; font-weight: 700; font-size: 1.4rem;
  border-radius: 12px; padding: 24px; min-height: 110px;
  display: flex; align-items: center; gap: 12px; text-align: left;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  word-break: break-word;
  transition: opacity 0.3s, transform 0.15s, outline-color 0.2s;
  animation: option-rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.option > span:not(.marker) { min-width: 0; flex: 1; }
.options-grid > .option:nth-child(1), .player-options > .option:nth-child(1) { animation-delay: 0.05s; }
.options-grid > .option:nth-child(2), .player-options > .option:nth-child(2) { animation-delay: 0.13s; }
.options-grid > .option:nth-child(3), .player-options > .option:nth-child(3) { animation-delay: 0.21s; }
.options-grid > .option:nth-child(4), .player-options > .option:nth-child(4) { animation-delay: 0.29s; }
@keyframes option-rise {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}
button.option:hover { transform: translateY(-2px); }
button.option:active { transform: translateY(1px) scale(0.97); }
.option .marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.2rem;
  height: 3.2rem;
  flex-shrink: 0;
}
.option .marker svg {
  width: 100%;
  height: 100%;
  fill: #fff;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
}
.options-grid > .option:nth-child(1), .player-options > .option:nth-child(1) { background: var(--c1); }
.options-grid > .option:nth-child(2), .player-options > .option:nth-child(2) { background: var(--c2); }
.options-grid > .option:nth-child(3), .player-options > .option:nth-child(3) { background: var(--c3); }
.options-grid > .option:nth-child(4), .player-options > .option:nth-child(4) { background: var(--c4); }
.option.dim { opacity: 0.22; transform: scale(0.94); }
.option.correct {
  outline: 6px solid #fff;
  animation: correct-pulse 1.2s ease-in-out infinite;
}
@keyframes correct-pulse {
  0%, 100% { box-shadow: 0 0 0 rgba(255,255,255,0); }
  50%      { box-shadow: 0 0 32px rgba(255,255,255,0.6); }
}

/* ---- Player ---- */

.player-view { padding: 20px; }
.player-options .option {
  min-height: 140px;
  justify-content: center;
  padding: 16px;
}
.player-options .option svg {
  width: 5rem;
  height: 5rem;
  fill: #fff;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.35));
}

.player-status {
  font-size: 1.4rem; text-align: center; padding: 30px 12px;
  animation: status-bounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.player-status.good { color: var(--good); }
.player-status.bad  { color: var(--bad); animation: status-shake 0.45s ease both; }
@keyframes status-bounce {
  0%   { opacity: 0; transform: scale(0.4); }
  60%  { opacity: 1; transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes status-shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-12px); }
  40%      { transform: translateX(10px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(4px); }
}

.points {
  font-size: 3rem; font-weight: 800; text-align: center; color: var(--accent);
  animation: points-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes points-pop {
  0%   { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  60%  { opacity: 1; transform: scale(1.2) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---- Leaderboard / Podium ---- */

.leaderboard { list-style: none; padding: 0; margin: 0; }
.leaderboard li {
  background: var(--card); padding: 14px 18px; border-radius: 10px;
  margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center;
  font-size: 1.2rem; font-weight: 600;
  animation: leader-slide 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}
@keyframes leader-slide {
  from { opacity: 0; transform: translateX(-24px); }
  to   { opacity: 1; transform: translateX(0); }
}
.leaderboard li .rank { color: var(--accent); margin-right: 12px; min-width: 30px; display: inline-block; }
.leaderboard li .score { color: var(--accent); }

.podium {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px;
  align-items: end; margin: 24px 0;
}
.podium .pillar {
  background: var(--card); border-radius: 12px 12px 0 0; padding: 16px;
  text-align: center; font-weight: 700;
  transform-origin: bottom;
  animation: pillar-rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.podium .pillar.p1 { background: #c9a227; min-height: 220px; color: #111; animation-delay: 0.45s; }
.podium .pillar.p2 { background: #99a3a8; min-height: 170px; color: #111; animation-delay: 0.15s; }
.podium .pillar.p3 { background: #b8743b; min-height: 130px; color: #111; animation-delay: 0.30s; }
@keyframes pillar-rise {
  0%   { opacity: 0; transform: scaleY(0); }
  100% { opacity: 1; transform: scaleY(1); }
}
.podium .pillar > * { animation: fade-in 0.35s ease 0.7s both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.podium .pillar .rank { font-size: 2.5rem; }
.podium .pillar .nick { font-size: 1.4rem; margin-top: 6px; }
.podium .pillar .score { font-size: 1.2rem; margin-top: 4px; }

/* ---- Mobile-friendly ---- */
@media (max-width: 600px) {
  .wrap { padding: 12px; gap: 10px; }
  .card { padding: 14px; }
  h1 { font-size: 1.7rem; }
  .question-bar { gap: 8px; flex-wrap: wrap; }
  .question-text { font-size: 1.05rem; padding: 12px; }
  .question-image { max-height: 26vh; }
  .timer { font-size: 1.4rem; padding: 4px 10px; min-width: 60px; }
  .options-grid, .player-options { gap: 8px; }
  .option { padding: 12px; font-size: 0.95rem; min-height: 0; gap: 8px; }
  .option .marker { width: 2rem; height: 2rem; }
  .player-options .option { min-height: 0; padding: 8px; }
  .player-options .option svg { width: 56%; height: 56%; min-width: 2.6rem; min-height: 2.6rem; }
  .code-display { font-size: 2.6rem; padding: 14px; letter-spacing: 0.2rem; }
  .points { font-size: 2.4rem; }
  .player-status { font-size: 1.2rem; padding: 18px 8px; }
  .leaderboard li { font-size: 1rem; padding: 10px 12px; }
  .podium .pillar { padding: 10px; }
  .podium .pillar.p1 { min-height: 160px; }
  .podium .pillar.p2 { min-height: 130px; }
  .podium .pillar.p3 { min-height: 100px; }
}
