@font-face {
  font-family: 'Fredoka';
  src: url('../fonts/fredoka-variable.woff2') format('woff2-variations'),
       url('../fonts/fredoka-variable.woff2') format('woff2');
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0c1712;
  --bg-2: #17281f;
  --red: #e21b3c;
  --red-dark: #b8142f;
  --blue: #1368ce;
  --blue-dark: #0e4f9e;
  --yellow: #d89e00;
  --yellow-dark: #a97c00;
  --green: #26890c;
  --green-dark: #1c6809;
  --white: #ffffff;
  --ink: #1b1b3a;
  --gold: #f3b62c;
  --gold-light: #ffd873;
  --gold-deep: #b9820f;
  --ink-on-gold: #2a1c02;
  --emerald: #2f9e58;
  --emerald-dark: #1f7a41;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 18px;
  --font-display: 'Fredoka', 'Segoe UI', system-ui, sans-serif;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--white);
}

body {
  background: radial-gradient(circle at 20% 20%, var(--bg-2), var(--bg) 65%);
  min-height: 100vh;
  overflow-x: hidden;
}

button, a.btn {
  font-family: inherit;
  cursor: pointer;
}

h1, h2, .landing-title, .pin-code, .q-text, .feedback-title {
  font-family: var(--font-display);
}

/* ---------- Landing ---------- */
.landing-body {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.landing {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 40px 24px;
  animation: fadeInUp 0.8s ease both;
}

.landing-emoji {
  font-size: 4rem;
  animation: bounceIn 1s ease both;
}

.landing-title {
  font-size: clamp(2.4rem, 7vw, 4.2rem);
  margin: 8px 0 0;
  font-weight: 700;
  letter-spacing: 1px;
  text-shadow: 0 6px 24px var(--shadow);
}

.landing-title .accent {
  background: linear-gradient(90deg, var(--gold-light), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.landing-sub {
  font-size: 1.2rem;
  opacity: 0.85;
  margin: 10px 0 34px;
}

.landing-buttons {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.btn {
  display: inline-block;
  text-decoration: none;
  padding: 16px 40px;
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 700;
  border: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  box-shadow: 0 8px 0 rgba(0,0,0,0.25);
  min-width: 260px;
  color: var(--white);
}

.btn:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,0.25); }
.btn:hover { filter: brightness(1.08); }

.btn-primary { background: linear-gradient(135deg, var(--gold-light), var(--gold)); color: var(--ink-on-gold); }
.btn-secondary { background: linear-gradient(135deg, var(--emerald), var(--emerald-dark)); }
.btn-ghost {
  background: rgba(255,255,255,0.08);
  border: 2px solid rgba(255,255,255,0.4);
  box-shadow: none;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
}

.landing-shapes { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.shape { position: absolute; opacity: 0.25; }
.shape-triangle { width: 0; height: 0; border-left: 45px solid transparent; border-right: 45px solid transparent; border-bottom: 78px solid var(--red); top: 12%; left: 8%; }
.shape-diamond { width: 70px; height: 70px; background: var(--blue); transform: rotate(45deg); top: 70%; left: 12%; }
.shape-circle { width: 80px; height: 80px; border-radius: 50%; background: var(--yellow); top: 18%; right: 10%; }
.shape-square { width: 70px; height: 70px; border-radius: 12px; background: var(--green); top: 68%; right: 12%; }

.float-1 { animation: float 6s ease-in-out infinite; }
.float-2 { animation: float 7s ease-in-out infinite 0.5s; }
.float-3 { animation: float 5.5s ease-in-out infinite 0.2s; }
.float-4 { animation: float 6.5s ease-in-out infinite 0.8s; }

/* ---------- Shared layout ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  position: relative;
}

.card {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  padding: 32px;
  backdrop-filter: blur(6px);
  width: 100%;
  max-width: 460px;
  animation: fadeInUp 0.6s ease both;
}

.field {
  width: 100%;
  padding: 16px 18px;
  border-radius: 12px;
  border: none;
  font-size: 1.1rem;
  margin-bottom: 14px;
  outline: none;
  text-align: center;
  font-weight: 600;
  color: var(--ink);
}
.field:focus { box-shadow: 0 0 0 3px var(--gold); }

.error-text {
  color: #ffd2d2;
  background: rgba(226,27,60,0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-weight: 600;
  animation: shake 0.4s ease;
}
.hidden { display: none !important; }

/* ---------- Host: PIN + Lobby ---------- */
.pin-label { font-size: 1.1rem; opacity: 0.8; margin-bottom: 6px; }
.pin-code {
  font-size: clamp(2.6rem, 9vw, 5rem);
  font-weight: 700;
  letter-spacing: 6px;
  color: var(--gold-light);
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(243,182,44,0.35);
  border-radius: 16px;
  padding: 10px 26px;
  display: inline-block;
  margin: 10px 0 26px;
  animation: popIn 0.5s ease both;
}

.lobby-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.qr-box {
  background: #ffffff;
  padding: 10px;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: popIn 0.5s ease both;
}

.join-link {
  color: var(--gold-light);
  text-decoration: none;
  font-size: 0.88rem;
  opacity: 0.8;
  word-break: break-all;
  max-width: 420px;
}

.join-link:hover { opacity: 1; text-decoration: underline; }

.player-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 900px;
  margin: 0 auto 30px;
  min-height: 60px;
}

.player-chip {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-dark));
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 700;
  animation: popIn 0.4s ease both;
  box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}

.player-count {
  font-size: 1rem;
  opacity: 0.8;
  margin-bottom: 10px;
}

.waiting-hint { opacity: 0.7; margin-top: 6px; }

/* ---------- Question view ---------- */
.q-wrap {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.q-topbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  opacity: 0.85;
}

.timer-bar-track {
  width: 100%;
  height: 14px;
  background: rgba(255,255,255,0.15);
  border-radius: 999px;
  overflow: hidden;
}
.timer-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  width: 100%;
  transform-origin: left;
  transition: width 0.1s linear;
}

.q-text {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 700;
  margin: 6px 0 10px;
  animation: fadeInUp 0.5s ease both;
  text-shadow: 0 4px 14px var(--shadow);
}

.q-progress { font-weight: 600; opacity: 0.8; }

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
}
.options-grid.two-opt { grid-template-columns: 1fr; max-width: 420px; margin: 0 auto; }

.opt-btn {
  border: none;
  border-radius: 16px;
  padding: 26px 18px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.3s ease, filter 0.2s ease;
  animation: popIn 0.4s ease both;
  text-align: left;
}
.opt-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(0,0,0,0.28); }
.opt-btn .opt-icon { flex: 0 0 auto; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }
.opt-btn.opt-red { background: linear-gradient(135deg, var(--red), var(--red-dark)); }
.opt-btn.opt-blue { background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }
.opt-btn.opt-yellow { background: linear-gradient(135deg, var(--yellow), var(--yellow-dark)); }
.opt-btn.opt-green { background: linear-gradient(135deg, var(--green), var(--green-dark)); }

.opt-btn.selected { outline: 4px solid var(--white); transform: scale(0.97); }
.opt-btn.dim { opacity: 0.35; filter: grayscale(0.3); }
.opt-btn.correct-flash { outline: 5px solid #ffffff; box-shadow: 0 0 0 6px rgba(38,137,12,0.6), 0 6px 0 rgba(0,0,0,0.28); animation: correctPulse 0.7s ease; }
.opt-btn:disabled { cursor: default; }

.icon-triangle { width: 0; height: 0; border-left: 15px solid transparent; border-right: 15px solid transparent; border-bottom: 26px solid var(--white); }
.icon-diamond { width: 22px; height: 22px; background: var(--white); transform: rotate(45deg); border-radius: 3px; }
.icon-circle { width: 24px; height: 24px; background: var(--white); border-radius: 50%; }
.icon-square { width: 22px; height: 22px; background: var(--white); border-radius: 5px; }

/* Player full-screen shape buttons */
.player-answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
  max-width: 560px;
  height: min(70vh, 520px);
}
.player-answer-grid.two-opt { grid-template-columns: 1fr; }
.player-shape-btn {
  border: none;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 0 rgba(0,0,0,0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.3s ease;
}
.player-shape-btn:active { transform: translateY(6px) scale(0.98); box-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.player-shape-btn.opt-red { background: linear-gradient(135deg, var(--red), var(--red-dark)); }
.player-shape-btn.opt-blue { background: linear-gradient(135deg, var(--blue), var(--blue-dark)); }
.player-shape-btn.opt-yellow { background: linear-gradient(135deg, var(--yellow), var(--yellow-dark)); }
.player-shape-btn.opt-green { background: linear-gradient(135deg, var(--green), var(--green-dark)); }
.player-shape-btn .big-icon-triangle { width: 0; height: 0; border-left: 34px solid transparent; border-right: 34px solid transparent; border-bottom: 58px solid var(--white); }
.player-shape-btn .big-icon-diamond { width: 50px; height: 50px; background: var(--white); transform: rotate(45deg); border-radius: 6px; }
.player-shape-btn .big-icon-circle { width: 56px; height: 56px; background: var(--white); border-radius: 50%; }
.player-shape-btn .big-icon-square { width: 50px; height: 50px; background: var(--white); border-radius: 10px; }
.player-shape-btn:disabled { opacity: 0.5; }

/* ---------- Reveal / feedback ---------- */
.feedback-screen { animation: fadeIn 0.3s ease both; }
.feedback-icon { font-size: 5rem; animation: bounceIn 0.6s ease both; }
.feedback-title { font-size: 2rem; font-weight: 700; margin: 6px 0; }
.feedback-title.good { color: #b6ffb0; }
.feedback-title.bad { color: #ffb3b3; }
.feedback-points { font-size: 1.4rem; font-weight: 700; opacity: 0.9; }
.feedback-screen.wrong .feedback-icon { animation: shake 0.5s ease; }

/* bar chart on host reveal */
.bars-wrap {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 34px; height: 34px; border-radius: 8px; flex: 0 0 auto; }
.bar-track { flex: 1; background: rgba(255,255,255,0.12); border-radius: 8px; height: 34px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; border-radius: 8px; transition: width 0.8s cubic-bezier(.2,.8,.2,1); display: flex; align-items: center; justify-content: flex-end; padding-right: 10px; font-weight: 700; }
.bar-fill.correct-bar { box-shadow: 0 0 0 3px #ffffffaa inset; }

/* ---------- Leaderboard ---------- */
.leaderboard-list { width: 100%; max-width: 620px; display: flex; flex-direction: column; gap: 10px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 700;
  animation: slideInLB 0.5s ease both;
}
.lb-row.me { background: linear-gradient(135deg, rgba(243,182,44,0.35), rgba(47,158,88,0.35)); border: 2px solid var(--gold); }
.lb-rank { width: 34px; font-size: 1.2rem; }
.lb-name { flex: 1; text-align: left; }
.lb-score { font-variant-numeric: tabular-nums; }

/* ---------- Podium ---------- */
.podium-wrap {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  margin: 40px 0 20px;
}
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.podium-block {
  width: 110px;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14px;
  font-weight: 800;
  font-size: 1.6rem;
  animation: growUp 0.7s cubic-bezier(.2,.8,.2,1) both;
}
.podium-1 .podium-block { height: 190px; background: linear-gradient(180deg, #ffd23f, #d89e00); animation-delay: 0.4s; }
.podium-2 .podium-block { height: 140px; background: linear-gradient(180deg, #d9d9e6, #9a9ab0); animation-delay: 0.15s; }
.podium-3 .podium-block { height: 100px; background: linear-gradient(180deg, #e79a5c, #b06a2e); animation-delay: 0s; }
.podium-name { font-weight: 700; }
.podium-crown { font-size: 2rem; animation: bounceIn 0.6s ease 0.9s both; }

/* ---------- Buttons row (host controls) ---------- */
.controls-row { display: flex; gap: 14px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { 0% { opacity: 0; transform: scale(0.6); } 70% { transform: scale(1.05); } 100% { opacity: 1; transform: scale(1); } }
@keyframes bounceIn { 0% { opacity: 0; transform: scale(0.3); } 50% { opacity: 1; transform: scale(1.15); } 70% { transform: scale(0.92); } 100% { transform: scale(1); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-20px) rotate(6deg); } }
@keyframes correctPulse { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes slideInLB { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes growUp { from { height: 0; opacity: 0; } to { opacity: 1; } }

.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 5px solid rgba(255,255,255,0.25);
  border-top-color: var(--white);
  animation: spin 0.9s linear infinite;
  margin: 10px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.score-count {
  font-variant-numeric: tabular-nums;
}

canvas#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

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

@media (prefers-reduced-motion: reduce) {
  .float-1, .float-2, .float-3, .float-4 { animation: none; }
  * { scroll-behavior: auto !important; }
}
