@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500;700;800;900&display=swap');

:root {
  --purple: #46178f;
  --purple-dark: #381272;
  --purple-deep: #25076b;
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --ok: #66bf39;
  --bad: #f35;
  --ink: #333;
  --muted: #6e6e6e;
  --line: #e2e2e2;
  --bg: #f2f2f2;
  --card: #fff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Montserrat', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 4px; padding: 10px 18px; font-weight: 800; font-size: 15px;
  background: #fff; color: var(--ink); box-shadow: inset 0 -4px 0 rgba(0,0,0,.25);
  padding-bottom: 14px; min-height: 44px; transition: transform .05s;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.dark { background: #333; color: #fff; }
.btn.purple { background: var(--purple); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; border: 1px solid var(--line); padding-bottom: 10px; }
.btn.small { min-height: 34px; padding: 6px 12px 9px; font-size: 13px; }

/* ---------- purple screens ---------- */
.stage {
  min-height: 100%; background: var(--purple); color: #fff;
  display: flex; flex-direction: column;
}
.stage .shapes-bg { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.shapes-bg span { position: absolute; background: rgba(255,255,255,.05); }
.shapes-bg .s1 { width: 60vmax; height: 60vmax; border-radius: 50%; left: -25vmax; bottom: -30vmax; }
.shapes-bg .s2 { width: 40vmax; height: 40vmax; right: -12vmax; top: -12vmax; transform: rotate(45deg); }
.stage > *:not(.shapes-bg) { position: relative; z-index: 1; }

.logo { font-weight: 900; letter-spacing: -1px; font-size: 56px; line-height: 1; }
.logo i { font-style: normal; color: #fff; opacity: .85; }

.center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; text-align: center; }

.join-card {
  background: #fff; color: var(--ink); border-radius: 6px; padding: 16px; width: 100%; max-width: 330px;
  display: flex; flex-direction: column; gap: 10px; margin-top: 28px;
}
.join-card input {
  border: 2px solid #ccc; border-radius: 4px; padding: 12px; text-align: center;
  font-weight: 800; font-size: 20px; outline: none;
}
.join-card input:focus { border-color: #333; }
.join-card .btn { font-size: 18px; }
.err-msg { background: var(--bad); color: #fff; font-weight: 700; border-radius: 4px; padding: 10px 14px; margin-top: 14px; max-width: 330px; }
.foot-note { position: fixed; bottom: 12px; left: 0; right: 0; text-align: center; font-size: 13px; opacity: .75; }
.foot-note a { font-weight: 700; }

/* ---------- player ---------- */
.p-top {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  background: #fff; color: var(--ink); font-weight: 800; min-height: 52px;
}
.p-top .count { background: #333; color: #fff; border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-size: 15px; }
.p-bottom {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  background: #fff; color: var(--ink); font-weight: 800; min-height: 52px;
}
.p-bottom .score { background: #333; color: #fff; border-radius: 4px; padding: 6px 14px; }
.big-msg { font-size: 30px; font-weight: 800; margin: 0 0 10px; }
.sub-msg { font-size: 18px; font-weight: 700; opacity: .9; margin: 0; }
.p-qtext { font-weight: 800; font-size: 18px; padding: 12px 16px 0; text-align: center; }

.answer-grid {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px;
}
.answer-grid.two { grid-template-rows: 1fr; }
.ans {
  border: 0; border-radius: 4px; color: #fff; display: flex; align-items: center; justify-content: center;
  gap: 12px; padding: 12px; font-weight: 800; font-size: 18px; text-align: left;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.2); min-height: 90px; transition: transform .06s, opacity .2s;
  word-break: break-word;
}
.ans:active { transform: scale(.97); }
.ans svg { width: 44px; height: 44px; flex: none; fill: #fff; }
.ans.has-text { justify-content: flex-start; }
.ans.has-text svg { width: 30px; height: 30px; }
.c0 { background: var(--red); }
.c1 { background: var(--blue); }
.c2 { background: var(--yellow); }
.c3 { background: var(--green); }

.feedback { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; text-align: center; }
.feedback.ok { background: var(--ok); }
.feedback.bad { background: var(--bad); }
.feedback.neutral { background: var(--purple); }
.feedback .mark { width: 90px; height: 90px; border-radius: 50%; border: 5px solid #fff; display: grid; place-items: center; margin: 14px 0; }
.feedback .mark svg { width: 48px; height: 48px; stroke: #fff; stroke-width: 4; fill: none; }
.pts-pill { background: rgba(0,0,0,.25); border-radius: 4px; padding: 10px 22px; font-weight: 800; font-size: 26px; margin: 8px 0 18px; }
.streak { font-weight: 800; margin-bottom: 8px; }
.rank-note { font-weight: 700; font-size: 17px; }

.spinner {
  width: 64px; height: 64px; border-radius: 50%; border: 8px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: spin .9s linear infinite; margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0 } 70% { transform: scale(1.08) } 100% { transform: scale(1); opacity: 1 } }
.pop { animation: pop .35s ease-out both; }

/* ---------- host ---------- */
.h-lobby-top { display: flex; justify-content: center; padding: 16px 16px 0; gap: 12px; flex-wrap: wrap; }
.pin-box {
  background: #fff; color: var(--ink); border-radius: 6px; display: flex; align-items: stretch; overflow: hidden;
}
.pin-box .join-at { padding: 12px 20px; border-right: 2px solid var(--line); font-weight: 800; font-size: 20px; display: flex; flex-direction: column; justify-content: center; }
.pin-box .join-at small { font-size: 14px; font-weight: 700; color: var(--muted); }
.pin-box .pin { padding: 8px 24px; display: flex; flex-direction: column; justify-content: center; }
.pin-box .pin small { font-weight: 800; font-size: 16px; }
.pin-box .pin b { font-size: 64px; font-weight: 900; letter-spacing: 2px; line-height: 1; white-space: nowrap; }
.pin-box .qr { background: #fff; padding: 8px; display: grid; place-items: center; border-left: 2px solid var(--line); }
.pin-box .qr svg, .pin-box .qr img { width: 118px; height: 118px; display: block; }

.h-bar { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; gap: 12px; }
.h-count { background: rgba(0,0,0,.3); border-radius: 4px; padding: 8px 16px; font-weight: 800; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.h-count svg { width: 22px; height: 22px; fill: #fff; }
.h-title { font-weight: 900; font-size: 34px; text-align: center; flex: 1; }
.h-tools { display: flex; gap: 8px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: #fff; }

.players { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; padding: 8px 24px 40px; }
.players .pl {
  background: rgba(0,0,0,.25); color: #fff; border: 0; border-radius: 4px; padding: 10px 16px;
  font-weight: 800; font-size: 20px; animation: pop .3s ease-out both;
}
.players .pl:hover { text-decoration: line-through; background: rgba(0,0,0,.45); }
.waiting { text-align: center; font-weight: 800; font-size: 26px; padding: 30px; }
.waiting span { background: rgba(0,0,0,.3); border-radius: 4px; padding: 10px 20px; display: inline-block; }

/* question screen (host) */
.h-q { height: 100vh; height: 100dvh; background: var(--bg); display: flex; flex-direction: column; }
.h-q-title {
  background: #fff; margin: 16px auto 0; padding: 14px 24px; border-radius: 4px; font-weight: 800;
  font-size: clamp(22px, 3vw, 38px); text-align: center; max-width: 92%; box-shadow: 0 2px 0 rgba(0,0,0,.08);
}
.h-q-mid { flex: 1; display: grid; grid-template-columns: 140px 1fr 140px; align-items: center; padding: 16px 24px; gap: 16px; min-height: 0; }
.h-q-img { display: flex; justify-content: center; align-items: center; min-height: 0; height: 100%; }
.h-q-img img { max-width: 100%; max-height: 38vh; border-radius: 4px; object-fit: contain; }
.h-q-img .placeholder svg { width: 38vh; height: 20vh; }
.timer { width: 110px; height: 110px; border-radius: 50%; background: var(--purple); color: #fff; display: grid; place-items: center; font-weight: 900; font-size: 44px; }
.ans-count { text-align: center; font-weight: 800; }
.ans-count b { display: block; font-size: 52px; font-weight: 900; }
.h-answers { display: grid; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; gap: 10px; padding: 0 16px 16px; height: 36vh; flex: none; }
.h-answers .ans { min-height: 0; font-size: clamp(18px, 2.2vw, 30px); justify-content: flex-start; cursor: default; }
.h-answers .ans:active { transform: none; }
.h-answers .ans svg { width: 42px; height: 42px; }
.h-answers .ans .tick { margin-left: auto; width: 40px; height: 40px; stroke: #fff; stroke-width: 4; fill: none; }
.h-answers .ans.dim { opacity: .3; }
.h-q-top { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 0; font-weight: 800; color: var(--muted); }

.getready { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.getready .gr-q { background: #fff; color: var(--ink); border-radius: 4px; padding: 20px 32px; font-size: clamp(26px, 4vw, 52px); font-weight: 900; max-width: 90%; }
.getready .gr-bar { height: 10px; background: rgba(255,255,255,.25); border-radius: 5px; width: min(600px, 80%); margin-top: 36px; overflow: hidden; }
.getready .gr-bar i { display: block; height: 100%; background: #fff; width: 0; }

/* results chart */
.chart { flex: 1; display: flex; justify-content: center; align-items: flex-end; gap: 22px; padding: 10px 24px; min-height: 0; }
.chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 130px; height: 100%; }
.chart .bar { width: 100%; border-radius: 4px 4px 0 0; transition: height .6s ease-out; min-height: 6px; }
.chart .lbl { width: 100%; color: #fff; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px; font-weight: 900; font-size: 24px; border-radius: 0 0 4px 4px; }
.chart .lbl svg { width: 26px; height: 26px; fill: #fff; }
.chart .lbl .tick { stroke: #fff; stroke-width: 4; fill: none; }
.chart .col.dim .bar, .chart .col.dim .lbl { opacity: .35; }

/* scoreboard */
.board { display: flex; flex-direction: column; gap: 10px; width: min(900px, 92%); margin: 24px auto; }
.board .row { background: #fff; color: var(--ink); border-radius: 4px; padding: 14px 22px; display: flex; justify-content: space-between; font-weight: 800; font-size: 26px; animation: pop .35s both; }
.board .row:first-child { background: var(--purple-dark); color: #fff; }
.board .row .d { color: var(--muted); font-size: 16px; margin-right: 14px; }
.board .row:first-child .d { color: rgba(255,255,255,.7); }

/* podium */
.podium { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 12px; padding: 0 16px; }
.podium .step { width: min(240px, 28vw); display: flex; flex-direction: column; align-items: center; }
.podium .step .who { font-weight: 900; font-size: clamp(18px, 2.6vw, 34px); text-align: center; margin-bottom: 10px; word-break: break-word; opacity: 0; }
.podium .step .block { width: 100%; background: var(--purple-dark); border-radius: 4px 4px 0 0; display: flex; flex-direction: column; align-items: center; padding-top: 16px; height: 0; transition: height 1s ease-out; overflow: hidden; }
.podium .step .medal { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 30px; color: #fff; border: 4px solid rgba(255,255,255,.6); }
.podium .step .pts { font-weight: 800; margin-top: 10px; font-size: 20px; }
.podium .step .cnt { font-weight: 700; margin-top: 4px; opacity: .8; font-size: 14px; }
.m1 { background: #d4a106; } .m2 { background: #9c9c9c; } .m3 { background: #b06b2c; }

/* ---------- admin / editor ---------- */
.a-top { background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 12px; position: sticky; top: 0; z-index: 5; }
.a-top .brand { font-weight: 900; font-size: 26px; color: var(--purple); letter-spacing: -1px; text-decoration: none; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
h1 { font-weight: 900; font-size: 26px; margin: 0 0 16px; }
.qlist { display: flex; flex-direction: column; gap: 10px; }
.qitem { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; flex-wrap: wrap; }
.qitem .thumb { width: 64px; height: 48px; border-radius: 4px; background: var(--purple); color: #fff; display: grid; place-items: center; font-weight: 900; flex: none; }
.qitem .meta { flex: 1; min-width: 160px; }
.qitem .meta b { display: block; font-size: 17px; }
.qitem .meta small { color: var(--muted); font-weight: 600; }
.qitem .acts { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 700; font-size: 13px; color: var(--muted); }
.input { border: 1px solid #ccc; border-radius: 4px; padding: 10px 12px; background: #fff; outline: none; width: 100%; }
.input:focus { border-color: var(--purple); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs .btn.on { background: var(--purple); color: #fff; }

/* editor */
.ed { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.ed > * { min-width: 0; }
.ed-side { position: sticky; top: 70px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 90px); overflow: auto; }
.ed-slide { background: #fff; border: 2px solid var(--line); border-radius: 6px; padding: 8px 10px; text-align: left; font-weight: 700; font-size: 13px; display: flex; gap: 8px; }
.ed-slide.on { border-color: var(--purple); }
.ed-slide .n { color: var(--muted); }
.ed-slide .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-slide.bad { border-color: var(--red); }
.ed-main .qtext { font-size: 22px; font-weight: 800; text-align: center; padding: 16px; }
.ed-img { border: 2px dashed #ccc; border-radius: 6px; min-height: 160px; display: grid; place-items: center; margin: 14px 0; position: relative; background: #fafafa; }
.ed-img img { max-width: 100%; max-height: 260px; border-radius: 4px; }
.ed-img .rm { position: absolute; top: 8px; right: 8px; }
.ed-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ed-ans { display: flex; align-items: center; gap: 10px; border-radius: 4px; padding: 8px 10px; color: #fff; min-height: 70px; }
.ed-ans svg.shape { width: 30px; height: 30px; fill: #fff; flex: none; }
.ed-ans input[type=text] { flex: 1; border: 0; background: rgba(255,255,255,.95); color: var(--ink); border-radius: 4px; padding: 10px; font-weight: 700; min-width: 0; }
.ed-ans .ok { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; background: transparent; flex: none; display: grid; place-items: center; padding: 0; }
.ed-ans .ok svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 4; fill: none; visibility: hidden; }
.ed-ans .ok.on { background: var(--ok); border-color: #fff; }
.ed-ans .ok.on svg { visibility: visible; }
.ed-opts { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.ed-opts .field { min-width: 150px; flex: 1; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #333; color: #fff; padding: 12px 20px; border-radius: 4px; font-weight: 700; z-index: 50; max-width: 90%; }
.toast.err { background: var(--red); }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: #fff; border-radius: 6px; padding: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; font-weight: 900; }
textarea.input { min-height: 180px; font-family: ui-monospace, monospace; font-size: 13px; }
table.res { width: 100%; border-collapse: collapse; font-size: 14px; }
table.res td, table.res th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }

@media (max-width: 760px) {
  .ed { grid-template-columns: 1fr; }
  .a-top { flex-wrap: wrap; }
  .a-top #title { order: 3; max-width: none !important; flex: 1 1 100%; }
  .ed-main.card { padding: 12px; }
  .ed-main .qtext { font-size: 17px; padding: 12px; }
  .ed-opts .field { min-width: 0; flex: 1 1 140px; }
  .ed-opts .field div { flex-wrap: wrap; }
  .ed-side { position: static; flex-direction: row; overflow-x: auto; max-height: none; }
  .ed-slide { min-width: 140px; }
  .ed-answers { grid-template-columns: 1fr; }
  .h-q-mid { grid-template-columns: 80px 1fr 80px; padding: 10px; }
  .timer { width: 70px; height: 70px; font-size: 28px; }
  .ans-count b { font-size: 32px; }
  .h-answers { grid-template-columns: 1fr; height: auto; }
  .h-answers .ans { min-height: 52px; font-size: 16px; padding: 8px 12px; }
  .h-answers .ans svg { width: 26px; height: 26px; }
  .h-answers .ans .tick { width: 26px; height: 26px; }
  .h-answers { gap: 8px; padding: 0 12px 12px; }
  .h-q { height: auto; min-height: 100dvh; }
  .h-q-title { font-size: 19px; padding: 12px 14px; margin-top: 10px; }
  .h-q .chart { height: 24vh !important; gap: 10px; }
  .chart .lbl { font-size: 18px; padding: 6px 4px; }
  .chart .lbl svg { width: 18px; height: 18px; }
  .podium .step .medal { width: 44px; height: 44px; font-size: 22px; }
  .podium .step .pts { font-size: 16px; }
  .h-head .btn { min-height: 38px; font-size: 13px; padding: 6px 10px 9px; }
  /* host lobby on a phone: stack PIN, QR and controls */
  .h-lobby-top { padding: 12px 16px 0; }
  .pin-box { flex-direction: column; width: 100%; max-width: 420px; }
  .pin-box .join-at { border-right: 0; border-bottom: 2px solid var(--line); text-align: center; font-size: 17px; padding: 10px; }
  .pin-box .pin { text-align: center; padding: 10px; }
  .pin-box .pin b { font-size: 46px; }
  .pin-box .qr { border-left: 0; border-top: 2px solid var(--line); padding: 12px; }
  .pin-box .qr svg, .pin-box .qr img { width: 190px; height: 190px; }
  .h-bar { flex-wrap: wrap; padding: 12px 16px; }
  .h-title { display: none; }
  .h-tools { flex-wrap: wrap; flex: 1; justify-content: flex-end; gap: 10px; }
  .h-tools #fs { display: none; }
  .h-tools #start { flex: 1 1 100%; font-size: 18px; }
  .players { padding: 8px 16px 32px; gap: 8px; }
  .players .pl { font-size: 16px; padding: 8px 12px; }
  .waiting { font-size: 20px; padding: 16px; }
  .h-head { padding: 12px 16px 0; }
  .board .row { font-size: 18px; padding: 12px 14px; }
  .chart .col { width: 70px; }
  .logo { font-size: 44px; }
}
