:root {
  --bg: #f6f4f1;
  --card: #fff;
  --ink: #1d1b1a;
  --muted: #6f6a66;
  --line: #e4dfda;
  --accent: #b3261e;
  --accent-ink: #fff;
  --ok: #1e7a3c;
  --ok-bg: #e3f3e8;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --warn: #a05a00;
  --radius: 16px;
  --tap: 52px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --card: #1f1d1c;
    --ink: #f1eeeb;
    --muted: #a7a19c;
    --line: #34302d;
    --accent: #e0564c;
    --ok: #5fd07f;
    --ok-bg: #1b3324;
    --bad: #ff7a70;
    --bad-bg: #3a1e1c;
    --warn: #f0a640;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-top: env(safe-area-inset-top);
  min-height: 100vh;
}
body.with-tabs { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; min-height: 52px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#top h1 { flex: 1; margin: 0; font-size: 19px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; background: none; font-size: 26px; text-decoration: none; color: var(--ink); cursor: pointer;
}
#back { font-size: 34px; line-height: 1; }
#back[hidden] + h1 { margin-left: 52px; }

main { max-width: 560px; margin: 0 auto; padding: 14px 16px 24px; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
#tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); text-decoration: none; padding: 4px 0;
}
#tabs a span { font-size: 22px; filter: grayscale(1); opacity: .7; }
#tabs a.active { color: var(--accent); font-weight: 600; }
#tabs a.active span { filter: none; opacity: 1; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: 90vw; padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 15px; text-align: center;
}

h2 { font-size: 22px; margin: 10px 0; }
h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 26px 0 8px; }
.muted { color: var(--muted); }
.block { display: block; }
.center, .center-text { text-align: center; }
.center { padding: 28px 8px; display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
.big-emoji { font-size: 56px; margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.btn {
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  min-height: var(--tap); padding: 10px 16px; margin: 8px 0;
  border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  font-size: 17px; font-weight: 600; color: var(--ink); text-decoration: none; text-align: center;
  cursor: pointer; width: 100%; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { min-height: 60px; font-size: 19px; }
.btn.ghost { background: none; border-color: transparent; color: var(--muted); }
.btn.small { min-height: 36px; width: auto; margin: 0; padding: 6px 12px; font-size: 15px; }
.btn small { font-weight: 400; font-size: 12px; opacity: .8; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; font-size: 15px; }

input, select, textarea {
  font: inherit; font-size: 17px; width: 100%;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); min-height: 48px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; color: var(--muted); }
label.switch { flex-direction: row; align-items: center; gap: 12px; color: var(--ink); font-size: 17px; min-height: 44px; }
label.switch input { width: 24px; height: 24px; min-height: 0; accent-color: var(--accent); flex: none; }

/* вход */
.login { text-align: center; padding: 40px 4px; }
.login .logo { font-size: 64px; }
.login h1 { margin: 6px 0; font-size: 28px; }
.login .hint { margin-top: 28px; font-size: 14px; color: var(--muted); background: var(--card); border-radius: 12px; padding: 12px; }
#login-step { margin-top: 14px; text-align: left; }

/* главная */
.hello { font-size: 24px; font-weight: 700; margin: 4px 0 12px; }
.hero { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); }
.hero p { margin: 10px 0 4px; }
.progress { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; }
.tile b { display: block; font-size: 26px; }
.tile span { font-size: 13px; color: var(--muted); }
.list { display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 8px 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 56px; padding: 10px 14px; color: var(--ink); text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row > span { flex: 1; }
.row small { color: var(--muted); white-space: nowrap; }
.row small.ok { color: var(--ok); }
.row small.bad { color: var(--bad); }
.banner { display: block; margin-top: 14px; padding: 14px; border-radius: 14px; background: var(--card); border: 1px dashed var(--accent); text-decoration: none; color: var(--ink); }
.meter { display: block; height: 5px; border-radius: 3px; background: var(--line); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--ok); }

/* занятие */
.lesson-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lesson-top .progress { flex: 1; }
.lesson-top small { color: var(--muted); white-space: nowrap; }
.card, .question {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 16px 10px;
}
.card { text-align: center; }
.pill { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--bg); color: var(--muted); margin: 0 4px 8px 0; }
.pill.warn { color: var(--warn); }
.big-word { font-size: 34px; font-weight: 700; margin: 14px 0 6px; overflow-wrap: anywhere; }
.card .ru { font-size: 24px; margin: 14px 0 6px; }
.example { margin: 14px 0; padding: 10px; border-radius: 12px; background: var(--bg); }
.example .es { font-size: 18px; }
.note { font-size: 15px; color: var(--muted); }
.speak { display: inline-flex; gap: 6px; vertical-align: middle; }
.say {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 20px; cursor: pointer; padding: 0;
}
.say:active { background: var(--line); }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.rate .btn { padding: 6px 2px; font-size: 14px; margin: 8px 0; min-height: 60px; }
.rate .r1 { color: var(--bad); }
.rate .r4 { color: var(--ok); }
.report-link { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 12px 0 6px; cursor: pointer; display: block; margin: 0 auto; }

.q-img { display: block; max-width: 160px; max-height: 160px; margin: 0 auto 12px; }
.q-text { font-size: 19px; font-weight: 600; }
.q-text .speak { margin-left: 4px; }
.tr { color: var(--muted); font-size: 16px; margin: 6px 0; }
.tr.small { font-size: 14px; margin: 2px 0 0; }
.options { display: flex; flex-direction: column; gap: 8px; margin: 14px 0 4px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  min-height: var(--tap); padding: 12px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card); cursor: pointer; font-size: 17px;
  touch-action: manipulation;
}
.opt b { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); font-size: 14px; }
.opt:disabled { opacity: 1; cursor: default; }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.picked { border-color: var(--accent); }
.opt.picked b { background: var(--accent); color: var(--accent-ink); }
.explain { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.ref { font-size: 15px; }
.quote { font-size: 15px; font-style: italic; }
details summary { cursor: pointer; color: var(--accent); font-size: 15px; padding: 6px 0; }
.kw { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { font-size: 13px; background: var(--bg); border-radius: 10px; padding: 4px 8px; }
.question.disputed { border-color: var(--warn); }

/* экзамен */
.exam-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.timer { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.ix { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin-bottom: 12px; }
.grid button {
  aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  font-size: 13px; padding: 0; cursor: pointer;
}
.grid button.answered { background: var(--line); }
.grid button.current { border: 2px solid var(--accent); font-weight: 700; }
.exam-nav { display: flex; gap: 8px; }
.exam-nav .btn { flex: 1; }
.result { text-align: center; }
.result.pass h2 { color: var(--ok); }
.result.fail h2 { color: var(--bad); }
.review-item { margin: 14px 0; }

/* статистика */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal i { aspect-ratio: 1; border-radius: 6px; background: var(--line); }
.cal i.some { background: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.cal i.on { background: var(--ok); }

/* окно «тут ошибка» */
.sheet-bg { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet h2 { margin-top: 0; }
