/* Colors come from the Telegram theme (light/dark); fallbacks are for a normal browser. */
:root {
  --fb-bg: #f1f2f6;
  --fb-card: #ffffff;
  --fb-text: #111827;
  --fb-hint: #8a8f98;
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --ok: #2fa84f;
  --bad: #e5484d;
  --warn: #f59e0b;
  --ok-bg: rgba(47, 168, 79, 0.14);
  --bad-bg: rgba(229, 72, 77, 0.14);
  --line: rgba(128, 128, 128, 0.2);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --fb-bg: #0f1115; --fb-card: #1a1d23; --fb-text: #e8eaed; --fb-hint: #8b919a; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; text-align: inherit; }
button:disabled { cursor: default; opacity: .45; }
h3 { margin: 22px 4px 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); font-weight: 600; }
.hint { color: var(--hint); font-size: 13px; }
.center { min-height: 60vh; display: grid; place-items: center; text-align: center; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 12px; font-weight: 600; background: var(--card); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.outline { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); background: transparent; }
.btn.ghost { background: var(--card); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; background: var(--accent); color: var(--accent-text); white-space: nowrap; }
.btn.wide { width: 100%; margin-top: 12px; }
.back-link { font-size: 28px; line-height: 1; padding: 0 8px 8px 0; color: var(--accent); }

/* Home */
.hero { padding: 6px 4px 4px; }
.hero .hello { font-size: 22px; font-weight: 700; }
.hero .subject { color: var(--hint); font-size: 14px; margin: 2px 0 10px; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--card); color: var(--hint); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--card); }
.banner.accent { box-shadow: inset 0 0 0 1.5px var(--accent); }
.banner.ok { background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.banner > div { min-width: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.tile { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px; min-height: 96px; border-radius: var(--radius); background: var(--card); }
.tile .icon { font-size: 22px; }
.tile.wide { grid-column: span 2; min-height: 0; }
.tile b { font-size: 15px; line-height: 1.25; }
.tile .lock { position: absolute; top: 10px; right: 12px; font-size: 14px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 14px; border-radius: var(--radius); background: var(--card); }
.row .score { text-align: right; font-weight: 700; white-space: nowrap; }
.row.locked { opacity: .6; }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.langs { display: flex; justify-content: center; gap: 8px; margin-top: 26px; }
.langs button { padding: 6px 14px; border-radius: 999px; background: var(--card); font-size: 14px; color: var(--hint); }
.langs button.active { background: var(--accent); color: var(--accent-text); }
.empty { padding: 24px 8px; text-align: center; color: var(--hint); }

/* Bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; z-index: 10; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; background: var(--bg); animation: up .2s ease-out; }
.sheet .title { font-weight: 700; font-size: 18px; margin: 0 4px 12px; }
.sheet .row { margin-bottom: 8px; text-align: left; }
.sheet .row > div { min-width: 0; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* Quiz */
.quiz-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.quiz-mode { font-weight: 600; color: var(--hint); font-size: 14px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 4px 10px; border-radius: 10px; background: var(--card); }
.timer.warn { color: var(--bad); background: var(--bad-bg); }
.progress { height: 4px; border-radius: 4px; background: var(--line); margin: 12px 0 14px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s; }
.q-head { font-weight: 700; margin: 0 4px 8px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; }
.q-text { white-space: pre-wrap; word-wrap: break-word; font-size: 17px; }
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.opt { display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 12px; background: var(--card); box-shadow: inset 0 0 0 1.5px transparent; transition: box-shadow .15s, background .15s; }
.opt .letter { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--bg); font-weight: 700; font-size: 14px; }
.opt .opt-text { padding-top: 3px; white-space: pre-wrap; word-wrap: break-word; min-width: 0; }
.opt.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.opt.selected .letter { background: var(--accent); color: var(--accent-text); }
.opt.correct { background: var(--ok-bg); box-shadow: inset 0 0 0 2px var(--ok); }
.opt.correct .letter { background: var(--ok); color: #fff; }
.opt.wrong { background: var(--bad-bg); box-shadow: inset 0 0 0 2px var(--bad); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt:disabled { opacity: 1; }
.opt.dim { opacity: .6; }
.feedback { margin-top: 12px; padding: 10px 14px; border-radius: 12px; font-weight: 700; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }
.nav { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 18px; }
.cell { aspect-ratio: 1; border-radius: 9px; background: var(--card); font-size: 13px; font-weight: 600; text-align: center; color: var(--hint); }
.cell.done { background: var(--accent); color: var(--accent-text); }
.cell.ok { background: var(--ok-bg); color: var(--ok); }
.cell.bad { background: var(--bad-bg); color: var(--bad); }
.cell.current { box-shadow: inset 0 0 0 2px var(--text); color: var(--text); }

/* Result */
.result { text-align: center; }
.ring { width: 132px; height: 132px; margin: 8px auto 12px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.ring span { display: grid; place-items: center; width: 108px; height: 108px; border-radius: 50%; background: var(--bg); font-size: 28px; font-weight: 800; }
.result .big { font-size: 22px; font-weight: 700; }
.result .facts { margin: 10px 0 4px; display: flex; flex-direction: column; gap: 2px; color: var(--hint); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; margin: 18px 0 12px; border-radius: 12px; background: var(--card); }
.tab { padding: 8px; border-radius: 9px; font-weight: 600; font-size: 14px; text-align: center; color: var(--hint); }
.tab.active { background: var(--accent); color: var(--accent-text); }
.review { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.review .q-text { font-size: 15px; }
.review .opt { padding: 8px 10px; }
.review .q-head { margin: 0 0 6px; display: flex; justify-content: space-between; }
.mark-ok { color: var(--ok); }
.mark-bad { color: var(--bad); }

/* Subscription */
.price { text-align: center; padding: 22px 16px; }
.price .amount { font-size: 32px; font-weight: 800; }
.features { margin: 14px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.features li::before { content: "✓"; color: var(--ok); font-weight: 700; margin-right: 8px; }
.pay { display: flex; flex-direction: column; gap: 8px; }
.pay .btn { width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 12px; background: rgba(20, 20, 20, .9); color: #fff; font-size: 14px; z-index: 20; text-align: center; }

/* ---------- Question types ---------- */
.type-hint { margin: 10px 4px 0; font-size: 13px; font-weight: 600; color: var(--accent); }
.opt .letter.box { border-radius: 7px; }
.submit-bar { display: flex; gap: 8px; margin-top: 12px; }
.submit-bar .btn { flex: 1; }
.submit-bar .btn:disabled { opacity: .45; }
.m-right-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.m-right { display: flex; align-items: flex-start; gap: 10px; }
.m-right .letter { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--bg); font-weight: 700; font-size: 13px; }
.m-right .opt-text { padding-top: 2px; }
.m-row { padding: 12px 14px; border-radius: 12px; background: var(--card); }
.m-left { display: flex; gap: 10px; align-items: flex-start; }
.m-left .num { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--bg); font-weight: 700; font-size: 13px; }
.m-left span:last-child { padding-top: 2px; }
.chips { display: flex; gap: 8px; margin: 10px 0 0 36px; flex-wrap: wrap; }
.chip { min-width: 42px; min-height: 38px; padding: 0 10px; border-radius: 10px; font-weight: 700; background: var(--bg); box-shadow: inset 0 0 0 1.5px var(--line); }
.chip.selected { background: var(--accent); color: var(--accent-text); box-shadow: none; }
.chip.correct { background: var(--ok); color: #fff; box-shadow: none; }
.chip.wrong { background: var(--bad); color: #fff; box-shadow: none; }
.opt.order .letter:empty { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.right-pos { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--ok); }
.explain { margin-top: 12px; padding: 12px 14px; border-radius: 12px; background: var(--card); box-shadow: inset 3px 0 0 var(--accent); display: flex; flex-direction: column; gap: 6px; }
.review .explain { background: var(--bg); }
.review .m-row { background: var(--bg); }
