:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #15171a);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #3e63dd);
  --btn: var(--tg-theme-button-color, #5b5bd6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f3f6);
  --section: var(--tg-theme-section-bg-color, #ffffff);
  --accent: #6e56cf;
  --ok: #22a06b;
  --danger: #e5484d;
  --gold: #f5a524;
  --fig-bg: var(--section);
  --poly: color-mix(in srgb, var(--accent) 35%, var(--section));
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --soft: color-mix(in srgb, var(--btn) 12%, var(--section));
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #17181c; --text: #eceef2; --hint: #8b919c; --card: #0f1013; --section: #202228; --link: #8da4ef; --btn: #6e6ade;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--card); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input { font: inherit; color: inherit; }
#app { max-width: 560px; margin: 0 auto; padding: 12px 14px 96px; }
.hidden { display: none !important; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; }

.card { background: var(--section); border-radius: var(--radius); padding: 16px; }
.card.flat { padding: 12px 14px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 4px 8px; }
.see-all { font-size: 13px; font-weight: 600; text-transform: none; letter-spacing: 0; color: var(--link); padding: 2px 0; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 48px; padding: 12px 16px; border-radius: 12px; font-weight: 600;
  background: var(--btn); color: var(--btn-text); transition: transform .08s, opacity .2s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.secondary { background: var(--soft); color: var(--text); }
.btn.ghost { background: transparent; color: var(--link); min-height: 40px; }
.btn.gold { background: linear-gradient(135deg, #f7b733, #f5a524); color: #2b1d00; }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, var(--section)); color: var(--danger); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; width: auto; border-radius: 10px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 36px; }
.topbar .title { font-weight: 700; font-size: 17px; flex: 1; }
.lang-btn { padding: 6px 10px; border-radius: 20px; background: var(--section); font-size: 14px; }
.iconbtn { width: 36px; height: 36px; border-radius: 50%; background: var(--section); display: grid; place-items: center; font-size: 18px; }

/* hero */
.hero {
  position: relative; overflow: hidden; color: #fff; border-radius: 20px; padding: 20px;
  background: radial-gradient(120% 140% at 100% 0%, #8e7cf0 0%, #6e56cf 45%, #4b3aa8 100%);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.hero .label { opacity: .85; font-size: 14px; }
.hero .iq { font-size: 56px; font-weight: 800; line-height: 1; margin: 6px 0 4px; letter-spacing: -1px; }
.hero .sub { opacity: .9; font-size: 14px; }
.hero .btn { background: #fff; color: #4b3aa8; margin-top: 16px; position: relative; z-index: 1; }
.hero .chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; position: relative; z-index: 1; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: rgba(255,255,255,.18); }
.chip.dark { background: var(--soft); color: var(--text); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.tile-btn { text-align: left; background: var(--section); border-radius: var(--radius); padding: 14px; min-height: 104px; display: flex; flex-direction: column; gap: 4px; }
.tile-btn .ico { font-size: 26px; line-height: 1; margin-bottom: 4px; }
.tile-btn b { font-size: 15px; }
.tile-btn span { font-size: 12.5px; color: var(--hint); }
.tile-btn:active { transform: scale(.98); }

/* test */
.test-top { position: sticky; top: 0; z-index: 5; background: var(--card); padding: 6px 0 10px; }
.progress { height: 6px; background: var(--line); border-radius: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 20px; background: var(--section); }
.timer.low { color: #fff; background: var(--danger); }
.dots { display: flex; gap: 3px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--gold); }
.prompt { white-space: pre-line; font-size: 16px; font-weight: 600; margin-bottom: 14px; }
.stem { margin: 6px 0 16px; display: flex; justify-content: center; }
.options { display: grid; gap: 10px; }
.options.text { grid-template-columns: 1fr; }
.options.text.short { grid-template-columns: 1fr 1fr; }
.options.fig { grid-template-columns: repeat(3, 1fr); }
.opt {
  position: relative; background: var(--section); border: 2px solid var(--line); border-radius: 14px;
  padding: 12px 14px; min-height: 52px; text-align: left; font-weight: 500; display: flex; align-items: center; gap: 10px;
  transition: border-color .15s, background .15s;
}
.opt .let { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--soft); }
.opt.fig { padding: 7%; flex-direction: column; justify-content: center; aspect-ratio: 1; }
.opt.fig .let { position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; font-size: 12px; }
.opt.fig svg { width: 100%; height: auto; }
.opt.sel { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--section)); }
.opt.sel .let { background: var(--accent); color: #fff; }
.opt.good { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--section)); }
.opt.bad { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, var(--section)); }
.opt.good .let { background: var(--ok); color: #fff; } .opt.bad .let { background: var(--danger); color: #fff; }
.opt[disabled] { pointer-events: none; }
.test-nav { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); z-index: 6; }
.test-nav .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 8px; }
.test-nav .btn { flex: 1; font-size: 14.5px; padding: 10px 8px; white-space: nowrap; }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.qnav button { width: 32px; height: 32px; border-radius: 8px; background: var(--section); font-size: 12px; font-weight: 600; border: 2px solid transparent; }
.qnav button.done { background: var(--soft); }
.qnav button.cur { border-color: var(--accent); }

/* stems */
.tile { display: inline-grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px; border-radius: 10px; background: var(--section); font-weight: 700; font-size: 17px; border: 2px solid var(--line); }
.tile.wide { min-width: 64px; letter-spacing: .04em; }
.ask { color: var(--accent); border: 2px dashed var(--accent) !important; background: color-mix(in srgb, var(--accent) 8%, var(--section)) !important; }
.seq { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.grid3 { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; }
.grid3 .cell { height: 56px; display: grid; place-items: center; border-radius: 10px; background: var(--section); font-weight: 700; font-size: 18px; border: 2px solid var(--line); }
.pyr { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.pyr-row { display: flex; gap: 4px; }
.brick { width: 58px; height: 40px; display: grid; place-items: center; border-radius: 6px; background: color-mix(in srgb, var(--gold) 22%, var(--section)); font-weight: 700; border: 2px solid color-mix(in srgb, var(--gold) 45%, transparent); }
.brick.blank { background: var(--section); border-style: dotted; }
.map { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.map-row { display: flex; align-items: center; gap: 10px; }
.arrow { color: var(--hint); font-size: 20px; }
.eqs { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.eq { display: flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 700; }
.eq .op { min-width: 14px; text-align: center; }
.eq .tile { height: 36px; min-width: 36px; }
.sym { width: 32px; height: 32px; }
.matrix { display: grid; grid-template-columns: repeat(3, 1fr); width: min(100%, 330px); border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--fig-bg); }
.mcell { aspect-ratio: 1; display: grid; place-items: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6%; }
.mcell:nth-child(3n) { border-right: 0; } .mcell:nth-child(n+7) { border-bottom: 0; }
.mcell svg { width: 100%; height: 100%; }
.qmark { font-size: 34px; font-weight: 800; color: var(--accent); }
.poly-stem { width: 150px; height: 150px; padding: 8px; background: var(--section); border-radius: 14px; border: 2px solid var(--line); }
.poly-stem svg { width: 100%; height: 100%; }
.clocks, .dominoes { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.clock { width: 70px; height: 70px; }
.domino { width: 44px; height: 84px; }
.opt .domino { width: 40%; height: auto; }
.analogy { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.analogy .op { font-weight: 800; font-size: 20px; color: var(--hint); }
.compass svg { width: 64px; height: 64px; }

/* result */
.result-hero { text-align: center; }
.result-hero .iq { font-size: 72px; }
.bell { width: 100%; height: auto; margin-top: 8px; }
.bars .bar { margin-top: 10px; }
.bar .track { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 4px; }
.bar .track i { display: block; height: 100%; background: var(--accent); border-radius: 8px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--section); border-radius: 14px; padding: 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12.5px; color: var(--hint); }
.badge-record { display: inline-block; background: var(--gold); color: #2b1d00; font-weight: 700; padding: 4px 10px; border-radius: 20px; font-size: 13px; position: relative; z-index: 1; }

/* review */
.rv { background: var(--section); border-radius: var(--radius); padding: 14px; margin-top: 12px; }
.rv-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rv-num { font-weight: 700; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.rv .prompt { font-size: 15px; }
.rv .stem { transform-origin: top center; }
.locked { margin-top: 12px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--gold) 12%, var(--section)); border: 1px dashed color-mix(in srgb, var(--gold) 60%, transparent); }
.expl { margin-top: 12px; padding: 12px; border-radius: 12px; background: color-mix(in srgb, var(--ok) 9%, var(--section)); white-space: pre-line; }
.expl h4 { margin: 0 0 6px; font-size: 14px; color: var(--ok); }
.sticky-bottom { position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--card) 30%); z-index: 4; }

/* tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; padding: 8px 14px; border-radius: 20px; background: var(--section); font-weight: 600; font-size: 14px; }
.tabs button.on { background: var(--btn); color: var(--btn-text); }

/* leaderboard */
.lb { margin-top: 12px; background: var(--section); border-radius: var(--radius); overflow: hidden; }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.lb-row:last-child { border-bottom: 0; }
.lb-row.me { background: color-mix(in srgb, var(--accent) 10%, var(--section)); }
.lb-rank { width: 30px; text-align: center; font-weight: 700; color: var(--hint); flex: none; }
.lb-rank.medal { font-size: 22px; }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb-name small { display: block; font-weight: 400; color: var(--hint); font-size: 12px; }
.lb-val { font-weight: 800; font-size: 17px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; overflow: hidden; background-size: cover; background-position: center; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.star-badge { color: var(--gold); margin-left: 4px; }
.me-bar { position: sticky; bottom: 0; margin-top: 12px; padding-bottom: env(safe-area-inset-bottom); }
.me-bar .lb-row { border-radius: var(--radius); background: var(--btn); color: var(--btn-text); border: 0; }
.me-bar .lb-rank, .me-bar small { color: inherit !important; opacity: .85; }

/* arena */
.code-big { font-size: 34px; font-weight: 800; letter-spacing: .18em; text-align: center; padding: 6px 0; }
.player { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.player:last-child { border-bottom: 0; }
.player .tag { font-size: 11px; padding: 2px 6px; border-radius: 10px; background: var(--soft); color: var(--hint); font-weight: 600; }
.player.off { opacity: .5; }
.player .check { color: var(--ok); font-weight: 800; }
.input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--section); text-transform: uppercase; letter-spacing: .12em; font-weight: 700; outline: none; }
.input:focus { border-color: var(--accent); }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 42px; height: 24px; appearance: none; background: var(--line); border-radius: 20px; position: relative; transition: background .2s; flex: none; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 21px; }
.ring { width: 54px; height: 54px; flex: none; }
.ring text { font-weight: 800; font-size: 30px; fill: currentColor; }
.countdown-big { font-size: 96px; font-weight: 800; text-align: center; color: var(--accent); padding: 40px 0; }
.banner { padding: 12px; border-radius: 12px; text-align: center; font-weight: 700; margin-top: 12px; }
.banner.ok { background: color-mix(in srgb, var(--ok) 15%, var(--section)); color: var(--ok); }
.banner.bad { background: color-mix(in srgb, var(--danger) 13%, var(--section)); color: var(--danger); }
.banner.wait { background: var(--soft); color: var(--hint); }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 8px; margin: 10px 0 4px; }
.podium .p { text-align: center; width: 31%; }
.podium .p .blk { margin-top: 6px; border-radius: 10px 10px 4px 4px; background: var(--soft); display: grid; place-items: center; font-size: 24px; font-weight: 800; }
.podium .avatar { margin: 0 auto; width: 46px; height: 46px; }
.podium .nm { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; }
.delta-up { color: var(--ok); font-weight: 700; } .delta-down { color: var(--danger); font-weight: 700; }

/* donate */
.amounts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.amounts button { background: var(--section); border: 2px solid var(--line); border-radius: 12px; padding: 14px 6px; font-weight: 800; font-size: 17px; }
.amounts button.on { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 14%, var(--section)); }

/* misc */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(20,20,24,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: 90vw; text-align: center; animation: pop .2s; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--hint); padding: 28px 10px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--section); border-radius: 14px; margin-top: 8px; width: 100%; text-align: left; }
.list-item .big { font-size: 22px; font-weight: 800; min-width: 52px; text-align: center; }
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--section); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet .opt { width: 100%; margin-top: 8px; }
ul.rules { padding-left: 20px; margin: 8px 0 0; } ul.rules li { margin: 6px 0; }
