/* ===== TEEDEQUIZ stiilid ===== */
/* Lihtsalt muudetav: värvid, fondid, kujundus on ülemistes CSS muutujates */

:root {
  /* Vastusevariantide värvid (Kahoot-laadne) */
  --ans-0: #e21b3c;  /* punane / kolmnurk */
  --ans-1: #1368ce;  /* sinine / romb */
  --ans-2: #d89e00;  /* kollane / ring */
  --ans-3: #26890c;  /* roheline / ruut */

  /* Bränd */
  --brand-dark: #0e1a2b;
  --brand-mid: #1a2942;
  --brand-light: #4f6796;
  --accent: #ffb800;

  --text: #ffffff;
  --text-muted: #b8c4d6;

  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --radius: 12px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(135deg, var(--brand-dark) 0%, var(--brand-mid) 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 700; }

/* ============ HOST VAATED ============ */

body.host {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: calc(100vh - 3rem);
}
.screen.active { display: flex; }

.host-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.host-header h1 { font-size: 2rem; }
.host-header h2 { font-size: 1.5rem; }

.question-counter {
  background: rgba(255,255,255,.1);
  padding: .5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1.1rem;
}

.timer {
  background: var(--accent);
  color: var(--brand-dark);
  font-weight: 800;
  font-size: 2rem;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}

.answers-received {
  background: rgba(255,255,255,.1);
  padding: .5rem 1rem;
  border-radius: 999px;
  font-weight: 600;
}

/* Lobby */
.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  flex: 1;
  align-items: start;
}
@media (max-width: 900px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

.join-info {
  background: rgba(255,255,255,.05);
  padding: 2rem;
  border-radius: var(--radius);
  text-align: center;
  border: 1px solid rgba(255,255,255,.1);
}
.join-info .instruction {
  color: var(--text-muted);
  margin: 1rem 0 .5rem;
}
.join-url {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 600;
  background: rgba(0,0,0,.3);
  padding: .75rem 1rem;
  border-radius: 8px;
  word-break: break-all;
}
.qr-code {
  width: 240px;
  height: 240px;
  border-radius: 8px;
  margin: 1rem auto;
  display: block;
  background: white;
  padding: 8px;
}
.pin-display {
  margin-top: 1rem;
}
.pin-label {
  display: block;
  color: var(--text-muted);
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .15em;
  margin-bottom: .25rem;
}
.pin-value {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: .15em;
  color: var(--accent);
}

.player-list-wrap {
  background: rgba(255,255,255,.05);
  padding: 2rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.1);
}
.player-list-wrap h2 { margin-bottom: 1rem; }
.player-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.player-list li {
  background: rgba(255,255,255,.15);
  padding: .5rem 1rem;
  border-radius: 999px;
  font-weight: 500;
  animation: pop-in .3s ease;
}
@keyframes pop-in {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Question / Reveal */
.question-text {
  background: rgba(255,255,255,.08);
  padding: 2rem;
  border-radius: var(--radius);
  font-size: 2.1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 1.5rem;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.1);
}

/* Question-faasis on küsimus suurem kui reveal-faasis */
#question .question-text {
  font-size: 2.8rem;
  padding: 2.25rem;
}

/* Intro-mode: kui vastused on veel peidus, küsimus dominerib veelgi rohkem */
#question.intro-mode .question-text {
  font-size: 3.2rem;
  padding: 2.5rem;
}
#question.intro-mode .answer-grid,
#question.intro-mode #btn-reveal,
#question.intro-mode .timer,
#question.intro-mode .answers-received {
  display: none;
}
#question:not(.intro-mode) #btn-show-answers {
  display: none;
}

.question-image {
  display: block;
  margin: 0 auto 1.5rem;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: white;
  padding: 4px;
  /* Vaikeväärtus (küsimuse faas): keskmise suurusega */
  max-width: min(900px, 85%);
  max-height: 38vh;
}

/* Reveal-faasis pilt on suurem ja publikule loetav */
#reveal-image {
  max-width: min(1100px, 92%);
  max-height: 58vh;
}

/* Kui reveal-ekraanil on pilt, suru vastusekastid kokku, et pilt domineeriks */
#reveal.has-image .question-text {
  font-size: 1.25rem;
  padding: .9rem 1.5rem;
  min-height: auto;
  margin-bottom: .75rem;
}
#reveal.has-image .answer-grid {
  flex: 0 0 auto;
}
#reveal.has-image .host-answers .answer-box {
  min-height: 78px;
  padding: .7rem 1rem;
}
#reveal.has-image .host-answers .answer-box .answer-text {
  font-size: 1.2rem;
}

/* Sama küsimuse faasis (image), aga pisut leebem — vastused jäävad loetavad */
#question.has-image .question-text {
  font-size: 1.9rem;
  padding: 1.25rem 1.75rem;
  min-height: auto;
  margin-bottom: 1rem;
}
#question.intro-mode.has-image .question-text {
  font-size: 2.3rem;
  padding: 1.5rem 2rem;
}
#question.has-image .host-answers .answer-box {
  min-height: 100px;
}

/* === LOGO === */
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .5rem;
}
.brand-logo {
  display: block;
  height: 80px;
  width: auto;
  max-width: 320px;
  object-fit: contain;
  /* Valge "alustaldrik" — kui logo on juba sobiva taustaga, eemalda need 3 rida */
  background: white;
  padding: 6px 12px;
  border-radius: 6px;
}
.brand-logo.hidden { display: none; }

/* Mängija (join.html) — logo veidi väiksem ja keskel */
.player .brand-logo {
  height: 90px;
  max-width: 260px;
  margin: 0 auto 1rem;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}
.host-answers .answer-box {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 150px;
  overflow: hidden;
  transition: opacity .4s ease, transform .4s ease;
}
.host-answers .answer-box .shape {
  position: absolute;
  top: .6rem;
  left: .8rem;
  font-size: 1.4rem;
  opacity: .65;
  pointer-events: none;
}
.host-answers .answer-box .answer-text {
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  width: 100%;
  word-break: break-word;
  hyphens: auto;
  /* font-size dünaamiliselt seatud fitText() poolt */
  font-size: 1.6rem;
}
.host-answers .answer-box .vote-count {
  position: absolute;
  bottom: .5rem;
  right: .75rem;
  background: rgba(0,0,0,.35);
  padding: .15rem .65rem;
  border-radius: 999px;
  font-size: .95rem;
  font-weight: 600;
  display: none;
}
.host-answers .answer-box.show-votes .vote-count { display: block; }
.host-answers .answer-box.dimmed { opacity: 0.3; transform: scale(0.95); }
.host-answers .answer-box.correct {
  outline: 4px solid white;
  outline-offset: -4px;
  animation: pulse-correct 1s ease infinite;
}
@keyframes pulse-correct {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,.6); }
  50% { box-shadow: 0 0 0 16px rgba(255,255,255,0); }
}

.ans-0 { background: var(--ans-0); }
.ans-1 { background: var(--ans-1); }
.ans-2 { background: var(--ans-2); }
.ans-3 { background: var(--ans-3); }

.reveal-title { color: var(--accent); }

/* Leaderboard */
.leaderboard {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin: 2rem auto;
  max-width: 700px;
  width: 100%;
}
.leaderboard li {
  background: rgba(255,255,255,.08);
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 1.2rem;
  border: 1px solid rgba(255,255,255,.1);
}
/* Tavaline edetabel (küsimuste vahel) — kõik kohad ilmuvad korraga */
.leaderboard:not(.final) li {
  animation: slide-in .5s ease both;
}
.leaderboard:not(.final) li:nth-child(1) { background: linear-gradient(90deg, #ffb800, #ff8a00); animation-delay: .1s; }
.leaderboard:not(.final) li:nth-child(2) { background: linear-gradient(90deg, #c0c0c0, #909090); color: #1a1a1a; animation-delay: .2s; }
.leaderboard:not(.final) li:nth-child(3) { background: linear-gradient(90deg, #cd7f32, #a0521d); animation-delay: .3s; }
.leaderboard:not(.final) li:nth-child(4) { animation-delay: .4s; }
.leaderboard:not(.final) li:nth-child(5) { animation-delay: .5s; }

.leaderboard li .rank {
  font-weight: 800;
  font-size: 1.5rem;
  min-width: 2.5rem;
}
.leaderboard li .name { flex: 1; font-weight: 600; }
.leaderboard li .score {
  font-family: ui-monospace, monospace;
  font-weight: 700;
}
@keyframes slide-in {
  from { transform: translateX(-30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* === FINAL PJEDESTAAL — dramaatiline avastamine 3→2→1 === */
.leaderboard.final li {
  animation: podium-entry .9s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.leaderboard.final li.podium-bronze {
  background: linear-gradient(135deg, #d4915e, #b87333 50%, #8b4513);
  color: white;
  font-size: 1.3rem;
}
.leaderboard.final li.podium-silver {
  background: linear-gradient(135deg, #e8e8e8, #b0b0b0 50%, #909090);
  color: #1a1a1a;
  font-size: 1.45rem;
  padding: 1.2rem 1.5rem;
}
.leaderboard.final li.podium-gold {
  background: linear-gradient(135deg, #ffe27a, #ffb800 50%, #ff8a00);
  color: #1a1a1a;
  font-size: 1.7rem;
  padding: 1.6rem 1.5rem;
  font-weight: 800;
  animation:
    podium-entry .9s cubic-bezier(0.34, 1.56, 0.64, 1) both,
    golden-pulse 2.4s ease-in-out infinite .9s;
  position: relative;
}
.leaderboard.final li.podium-gold .rank { font-size: 2rem; }
.leaderboard.final li.podium-gold .name { font-weight: 800; }
.leaderboard.final li.final-rest {
  opacity: 0.85;
  font-size: 1.05rem;
  padding: .75rem 1.5rem;
  animation: fade-in .5s ease both;
}

@keyframes podium-entry {
  0% { transform: translateY(-30px) scale(0.7); opacity: 0; }
  60% { transform: translateY(6px) scale(1.04); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes golden-pulse {
  0%, 100% { box-shadow: 0 0 30px rgba(255, 184, 0, 0.55); }
  50% { box-shadow: 0 0 60px rgba(255, 184, 0, 0.95); }
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 0.85; transform: translateY(0); }
}

/* Lahkunud mängija edetabelis — pisut tuhmim, väike ⊘ tähis */
.leaderboard li.disconnected .name { opacity: 0.65; }
.leaderboard li.disconnected .name::after {
  content: ' ⊘';
  opacity: 0.6;
  font-size: 0.85em;
  margin-left: 0.25rem;
}

/* Host buttons */
.host-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  margin-top: 1.5rem;
}
.host-btn {
  background: var(--accent);
  color: var(--brand-dark);
  border: none;
  padding: 1rem 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .15s ease;
}
.host-btn:hover:not(:disabled) { transform: translateY(-2px); }
.host-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.host-btn.secondary {
  background: rgba(255,255,255,.15);
  color: white;
}

/* ============ PLAYER VAATED ============ */

body.player {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  min-height: 100vh;
}

.join-screen {
  margin: auto;
  max-width: 400px;
  width: 100%;
  text-align: center;
  background: rgba(255,255,255,.05);
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.1);
}
.join-screen h1 {
  font-size: 2.5rem;
  margin-bottom: .5rem;
}
.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}
#join-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
#join-form input {
  font-size: 1.2rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,.1);
  background: rgba(0,0,0,.3);
  color: white;
  text-align: center;
  font-weight: 600;
}
#join-form input:focus { outline: none; border-color: var(--accent); }
#join-form button {
  background: var(--accent);
  color: var(--brand-dark);
  border: none;
  padding: 1rem;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
}
.error {
  color: #ff5577;
  margin-top: 1rem;
  min-height: 1.5rem;
}

.player-wait, .player-locked, .player-result, .player-intro {
  margin: auto;
  text-align: center;
  max-width: 400px;
  width: 100%;
  padding: 2rem;
}
.player-wait h2, .player-intro h2 { font-size: 2rem; margin-bottom: 1.5rem; color: var(--accent); }
.spinner {
  width: 60px;
  height: 60px;
  border: 5px solid rgba(255,255,255,.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 1.5rem;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.player-question {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: .5rem;
}
.player-question .answer-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.answer-btn {
  border: none;
  border-radius: var(--radius);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 1rem;
  min-height: 140px;
  box-shadow: var(--shadow);
  transition: transform .1s ease;
  font-family: var(--font);
  overflow: hidden;
}
.answer-btn:active { transform: scale(0.96); }
.answer-btn .shape {
  position: absolute;
  top: .5rem;
  left: .75rem;
  font-size: 1.6rem;
  opacity: .7;
  pointer-events: none;
}
.answer-btn .answer-text {
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
  width: 100%;
  word-break: break-word;
  hyphens: auto;
  /* font-size dünaamiliselt seatud fitText() poolt */
  font-size: 1.2rem;
}
.answer-btn.ans-0 { background: var(--ans-0); }
.answer-btn.ans-1 { background: var(--ans-1); }
.answer-btn.ans-2 { background: var(--ans-2); }
.answer-btn.ans-3 { background: var(--ans-3); }

.player-locked h2 { font-size: 2rem; color: var(--accent); margin-bottom: 1rem; }
.player-result h2 { font-size: 2.5rem; margin-bottom: 1rem; }
.player-result.correct h2 { color: #4ade80; }
.player-result.wrong h2 { color: #f87171; }
#result-score { font-size: 1.5rem; font-weight: 700; margin: 1rem 0; }
#result-rank { color: var(--text-muted); }

/* Final leaderboard - vana stiil eemaldatud, kuna pjedestaali kohad on nüüd
   individuaalsete klassidega (podium-gold, podium-silver, podium-bronze, final-rest) */
