:root {
  --bg: var(--tg-theme-bg-color, #0e1411);
  --bg2: var(--tg-theme-secondary-bg-color, #17201b);
  --text: var(--tg-theme-text-color, #f2f5f3);
  --muted: var(--tg-theme-hint-color, #93a39a);
  --card: var(--tg-theme-section-bg-color, #17201b);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --green: #12a150;
  --yellow: #f5c518;
  --red: #e0363d;
  --accent: var(--tg-theme-button-color, #12a150);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "Noto Sans Ethiopic", "Nyala", "Abyssinica SIL", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; min-height: 100dvh; font-size: 16px; line-height: 1.45; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; min-width: 0; }
input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

.screen { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
main { padding: 12px 14px calc(88px + var(--safe-b)); }

.logo { font-weight: 800; font-size: 22px; letter-spacing: .5px; }
.logo span { margin-left: 6px; font-size: .55em; padding: 2px 6px; border-radius: 6px; background: var(--red); color: #fff; vertical-align: middle; letter-spacing: 1px; }
.logo.big { font-size: 44px; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, var(--green) 0 33.3%, var(--yellow) 33.3% 66.6%, var(--red) 66.6%); }
.topbar-right { display: flex; gap: 10px; align-items: center; }
.lives { font-size: 15px; }
.chip { border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 12px 0; }
.card h3 { margin: 0 0 10px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

.game-card { text-align: center; position: relative; overflow: hidden; }
.game-card h2 { margin: 6px 0 4px; font-size: 20px; }
.sponsor { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.prize { font-size: 46px; font-weight: 800; color: var(--yellow); line-height: 1.1; margin-top: 8px; font-variant-numeric: tabular-nums; }
.prize small { font-size: 18px; color: var(--text); font-weight: 600; }
.countdown { font-size: 30px; font-weight: 700; margin: 14px 0 4px; font-variant-numeric: tabular-nums; }
.countdown.live { color: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.joined { margin-top: 14px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--green) 18%, transparent); font-weight: 600; }

.btn { border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; padding: 12px 16px; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.wide { width: 100%; margin-top: 16px; padding: 15px; font-size: 17px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; }
.row { display: flex; gap: 8px; align-items: center; }
.field { display: grid; gap: 8px; }

.rules { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.leaderboard { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.leaderboard li { counter-increment: rank; display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.leaderboard li::before { content: counter(rank); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--bg2); }
.leaderboard li:nth-child(1)::before { background: var(--yellow); color: #222; }
.leaderboard li:nth-child(2)::before { background: #c9ced6; color: #222; }
.leaderboard li:nth-child(3)::before { background: #cd8b52; color: #222; }
.leaderboard .name { flex: 1; }
.leaderboard .pts { font-weight: 700; font-variant-numeric: tabular-nums; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); }
.tabbar button { flex: 1; max-width: 173px; background: none; border: 0; padding: 8px 0 10px; display: grid; gap: 2px; justify-items: center; color: var(--muted); font-size: 12px; }
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--text); }
.tabbar button.active span { filter: none; opacity: 1; }

/* Login */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; text-align: center; gap: 14px; padding: 24px; }
.tagline { font-size: 18px; margin: 0; }
#dev-login { display: flex; gap: 8px; margin-top: 18px; }

/* Live game */
.game { padding: 14px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; }
.game-top { display: flex; justify-content: space-between; }
.pill { background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-weight: 700; font-size: 14px; }
.timer { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 14px 0 6px; }
.timer-bar { height: 100%; width: 100%; background: var(--green); border-radius: 99px; transform-origin: left; }
.timer-bar.warn { background: var(--yellow); }
.timer-bar.danger { background: var(--red); }
.g-panel { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 8px 0; }
.big-emoji { font-size: 64px; }
.q-text { font-size: 22px; line-height: 1.35; margin: 0 0 22px; }
.options { display: grid; gap: 12px; }
.opt { position: relative; overflow: hidden; text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 16px; font-size: 17px; font-weight: 600; min-height: 58px; }
.opt .fill { position: absolute; inset: 0; width: 0; background: color-mix(in srgb, var(--text) 8%, transparent); transition: width .6s ease; }
.opt .label, .opt .count { position: relative; }
.opt .count { float: right; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; }
.opt.chosen { border-color: var(--accent); }
.opt.correct { border-color: var(--green); background: color-mix(in srgb, var(--green) 22%, var(--card)); }
.opt.wrong { border-color: var(--red); background: color-mix(in srgb, var(--red) 18%, var(--card)); }
.opt:disabled { cursor: default; color: var(--text); }
.status { min-height: 24px; font-weight: 600; margin-top: 18px; }
.status.good { color: var(--green); }
.status.bad { color: var(--red); }
.winners { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 14px 0; }
.winners span { background: var(--bg2); border-radius: 99px; padding: 4px 10px; font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; max-width: 90vw; }
