/* QuizTN player app. Every screen is laid out to fit the visible area exactly: no scrolling anywhere.
   --u scales every size with the screen (set from JS), --app-h is the real visible height (it shrinks when the keyboard opens). */

:root {
  --u: 1;
  --app-h: 100vh;
  --bg1: #100d3f;
  --bg2: #2a1a72;
  --glass: rgba(255, 255, 255, .09);
  --glass-b: rgba(255, 255, 255, .16);
  --ink: #fff;
  --muted: #c4c0f0;
  --accent: #ffc83d;
  --accent-ink: #2b1c00;
  --ok: #25c26e;
  --bad: #f0545b;
  --sel: #5b8cff;
  --warn: #ffb020;

  --g1: calc(var(--u) * 4px);
  --g2: calc(var(--u) * 8px);
  --g3: calc(var(--u) * 12px);
  --g4: calc(var(--u) * 16px);
  --f-xs: calc(var(--u) * 11px);
  --f-s: calc(var(--u) * 13px);
  --f-m: calc(var(--u) * 15px);
  --f-l: calc(var(--u) * 18px);
  --f-xl: calc(var(--u) * 24px);
  --r: calc(var(--u) * 16px);
  --btn-h: calc(var(--u) * 48px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-user-select: none; user-select: none; }
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
  background: var(--bg1); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Noto Naskh Arabic", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}

#app {
  position: fixed; left: 0; top: 0; width: 100%; height: var(--app-h);
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2) 0%, var(--bg1) 70%);
}

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0;
  gap: var(--g2);
  padding: calc(env(safe-area-inset-top, 0px) + var(--g3)) calc(env(safe-area-inset-right, 0px) + var(--g4))
           calc(env(safe-area-inset-bottom, 0px) + var(--g3)) calc(env(safe-area-inset-left, 0px) + var(--g4));
}
.screen.active { display: flex; }

/* ---------------------------------------------------------------- buttons, inputs */
.btn {
  flex: 0 0 var(--btn-h); height: var(--btn-h); padding: 0 var(--g4);
  border: 1px solid var(--glass-b); border-radius: calc(var(--u) * 14px);
  background: var(--glass); color: #fff; font: inherit; font-size: var(--f-m); font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn:disabled { opacity: .45; }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:empty { display: none; }

input {
  width: 100%; height: calc(var(--u) * 46px); padding: 0 var(--g3);
  border: 1px solid var(--glass-b); border-radius: calc(var(--u) * 12px);
  background: rgba(0, 0, 0, .28); color: #fff; font: inherit; font-size: calc(var(--u) * 16px); outline: none;
}
input:focus { border-color: var(--accent); }
input.code { text-align: center; letter-spacing: .45em; font-size: calc(var(--u) * 26px); font-variant-numeric: tabular-nums; }
label { font-size: var(--f-s); color: var(--muted); }

.topbar { flex: 0 0 calc(var(--u) * 40px); display: flex; align-items: center; gap: var(--g2); }
.topbar-title { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: var(--f-l); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: 0 0 calc(var(--u) * 40px); width: calc(var(--u) * 40px); height: calc(var(--u) * 40px);
  border: 0; border-radius: 50%; background: var(--glass); color: #fff; font: inherit; font-size: calc(var(--u) * 26px); line-height: 1;
  display: grid; place-items: center; padding: 0;
}
.icon-btn.ghost-space { background: transparent; visibility: hidden; }
[dir="rtl"] .icon-btn .arrow { transform: scaleX(-1); }

.dot { display: inline-block; flex: 0 0 auto; width: calc(var(--u) * 9px); height: calc(var(--u) * 9px); border-radius: 50%; background: var(--ok); }
.dot.off { background: var(--bad); }
.dot.wait { background: var(--warn); }

.chip {
  display: inline-flex; align-items: center; gap: var(--g2); max-width: 60%;
  padding: calc(var(--u) * 8px) calc(var(--u) * 12px); border: 1px solid var(--glass-b); border-radius: 999px;
  background: var(--glass); color: #fff; font: inherit; font-size: var(--f-xs);
}
.chip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- home */
.home-head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: var(--g2); }
.brand { display: flex; align-items: center; gap: var(--g2); font-weight: 900; font-size: var(--f-xl); letter-spacing: .5px; }
.logo {
  width: calc(var(--u) * 30px); height: calc(var(--u) * 30px); border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 900; font-size: var(--f-l);
}
.langs { direction: ltr; display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-b); }
.langs button {
  border: 0; border-radius: 999px; background: transparent; color: var(--muted); font: inherit; font-size: var(--f-xs); font-weight: 800;
  padding: calc(var(--u) * 6px) calc(var(--u) * 10px);
}
.langs button.on { background: var(--accent); color: var(--accent-ink); }

.hello { flex: 0 0 auto; margin: 0; font-size: var(--f-s); color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.live-card {
  flex: 3 1 0; min-height: 0; display: flex; flex-direction: column; gap: var(--g2); padding: var(--g3);
  border: 1px solid var(--glass-b); border-radius: var(--r);
  background: linear-gradient(160deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .05));
}
.live-top { flex: 0 0 auto; display: flex; align-items: center; gap: var(--g2); }
.live-top h2 { margin: 0; font-size: var(--f-l); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: calc(var(--u) * 3px) calc(var(--u) * 9px); border-radius: 999px;
  background: rgba(255, 255, 255, .14); color: var(--muted); font-size: var(--f-xs); font-weight: 900; letter-spacing: 1px;
}
.pill::before { content: ""; width: calc(var(--u) * 7px); height: calc(var(--u) * 7px); border-radius: 50%; background: var(--muted); }
.pill.on { background: rgba(240, 84, 91, .25); color: #ffb3b6; }
.pill.on::before { background: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.live-text { flex: 0 0 auto; font-size: var(--f-s); color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; line-height: 1.3; }
.count {
  flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: calc(var(--u) * 46px); font-weight: 900; font-variant-numeric: tabular-nums; color: var(--accent); direction: ltr;
}
body.short .count { font-size: calc(var(--u) * 30px); }

.row2 { flex: 1.1 1 0; min-height: 0; display: flex; gap: var(--g2); }
.tile {
  flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: var(--g2);
  border: 1px solid var(--glass-b); border-radius: var(--r); background: var(--glass); color: #fff; font: inherit; text-align: center;
}
.tile:active { transform: scale(.98); }
.tile-ic { font-size: calc(var(--u) * 28px); line-height: 1.1; }
.tile-t { font-size: var(--f-m); font-weight: 800; }
.tile-s { font-size: var(--f-xs); color: var(--muted); }
body.short .tile-ic { display: none; }

.lastwin { flex: 0 0 auto; min-height: 1.3em; text-align: center; font-size: var(--f-s); color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-foot { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: var(--g2); }

/* ---------------------------------------------------------------- login */
.form { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: var(--g2); }
.intro { margin: 0; font-size: var(--f-s); color: var(--muted); line-height: 1.35; }
body.short .opt-hide { display: none; }
.err { flex: 1 1 auto; min-height: 0; overflow: hidden; color: #ff9aa0; font-size: var(--f-s); line-height: 1.3; }
.form > .btn { margin-top: 0; }

/* ---------------------------------------------------------------- quiz */
.q-play { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: var(--g2); }
.meta { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: baseline; font-weight: 800; font-size: var(--f-m); }
.timer { font-size: var(--f-xl); line-height: 1; font-variant-numeric: tabular-nums; color: var(--accent); direction: ltr; }
.timer.low { color: var(--bad); }
.timerbar { flex: 0 0 calc(var(--u) * 6px); display: flex; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, .14); }
.timerbar i { display: block; height: 100%; width: 100%; border-radius: 999px; background: var(--accent); transition: width .22s linear; }
.timerbar.low i { background: var(--bad); }
.sub { flex: 0 0 calc(var(--u) * 17px); display: flex; align-items: center; justify-content: space-between; gap: var(--g2); font-size: var(--f-xs); color: var(--muted); }
.sub span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.final { padding: 1px calc(var(--u) * 9px); border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 900; }

.qbox {
  flex: 2.8 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden;
  padding: var(--g3); border: 1px solid var(--glass-b); border-radius: var(--r); background: var(--glass);
}
.fit { display: block; max-width: 100%; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.fit .ln + .ln { margin-top: .3em; }
.fit .ln:nth-child(n+2) { opacity: .92; }

.fb { flex: 1.7 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; text-align: center; overflow: hidden; padding: 0 var(--g2); }
.fit-fb { max-width: 100%; overflow-wrap: anywhere; line-height: 1.25; }
.fb-main { font-weight: 800; }
.fb-main.ok { color: var(--ok); }
.fb-main.bad { color: #ff8a90; }
.fb-exp { margin-top: .15em; font-size: .78em; color: var(--muted); }
.fb-exp:empty { display: none; }

.opts { flex: 4.8 1 0; min-height: 0; display: flex; flex-direction: column; gap: var(--g2); }
.opt {
  flex: 1 1 0; min-height: 0; display: flex; align-items: stretch; gap: var(--g2); padding: 0 var(--g3);
  border: 2px solid var(--glass-b); border-radius: calc(var(--u) * 14px); background: var(--glass); color: #fff; font: inherit; text-align: center;
}
.opt:active:not([disabled]) { transform: scale(.985); }
.opt[data-s]:not([data-s="normal"]) { pointer-events: none; }
.opt-k {
  flex: 0 0 calc(var(--u) * 28px); align-self: center; width: calc(var(--u) * 28px); height: calc(var(--u) * 28px);
  display: grid; place-items: center; border-radius: 50%; background: rgba(255, 255, 255, .16); font-size: var(--f-s); font-weight: 900;
}
.opt-t { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; padding: calc(var(--u) * 3px) 0; }
.opt[data-s="selected"] { border-color: var(--sel); background: rgba(91, 140, 255, .26); }
.opt[data-s="selected"] .opt-k { background: var(--sel); }
.opt[data-s="dim"] { opacity: .42; }
.opt[data-s="correct"] { border-color: var(--ok); background: rgba(37, 194, 110, .28); }
.opt[data-s="correct"] .opt-k { background: var(--ok); }
.opt[data-s="wrong"] { border-color: var(--bad); background: rgba(240, 84, 91, .28); }
.opt[data-s="wrong"] .opt-k { background: var(--bad); }

.nextrow { flex: 0 0 var(--btn-h); display: flex; }
.nextrow .btn { flex: 1; }
.nextrow.off .btn { visibility: hidden; }
.mode-live .nextrow { display: none; }

.panel {
  flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--g3);
  text-align: center; padding: var(--g2) 0;
}
.p-icon { flex: 0 0 auto; font-size: calc(var(--u) * 54px); line-height: 1; }
.p-icon:empty { display: none; }
body.short .p-icon { display: none; }
.p-title { flex: 0 0 auto; margin: 0; max-width: 100%; font-size: var(--f-xl); font-weight: 900; line-height: 1.15; overflow-wrap: anywhere; }
.p-big { flex: 0 0 auto; font-size: calc(var(--u) * 50px); font-weight: 900; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; direction: ltr; }
.p-big:empty { display: none; }
.p-body-box { flex: 0 1 auto; min-height: 0; width: 100%; max-height: 42%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.fit-body { max-width: 100%; color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; white-space: pre-line; }
.p-btns { flex: 0 0 auto; width: 100%; display: flex; flex-direction: column; gap: var(--g2); }

/* ---------------------------------------------------------------- winners */
.tabs { flex: 0 0 auto; display: flex; gap: var(--g2); }
.tabs button {
  flex: 1; height: calc(var(--u) * 38px); border: 1px solid var(--glass-b); border-radius: 999px; background: var(--glass); color: var(--muted);
  font: inherit; font-size: var(--f-s); font-weight: 800;
}
.tabs button.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.wlist { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: calc(var(--u) * 6px); overflow: hidden; }
.wrow {
  flex: 1 1 0; min-height: 0; max-height: calc(var(--u) * 54px); display: flex; align-items: center; gap: var(--g3); padding: 0 var(--g3);
  border: 1px solid var(--glass-b); border-radius: calc(var(--u) * 12px); background: var(--glass);
}
.wrow.top1 { border-color: rgba(255, 200, 61, .65); background: linear-gradient(90deg, rgba(255, 200, 61, .28), rgba(255, 200, 61, .07)); }
.wrank { flex: 0 0 calc(var(--u) * 30px); text-align: center; font-weight: 900; font-size: var(--f-m); }
.wname { flex: 1 1 0; min-width: 0; font-size: var(--f-m); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wnum { flex: 0 0 auto; text-align: end; line-height: 1.15; }
.wnum b { display: block; color: var(--accent); font-size: var(--f-s); }
.wnum small { display: block; color: var(--muted); font-size: var(--f-xs); }
.wmsg { margin: auto; text-align: center; color: var(--muted); font-size: var(--f-m); display: flex; flex-direction: column; gap: var(--g3); align-items: center; }
.wmsg .btn { flex: 0 0 auto; }

/* ---------------------------------------------------------------- overlays */
.banner {
  position: absolute; left: 0; right: 0; top: 0; z-index: 35; padding: calc(env(safe-area-inset-top, 0px) + var(--g1)) var(--g3) var(--g1);
  background: var(--warn); color: #2b1c00; font-size: var(--f-xs); font-weight: 800; text-align: center;
}
.toast {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + var(--g4) * 3); z-index: 40; transform: translateX(-50%);
  max-width: 88%; padding: calc(var(--u) * 9px) var(--g4); border-radius: 999px; background: rgba(0, 0, 0, .82); color: #fff;
  font-size: var(--f-s); font-weight: 700; text-align: center; pointer-events: none;
}
.modal { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: var(--g4); background: rgba(5, 3, 30, .72); }
.modal-card {
  width: 100%; max-width: calc(var(--u) * 420px); max-height: 100%; overflow: hidden; display: flex; flex-direction: column; gap: var(--g3);
  padding: var(--g4); border: 1px solid var(--glass-b); border-radius: var(--r); background: #251b69;
}
.modal-card h3 { margin: 0; font-size: var(--f-l); }
.modal-card p { margin: 0; color: var(--muted); font-size: var(--f-s); line-height: 1.4; }
.m-btns { display: flex; flex-direction: column; gap: var(--g2); }
