* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: #46178f;
  color: #fff;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; border: 0; }
input, select { font: inherit; }

.screen { display: none; min-height: 100vh; padding: 24px 16px; flex-direction: column; align-items: center; }
.screen.active { display: flex; }
.center { justify-content: center; text-align: center; }

.btn {
  background: #fff; color: #333; font-weight: 700; padding: 12px 22px; border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.dark { background: #333; color: #fff; }
.btn.green { background: #26890c; color: #fff; }
.btn.big { font-size: 1.25rem; padding: 14px 32px; }
.link { background: none; color: #46178f; padding: 4px 8px; font-weight: 600; }
.link.danger { color: #c0102b; }

.logo { font-size: 2.4rem; font-weight: 900; letter-spacing: -1px; margin: 8px 0 20px; }
.muted { opacity: .8; }
.error { color: #ffd1d8; min-height: 1.4em; margin: 8px 0; font-weight: 600; }

/* ---------- Cards / forms ---------- */
.card { background: #fff; color: #333; border-radius: 10px; padding: 20px; width: 100%; max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.card input { width: 100%; padding: 12px; border: 2px solid #ccc; border-radius: 6px; font-size: 1.1rem; text-align: center; font-weight: 700; margin-bottom: 10px; }
.card .btn { width: 100%; }

/* ---------- Answer colours ---------- */
.opt-0 { background: #e21b3c; }
.opt-1 { background: #1368ce; }
.opt-2 { background: #d89e00; }
.opt-3 { background: #26890c; }

/* ---------- Editor (host) ---------- */
.editor { width: 100%; max-width: 900px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input { flex: 1 1 240px; padding: 10px 12px; border-radius: 6px; border: 0; font-size: 1.1rem; font-weight: 700; }
.qcard { background: #fff; color: #333; border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.qhead { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.qhead b { font-size: 1.1rem; margin-right: auto; }
.qhead select { padding: 4px; }
.qcard > input { width: 100%; padding: 10px; border: 2px solid #ddd; border-radius: 6px; font-size: 1.05rem; margin-bottom: 8px; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; }
.optedit { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; color: #fff; }
.optedit span { font-size: 1.2rem; width: 1.2em; text-align: center; }
.optedit input[type=text], .optedit input:not([type]) { flex: 1; min-width: 0; padding: 8px; border: 0; border-radius: 4px; }
.optedit input[type=radio] { width: 20px; height: 20px; accent-color: #fff; flex: none; }
.hint { font-size: .9rem; opacity: .85; margin: 0 0 12px; }
.errors { background: #fff; color: #c0102b; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.errors:empty { display: none; }

/* ---------- Lobby ---------- */
.lobby { width: 100%; max-width: 1000px; display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; align-items: flex-start; }
.joinbox { background: #fff; color: #333; border-radius: 10px; padding: 20px; text-align: center; flex: 1 1 320px; max-width: 460px; }
.pin { font-size: 3.6rem; font-weight: 900; letter-spacing: 4px; line-height: 1.1; }
.qr { width: 240px; max-width: 100%; aspect-ratio: 1; margin: 12px auto; display: block; background: #eee; }
.urlrow { display: flex; gap: 6px; }
.urlrow input { flex: 1; min-width: 0; padding: 8px; border: 2px solid #ddd; border-radius: 6px; font-size: .9rem; }
.playersbox { flex: 1 1 320px; text-align: center; }
.count { font-size: 1.4rem; font-weight: 800; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 20px; }
.chip { background: rgba(255,255,255,.15); padding: 8px 14px; border-radius: 6px; font-weight: 700; cursor: pointer; }
.chip:hover { background: #c0102b; text-decoration: line-through; }
.chip.off { opacity: .45; }

/* ---------- Question (host) ---------- */
.qtop { width: 100%; max-width: 1100px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.qtext { background: #fff; color: #333; border-radius: 8px; padding: 18px 24px; font-size: clamp(1.3rem, 3.5vw, 2.2rem); font-weight: 800; text-align: center; width: 100%; max-width: 1100px; margin: 16px 0; }
.qmid { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 1100px; margin-bottom: 16px; gap: 12px; }
.timer { width: 90px; height: 90px; border-radius: 50%; background: #864cbf; display: flex; align-items: center; justify-content: center; font-size: 2.2rem; font-weight: 900; flex: none; }
.ansnum { text-align: center; font-weight: 800; font-size: 1.3rem; }
.ansnum small { display: block; font-size: .9rem; font-weight: 600; opacity: .8; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 1100px; }
.tile { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 6px; font-size: clamp(1rem, 2.4vw, 1.5rem); font-weight: 700; min-height: 80px; transition: opacity .3s; }
.tile .shape { font-size: 1.6em; }
.tile .mark { margin-left: auto; font-size: 1.6em; }
.tile.dim { opacity: .3; }

/* reveal bars */
.bars { display: flex; justify-content: center; align-items: flex-end; gap: 16px; height: 200px; margin-bottom: 16px; }
.bar { width: 80px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar .fill { width: 100%; border-radius: 4px 4px 0 0; min-height: 6px; transition: height .6s; }
.bar .lbl { padding: 6px 0; font-weight: 800; font-size: 1.2rem; }
.bar.dim { opacity: .35; }

/* ---------- Scoreboard ---------- */
.board { width: 100%; max-width: 700px; }
.row { display: flex; align-items: center; background: #fff; color: #333; border-radius: 6px; padding: 12px 16px; margin-bottom: 8px; font-weight: 800; font-size: 1.15rem; }
.row .rk { width: 2.2em; opacity: .6; }
.row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.first { background: #ffd500; }
h1.title { font-size: 2rem; margin: 8px 0 20px; text-align: center; }
.actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Podium */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 20px 0 30px; width: 100%; max-width: 640px; }
.pod { flex: 1; text-align: center; }
.pod .nm { font-weight: 800; font-size: 1.15rem; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .block { background: #864cbf; border-radius: 6px 6px 0 0; display: flex; flex-direction: column; justify-content: flex-start; align-items: center; padding-top: 12px; font-weight: 900; }
.pod .block .medal { font-size: 2.4rem; }
.pod.p1 .block { height: 200px; background: #ffd500; color: #333; }
.pod.p2 .block { height: 150px; }
.pod.p3 .block { height: 110px; }

/* ---------- Player (phone) ---------- */
.pq { font-size: 1.3rem; font-weight: 800; text-align: center; margin: 8px 0 14px; max-width: 700px; }
.pinfo { width: 100%; max-width: 700px; display: flex; justify-content: space-between; font-weight: 700; opacity: .9; }
.pbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 700px; flex: 1; max-height: 520px; }
.pbtn { border-radius: 8px; color: #fff; font-size: 1.1rem; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 12px; min-height: 120px; box-shadow: 0 5px 0 rgba(0,0,0,.25); }
.pbtn .shape { font-size: 2.4rem; }
.pbtn:active { transform: translateY(3px); }
.bigicon { font-size: 5rem; line-height: 1; margin-bottom: 10px; }
.res-good { background: #26890c; }
.res-bad { background: #c0102b; }
.points { display: inline-block; background: rgba(0,0,0,.25); padding: 10px 22px; border-radius: 6px; font-size: 1.6rem; font-weight: 900; margin: 14px 0; }
.scoreline { font-size: 1.15rem; font-weight: 700; }
.spinner { width: 54px; height: 54px; border: 6px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.footer-name { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; color: #333; display: flex; justify-content: space-between; padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); font-weight: 800; }
.footer-name[hidden] { display: none; }

@media (max-width: 600px) {
  .tiles { grid-template-columns: 1fr; }
  .tile { min-height: 60px; padding: 12px; }
  .bars { gap: 8px; }
  .bar { width: 56px; }
  .pin { font-size: 2.8rem; }
  .timer { width: 64px; height: 64px; font-size: 1.6rem; }
}
