:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #7d8590);
  --link: var(--tg-theme-link-color, #2a7ae2);
  --btn: var(--tg-theme-button-color, #2a7ae2);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --ok: #2fb45a;
  --ok-bg: rgba(47, 180, 90, .14);
  --bad: #e5484d;
  --bad-bg: rgba(229, 72, 77, .13);
  --warn: #f5a524;
  --fire: #ff7a1a;
  --radius: 14px;
  --gap: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 24px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 20px 0 10px; }
h3 { font-size: 16px; margin: 16px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--hint); font-size: 14px; }
.small { font-size: 13px; }
.loading, .empty { text-align: center; color: var(--hint); padding: 48px 0; }
.card { background: var(--bg2); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 var(--gap); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.between > * { min-width: 0; }
.row.between > .muted { flex-shrink: 0; }
.grow { flex: 1; min-width: 0; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.btn {
  display: block; width: 100%; padding: 14px 16px; border-radius: 12px; font-weight: 600; font-size: 16px;
  background: var(--btn); color: var(--btn-text); text-align: center; margin: 0 0 10px;
}
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.accent { background: #22a35a; color: #fff; }
.btn.ghost { background: transparent; color: var(--link); padding: 10px; }
.btn:disabled { opacity: .45; }
.btn .sub { display: block; font-weight: 400; font-size: 13px; opacity: .85; }

/* Головна */
.hero { display: flex; gap: var(--gap); margin-bottom: var(--gap); }
.hero .card { flex: 1; min-width: 0; margin: 0; text-align: center; padding: 14px 6px; }
.unit-xp { font-size: 16px; font-weight: 600; }
.card.tap { font: inherit; color: inherit; cursor: pointer; }
.card.tap:active { opacity: .7; }
.big { font-size: 30px; font-weight: 700; line-height: 1.1; }
.fire { color: var(--fire); }
.bar { height: 8px; border-radius: 4px; background: rgba(127, 127, 127, .2); overflow: hidden; margin: 8px 0 4px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .3s; }
.alert { border-radius: 12px; padding: 10px 14px; margin: 0 0 var(--gap); font-size: 14px; }
.alert.warn { background: rgba(245, 165, 36, .15); }
.alert.ok { background: var(--ok-bg); }

/* Шпаргалка */
.search { width: 100%; font: inherit; padding: 12px 14px; border-radius: 12px; border: 1.5px solid rgba(127, 127, 127, .35); background: var(--bg2); color: var(--text); margin: 4px 0 8px; }
.term[hidden], section[hidden] { display: none; }
.nothing { text-align: center; color: var(--hint); padding: 28px 12px 36px; }
.nothing[hidden] { display: none; }
.play-after { margin-top: 28px; }
.term { display: block; width: 100%; text-align: left; background: var(--bg2); border-radius: 12px; padding: 12px 14px; margin: 0 0 8px; }
.term b { font-size: 16px; }
.term .one { color: var(--hint); font-size: 14px; margin-top: 2px; }
.term .seen { float: right; color: var(--ok); font-size: 13px; }
.formula { background: var(--bg2); border-left: 4px solid var(--ok); border-radius: 0 10px 10px 0; padding: 10px 14px; margin: 12px 0; }
.formula-label { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; }
.formula-body, .formula .f { font-weight: 600; font-size: 17px; }
.article { overflow-wrap: anywhere; }
.article h2 { font-size: 18px; }
.article ul, .article ol { padding-left: 22px; }
.article table { border-collapse: collapse; width: 100%; font-size: 14px; display: block; overflow-x: auto; }
.article td, .article th { border: 1px solid rgba(127, 127, 127, .3); padding: 6px 8px; }

/* Гра */
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 14px; color: var(--hint); }
.timer { height: 6px; border-radius: 3px; background: rgba(127, 127, 127, .2); overflow: hidden; margin-bottom: 16px; }
.timer > i { display: block; height: 100%; background: var(--btn); transition: width 1s linear; }
.timer.low > i { background: var(--bad); }
.hint { font-size: 13px; color: var(--hint); margin: -8px 0 12px; }
.prompt { font-size: 18px; font-weight: 600; margin: 0 0 16px; white-space: pre-line; }
.opt {
  display: block; width: 100%; text-align: left; padding: 13px 14px; border-radius: 12px; margin: 0 0 8px;
  background: var(--bg2); border: 2px solid transparent; font-size: 15px;
}
.opt.sel { border-color: var(--btn); }
.opt.right { background: var(--ok-bg); border-color: var(--ok); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); }
.opt .box { display: inline-block; width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--hint); vertical-align: -4px; margin-right: 8px; }
.opt.sel .box { background: var(--btn); border-color: var(--btn); }
.pair { background: var(--bg2); border-radius: 12px; padding: 10px 12px; margin: 0 0 8px; }
.pair .label { font-weight: 600; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 12px; border-radius: 999px; background: var(--bg); border: 1.5px solid rgba(127, 127, 127, .35); font-size: 14px; }
.chip.sel { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.chip.right { border-color: var(--ok); background: var(--ok-bg); }
.chip.wrong { border-color: var(--bad); background: var(--bad-bg); }
input.num {
  width: 100%; font: inherit; font-size: 22px; padding: 12px 14px; border-radius: 12px; border: 2px solid rgba(127, 127, 127, .35);
  background: var(--bg2); color: var(--text); margin-bottom: 12px;
}
.unit { color: var(--hint); margin: -6px 0 12px; font-size: 14px; }
.feedback { border-radius: var(--radius); padding: 14px 16px; margin: 16px 0 12px; }
.feedback.ok { background: var(--ok-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback .title { font-weight: 700; font-size: 17px; margin-bottom: 6px; }
.feedback .right-answer { white-space: pre-line; font-weight: 600; margin: 6px 0; }
.more { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.more button { padding: 6px 12px; border-radius: 999px; background: var(--bg); font-size: 14px; color: var(--link); }

/* Рейтинг */
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 8px; font-size: 14px; }
.seg button.on { background: var(--bg); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.rank { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
.rank:nth-child(odd) { background: var(--bg2); }
.rank.me { outline: 2px solid var(--btn); }
.rank .pos { width: 26px; text-align: center; font-weight: 700; color: var(--hint); }
.rank .val { font-weight: 600; }

/* Налаштування */
select { font: inherit; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(127, 127, 127, .35); background: var(--bg2); color: var(--text); }
label.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* Аналітика */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.grid { border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid rgba(127, 127, 127, .2); text-align: right; }
table.grid th { position: sticky; top: 0; background: var(--bg); cursor: pointer; }
table.grid td:first-child, table.grid th:first-child, table.grid td:nth-child(2), table.grid th:nth-child(2) { text-align: left; }
.flag { color: var(--warn); }
.link-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid rgba(127, 127, 127, .2); }
.link-row code { font-size: 12px; overflow-wrap: anywhere; flex: 1; }

/* Нижнє меню */
nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--bg);
  border-top: 1px solid rgba(127, 127, 127, .2); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
nav#tabs[hidden] { display: none; }
nav#tabs button { flex: 1; padding: 8px 0 10px; font-size: 11px; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav#tabs button span { font-size: 20px; }
nav#tabs button.on { color: var(--btn); }
