/* Palette "Шалфей": #314C3B #4C6B55 #6D8C73 #92AA97 #BDC9B8 #E2DED2 #F7F3EA.
   --accent fills the main buttons, --ink is the accent for text and icons, --bar draws progress.
   Light or dark follows the user's choice, the system or Telegram. */
:root {
  --page: #F7F3EA;
  --card: #FFFDF8;
  --text: #22342A;
  --hint: #66776A;
  --ink: #314C3B;
  --accent: #4C6B55;
  --accent-text: #F7F3EA;
  --bar: #6D8C73;
  --hero-a: #4C6B55;
  --hero-b: #6D8C73;
  --hero-text: #F7F3EA;
  --danger: #A9533F;
  --ok: #3F7A4E;
  --warn: #A8742A;
  --toast: #314C3B;
  --line: color-mix(in srgb, #92AA97 32%, transparent);
  --soft: color-mix(in srgb, #92AA97 18%, transparent);
  --shadow: 0 4px 18px rgba(49, 76, 59, .07);
  --tile-1: #BDC9B8; --tile-1-ink: #314C3B;
  --tile-2: #6D8C73; --tile-2-ink: #F7F3EA;
  --tile-3: #314C3B; --tile-3-ink: #E2DED2;
  --radius: 18px;
  --math: "Cambria Math", "STIX Two Math", "Latin Modern Math", "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #151C17; --card: #1F2A23; --text: #EFEBE0; --hint: #A0AFA3; --ink: #BDC9B8;
    --accent: #92AA97; --accent-text: #17201A; --bar: #92AA97; --hero-a: #4C6B55; --hero-b: #6D8C73; --hero-text: #F7F3EA;
    --danger: #E39A86; --ok: #A9C9A4; --warn: #E0B46A; --toast: #314C3B;
    --line: color-mix(in srgb, #92AA97 18%, transparent); --soft: color-mix(in srgb, #92AA97 13%, transparent);
    --shadow: 0 4px 18px rgba(0, 0, 0, .3);
    --tile-1: #4C6B55; --tile-1-ink: #E2DED2; --tile-2: #6D8C73; --tile-2-ink: #F7F3EA; --tile-3: #314C3B; --tile-3-ink: #BDC9B8;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #151C17; --card: #1F2A23; --text: #EFEBE0; --hint: #A0AFA3; --ink: #BDC9B8;
  --accent: #92AA97; --accent-text: #17201A; --bar: #92AA97; --hero-a: #4C6B55; --hero-b: #6D8C73; --hero-text: #F7F3EA;
  --danger: #E39A86; --ok: #A9C9A4; --warn: #E0B46A; --toast: #314C3B;
  --line: color-mix(in srgb, #92AA97 18%, transparent); --soft: color-mix(in srgb, #92AA97 13%, transparent);
  --shadow: 0 4px 18px rgba(0, 0, 0, .3);
  --tile-1: #4C6B55; --tile-1-ink: #E2DED2; --tile-2: #6D8C73; --tile-2-ink: #F7F3EA; --tile-3: #314C3B; --tile-3-ink: #BDC9B8;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 18px 16px calc(96px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.app.no-tabs { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

h1 { font-size: 26px; line-height: 1.2; margin: 6px 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 21px; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--hint); margin: 26px 4px 10px; font-weight: 600; }
p { margin: 0; }
.hint { color: var(--hint); font-size: 14px; }
.screen { animation: enter .22s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* segmented control */
.segment {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--card); border-radius: 14px; padding: 4px; gap: 4px; margin: 18px 0 4px;
}
.segment button {
  border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600;
  padding: 10px 0; border-radius: 10px; cursor: pointer; transition: background .15s, color .15s;
}
.segment button.on { background: var(--accent); color: var(--accent-text); }

/* lists */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 16px;
  border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--soft); }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub.math { font-family: var(--math); font-size: 15px; }
.chev { color: var(--hint); font-size: 20px; }
.badge {
  flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #fff;
}
.count { color: var(--hint); font-size: 14px; font-variant-numeric: tabular-nums; }

.hero-row {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; margin: 14px 0 0;
  border: 0; border-radius: var(--radius); cursor: pointer; font: inherit; text-align: left;
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b));
  color: var(--hero-text);
}
.hero-row .title { font-weight: 700; }
.hero-row .sub { opacity: .85; font-size: 14px; }
.hero-row .body { flex: 1; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 14px 18px; font: inherit; font-weight: 600;
  cursor: pointer; background: var(--soft); color: var(--ink); transition: transform .08s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ok { background: var(--accent); color: var(--accent-text); }
.btn.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; margin-top: 16px; }
.stack { display: grid; gap: 10px; margin-top: 16px; }

.back {
  border: 0; background: none; color: var(--ink); font: inherit; padding: 4px 0; margin-bottom: 6px; cursor: pointer;
}

/* mode cards */
.modes { display: grid; gap: 12px; margin-top: 18px; }
.mode {
  display: flex; gap: 16px; align-items: center; padding: 18px; border-radius: var(--radius);
  background: var(--card); border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.mode:disabled { opacity: .5; cursor: default; }
.mode .icon { font-size: 30px; width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: var(--soft); flex: none; }
.mode .title { font-weight: 700; font-size: 17px; }

/* quiz */
.quiz-top { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; }
.progress { flex: 1; height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--bar); border-radius: 8px; transition: width .3s ease; }
.quiz-top .count { min-width: 44px; text-align: right; }
.close { border: 0; background: var(--card); color: var(--hint); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; cursor: pointer; }

.qcard { background: var(--card); border-radius: 22px; padding: 26px 20px; text-align: center; box-shadow: var(--shadow); }
.qlabel { color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .07em; margin-bottom: 10px; }
.variant {
  display: inline-block; margin-top: 10px; padding: 5px 12px; border-radius: 999px;
  background: var(--soft); color: var(--ink); font-size: 14px; font-weight: 600;
}
.formula {
  font-family: var(--math); font-size: 30px; line-height: 1.3; margin: 18px 0 6px; word-break: break-word;
}
.reveal { animation: pop .28s cubic-bezier(.2,.9,.3,1.3) both; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }

.legend { margin: 14px 0 0; padding: 0; list-style: none; text-align: left; }
.legend li { padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; }
.legend b { font-family: var(--math); font-size: 17px; font-weight: 600; margin-right: 4px; }
.note { margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--soft); font-size: 14px; text-align: left; }

.options { display: grid; gap: 10px; margin-top: 16px; }
.opt {
  border: 2px solid transparent; background: var(--card); color: var(--text); border-radius: 16px;
  padding: 16px; font-family: var(--math); font-size: 20px; cursor: pointer; transition: border-color .15s, background .15s, transform .08s;
}
.opt:active { transform: scale(.98); }
.opt:disabled { cursor: default; transform: none; }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--card)); }
.opt.wrong { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--card)); }
.opt.dim { opacity: .5; }

.verdict { font-weight: 700; font-size: 18px; margin-top: 18px; text-align: center; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--danger); }

/* result */
.result { text-align: center; padding-top: 30px; }
.ring { width: 170px; height: 170px; margin: 0 auto 18px; }
.ring circle { fill: none; stroke-width: 14; }
.ring .track { stroke: var(--line); }
.ring .bar { stroke: var(--bar); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset .8s ease; }
.ring text { fill: var(--text); font-size: 34px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }

/* stats */
.stat { padding: 14px 16px; }
.stat + .stat { border-top: 1px solid var(--line); }
.stat .top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.stat .pct { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 8px; }

/* forms */
.field { display: grid; gap: 6px; margin-top: 14px; }
.field span { font-size: 14px; color: var(--hint); font-weight: 600; }
input, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; outline: none;
}
input:focus, textarea:focus { border-color: var(--bar); }
textarea { min-height: 110px; resize: vertical; }
input.math { font-family: var(--math); font-size: 20px; }
.symbols { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.symbols button {
  min-width: 38px; height: 36px; border: 0; border-radius: 10px; background: var(--card); color: var(--text);
  font-family: var(--math); font-size: 17px; cursor: pointer;
}
.symbols button:active { background: var(--soft); }
.preview { font-family: var(--math); font-size: 24px; text-align: center; padding: 14px; background: var(--card); border-radius: 14px; min-height: 60px; }

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.empty { text-align: center; padding: 40px 20px; color: var(--hint); }
.empty .big { font-size: 44px; margin-bottom: 10px; }

/* panel: requests and statuses */
.req { padding: 14px 16px; }
.req + .req { border-top: 1px solid var(--line); }
.req .title { font-weight: 600; }
.req .sub { color: var(--hint); font-size: 14px; }
.req .actions { margin-top: 10px; }
.pill { display: inline-block; margin-top: 10px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.pill.approved { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.pending { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.rejected { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; max-width: 180px; border: 0; background: none; color: var(--hint); font: inherit; font-size: 12px;
  display: grid; gap: 2px; justify-items: center; padding: 6px 0; cursor: pointer; font-weight: 600;
}
.tabs button .i { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs button.on { color: var(--ink); }
.tabs button.on .i { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--toast); color: #F7F3EA; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: enter .2s ease both; z-index: 10;
}

.loader { width: 34px; height: 34px; margin: 120px auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* --- v2 additions --- */
.opt.text { font-family: inherit; font-size: 17px; text-align: left; }
.qtext { font-size: 19px; font-weight: 600; line-height: 1.35; }
.qexpr { font-family: var(--math); font-size: 28px; margin-top: 14px; word-break: break-word; }
.steps { color: var(--hint); font-size: 13px; font-weight: 600; margin-bottom: 4px; }

.choice { display: grid; gap: 10px; margin-top: 16px; }
.choice button {
  display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: 16px; border: 2px solid transparent;
  background: var(--card); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.choice button.on { border-color: var(--bar); background: var(--soft); }
.choice .icon { font-size: 26px; }
.choice .title { font-weight: 700; }

.grades { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 16px; }
.grades button {
  padding: 18px 0; border-radius: 14px; border: 2px solid transparent; background: var(--card); color: inherit;
  font: inherit; font-size: 20px; font-weight: 700; cursor: pointer;
}
.grades button.on { border-color: var(--bar); background: var(--soft); color: var(--ink); }

.check { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; cursor: pointer; }
.check + .check { border-top: 1px solid var(--line); }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
.check .body { flex: 1; min-width: 0; }
.check .sub { color: var(--hint); font-size: 13px; }
.check .sub.math { font-family: var(--math); font-size: 15px; }
.group-title { font-size: 13px; color: var(--hint); font-weight: 600; margin: 18px 4px 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chips button {
  padding: 8px 14px; border-radius: 999px; border: 0; background: var(--card); color: var(--text);
  font: inherit; font-size: 15px; cursor: pointer;
}
.chips button.on { background: var(--accent); color: var(--accent-text); }

select {
  width: 100%; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit;
}
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.cardbox { background: var(--card); border-radius: 22px; padding: 22px 20px; box-shadow: var(--shadow); }
.cardbox .crumb { color: var(--hint); font-size: 13px; }
.cardbox h2 { margin-top: 6px; }
.cardbox .formula { text-align: center; }
.cardbox img { width: 100%; border-radius: 14px; margin-top: 14px; }
.comps { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 15px; }
.comps td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
.comps td:first-child { font-family: var(--math); font-size: 18px; font-weight: 600; white-space: nowrap; }
.comps td:last-child { color: var(--hint); white-space: nowrap; text-align: right; }
.cardbox .note { white-space: pre-line; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.tile { background: var(--card); border-radius: 16px; padding: 12px; text-align: center; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--hint); font-size: 12px; }

.track { background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.track .title { font-weight: 700; font-size: 17px; }
.track .sub { color: var(--hint); font-size: 14px; margin-top: 2px; }
.track .stack { margin-top: 12px; }

.days { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding: 12px 12px 0; }
.days div { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; }
.days i { display: block; border-radius: 4px 4px 0 0; background: var(--bar); min-height: 2px; }
.days i.bad { background: color-mix(in srgb, var(--danger) 60%, transparent); border-radius: 0; }
.days-labels { display: flex; gap: 4px; padding: 4px 12px 12px; color: var(--hint); font-size: 10px; }
.days-labels span { flex: 1; text-align: center; }

.codebox { text-align: center; padding: 22px; background: var(--card); border-radius: 22px; margin-top: 16px; }
.codebox .code { font-family: ui-monospace, Consolas, monospace; font-size: 36px; font-weight: 700; letter-spacing: .2em; margin: 8px 0; }
.codebox .link { word-break: break-all; font-size: 14px; color: var(--hint); }

.warn { color: var(--warn); }
.okc { color: var(--ok); }
.badc { color: var(--danger); }
.comp-row { display: grid; grid-template-columns: 80px 1fr 80px 34px; gap: 6px; margin-top: 6px; }
.comp-row input { padding: 10px; }
.comp-row button { border: 0; background: none; color: var(--danger); font-size: 20px; cursor: pointer; }
.search { margin-top: 14px; }
.preview-q { padding: 12px 16px; }
.preview-q + .preview-q { border-top: 1px solid var(--line); }
.preview-q ol { margin: 6px 0 0; padding-left: 20px; }
.preview-q li.right { color: var(--ok); font-weight: 600; }
.login { text-align: center; padding-top: 60px; }
.login .big { font-size: 56px; }
sub { font-size: .62em; vertical-align: -.25em; line-height: 0; }

/* --- v2.1: home, streaks, animations --- */
.today { display: flex; gap: 14px; align-items: center; background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-top: 16px; }
.today .body { flex: 1; min-width: 0; }
.today .title { font-weight: 700; }
.today .sub { color: var(--hint); font-size: 14px; margin-bottom: 8px; }
.fire { font-size: 30px; display: grid; justify-items: center; line-height: 1; min-width: 48px; }
.fire b { font-size: 16px; margin-top: 2px; }
.fire.off { filter: grayscale(1); opacity: .5; }
.hero-row.big { padding: 20px 18px; box-shadow: 0 10px 26px color-mix(in srgb, var(--hero-b) 30%, transparent); }
.hero-row.big .icon { font-size: 32px; width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; background: rgba(255,255,255,.16); flex: none; }
.hero-row.big .title { font-size: 18px; }
.meter { display: flex; height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; margin-top: 12px; }
.meter i { display: block; height: 100%; transition: width .5s ease; }
.m-ok { background: var(--ok); }
.m-act { background: var(--bar); }
.legend-row { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; color: var(--hint); }
.legend-row i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; background: var(--line); }
.legend-row i.m-ok { background: var(--ok); }
.legend-row i.m-act { background: var(--bar); }
.mini-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mini-actions .btn { flex: 1 1 auto; }
.quiz-stats { display: flex; gap: 8px; margin: -8px 0 12px; min-height: 26px; }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--card); font-size: 14px; font-weight: 700; }
.fire-chip { background: color-mix(in srgb, var(--warn) 16%, var(--card)); color: var(--warn); animation: pop .3s ease both; }
.qlabel { font-weight: 600; }
.opt.pop { animation: pop .35s cubic-bezier(.2,.9,.3,1.4) both; }
.opt.shake { animation: shake .4s ease both; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.burst { position: relative; height: 0; }
.burst span { position: absolute; left: 50%; top: 80px; font-size: 26px; opacity: 0; animation: fly 1.3s ease-out forwards; }
@keyframes fly { 0% { opacity: 1; transform: translate(-50%, 0) scale(.4); } 100% { opacity: 0; transform: translate(calc(-50% + var(--x)), var(--y)) scale(1.2) rotate(30deg); } }

/* --- v3: tablet and desktop --- */
/* Tablet: wider column, two-column grids for cards and answer options. */
@media (min-width: 700px) {
  .app { max-width: 780px; padding: 28px 28px calc(110px + env(safe-area-inset-bottom)); }
  h1 { font-size: 30px; }
  .modes, .choice, .options { grid-template-columns: 1fr 1fr; }
  .options .opt.text { grid-column: 1 / -1; }
  .qcard, .cardbox { padding: 34px 32px; }
  .formula { font-size: 34px; }
  .qexpr { font-size: 32px; }
  .tabs button { max-width: 200px; font-size: 13px; }
  .row:hover, .mode:hover, .choice button:hover, .opt:not(:disabled):hover { background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
}

/* Desktop: tabs become a sidebar, content gets a wide centered column. */
@media (min-width: 1000px) {
  .tabs {
    top: 0; right: auto; width: 230px; flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 28px 14px; border-top: 0; border-right: 1px solid var(--line);
  }
  .tabs button {
    flex: none; max-width: none; display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 12px; font-size: 15px; text-align: left;
  }
  .tabs button:hover { background: var(--soft); }
  .tabs button.on { background: var(--soft); }
  .app { max-width: 1000px; padding: 40px 48px 48px; }
  .app:not(.no-tabs) { margin-left: 230px; max-width: none; }
  .app:not(.no-tabs) > .screen { max-width: 980px; margin: 0 auto; }
  h1 { font-size: 34px; }
  .modes { grid-template-columns: repeat(3, 1fr); }
  .mode { flex-direction: column; align-items: flex-start; }
  /* Single-card screens (cards, quiz, result) read better in a narrower column. */
  .app > .screen:has(.qcard, .cardbox, .result) { max-width: 760px; }
  .app > .screen:has(> .empty), .app > .screen:has(.login) { max-width: 560px; }
  .toast { bottom: 28px; }
  .days { height: 140px; }
}

/* v4: sign-in with login and password */
.login .logo {
  width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 22px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: var(--hero-text);
  box-shadow: var(--shadow);
}
.login .segment { max-width: 320px; margin: 22px auto 14px; }
.form { padding: 4px 16px 16px; text-align: left; }
.form .field:first-child { margin-top: 12px; }
.form .hint { margin-top: 10px; font-size: 13px; }
.form .btn { margin-top: 16px; }
.or { display: flex; align-items: center; gap: 12px; color: var(--hint); font-size: 13px; margin: 18px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ok-mark { color: var(--ok); font-weight: 700; }

/* v5: line icons instead of emoji, atom logo, theme switch */
.ico { width: 1.2em; height: 1.2em; vertical-align: -0.22em; flex: none; }
.ico.solid { fill: currentColor; stroke: none; }
.tabs button .i { filter: none; opacity: .75; }
.tabs button .i .ico { width: 24px; height: 24px; vertical-align: 0; }
.tabs button.on .i { opacity: 1; }
.choice .icon, .mode .icon { color: var(--ink); }
.choice .icon .ico { width: 28px; height: 28px; }
.mode .icon .ico { width: 30px; height: 30px; }
.hero-row.big .icon .ico { width: 30px; height: 30px; }
.empty .big { color: var(--hint); }
.empty .big .ico { width: 48px; height: 48px; stroke-width: 1.5; }
.fire { color: var(--warn); }
.fire .ico { width: 30px; height: 30px; fill: color-mix(in srgb, var(--warn) 22%, transparent); }
.close { display: grid; place-items: center; }
.close .ico { width: 18px; height: 18px; vertical-align: 0; }
.note .ico { color: var(--hint); }
.burst span .ico { width: 26px; height: 26px; }
.burst .c0 { color: #92AA97; } .burst .c1 { color: var(--warn); } .burst .c2 { color: #4C6B55; } .burst .c3 { color: #BDC9B8; }
.result h2 .ico { color: var(--ink); }
.theme-seg { margin-top: 0; }
.theme-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.theme-seg .ico { width: 18px; height: 18px; vertical-align: 0; }
.theme-btn {
  border: 0; background: var(--card); color: var(--hint); width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex: none; box-shadow: var(--shadow);
}
.theme-btn:hover { color: var(--text); }
.theme-btn .ico { width: 20px; height: 20px; vertical-align: 0; }
.login { position: relative; }
.login > .theme-btn { position: absolute; top: 12px; right: 0; }
.login .logo .ico { width: 46px; height: 46px; stroke-width: 1.5; vertical-align: 0; }
.brand { display: none; }
.side-foot { display: none; }
@media (min-width: 1000px) {
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 12px 18px; }
  .brand > .ico { width: 28px; height: 28px; color: var(--ink); vertical-align: 0; }
  .tabs .bar-only { display: none; }
  .side-foot {
    display: flex; align-items: center; gap: 8px; margin-top: auto;
    padding-top: 12px; border-top: 1px solid var(--line);
  }
  .side-foot [data-tab] { flex: 1; min-width: 0; }
  .tabs .side-foot .theme-btn {
    flex: none; width: 42px; height: 42px; padding: 0; border-radius: 12px; display: grid; place-items: center;
    background: var(--soft); box-shadow: none; font-size: inherit;
  }
}

/* v6: settings in groups, lime accents */
.me-card {
  display: flex; align-items: center; gap: 14px; margin-top: 14px; padding: 16px;
  border-radius: var(--radius); background: linear-gradient(135deg, var(--hero-a), var(--hero-b)); color: var(--hero-text);
}
.me-card .avatar {
  width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: #F7F3EA; color: #314C3B; font-weight: 800; font-size: 20px; letter-spacing: .02em;
}
.me-card .name { font-weight: 800; font-size: 19px; }
.me-card .sub { font-size: 14px; opacity: .8; }
.notice {
  display: flex; gap: 10px; margin-top: 12px; padding: 12px 14px; border-radius: 14px; font-size: 14px;
  background: color-mix(in srgb, var(--warn) 12%, var(--card)); color: var(--text);
}
.notice .ico { color: var(--warn); margin-top: 1px; }
.settings h3 { margin-top: 28px; color: var(--ink); }
.set-row { gap: 12px; padding: 12px 14px; }
.set-row .lead { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.set-row .lead .ico { width: 20px; height: 20px; vertical-align: 0; }
.lead.lime { background: var(--tile-1); color: var(--tile-1-ink); }
.lead.olive { background: var(--tile-2); color: var(--tile-2-ink); }
.lead.dark { background: var(--tile-3); color: var(--tile-3-ink); }
.set-row .value { color: var(--hint); font-size: 14px; text-align: right; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-row .sub { white-space: normal; }
.ok-mark { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.theme-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 14px 14px 62px; }
.theme-pick button {
  display: grid; justify-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: transparent; color: var(--hint); font: inherit; font-size: 13px; font-weight: 600;
}
.theme-pick button .ico { width: 22px; height: 22px; vertical-align: 0; }
.theme-pick button.on { border-color: var(--bar); background: var(--soft); color: var(--text); }
.set-row + .theme-pick { border-top: 0; }
.theme-pick + .set-row { border-top: 1px solid var(--line); }
.switch { position: relative; width: 46px; height: 28px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 14px; background: var(--line); transition: background .2s; pointer-events: none; }
.switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch input:checked + i { background: var(--bar); }
.switch input:checked + i::after { transform: translateX(18px); }
.logout {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; margin-top: 28px; padding: 14px;
  border: 1.5px solid color-mix(in srgb, var(--danger) 35%, transparent); border-radius: 14px;
  background: transparent; color: var(--danger); font: inherit; font-weight: 600; cursor: pointer;
}
.form > .btn:last-child { margin-top: 18px; }
@media (min-width: 1000px) {
  .app > .screen.settings { max-width: 680px; }
}

/* v7: fixed meaning of colors in statistics, admin view switch */
:root { --good: #4F8A5B; --bad: #C8664F; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --good: #86B98E; --bad: #DB846E; } }
:root[data-theme="dark"] { --good: #86B98E; --bad: #DB846E; }
.tile b { color: var(--text); }
.tile span { display: inline-flex; align-items: center; gap: 5px; }

.tile.good { --tone: var(--good); }
.tile.bad { --tone: var(--bad); }
.tile span i { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); }
.bar.split { display: flex; gap: 2px; background: transparent; }
.bar.split i { border-radius: 0; }
.bar.split i:first-child { border-radius: 8px 0 0 8px; }
.bar.split i:last-child { border-radius: 0 8px 8px 0; }
.bar.split i[style="width:0%"] { display: none; }
.bar.split i[style="width:100%"] { border-radius: 8px; }
.bar i.good, .days i.good, .legend i.good, .dot.good { background: var(--good); }
.bar i.bad, .days i.bad, .legend i.bad, .dot.bad { background: var(--bad); }
.total-bar { margin-top: 10px; padding: 14px 16px; }
.total-bar .hint { margin-top: 8px; font-size: 13px; }
.days { border-bottom: 1px solid var(--line); margin: 0 12px; padding: 12px 0 0; }
.days i { min-height: 0; border-radius: 0; }
.days div > i:first-child { border-radius: 4px 4px 0 0; }
.days i.bad { border-radius: 4px 4px 0 0; }
.days i.bad + i.good { border-radius: 0; }
.legend { display: flex; gap: 16px; padding: 0 16px 12px; font-size: 13px; color: var(--hint); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.count .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.view-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 10px; padding: 4px;
  border-radius: 14px; background: var(--card); box-shadow: var(--shadow);
}
.view-switch button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 6px; border: 0; border-radius: 10px;
  background: transparent; color: var(--hint); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
}
.view-switch button.on { background: var(--accent); color: var(--accent-text); }
.view-switch .ico { width: 18px; height: 18px; vertical-align: 0; }

/* v8: logo and motion */
.atom .nucleus { transform-origin: 12px 12px; animation: nucleus 2.4s ease-in-out infinite; }
@keyframes nucleus { 50% { transform: scale(1.25); } }
.login .logo .atom { width: 50px; height: 50px; }
.rise { animation: rise .42s cubic-bezier(.2,.8,.2,1) both; animation-delay: calc(var(--i, 0) * 45ms); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.days > div.rise { animation-name: grow-up; transform-origin: bottom; animation-delay: calc(var(--i, 0) * 30ms + 120ms); }
@keyframes grow-up { from { transform: scaleY(0); } to { transform: none; } }
.bar i, .progress i { animation: grow-x .8s cubic-bezier(.2,.8,.2,1) both .15s; transform-origin: left; }
@keyframes grow-x { from { transform: scaleX(0); } to { transform: none; } }
.hero-row { position: relative; overflow: hidden; transition: transform .15s, box-shadow .2s; }
.hero-row::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.22) 50%, transparent 65%);
  transform: translateX(-100%); animation: sheen 1.4s ease .5s 1 both;
}
@keyframes sheen { to { transform: translateX(100%); } }
.hero-row:hover { transform: translateY(-2px); }
.hero-row .icon .ico { transition: transform .25s; }
.hero-row:hover .icon .ico { transform: scale(1.12); }
.fire:not(.off) .ico { transform-origin: 50% 90%; animation: flicker 1.8s ease-in-out infinite; }
@keyframes flicker { 0%, 100% { transform: scale(1) rotate(0); } 30% { transform: scale(1.06, .96) rotate(-3deg); } 60% { transform: scale(.97, 1.05) rotate(2deg); } }
.btn, .row, .tile, .theme-pick button, .view-switch button, .tabs button { transition: background-color .2s, color .2s, transform .1s; }
.theme-fade, .theme-fade body, .theme-fade .list, .theme-fade .tile, .theme-fade .tabs, .theme-fade .btn, .theme-fade .me-card {
  transition: background-color .4s ease, color .4s ease, border-color .4s ease !important;
}
.tabs button .i .ico { transition: transform .2s; }
.tabs button:hover .i .ico { transform: translateY(-1px) scale(1.08); }
@media (prefers-reduced-motion: reduce) { .hero-row::after { display: none; } }

/* v9: a split bar is one bar: it opens from the left as a whole; static rows don't react to the pointer */
.bar.split i { animation: none; }
.bar.split { animation: reveal-x .9s cubic-bezier(.2,.8,.2,1) both .15s; }
@keyframes reveal-x { from { clip-path: inset(0 100% 0 0 round 8px); } to { clip-path: inset(0 0 0 0 round 8px); } }
.list div.row:hover, .list div.row:active { background: transparent; cursor: default; }

/* v10: codifier */
.tabs .short { display: none; }
@media (max-width: 999px) { .tabs .long { display: none; } .tabs .short { display: inline; } }
.kf-search {
  display: flex; align-items: center; gap: 10px; margin-top: 16px; padding: 0 14px; border-radius: 14px;
  background: var(--card); border: 1.5px solid var(--line);
}
.kf-search:focus-within { border-color: var(--bar); }
.kf-search .ico { color: var(--hint); }
.kf-search input { border: 0; background: transparent; padding: 13px 0; box-shadow: none; outline: none; }
.kf-sec { margin-top: 26px; }
.kf-head { display: flex; align-items: center; gap: 12px; margin: 0 4px 10px; }
.kf-head h2 { font-size: 19px; }
.kf-num {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none;
  font-weight: 800; font-size: 17px;
}
.kf-num.tile-1 { background: var(--tile-1); color: var(--tile-1-ink); }
.kf-num.tile-2 { background: var(--tile-2); color: var(--tile-2-ink); }
.kf-num.tile-3 { background: var(--tile-3); color: var(--tile-3-ink); }
.kf-num.tile-4 { background: var(--accent); color: var(--accent-text); }
.kf-topic + .kf-topic { border-top: 1px solid var(--line); }
.kf-topic .row { gap: 12px; }
.kf-tcode { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 30px; }
.kf-topic .value { color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.kf-topic .chev { transition: transform .2s; }
.kf-topic.open .chev { transform: rotate(90deg); }
.kf-items { padding: 2px 12px 12px; animation: rise .3s ease both; }
.kf-item {
  display: flex; gap: 12px; padding: 12px; border-radius: 14px; background: color-mix(in srgb, var(--soft) 60%, transparent);
  transition: background-color .2s, opacity .2s;
}
.kf-item + .kf-item { margin-top: 8px; }
.kf-item .body { flex: 1; min-width: 0; }
.kf-text { font-size: 15px; line-height: 1.45; }
.kf-code { display: inline-block; margin-right: 8px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.kf-lvl {
  display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; vertical-align: 1px;
  background: var(--tile-2); color: var(--tile-2-ink);
}
.kf-formulas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.kf-f {
  font-family: var(--math); font-size: 17px; padding: 5px 10px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); white-space: nowrap; max-width: 100%; overflow-x: auto;
}
.kf-f sup, .kf-f sub { font-size: .65em; }
.nuc { display: inline-flex; flex-direction: column; vertical-align: middle; line-height: 1; margin-right: 1px; text-align: right; }
.nuc sup, .nuc sub { position: static; font-size: .6em; }
.kf-source { margin: 22px 4px 0; font-size: 12px; }
@media (min-width: 1000px) { .app > .screen.kodif { max-width: 860px; } }

/* v11: install help */
.install-steps { margin-top: 18px; }
.install-steps .stat { line-height: 1.5; }
.vec { position: relative; display: inline-block; }
.vec::after {
  content: ""; position: absolute; left: 8%; right: -4%; top: -.12em; height: .32em;
  background: no-repeat center / 100% 100% url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 6'%3E%3Cpath d='M0 3h18M15 .5 19 3l-4 2.5' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .vec::after { filter: invert(1) brightness(.95); }
/* word indices in codifier formulas: small, in the text font so Cyrillic reads well */
.kf-f sub.ix { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; font-size: .58em; margin-left: 1px; }

/* v12: home in clear blocks */
.home h3 { margin-top: 26px; }
.home .hero-row.big { margin-top: 0; }
.day-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.day-tiles .tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 14px 10px; }
.day-tiles .tile b { font-size: 24px; line-height: 1.1; }
.day-tiles .tile b small { font-size: 14px; color: var(--hint); font-weight: 600; }
.day-tiles .tile span { text-align: center; line-height: 1.25; }
.day-tiles .tile .progress { width: 100%; margin-top: 8px; }
.day-tiles .fire { min-width: 0; font-size: inherit; display: block; }
.day-tiles .fire .ico { width: 24px; height: 24px; }
.day-tiles .day-streak.off .fire { filter: grayscale(1); opacity: .5; }
.day-tiles .tile.due b { color: var(--warn); }
.program-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 16px 16px 10px; text-align: center; }
.program-stats b { display: block; font-size: 22px; }
.program-stats span { display: inline-flex; align-items: center; gap: 6px; color: var(--hint); font-size: 13px; }
.program-stats .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.program-stats .dot.learn { background: var(--bar); }
.program .meter { margin: 0 16px; }
.program .m-ok { background: var(--good); }
.program-note { padding: 10px 16px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.program .set-row + .set-row { border-top: 1px solid var(--line); }
@media (max-width: 420px) {
  .day-tiles { gap: 8px; }
  .day-tiles .tile { padding: 12px 6px; }
  .day-tiles .tile span { font-size: 11px; }
}

/* v13: bright accent colors for icons */
:root {
  --c-blue: #3B82F6; --c-orange: #F97316; --c-violet: #8B5CF6; --c-pink: #EC4899; --c-teal: #14B8A6;
  --c-amber: #F59E0B; --c-green: #22C55E; --c-indigo: #6366F1; --c-rose: #F43F5E; --c-sky: #0EA5E9;
}
.lead[class*="c-"], .kf-num[class*="c-"] { color: #fff; box-shadow: 0 3px 10px -3px var(--tile-c); background: linear-gradient(140deg, color-mix(in srgb, var(--tile-c) 82%, #fff), var(--tile-c)); }
.c-blue { --tile-c: var(--c-blue); } .c-orange { --tile-c: var(--c-orange); } .c-violet { --tile-c: var(--c-violet); }
.c-pink { --tile-c: var(--c-pink); } .c-teal { --tile-c: var(--c-teal); } .c-amber { --tile-c: var(--c-amber); }
.c-green { --tile-c: var(--c-green); } .c-indigo { --tile-c: var(--c-indigo); } .c-rose { --tile-c: var(--c-rose); }
.c-sky { --tile-c: var(--c-sky); }
.set-row .lead .ico { stroke-width: 2; }
/* Menu: every section has its own icon color */
.tabs button .i { opacity: 1; }
.tabs [data-tab="home"] .i { color: var(--c-green); }
.tabs [data-tab="stats"] .i { color: var(--c-blue); }
.tabs [data-tab="students"] .i { color: var(--c-teal); }
.tabs [data-tab="content"] .i { color: var(--c-violet); }
.tabs [data-tab="kodif"] .i { color: var(--c-orange); }
.tabs [data-tab="profile"] .i { color: var(--c-indigo); }
.tabs button:not(.on) .i { opacity: .8; }

/* v14: avatar and name editing */
.me-card .avatar { overflow: hidden; }
.me-card .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.me-card .body { flex: 1; min-width: 0; }
.me-edit {
  display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 8px 12px; border: 0; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,.18); color: inherit; font: inherit; font-size: 14px; font-weight: 600;
}
.me-edit:hover { background: rgba(255,255,255,.28); }
.me-edit .ico { width: 16px; height: 16px; vertical-align: 0; }
@media (max-width: 420px) { .me-edit span { display: none; } .me-edit { padding: 9px; } }

/* v15: student page, avatars in lists, topic training */
.avatar.sm {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; overflow: hidden;
  background: var(--tile-1); color: var(--tile-1-ink); font-weight: 800; font-size: 14px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.student-page .me-card { margin-top: 6px; }
.trainings .training { padding: 14px 16px; }
.trainings .training + .training { border-top: 1px solid var(--line); }
.training .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.training .score { font-size: 15px; color: var(--hint); white-space: nowrap; }
.training .score b { font-size: 20px; color: var(--text); }
.mistakes { margin-top: 10px; }
.mistakes summary { cursor: pointer; font-size: 14px; color: var(--text); list-style: none; display: flex; gap: 6px; align-items: flex-start; }
.mistakes summary::-webkit-details-marker { display: none; }
.mistakes summary .ico { color: var(--bad); flex: none; margin-top: 1px; }
.mistakes[open] summary { margin-bottom: 8px; }
.mistake { padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--bad) 8%, transparent); font-size: 14px; }
.mistake + .mistake { margin-top: 6px; }
.mistake .q { margin-bottom: 2px; }
.mistake .chosen { color: var(--bad); font-weight: 600; }
.all-right { margin-top: 10px; font-size: 14px; color: var(--good); display: flex; align-items: center; gap: 6px; }
.topic-pick { gap: 12px; }
.topic-pick:disabled { opacity: .5; cursor: default; }
.topic-pick .pick {
  width: 24px; height: 24px; border-radius: 7px; border: 1.5px solid var(--line); flex: none; display: grid; place-items: center;
  color: transparent; transition: background-color .15s, border-color .15s;
}
.topic-pick .pick .ico { width: 15px; height: 15px; stroke-width: 2.4; vertical-align: 0; }
.topic-pick.on .pick { background: var(--good); border-color: var(--good); color: #fff; }
.sizes { margin-top: 0; }
.sticky-go { position: sticky; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 2; }
.no-tabs .sticky-go { bottom: 12px; }
@media (min-width: 1000px) { .sticky-go { bottom: 16px; } }
