:root {
  --bg: #0b0b12;
  --bg2: #12121c;
  --card: #1a1a27;
  --card2: #232334;
  --line: #2d2d42;
  --text: #f6f6fb;
  --muted: #a0a0b8;
  --cyan: #25f4ee;
  --pink: #fe2c55;
  --ok: #19c37d;
  --bad: #ff4d5e;
  --gold: #ffc53d;
  --silver: #c8d0e0;
  --bronze: #e0915a;
  --a: #fe2c55;
  --b: #2f7cf6;
  --c: #f0a500;
  --d: #19b36f;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--muted); }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- layout ---------- */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(12px + var(--safe-t)) 16px calc(16px + var(--safe-b));
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 4px 0 12px;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.brand-dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: conic-gradient(from 200deg, var(--cyan), var(--pink), var(--cyan));
  box-shadow: 0 0 18px rgba(37, 244, 238, .35);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; font-size: 14px; font-weight: 700;
  white-space: nowrap;
}
.chip .live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.chip.off .live-dot { background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.view { flex: 1; display: flex; flex-direction: column; gap: 14px; animation: rise .28s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.center { justify-content: center; text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
.title-xl { font-size: 30px; font-weight: 800; line-height: 1.25; margin: 0; }
.title-l { font-size: 22px; font-weight: 800; margin: 0; }
.lead { color: var(--muted); margin: 0; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-weight: 700; font-size: 15px; }
.input-wrap {
  display: flex; align-items: center; direction: ltr;
  background: var(--bg2); border: 2px solid var(--line); border-radius: 14px;
  padding: 0 14px; transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--cyan); }
.input-wrap .at { color: var(--muted); font-size: 20px; font-weight: 700; }
.input-wrap input, .input {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: 0;
  padding: 14px 6px; font-size: 20px; font-weight: 700;
}
.input {
  background: var(--bg2); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px;
  font-size: 17px; font-weight: 500; width: 100%;
}
.input:focus { border-color: var(--cyan); outline: 0; }
textarea.input { resize: vertical; min-height: 80px; }
.pin-input { letter-spacing: 14px; text-align: center; font-size: 30px !important; }
.hint { font-size: 14px; color: var(--muted); margin: 0; }
.error { color: var(--bad); font-weight: 700; font-size: 15px; min-height: 1.4em; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 54px; padding: 0 22px; border-radius: 16px;
  font-weight: 800; font-size: 18px;
  background: linear-gradient(90deg, var(--pink), #ff5f7e);
  color: #fff; box-shadow: 0 8px 24px rgba(254, 44, 85, .3);
  transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--card2); box-shadow: none; border: 1px solid var(--line); }
.btn.cyan { background: var(--cyan); color: #05252a; box-shadow: 0 8px 24px rgba(37, 244, 238, .25); }
.btn.ok { background: var(--ok); box-shadow: none; }
.btn.small { min-height: 40px; font-size: 15px; padding: 0 14px; border-radius: 12px; }
.link { color: var(--cyan); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- PIN reveal ---------- */
.pin-box {
  display: flex; justify-content: center; gap: 10px; direction: ltr; margin: 8px 0;
}
.pin-box span {
  width: 60px; height: 74px; border-radius: 14px; display: grid; place-items: center;
  font-size: 40px; font-weight: 800; background: var(--bg2); border: 2px solid var(--cyan);
  box-shadow: 0 0 18px rgba(37, 244, 238, .2);
}

/* ---------- lobby ---------- */
.pulse-ring {
  width: 120px; height: 120px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center; font-size: 46px;
  background: radial-gradient(circle, rgba(37, 244, 238, .25), transparent 70%);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { transform: scale(.92); } 50% { transform: scale(1.05); } }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 22px; font-weight: 800; }
.stat small { color: var(--muted); font-size: 13px; }

/* ---------- question ---------- */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.q-count { font-weight: 800; color: var(--muted); }
.timer {
  position: relative; width: 58px; height: 58px; flex: none;
}
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 6; }
.timer .track { stroke: var(--card2); }
.timer .bar { stroke: var(--cyan); stroke-linecap: round; transition: stroke .3s; }
.timer.low .bar { stroke: var(--pink); }
.timer b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 20px; font-weight: 800; }
.progress { height: 6px; border-radius: 6px; background: var(--card2); overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); width: 0; }

.q-text {
  font-size: 23px; font-weight: 800; line-height: 1.45; margin: 4px 0;
  min-height: 3em; display: flex; align-items: center;
}
.options { display: grid; gap: 12px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 66px; padding: 12px 14px; border-radius: 18px;
  font-size: 19px; font-weight: 800; text-align: start; color: #fff;
  background: var(--c-opt); box-shadow: 0 5px 0 rgba(0, 0, 0, .35);
  transition: transform .08s, opacity .2s, box-shadow .08s, filter .2s;
}
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
.opt .key {
  flex: none; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(0, 0, 0, .22); font-size: 20px;
}
.opt .txt { flex: 1; }
.opt .mark { flex: none; font-size: 22px; }
.opt:nth-child(1) { --c-opt: var(--a); }
.opt:nth-child(2) { --c-opt: var(--b); }
.opt:nth-child(3) { --c-opt: var(--c); }
.opt:nth-child(4) { --c-opt: var(--d); }
.options.locked .opt { opacity: .35; filter: saturate(.4); }
.options.locked .opt.chosen { opacity: 1; filter: none; outline: 3px solid #fff; outline-offset: 2px; }
.options.revealed .opt { opacity: .3; filter: saturate(.3); }
.options.revealed .opt.right { opacity: 1; filter: none; outline: 3px solid #fff; outline-offset: 2px; }
.options.revealed .opt.chosen:not(.right) { opacity: .75; filter: none; text-decoration: line-through; }
.opt .count { flex: none; font-size: 15px; background: rgba(0, 0, 0, .25); padding: 2px 9px; border-radius: 99px; }

.ready {
  flex: 1; display: grid; place-items: center; text-align: center;
}
.ready .big { font-size: 110px; font-weight: 800; line-height: 1; color: var(--cyan); animation: pop .9s ease infinite; }
@keyframes pop { 0% { transform: scale(1.3); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { opacity: .9; } }

.sent {
  text-align: center; padding: 12px; border-radius: 14px;
  background: rgba(37, 244, 238, .1); border: 1px dashed rgba(37, 244, 238, .5); font-weight: 700;
}

/* ---------- result ---------- */
.result-hero {
  border-radius: 22px; padding: 22px 18px; text-align: center;
  background: var(--card); border: 1px solid var(--line);
}
.result-hero.right { background: linear-gradient(160deg, rgba(25, 195, 125, .35), rgba(25, 195, 125, .08)); border-color: rgba(25, 195, 125, .6); }
.result-hero.wrong { background: linear-gradient(160deg, rgba(255, 77, 94, .32), rgba(255, 77, 94, .06)); border-color: rgba(255, 77, 94, .55); }
.result-hero .icon { font-size: 56px; line-height: 1; }
.result-hero h2 { font-size: 28px; margin: 8px 0 4px; }
.result-hero .pts { font-size: 34px; font-weight: 800; color: var(--gold); }
.explain { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font-size: 16px; }
.explain b { color: var(--ok); }

/* ---------- leaderboard ---------- */
.board { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.row .rk {
  flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--card2); font-weight: 800; font-size: 16px;
}
.row:nth-child(1) .rk { background: var(--gold); color: #3a2a00; }
.row:nth-child(2) .rk { background: var(--silver); color: #222; }
.row:nth-child(3) .rk { background: var(--bronze); color: #331a00; }
.row .nm { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.row .sc { font-weight: 800; }
.row.me { border-color: var(--cyan); background: rgba(37, 244, 238, .08); }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; margin-top: 6px; }
.pod { text-align: center; }
.pod .nm { font-weight: 800; font-size: 14px; direction: ltr; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .block {
  margin-top: 6px; border-radius: 14px 14px 6px 6px; display: grid; place-items: center;
  font-size: 30px; font-weight: 800; color: #1b1300;
}
.pod.p1 .block { height: 120px; background: linear-gradient(var(--gold), #d89b00); }
.pod.p2 .block { height: 90px; background: linear-gradient(var(--silver), #8d97aa); }
.pod.p3 .block { height: 70px; background: linear-gradient(var(--bronze), #a4602d); }
.pod .sc { font-size: 13px; color: var(--muted); }

.me-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--card2); border-radius: 14px; padding: 10px 14px; font-weight: 700;
}
.me-bar b { font-size: 20px; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(18px + var(--safe-b)); z-index: 50;
  max-width: 480px; margin: 0 auto; text-align: center;
  background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
  font-weight: 700; box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
  animation: rise .2s ease;
}

.menu-btn { width: 42px; height: 42px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 20px; }
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 40; display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 520px; margin: 0 auto; background: var(--bg2); border-radius: 22px 22px 0 0;
  padding: 20px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px;
  border-top: 1px solid var(--line); animation: rise .2s ease;
}

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; opacity: .95;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ======================= host panel ======================= */
.host .app { max-width: 760px; padding-bottom: calc(86px + var(--safe-b)); }
.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 30;
  display: flex; justify-content: center; gap: 6px;
  background: rgba(11, 11, 18, .94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line); padding: 8px 12px calc(8px + var(--safe-b));
}
.tabs button {
  flex: 1; max-width: 220px; min-height: 52px; border-radius: 14px; font-weight: 800; font-size: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted);
}
.tabs button.on { background: var(--card2); color: var(--text); }
.tabs button .ic { font-size: 19px; line-height: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.qz { display: flex; flex-direction: column; gap: 10px; }
.qz-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.qz-title { font-weight: 800; font-size: 18px; margin: 0; }
.badge { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 99px; background: var(--card2); color: var(--muted); white-space: nowrap; }
.badge.live { background: rgba(254, 44, 85, .18); color: var(--pink); }
.badge.finished { background: rgba(25, 195, 125, .15); color: var(--ok); }
.qitem { display: flex; flex-direction: column; gap: 8px; }
.qitem .qn { display: flex; gap: 8px; align-items: flex-start; }
.qitem .qn b { flex: none; width: 30px; height: 30px; border-radius: 9px; background: var(--card2); display: grid; place-items: center; font-size: 14px; }
.qitem .qn p { margin: 0; font-weight: 700; flex: 1; }
.qitem.asked { opacity: .55; }
.olist { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.olist span { font-size: 14px; background: var(--bg2); border-radius: 10px; padding: 6px 9px; border: 1px solid var(--line); }
.olist span.ok { border-color: var(--ok); color: var(--ok); font-weight: 800; }
.icon-btn { min-width: 40px; height: 40px; border-radius: 11px; background: var(--card2); border: 1px solid var(--line); display: inline-grid; place-items: center; font-size: 16px; padding: 0 10px; font-weight: 700; }
.icon-btn.danger { color: var(--bad); }
.opt-edit { display: flex; gap: 8px; align-items: center; }
.opt-edit input[type=radio] { width: 24px; height: 24px; accent-color: var(--ok); flex: none; }
select.input { appearance: none; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.live-panel { display: flex; flex-direction: column; gap: 12px; }
.phase-pill { font-weight: 800; font-size: 14px; padding: 4px 12px; border-radius: 99px; background: var(--card2); }
.big-action { min-height: 72px; font-size: 22px; }
.dist { display: flex; flex-direction: column; gap: 6px; }
.dist .dl { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.dist .dl .bar { flex: 1; height: 26px; background: var(--bg2); border-radius: 8px; overflow: hidden; position: relative; }
.dist .dl .bar i { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 8px; background: var(--c-opt); opacity: .85; }
.dist .dl .bar span { position: relative; padding: 0 8px; line-height: 26px; }
.dist .dl:nth-child(1) { --c-opt: var(--a); } .dist .dl:nth-child(2) { --c-opt: var(--b); }
.dist .dl:nth-child(3) { --c-opt: var(--c); } .dist .dl:nth-child(4) { --c-opt: var(--d); }
.dist .dl.right .bar { outline: 2px solid var(--ok); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; }
.switch input { width: 52px; height: 30px; accent-color: var(--cyan); }
.copy { display: flex; gap: 8px; align-items: center; }
.copy code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; background: var(--bg2); border-radius: 10px; padding: 9px 10px; font-size: 13px; border: 1px solid var(--line); }
.prow { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.prow .nm { flex: 1; min-width: 0; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.section-title { font-size: 15px; font-weight: 800; color: var(--muted); margin: 6px 0 -2px; }
.qr-img { width: 160px; height: 160px; background: #fff; border-radius: 14px; padding: 8px; display: block; margin: 0 auto; }
@media (min-width: 700px) { .olist { grid-template-columns: repeat(4, 1fr); } }
