:root {
  --bg: #46178f;
  --bg-dark: #2a0d5e;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6b6b76;
  --c0: #e21b3c;
  --c1: #1368ce;
  --c2: #d89e00;
  --c3: #26890c;
  --good: #26890c;
  --bad: #c8102e;
  --gold: #ffd84d;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(circle at 20% 0%, #5d27b3 0%, var(--bg) 45%, var(--bg-dark) 100%) fixed;
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
body.good { background: var(--good); }
body.bad { background: var(--bad); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.22);
  font-weight: 700;
}
.topbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.brand { font-size: 1.1rem; letter-spacing: 0.02em; }
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
}
.screen { flex: 1; display: flex; flex-direction: column; gap: 16px; }
.center { align-items: center; justify-content: center; text-align: center; }
.card {
  flex: 0 0 auto;
  margin: auto;
  width: 100%;
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}
.narrow { max-width: 420px; }
.wide { max-width: 900px; }
h1, h2 { margin: 0; }
h1 { font-size: clamp(1.5rem, 4vw, 2.4rem); }
.muted { color: rgba(255, 255, 255, 0.82); margin: 0; }
.card .muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* ---------- controls ---------- */
form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
input, textarea {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  padding: 14px;
  border: 2px solid #d0d0d8;
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}
input:focus, textarea:focus { outline: none; border-color: var(--bg); }
textarea { min-height: 50vh; font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; resize: vertical; }
#pinInput { text-align: center; font-size: 1.7rem; font-weight: 800; letter-spacing: 0.25em; }
#nameInput { text-align: center; font-size: 1.3rem; font-weight: 700; }
button {
  font: inherit;
  font-weight: 700;
  border: 0;
  border-radius: 8px;
  padding: 12px 20px;
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: #262626; color: #fff; box-shadow: 0 4px 0 #000; }
.primary:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #000; }
.ghost { background: rgba(255, 255, 255, 0.16); color: #fff; }
.ghost:hover { background: rgba(255, 255, 255, 0.26); }
.big { font-size: 1.25rem; padding: 16px 30px; }
.error { color: var(--bad); font-weight: 600; min-height: 1.3em; margin: 10px 0 0; }
.danger { background: var(--bad); color: #fff; }
.plain { background: #ececf2; color: var(--text); }
dialog.card { border: 0; padding: 24px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { margin-top: 0; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.dialog-actions .primary { flex: 1; }
.editable { cursor: pointer; }
.editable:hover { outline: 3px solid rgba(255, 255, 255, 0.7); }
.results tr.editable:hover { outline: 0; background: #f4f0ff; }
.me { background: rgba(0, 0, 0, 0.25); padding: 6px 12px; border-radius: 20px; font-size: 0.95rem; }

.offline {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.85);
  text-align: center;
  padding: 8px;
  font-weight: 700;
}

.spinner {
  width: 56px; height: 56px;
  border: 6px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- lobby (host) ---------- */
.lobby-top {
  display: flex;
  gap: 32px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  background: #fff;
  color: var(--text);
  border-radius: 14px;
  padding: 20px 28px;
}
.join-box { text-align: center; }
.join-label { font-size: 1.1rem; font-weight: 600; color: var(--muted); }
.join-url { font-size: clamp(1.4rem, 3vw, 2.3rem); font-weight: 800; margin-bottom: 14px; word-break: break-all; }
.pin { font-size: clamp(3rem, 9vw, 6.5rem); font-weight: 900; letter-spacing: 0.06em; line-height: 1.05; }
.qr { width: min(40vh, 340px); aspect-ratio: 1; background: #fff; }
.lobby-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.count { font-size: 1.6rem; font-weight: 800; background: rgba(0, 0, 0, 0.25); padding: 8px 18px; border-radius: 8px; }
.players { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-content: flex-start; }
.chip { background: rgba(255, 255, 255, 0.95); color: var(--text); padding: 8px 14px; font-size: 1.05rem; }
.chip.offline-p { opacity: 0.5; }
.chip:hover { background: #e9ddff; }

/* ---------- questions ---------- */
.q-meta { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 1.15rem; gap: 12px; }
.q-text {
  background: #fff;
  color: var(--text);
  padding: 20px 24px;
  border-radius: 12px;
  text-align: center;
  font-size: clamp(1.4rem, 3.2vw, 2.6rem);
  line-height: 1.25;
}
.q-middle { flex: 1; display: flex; justify-content: center; align-items: center; min-height: 140px; }
.timer {
  width: 130px; height: 130px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-dark);
  border: 6px solid #fff;
  font-size: 3.2rem;
  font-weight: 900;
}
.timer.low { background: var(--bad); }
.timer.pill { width: auto; height: auto; border: 0; border-radius: 20px; padding: 4px 14px; font-size: 1.3rem; background: rgba(0, 0, 0, 0.3); }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 20px;
  border-radius: 10px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(1.1rem, 2.4vw, 1.9rem);
  text-align: left;
  min-height: 84px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
  word-break: break-word;
}
.c0 { background: var(--c0); }
.c1 { background: var(--c1); }
.c2 { background: var(--c2); }
.c3 { background: var(--c3); }
.shape { font-size: 1.4em; line-height: 1; flex: 0 0 auto; }
.option.dim { opacity: 0.3; }
.option.correct { outline: 5px solid #fff; outline-offset: -5px; }
.option.correct::after { content: "✔"; margin-left: auto; font-size: 1.3em; }

/* player answer buttons fill the screen */
.p-q {
  background: #fff;
  color: var(--text);
  padding: 14px;
  border-radius: 10px;
  text-align: center;
  font-size: 1.15rem;
  line-height: 1.3;
}
.player-options { flex: 1; grid-auto-rows: 1fr; min-height: 55vh; }
.player-options .option { font-size: 1.15rem; min-height: 0; flex-direction: column; justify-content: center; text-align: center; }
.player-options .option:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28); }

/* ---------- reveal ---------- */
.bars { display: flex; justify-content: center; align-items: flex-end; gap: 16px; height: 30vh; min-height: 160px; }
.bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 120px; height: 100%; }
.bar-col.dim { opacity: 0.35; }
.bar-label { font-size: 1.7rem; font-weight: 800; margin-bottom: 6px; }
.bar { width: 100%; min-height: 8px; border-radius: 6px 6px 0 0; transition: height 0.6s ease; }
.bar-foot { width: 100%; text-align: center; padding: 6px; font-size: 1.4rem; border-radius: 0 0 6px 6px; }

/* ---------- leaderboard ---------- */
.board { list-style: none; padding: 0; margin: 0 auto; width: 100%; max-width: 820px; display: flex; flex-direction: column; gap: 8px; }
.board li {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff;
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  font-weight: 700;
}
.board li:first-child { background: var(--gold); }
.board .rk { width: 2.2em; color: var(--muted); }
.board li:first-child .rk { color: #6b5200; }
.board .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- podium ---------- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 12px; min-height: 320px; }
.pod { display: flex; flex-direction: column; align-items: center; width: min(28vw, 230px); }
.pod .nm { font-size: clamp(1.1rem, 2.6vw, 1.6rem); font-weight: 800; text-align: center; word-break: break-word; margin-bottom: 8px; }
.pod .block {
  width: 100%;
  border-radius: 10px 10px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 14px;
  font-size: 2.6rem;
  font-weight: 900;
}
.pod .sc { font-size: 1rem; font-weight: 700; }
.pod.p1 .block { height: 230px; background: var(--gold); color: #5a4500; }
.pod.p2 .block { height: 170px; background: #dcdce6; color: #3a3a48; }
.pod.p3 .block { height: 120px; background: #e3a466; color: #5a3310; }
.results-wrap { background: #fff; color: var(--text); border-radius: 12px; max-height: 40vh; overflow: auto; width: 100%; max-width: 820px; margin: 0 auto; }
.results { width: 100%; border-collapse: collapse; }
.results th, .results td { padding: 8px 14px; text-align: left; border-bottom: 1px solid #eee; }
.results th { position: sticky; top: 0; background: #f4f4f8; }

/* ---------- player result ---------- */
.result-icon { font-size: 5rem; line-height: 1; }
.points { font-size: 1.7rem; font-weight: 800; margin: 0; }
.rank { background: rgba(0, 0, 0, 0.25); padding: 10px 20px; border-radius: 30px; font-weight: 700; margin: 0; }
.rank:empty { display: none; }
.big-name { font-size: 2rem; font-weight: 800; margin: 0; word-break: break-word; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .bars { gap: 8px; }
  .bar-col { width: 70px; }
  .lobby-top { gap: 12px; padding: 16px; }
}
