:root {
  --bg: #0d1430;
  --bg2: #16204a;
  --card: #1c2858;
  --line: #2c3a75;
  --text: #f4f1e8;
  --muted: #a9b0d0;
  --gold: #f5b83d;
  --gold2: #ffd77a;
  --good: #3ccf8e;
  --bad: #ff5d6c;
  --blue: #5aa9ff;
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 80% -10%, #263a8a 0%, transparent 60%),
              radial-gradient(900px 600px at -10% 110%, #3a1f6b 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background-attachment: fixed;
  min-height: 100dvh;
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--gold2); }

.wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 24px 16px 40px; }
.wrap.wide { max-width: 1280px; }

.logo { font-weight: 900; font-size: 44px; letter-spacing: 0; margin: 8px 0 0; line-height: 1.1; }
.logo span { color: var(--gold); }
.sub { color: var(--muted); margin: 4px 0 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.card h3 { margin: 0 0 6px; font-size: 20px; }
.card p { margin: 0; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px;
  padding: 14px 20px; font-weight: 800; font-size: 18px; cursor: pointer; background: var(--line); transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.gold { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #241500; }
.btn.good { background: var(--good); color: #002414; }
.btn.bad { background: var(--bad); color: #2a0006; }
.btn.blue { background: var(--blue); color: #001634; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.big { font-size: 24px; padding: 18px 26px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.stack > * + * { margin-top: 10px; }

label { display: block; font-weight: 600; margin: 12px 0 6px; }
input:not([type=checkbox]):not([type=radio]), select {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 18px; outline: none;
}
input:focus { border-color: var(--gold); }
.hint { color: var(--muted); font-size: 14px; margin-top: 4px; }

.choice { display: block; width: 100%; text-align: right; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; margin-bottom: 12px; }
.choice:hover { border-color: var(--gold); }
.choice .t { font-size: 22px; font-weight: 800; }
.choice .d { color: var(--muted); margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; display: inline-flex; gap: 8px; align-items: center; }
.chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; font-size: 18px; line-height: 1; }
.chip.off { opacity: .5; }

.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 .h { color: var(--muted); font-size: 14px; text-align: center; }
.grid3 input { text-align: center; padding: 10px 6px; }

/* ---------- TV ---------- */
.tv { min-height: 100dvh; display: flex; flex-direction: column; padding: 2.2vmin 3vmin; gap: 2vmin; }
.tv .top { display: flex; justify-content: space-between; align-items: center; gap: 2vmin; color: var(--muted); font-size: clamp(14px, 2.2vmin, 26px); }
.tv .top b { color: var(--text); }
.tv .center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 3vmin; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 15vmin; height: 15vmin; padding: 0 3vmin; border-radius: 999px;
  background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #241500; font-weight: 900; font-size: 9vmin; box-shadow: 0 0 60px rgba(245,184,61,.35); }
.badge.sm { min-width: 0; height: auto; font-size: clamp(16px, 2.6vmin, 30px); padding: .3em 1em; box-shadow: none; }
.who { font-size: clamp(22px, 4.6vmin, 64px); font-weight: 900; }
.who .pass { color: var(--bad); display: block; font-size: .55em; }
.qtext { font-size: clamp(24px, 5.2vmin, 76px); font-weight: 800; line-height: 1.35; max-width: 92%; }
.answer { font-size: clamp(30px, 7vmin, 100px); font-weight: 900; color: var(--gold2); }
.result { font-size: clamp(22px, 4vmin, 56px); font-weight: 900; }
.result.good { color: var(--good); }
.result.bad { color: var(--bad); }
.typed { color: var(--muted); font-size: clamp(16px, 2.6vmin, 32px); }
.typed s { color: var(--bad); }
.typed b { color: var(--good); }
.pts { color: var(--muted); font-size: clamp(14px, 2.4vmin, 28px); }
.hintbox { font-size: clamp(20px, 3.4vmin, 44px); color: var(--blue); font-weight: 800; }

.timer { --p: 1; width: 16vmin; height: 16vmin; border-radius: 50%; display: grid; place-items: center; font-size: 6.5vmin; font-weight: 900;
  background: conic-gradient(var(--gold) calc(var(--p) * 360deg), var(--line) 0); position: relative; }
.timer::before { content: ''; position: absolute; inset: 1.2vmin; border-radius: 50%; background: var(--bg); }
.timer span { position: relative; }
.timer.low { background: conic-gradient(var(--bad) calc(var(--p) * 360deg), var(--line) 0); }
.timer.idle span { font-size: 3vmin; color: var(--muted); }

.controls { display: flex; gap: 1.6vmin; justify-content: center; flex-wrap: wrap; }
.controls .btn { font-size: clamp(16px, 2.6vmin, 30px); padding: 1.6vmin 3.4vmin; min-width: 18vmin; }

.intro h1 { font-size: clamp(36px, 9vmin, 130px); margin: 0; font-weight: 900; color: var(--gold2); }
.intro p { font-size: clamp(18px, 3.4vmin, 44px); max-width: 80%; margin: 0 auto; line-height: 1.6; }

.board { width: min(900px, 94%); }
.board .r { display: grid; grid-template-columns: 7vmin 1fr 14vmin 14vmin; align-items: center; gap: 2vmin; padding: 1.6vmin 2.4vmin;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 1.2vmin; font-size: clamp(18px, 3.4vmin, 44px);
  opacity: 0; transform: translateY(14px); animation: rise .5s forwards; }
.board .r.first { border-color: var(--gold); box-shadow: 0 0 40px rgba(245,184,61,.25); }
.board .r .n { color: var(--muted); font-weight: 900; }
.board .r .nm { font-weight: 800; text-align: right; }
.board .r .p { color: var(--muted); font-size: .7em; }
.board .r .t { font-weight: 900; color: var(--gold2); }
.board .head { background: none; border: 0; color: var(--muted); font-size: clamp(12px, 2vmin, 22px); animation: none; opacity: 1; transform: none; padding-block: 0; }
@keyframes rise { to { opacity: 1; transform: none; } }

.lobby { display: grid; grid-template-columns: auto 1fr; gap: 5vmin; align-items: center; width: min(1200px, 96%); }
.qr { background: #fff; border-radius: 20px; padding: 2vmin; width: 42vmin; height: 42vmin; }
.qr img { width: 100%; height: 100%; display: block; }
.code { font-size: clamp(36px, 9vmin, 120px); font-weight: 900; letter-spacing: .1em; color: var(--gold2); direction: ltr; }
.joinurl { color: var(--muted); direction: ltr; font-size: clamp(14px, 2.4vmin, 28px); word-break: break-all; }
.lobby .chips .chip { font-size: clamp(16px, 2.8vmin, 34px); padding: .3em .9em; }
.winner { font-size: clamp(40px, 10vmin, 150px); font-weight: 900; color: var(--gold2); }
.confetti { font-size: 10vmin; }

.judgeqr { position: fixed; bottom: 2vmin; left: 2vmin; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); max-width: 300px; }
.judgeqr img { width: 84px; height: 84px; background: #fff; border-radius: 8px; padding: 4px; }
.peek { position: fixed; bottom: 2vmin; right: 2vmin; }

/* ---------- phone player ---------- */
.phone { display: flex; flex-direction: column; min-height: 100dvh; padding: 16px; gap: 14px; }
.phone .bar { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.phone .main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; text-align: center; }
.phone .qtext { font-size: 22px; max-width: none; }
.phone .who { font-size: 26px; }
.phone .answer { font-size: 36px; }
.phone .result { font-size: 26px; }
.phone .timer { width: 84px; height: 84px; font-size: 30px; margin: 0 auto; }
.phone .timer::before { inset: 7px; }
.phone .badge { min-width: 72px; height: 72px; font-size: 40px; margin: 0 auto; }
.phone .badge.sm { height: auto; font-size: 16px; }
.phone .board .r { grid-template-columns: 28px 1fr 56px 56px; font-size: 18px; padding: 10px 12px; }
.phone .board { width: 100%; }
.myturn { border: 2px solid var(--gold); border-radius: var(--radius); padding: 14px; background: var(--card); }
.myturn input { font-size: 22px; text-align: center; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #000c; padding: 10px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  .lobby { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .qr { width: 60vw; height: 60vw; }
  .judgeqr { display: none; }
}

.grid3.auto { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid3.auto .h { text-align: right; }
.grid3.auto input { text-align: right; }
table td, table th { padding: 8px 6px; }
.controls.small .btn { font-size: clamp(13px, 1.8vmin, 20px); padding: 1vmin 2.4vmin; min-width: 0; opacity: .8; }
details.card summary { cursor: pointer; font-weight: 700; }
