:root {
  --purple: #46178f;
  --purple-2: #6a1fc7;
  --bg: #2d0b5a;
  --white: #ffffff;
  --ink: #1f1235;
  --muted: #6e6a7c;
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  --radius: 14px;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", Montserrat, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--purple) 0%, var(--bg) 60%, #17053a 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--white);
  border-radius: 18px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  text-align: center;
  animation: pop 0.25s ease;
}

.wide { max-width: 900px; }

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

.brand {
  color: var(--white);
  text-align: center;
  margin: 18px 0 26px;
}
.brand h1 { font-size: 2.1rem; letter-spacing: 0.5px; }
.brand p { opacity: 0.8; margin-top: 6px; }

h2 { font-size: 1.5rem; margin-bottom: 6px; }
.sub { color: var(--muted); margin-bottom: 20px; }

/* ---------- Inputs & buttons ---------- */
input[type="text"], input[type="number"] {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  border: 3px solid #e3e3ea;
  border-radius: 10px;
  margin-bottom: 14px;
  text-align: center;
  font-weight: 600;
  transition: border-color 0.15s;
}
input:focus { outline: none; border-color: var(--purple-2); }

.pin-input {
  letter-spacing: 8px;
  font-size: 1.6rem;
  font-weight: 800;
}

button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-weight: 800;
  transition: transform 0.08s, filter 0.15s;
}
button:active { transform: translateY(2px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn {
  width: 100%;
  padding: 16px;
  font-size: 1.15rem;
  border-radius: 10px;
  background: var(--purple);
  color: var(--white);
  box-shadow: var(--shadow);
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn.secondary { background: #eceaf5; color: var(--purple); box-shadow: 0 4px 0 #cfc9e6; }
.btn.green { background: var(--green); box-shadow: 0 4px 0 #196b06; }
.btn.small { width: auto; padding: 10px 18px; font-size: 0.95rem; }

.link {
  display: inline-block;
  margin-top: 18px;
  color: var(--white);
  opacity: 0.85;
  text-decoration: none;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.5);
}
.link:hover { opacity: 1; }

.error {
  background: #ffe5e9;
  color: var(--red);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 0.95rem;
}

.notice { color: var(--muted); font-size: 0.9rem; margin-top: 10px; }

/* ---------- PIN display (host) ---------- */
.pin-box {
  background: var(--white);
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 26px;
  display: inline-block;
  margin: 10px 0;
}
.pin-box .label { font-size: 0.9rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.pin-box .pin { font-size: 3.4rem; font-weight: 900; letter-spacing: 10px; color: var(--purple); }

.join-url { color: var(--white); font-size: 1.1rem; margin: 8px 0 4px; }
.join-url b { background: rgba(255,255,255,0.15); padding: 2px 8px; border-radius: 6px; }

#qrcode { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; margin-top: 8px; }
#qrcode img, #qrcode canvas { display: block; }

/* ---------- Lobby players ---------- */
.counter {
  color: var(--white);
  font-size: 1.3rem;
  font-weight: 800;
  margin: 16px 0;
}
.counter b { font-size: 1.8rem; }

.players {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 10px 0 20px;
  max-width: 900px;
}
.chip {
  background: var(--white);
  color: var(--purple);
  padding: 10px 16px;
  border-radius: 30px;
  font-weight: 800;
  box-shadow: var(--shadow);
  animation: pop 0.2s ease;
}

/* ---------- Question / answers ---------- */
.qwrap { width: 100%; max-width: 1000px; }
.qbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--white);
  font-weight: 800;
  margin-bottom: 12px;
}
.timer {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: var(--white);
  color: var(--purple);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 900;
  box-shadow: var(--shadow);
}
.qcard {
  background: var(--white);
  border-radius: 16px;
  padding: 30px 24px;
  font-size: 1.8rem;
  font-weight: 800;
  text-align: center;
  min-height: 130px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 16px;
}
.category-tag {
  display: inline-block;
  background: var(--purple-2);
  color: #fff;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.answer {
  color: var(--white);
  padding: 22px 18px;
  border-radius: 12px;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: left;
  display: flex; align-items: center; gap: 14px;
  box-shadow: var(--shadow);
  min-height: 90px;
}
.answer .shape { font-size: 1.6rem; }
.answer.a0 { background: var(--red); }
.answer.a1 { background: var(--blue); }
.answer.a2 { background: var(--yellow); }
.answer.a3 { background: var(--green); }
.answer.dim { opacity: 0.35; }
.answer.correct { outline: 6px solid #fff; transform: scale(1.02); }
.answer.chosen { outline: 6px solid #ffe14d; }

/* Player answer buttons: big color blocks */
.answer-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 600px;
}
.answer-btns .answer { cursor: pointer; justify-content: center; text-align: center; font-size: 1.15rem; }
.answer-btns .answer:hover { filter: brightness(1.08); }

.waiting-big {
  color: var(--white);
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  margin: 30px 0;
}
.spinner {
  width: 54px; height: 54px;
  border: 6px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  margin: 20px auto;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Results / leaderboard ---------- */
.result-banner {
  padding: 26px;
  border-radius: 16px;
  color: #fff;
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 16px;
}
.result-banner.ok { background: var(--green); }
.result-banner.no { background: var(--red); }
.gain { font-size: 1.4rem; margin-top: 8px; font-weight: 800; }
.score-big { font-size: 1.2rem; color: var(--muted); font-weight: 800; margin-top: 6px; }

.leaderboard { width: 100%; max-width: 560px; margin: 0 auto; }
.lb-row {
  display: flex; align-items: center;
  background: var(--white);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  animation: pop 0.25s ease;
}
.lb-row .rank { font-weight: 900; font-size: 1.2rem; width: 40px; color: var(--purple); }
.lb-row .name { flex: 1; font-weight: 800; text-align: left; }
.lb-row .score { font-weight: 900; color: var(--purple-2); }
.lb-row.me { background: #fff6c9; }

.dist { display: flex; gap: 10px; justify-content: center; align-items: flex-end; height: 130px; margin: 16px 0; }
.dist .bar-wrap { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; height: 100%; }
.dist .bar { width: 100%; border-radius: 8px 8px 0 0; min-height: 6px; transition: height 0.5s; }
.dist .bar.b0 { background: var(--red); }
.dist .bar.b1 { background: var(--blue); }
.dist .bar.b2 { background: var(--yellow); }
.dist .bar.b3 { background: var(--green); }
.dist .cnt { color: #fff; font-weight: 800; margin-bottom: 4px; }
.dist .tick { color: #fff; font-size: 1.4rem; margin-top: 6px; }

/* ---------- Podium ---------- */
.podium { display: flex; gap: 14px; justify-content: center; align-items: flex-end; margin: 24px 0; }
.pod {
  background: var(--white);
  border-radius: 12px 12px 0 0;
  padding: 16px 14px;
  text-align: center;
  min-width: 120px;
  box-shadow: var(--shadow);
}
.pod .medal { font-size: 2.2rem; }
.pod .pname { font-weight: 900; margin: 6px 0; }
.pod .pscore { color: var(--purple-2); font-weight: 800; }
.pod.p1 { height: 200px; order: 2; }
.pod.p2 { height: 160px; order: 1; }
.pod.p3 { height: 130px; order: 3; }

.explain {
  background: #f2eeff;
  border-left: 5px solid var(--purple-2);
  padding: 12px 16px;
  border-radius: 8px;
  text-align: left;
  color: var(--ink);
  margin: 14px 0;
  font-size: 0.98rem;
}

.center { text-align: center; }
.mt { margin-top: 16px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

@media (max-width: 560px) {
  .qcard { font-size: 1.3rem; }
  .answers { grid-template-columns: 1fr; }
  .answer { font-size: 1.05rem; min-height: 70px; }
  .pin-box .pin { font-size: 2.4rem; letter-spacing: 6px; }
}
