:root {
  --bg: #f5f4ef; --card: #ffffff; --ink: #1c1d21; --muted: #6b6f78; --line: #e4e2da;
  --accent: #2563eb; --accent-ink: #ffffff; --accent-soft: #e6eeff;
  --ok: #15803d; --ok-soft: #e3f4e8; --hint: #b45309; --hint-soft: #fdf1dc;
  --bad: #b91c1c; --bad-soft: #fde8e8; --star: #f59e0b; --lock: #b9b7ae;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a; --card: #1f2026; --ink: #ecebe6; --muted: #9a9ca5; --line: #2e3038;
    --accent: #6b9bff; --accent-ink: #0d1424; --accent-soft: #1f2a44;
    --ok: #4ade80; --ok-soft: #173023; --hint: #fbbf24; --hint-soft: #33280f;
    --bad: #f87171; --bad-soft: #3a1b1b; --lock: #555761; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a; --card: #1f2026; --ink: #ecebe6; --muted: #9a9ca5; --line: #2e3038;
  --accent: #6b9bff; --accent-ink: #0d1424; --accent-soft: #1f2a44;
  --ok: #4ade80; --ok-soft: #173023; --hint: #fbbf24; --hint-soft: #33280f;
  --bad: #f87171; --bad-soft: #3a1b1b; --lock: #555761; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
h1 { font-size: 26px; line-height: 1.2; margin: 8px 0 4px; }
h2 { font-size: 20px; margin: 24px 0 10px; }
h3 { font-size: 17px; margin: 0 0 6px; }
p { margin: 8px 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.mono, .expr { font-variant-numeric: tabular-nums; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); }
.row { display: flex; gap: 10px; align-items: center; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

button, .btn {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none; display: inline-block; text-align: center;
}
button:disabled { opacity: .45; cursor: default; }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn-wide { width: 100%; padding: 15px; font-size: 18px; }
.btn-small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.iconbtn { background: transparent; color: var(--muted); padding: 6px 10px; font-size: 22px; line-height: 1; }

input[type=text], input[type=password], input:not([type]), textarea, .num {
  font: inherit; color: var(--ink); background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* шапка */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }

/* карта тем */
.topic { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.topic .num-badge { flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.topic.locked { opacity: .55; }
.topic.locked .num-badge { background: var(--line); color: var(--muted); }
.topic.done .num-badge { background: var(--ok-soft); color: var(--ok); }
.topic.next { border-color: var(--accent); border-width: 2px; }
.stars { color: var(--star); letter-spacing: 2px; white-space: nowrap; }
.stars .off { color: var(--line); }
.tag { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* тренировка */
.problem { text-align: center; padding: 28px 8px 8px; }
.problem .expr { font-size: 46px; font-weight: 700; letter-spacing: .02em; }
.answer-row { display: flex; gap: 10px; margin-top: 18px; }
.answer-row input { font-size: 30px; text-align: center; font-weight: 700; padding: 10px; }
.answer-row button { flex: none; }
.fb { border-radius: 12px; padding: 12px 14px; margin-top: 14px; }
.fb.ok { background: var(--ok-soft); color: var(--ok); }
.fb.hint { background: var(--hint-soft); color: var(--hint); }
.fb.bad { background: var(--bad-soft); color: var(--bad); }
.fb .ink { color: var(--ink); }
.fb b { font-weight: 700; }

.steps { margin-top: 14px; display: grid; gap: 10px; }
.step { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.step .why { font-size: 14px; color: var(--muted); }
.step .line { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 700; margin-top: 4px; }
.step .line input { width: 96px; font-size: 22px; text-align: center; padding: 6px; font-weight: 700; }
.step.solved { border-color: var(--ok); }
.step.solved .line { color: var(--ok); }

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.choice button { padding: 16px 10px; }

/* разбор */
.notebook { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ex { border: 2px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; font-size: 20px; font-weight: 700; background: var(--card); cursor: default; color: var(--ink); }
button.ex { cursor: pointer; }
.ex.sel { border-color: var(--accent); background: var(--accent-soft); }
.ex.right { border-color: var(--ok); }
.ex.wrong { border-color: var(--bad); }
.ex .sub { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.mark-ok { color: var(--ok); } .mark-bad { color: var(--bad); }
.big-note { font-size: 22px; font-weight: 700; text-align: center; padding: 6px 0; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 10px 0 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--accent); }
.rule { border-left: 4px solid var(--accent); padding: 4px 0 4px 12px; margin: 10px 0; }

/* прогресс */
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.ach > div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.ach .t { font-weight: 700; font-size: 15px; }
.ach .d { font-size: 13px; color: var(--muted); }
.ach .off { opacity: .4; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal i { aspect-ratio: 1; border-radius: 4px; background: var(--line); }
.cal i.on { background: var(--ok); }
.stat { text-align: center; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
td, th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }

.goal { background: var(--accent-soft); border-color: transparent; }
.goal.done { background: var(--ok-soft); }

#toasts { position: fixed; left: 0; right: 0; top: calc(12px + env(safe-area-inset-top)); z-index: 30; display: grid; gap: 8px; justify-items: center; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.2); animation: pop .3s ease; max-width: 100%; }
@keyframes pop { from { transform: translateY(-12px); opacity: 0; } }

.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login input { font-size: 28px; text-align: center; letter-spacing: .3em; }

/* цвета оформления */
:root[data-accent="green"]  { --accent: #15803d; --accent-soft: #e3f4e8; }
:root[data-accent="purple"] { --accent: #7c3aed; --accent-soft: #efe8ff; }
:root[data-accent="orange"] { --accent: #ea580c; --accent-soft: #ffedd5; }
:root[data-accent="teal"]   { --accent: #0d9488; --accent-soft: #dcf5f2; }
:root[data-accent="gold"]   { --accent: #b7791f; --accent-soft: #fbf0d4; }
:root[data-accent="red"]    { --accent: #dc2626; --accent-soft: #fde4e4; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-accent="green"]  { --accent: #4ade80; --accent-soft: #173023; }
  :root:not([data-theme="light"])[data-accent="purple"] { --accent: #a78bfa; --accent-soft: #2a2140; }
  :root:not([data-theme="light"])[data-accent="orange"] { --accent: #fb923c; --accent-soft: #3a2414; }
  :root:not([data-theme="light"])[data-accent="teal"]   { --accent: #2dd4bf; --accent-soft: #10302d; }
  :root:not([data-theme="light"])[data-accent="gold"]   { --accent: #f6c453; --accent-soft: #3a2f12; }
  :root:not([data-theme="light"])[data-accent="red"]    { --accent: #f87171; --accent-soft: #3a1b1b; }
}
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.theme-dot { background: var(--card); color: var(--ink); border: 2px solid var(--line); padding: 10px 6px; display: grid; justify-items: center; gap: 6px; font-weight: 500; }
.theme-dot.on { border-color: var(--ink); }
.theme-dot i { width: 28px; height: 28px; border-radius: 50%; display: block; }
[data-accent-preview="blue"] { background: #2563eb; } [data-accent-preview="green"] { background: #15803d; }
[data-accent-preview="purple"] { background: #7c3aed; } [data-accent-preview="orange"] { background: #ea580c; }
[data-accent-preview="teal"] { background: #0d9488; } [data-accent-preview="night"] { background: #1f2026; border: 2px solid #6b9bff; }
[data-accent-preview="gold"] { background: #b7791f; } [data-accent-preview="red"] { background: #dc2626; }

/* уровни */
.lvlcard { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; }
.lvl-badge { flex: none; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 22px;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 4px var(--accent-soft); }
.lvl-badge.sm { width: 34px; height: 34px; font-size: 15px; box-shadow: none; }
.lvl-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lvl-row.off { opacity: .5; }
.lvl-row.off .lvl-badge { background: var(--line); color: var(--muted); }
.lvl-row.cur { background: var(--accent-soft); border-radius: 12px; padding: 8px; margin: 2px -8px; border-bottom-color: transparent; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .25s ease; }
.levelup { background: var(--card); border-radius: 22px; padding: 26px 22px; width: min(360px, 100%); text-align: center; animation: zoom .35s cubic-bezier(.2,1.4,.4,1); }
.lvl-num { font-size: 84px; font-weight: 900; line-height: 1; color: var(--accent); margin-top: 8px; }
.lvl-rank { font-size: 24px; font-weight: 800; margin-top: 6px; }
.lvl-rew { margin-top: 16px; background: var(--accent-soft); border-radius: 14px; padding: 10px 12px; }
@keyframes fade { from { opacity: 0; } }
@keyframes zoom { from { transform: scale(.6); opacity: 0; } }

.plan { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.plan .plan-eq { font-size: 20px; font-weight: 700; }

.plan-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plan-row:last-of-type { border-bottom: 0; }
.plan-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; border: 2px solid var(--line); color: var(--muted); }
.plan-row.past .plan-mark { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.plan-row.past b { color: var(--muted); font-weight: 600; }
.plan-row.now { background: var(--accent-soft); border-radius: 12px; padding: 8px; margin: 2px -8px; border-bottom-color: transparent; }
.plan-row.now .plan-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.plan-row.future { opacity: .75; }

.photo-card { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; }
.chip-new { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-err { background: var(--hint-soft); color: var(--hint); border-color: transparent; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
textarea { resize: vertical; }

/* учебник */
.plan-row { text-decoration: none; color: inherit; }
.next-card { display: block; text-decoration: none; color: inherit; border: 2px solid var(--accent); }
.task-row { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; margin: 8px 0; }
.task-row.done { opacity: .75; }
.task-ic { flex: none; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); font-size: 18px; color: var(--accent); font-weight: 700; }
.task-row.done .task-ic { background: var(--ok-soft); color: var(--ok); }
.task-text { font-size: 18px; }
.problem .expr-sm { font-size: 30px; line-height: 1.5; }
.expr .mi { width: 70px; font-size: 26px; text-align: center; padding: 4px; font-weight: 700; display: inline-block; vertical-align: middle; margin: 2px; }
.mi.ok { border-color: var(--ok); color: var(--ok); }
.mi.bad { border-color: var(--bad); }
.cmpbox { display: inline-block; min-width: 1.4em; border: 2px dashed var(--line); border-radius: 8px; color: var(--muted); }
.choice3 { grid-template-columns: 1fr 1fr 1fr; }
.choice3 button { font-size: 26px; }
.pick-ok { background: var(--ok) !important; color: #fff !important; border-color: var(--ok) !important; }
.pick-bad { background: var(--bad) !important; color: #fff !important; border-color: var(--bad) !important; }
.colbox { display: flex; align-items: center; gap: 14px; justify-content: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.col { display: inline-grid; font: 700 26px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }
.col i { font-style: normal; min-height: 1.25em; }
.col i.mk { font-size: 15px; color: var(--hint); min-height: 1em; }
.col i.sg { color: var(--muted); }
.col i.rs { color: var(--ok); }
.col b { border-top: 2px solid var(--ink); height: 2px; margin: 2px 0; }
.quiz { display: grid; gap: 8px; margin-top: 10px; }
.quiz button { text-align: left; border-width: 2px; color: var(--ink); }
.dec { display: grid; gap: 8px; }
.dcard { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; font-size: 20px; flex-wrap: wrap; }
.dcard input { width: 80px; font-size: 20px; text-align: center; padding: 4px; font-weight: 700; }
.dcard.solved { border-color: var(--ok); }
.dch { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.dcard.solved .dch { background: var(--ok); color: #fff; }
.dmsg { color: var(--hint); flex-basis: 100%; }
.word { font: 800 24px/1.4 ui-monospace, Menlo, monospace; letter-spacing: .15em; text-align: center; word-break: break-word; }
.nb { border: 2px dashed var(--line); }
.nb-lines { background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 18px; columns: 2; }
.step .msg { color: var(--muted); }
.step.solved .msg { color: var(--ok); font-weight: 600; }

.test-card { display: block; text-decoration: none; color: inherit; border: 2px solid var(--hint); }
.plan-row.test .plan-mark { border-radius: 8px; }
.grade { font-size: 84px; font-weight: 900; line-height: 1; margin: 8px 0; }
.g5 { color: var(--ok); } .g4 { color: var(--accent); } .g3 { color: var(--hint); } .g2 { color: var(--bad); }
.grade-chip { padding: 2px 9px; }
.review-item.bad { border-left: 4px solid var(--bad); }
.review-item.ok { border-left: 4px solid var(--ok); }
details summary { cursor: pointer; color: var(--accent); margin-top: 6px; }
.unit { align-self: center; color: var(--muted); }

.review-item .step .line { font-size: 18px; }

.day .daybar { position: relative; height: 12px; background: var(--line); border-radius: 99px; margin-top: 26px; }
.day .daybar > i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--ok), var(--star)); border-radius: 99px; transition: width .5s; }
.day .tick { position: absolute; top: -22px; transform: translateX(-50%); text-align: center; font-size: 11px; color: var(--muted); }
.day .tick:last-child { transform: translateX(-90%); }
.day .tick em { font-style: normal; font-size: 16px; display: block; filter: grayscale(1); opacity: .5; }
.day .tick.on em { filter: none; opacity: 1; }
.day .tick small { position: absolute; top: 36px; left: 50%; transform: translateX(-50%); }
.week { display: flex; gap: 6px; align-items: flex-end; margin: 12px 0 6px; }
.wd { flex: 1; text-align: center; font-size: 11px; color: var(--muted); }
.wd.today span { color: var(--ink); font-weight: 700; }
.wbar { height: 48px; background: var(--line); border-radius: 6px; position: relative; overflow: hidden; }
.wbar i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--muted); }
.wbar i.ok { background: var(--ok); } .wbar i.gold { background: var(--star); }
.w14 .wd { font-size: 10px; }
.combo { font-weight: 800; color: var(--hint); font-size: 15px; }
