:root {
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --ink: #1f1135;
  --bg1: #46178f;
  --bg2: #7b2ff7;
  --paper: #ffffff;
  --muted: #6b6b80;
  --ok: #26890c;
  --bad: #e21b3c;
  --shadow: 0 6px 0 rgba(0,0,0,.18);
}

* { 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(--bg2), var(--bg1));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

a { color: inherit; }

.brand {
  color: #fff;
  font-weight: 800;
  font-size: clamp(28px, 7vw, 56px);
  letter-spacing: 1px;
  text-shadow: 0 4px 0 rgba(0,0,0,.25);
  margin: 10px 0 4px;
}
.brand span { color: #ffd000; }
.tagline { color: #e9defc; margin-bottom: 18px; font-size: 14px; }

.card {
  background: var(--paper);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.card.wide { max-width: 960px; }

.screen { display: none; width: 100%; align-items: center; flex-direction: column; }
.screen.active { display: flex; }

h1, h2 { line-height: 1.15; }
.center { text-align: center; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; }

input, select, textarea, button { font: inherit; }

input.field, select.field, textarea.field {
  width: 100%;
  padding: 14px 16px;
  border: 3px solid #e3e3ef;
  border-radius: 10px;
  font-size: 18px;
  outline: none;
}
input.field:focus, textarea.field:focus, select.field:focus { border-color: var(--bg2); }
input.pin {
  text-align: center;
  font-size: 30px;
  letter-spacing: 8px;
  font-weight: 800;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  background: var(--ink);
  box-shadow: var(--shadow);
  transition: transform .05s ease, filter .15s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(3px); box-shadow: none; }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; transform: none; }
button.block { width: 100%; }
button.ghost { background: #efeef6; color: var(--ink); box-shadow: 0 6px 0 #d7d6e4; }
button.green { background: var(--green); box-shadow: 0 6px 0 #1c6608; }
button.red { background: var(--red); box-shadow: 0 6px 0 #a5132c; }
button.small { padding: 8px 12px; font-size: 14px; border-radius: 8px; box-shadow: 0 4px 0 rgba(0,0,0,.18); }

/* ---- big PIN / lobby ---- */
.pinbox { background: var(--paper); color: var(--ink); border-radius: 14px; padding: 14px 22px; text-align: center; }
.pinbox .label { font-size: 14px; color: var(--muted); font-weight: 700; }
.pinbox .pin { font-size: clamp(40px, 12vw, 84px); font-weight: 900; letter-spacing: 6px; }
.joinurl { color:#fff; font-size: 15px; margin: 10px 0; }
.joinurl b { background: rgba(0,0,0,.25); padding: 3px 8px; border-radius: 6px; }
.joinlink { display:flex; gap:8px; align-items:center; width:100%; max-width:520px; margin:4px 0 8px; }
.joinlink .field { flex:1; font-size:13px; padding:10px 12px; color:var(--ink); background:#fff; }

.players { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 8px; }
.chip {
  background: #fff; color: var(--ink); font-weight: 800;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 4px 0 rgba(0,0,0,.15);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.counter { color:#fff; font-weight:800; font-size: 20px; }

/* ---- question + answers ---- */
.qtext {
  background: #fff; color: var(--ink); border-radius: 14px;
  padding: 18px; font-size: clamp(20px, 3.2vw, 34px); font-weight: 800;
  text-align: center; width: 100%; margin-bottom: 14px;
}
.qmeta { color:#fff; display:flex; justify-content: space-between; width:100%; margin-bottom:10px; font-weight:700;}

.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.answers.single { grid-template-columns: 1fr; }
.ans {
  display: flex; align-items: center; gap: 12px;
  color: #fff; font-size: clamp(16px, 2.4vw, 24px); font-weight: 800;
  padding: 18px; border-radius: 12px; min-height: 76px; text-align: left;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none;
}
.ans .shape { font-size: 26px; line-height: 1; }
.ans.c0 { background: var(--red); }
.ans.c1 { background: var(--blue); }
.ans.c2 { background: var(--yellow); }
.ans.c3 { background: var(--green); }
.ans.dim { opacity: .35; }
.ans.win { outline: 5px solid #fff; box-shadow: 0 0 0 6px rgba(255,255,255,.4), 0 6px 0 rgba(0,0,0,.25); }
.ans .tick { margin-left: auto; font-size: 26px; }

button.ans { cursor: pointer; }
.player-answers { grid-template-columns: 1fr 1fr; }
.player-answers .ans { min-height: 18vh; font-size: clamp(16px,4.5vw,22px); }
.player-answers .ans .shape { font-size: 34px; }

/* ---- timer ---- */
.timer {
  width: 64px; height: 64px; border-radius: 50%;
  background: #fff; color: var(--ink); font-weight: 900; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
}
.bar { width: 100%; height: 12px; background: rgba(255,255,255,.3); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.bar > i { display: block; height: 100%; background: #ffd000; width: 100%; transition: width .25s linear; }

/* ---- reveal distribution ---- */
.dist { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; align-items: end; }
.dist .col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dist .barv { width: 70%; border-radius: 8px 8px 0 0; min-height: 6px; transition: height .4s ease; }
.dist .barv.c0 { background: var(--red); }
.dist .barv.c1 { background: var(--blue); }
.dist .barv.c2 { background: var(--yellow); }
.dist .barv.c3 { background: var(--green); }
.dist .n { color: var(--ink); font-weight: 800; }
.dist .lab { color: var(--ink); font-weight:700; display:flex; gap:6px; align-items:center; justify-content:center; text-align:center; }
.dist .barv.win { outline: 4px solid var(--ink); }

.lb { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.lb .lrow {
  display: flex; align-items: center; gap: 10px; background: #fff;
  border-radius: 10px; padding: 10px 14px; font-weight: 800; box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
.lb .lrow .pos { width: 26px; color: var(--muted); }
.lb .lrow .sc { margin-left: auto; }
.lb .lrow.me { background: #fff3c4; outline: 3px solid #ffd000; }

/* ---- player result ---- */
.verdict { width: 100%; border-radius: 16px; padding: 28px; text-align: center; color:#fff; }
.verdict.good { background: var(--green); }
.verdict.bad { background: var(--red); }
.verdict .big { font-size: 36px; font-weight: 900; }
.verdict .pts { font-size: 26px; font-weight: 800; margin-top: 8px; }
.waitdot { color:#fff; font-size: 20px; font-weight: 700; text-align:center; }

/* ---- podium ---- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 12px; width: 100%; margin: 20px 0; }
.podium .stand { background: #fff; border-radius: 12px 12px 0 0; width: 28%; text-align: center; padding: 12px; box-shadow: 0 6px 0 rgba(0,0,0,.2); }
.podium .stand .nm { font-weight: 900; }
.podium .stand .sc { color: var(--muted); font-weight: 800; }
.podium .p1 { height: 200px; background: #ffd700; }
.podium .p2 { height: 160px; background: #e6e6e6; }
.podium .p3 { height: 130px; background: #e6a667; }
.podium .medal { font-size: 30px; }

/* ---- editor ---- */
.qcard { border: 3px solid #ece9f6; border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.qcard .opt { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.qcard .opt .dot { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.qcard .opt .dot.c0 { background: var(--red);} .qcard .opt .dot.c1 { background: var(--blue);}
.qcard .opt .dot.c2 { background: var(--yellow);} .qcard .opt .dot.c3 { background: var(--green);}
.qcard .opt input[type=radio] { width: 22px; height: 22px; }
.qhead { display:flex; gap:10px; align-items:center; }
.qhead .num { font-weight: 900; color: var(--bg1); }
.qhead .inc { display:flex; align-items:center; gap:4px; font-size:12px; font-weight:800; color:var(--green); white-space:nowrap; cursor:pointer; }
.qhead .inc input { width:20px; height:20px; }
.qcard.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgba(38,137,12,.22); }
.selbar { display:flex; flex-wrap:wrap; gap:8px; align-items:center; background:#efeef6; border-radius:10px; padding:10px 12px; margin-bottom:12px; font-weight:800; }

/* per-question image attachments — editor thumbnails */
.qimgs { display:flex; flex-wrap:wrap; align-items:center; gap:10px; margin-top:10px; }
.qimgs .thumb { position:relative; display:inline-block; }
.qimgs .thumb img { height:50px; width:auto; max-width:120px; border-radius:6px; display:block; border:2px solid #e3e3ef; object-fit:cover; }
.qimgs .rmimg { position:absolute; top:-7px; right:-7px; width:20px; height:20px; border-radius:50%; background:var(--red); color:#fff; border:none; font-size:13px; line-height:18px; padding:0; box-shadow:none; cursor:pointer; }
.qimgs .rmimg:active { transform:none; }
.qimgs .imgcount { font-size:12px; }
/* displayed images (host + player question/reveal) */
.qimgs-show { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
.qimgs-show:not(:empty) { margin:6px 0 12px; }
.qimgs-show img { max-height:30vh; max-width:100%; border-radius:10px; box-shadow:0 4px 14px rgba(0,0,0,.3); background:#fff; }

/* ---- game review ---- */
.revq { border:2px solid #ece9f6; border-radius:12px; padding:12px 14px; margin-bottom:10px; }
.revq-h { font-size:16px; margin-bottom:8px; }
.revopts { display:flex; flex-direction:column; gap:6px; }
.revopt { display:flex; align-items:center; gap:8px; background:#f4f2fb; border-radius:8px; padding:7px 10px; font-weight:700; }
.revopt.win { background:#d4f4cf; outline:2px solid var(--green); }
.revopt .rdot { width:16px; height:16px; border-radius:4px; flex:none; }
.revopt .rdot.c0{ background:var(--red); } .revopt .rdot.c1{ background:var(--blue); }
.revopt .rdot.c2{ background:var(--yellow); } .revopt .rdot.c3{ background:var(--green); }
.revopt .rtext { flex:1; } .revopt .rn { color:var(--muted); }

/* ---- series per-theme breakdown table ---- */
.seriestbl { width:100%; border-collapse:collapse; font-weight:700; }
.seriestbl th, .seriestbl td { padding:7px 10px; text-align:center; border-bottom:1px solid #ece9f6; white-space:nowrap; }
.seriestbl th:first-child, .seriestbl td:first-child { text-align:left; }
.seriestbl thead th { color:var(--muted); font-size:12px; }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; font-weight: 800; padding: 12px 18px;
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.3); display: none; z-index: 50;
}
.toast.show { display: block; animation: pop .2s ease; }

.footlink { color:#e9defc; margin-top:16px; font-size: 13px; }
.hide { display: none !important; }

/* ---- user bar + badges (host/admin) ---- */
.userbar {
  width: 100%; max-width: 960px; display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.12); color: #fff; border-radius: 10px;
  padding: 8px 14px; margin-bottom: 14px; font-size: 14px;
}
.userbar b { font-weight: 800; }
.badge {
  display: inline-block; background: #efeef6; color: var(--ink);
  font-size: 12px; font-weight: 800; padding: 2px 9px; border-radius: 999px;
  text-transform: capitalize;
}
.badge.admin { background: #ffd000; color: #4a3b00; }
.badge.on { background: #d4f4cf; color: #1c6608; }
.badge.off { background: #f6d4d4; color: #a5132c; }
#userList .lrow { gap: 8px; flex-wrap: wrap; }

/* ---- landing / front page ---- */
.home-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  width: 100%; max-width: 820px;
}
.home-card {
  background: var(--paper); border-radius: 16px; padding: 24px;
  display: flex; flex-direction: column; gap: 10px; min-height: 270px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
}
.home-card h2 { font-size: 26px; }
.home-ico { font-size: 50px; line-height: 1; }

/* ---- wheel of fortune ---- */
.wheel-layout {
  display: flex; gap: 24px; width: 100%; max-width: 900px;
  align-items: flex-start; justify-content: center;
}
.wheel-stage { position: relative; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.wheel-stage canvas {
  width: min(82vw, 440px); height: auto; border-radius: 50%;
  transform-origin: 50% 50%; box-shadow: 0 12px 34px rgba(0,0,0,.4);
  background: #fff;
}
.wheel-pointer {
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent;
  border-top: 30px solid #fff; z-index: 5; filter: drop-shadow(0 3px 2px rgba(0,0,0,.45));
}
#spinBtn { font-size: 22px; padding: 14px 44px; border-radius: 999px; letter-spacing: 1px; }
.wheel-panel { flex: 1; max-width: 360px; }
.namelist { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow: auto; margin-top: 4px; }
.nm-item { display: flex; align-items: center; gap: 8px; background: #f4f2fb; border-radius: 8px; padding: 8px 12px; font-weight: 700; }
.nm-item .x { margin-left: auto; cursor: pointer; color: var(--muted); font-weight: 800; border: none; background: none; font-size: 20px; box-shadow: none; padding: 0 4px; }
.nm-item .x:active { transform: none; }

/* ---- overlay (winner) ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(20,8,50,.72);
  display: flex; align-items: center; justify-content: center; z-index: 60; padding: 16px;
}
.overlay-card {
  background: var(--paper); border-radius: 18px; padding: 30px 34px; text-align: center;
  max-width: 92vw; box-shadow: 0 24px 70px rgba(0,0,0,.5); animation: pop .25s ease;
}
.overlay-card .muted { font-weight: 800; text-transform: uppercase; letter-spacing: 2px; }
.winner-name { font-size: clamp(30px, 8vw, 56px); font-weight: 900; color: var(--bg1); margin: 6px 0 20px; word-break: break-word; }

@media (max-width: 640px) {
  .home-grid { grid-template-columns: 1fr; }
  .wheel-layout { flex-direction: column; align-items: center; }
  .wheel-panel { max-width: min(82vw, 440px); width: 100%; }
}

@media (max-width: 520px) {
  .player-answers .ans { min-height: 18vh; }
}

/* ---- poll / survey mode ---- */
/* editor toggle */
.pollswitch { display:flex; align-items:center; gap:6px; font-weight:700; color:var(--ink);
  cursor:pointer; user-select:none; }
.pollswitch input { width:16px; height:16px; }
/* hide the "correct answer" pickers while building a poll */
#editor.poll-mode .opt .cor { display:none; }

/* result bars — colour is inherited so they read on light (host) or dark (player) */
.pollq { text-align:left; margin:14px auto 0; max-width:560px; }
.pollq-h { font-weight:800; margin-bottom:8px; }
.pbars { display:flex; flex-direction:column; gap:9px; }
.pbar-row { display:grid; grid-template-columns:minmax(88px,38%) 1fr auto; align-items:center;
  gap:8px; font-size:14px; }
.pbar-lab { display:flex; align-items:center; gap:6px; min-width:0;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.pbar-row.mine .pbar-lab { font-weight:800; }
.pbar-lab .rdot { width:14px; height:14px; border-radius:4px; flex:none; }
.rdot.c0 { background:var(--red); } .rdot.c1 { background:var(--blue); }
.rdot.c2 { background:var(--yellow); } .rdot.c3 { background:var(--green); }
.pbar-track { height:18px; border-radius:6px; background:rgba(128,128,128,.25); overflow:hidden; }
.pbar-fill { height:100%; border-radius:6px; min-width:3px; transition:width .5s ease; }
.pbar-fill.c0 { background:var(--red); } .pbar-fill.c1 { background:var(--blue); }
.pbar-fill.c2 { background:var(--yellow); } .pbar-fill.c3 { background:var(--green); }
.pbar-n { font-variant-numeric:tabular-nums; font-size:13px; white-space:nowrap; opacity:.85; }
.pbar-total { font-size:12px; opacity:.8; margin-top:6px; }
.pollq + .pollq { border-top:1px solid rgba(128,128,128,.25); padding-top:14px; }

/* admin access log table */
.logtbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.logtbl th, .logtbl td { text-align: left; padding: 7px 9px; border-bottom: 1px solid #eee; }
.logtbl thead th { position: sticky; top: 0; background: #f4f2fb; color: #46178f; font-weight: 700; }
.logtbl tbody tr:hover { background: #faf9ff; }
#accessSummary .badge { background: #eee7fb; color: #46178f; }
