/* Дизайн-система «+90%» — описание в DESIGN.md. В правилах ниже только токены. */

:root {
  --paper: #f6f3ec;
  --sheet: #fffdf8;
  --sheet-2: #eee9de;
  --ink: #1f1d18;
  --ink-2: #5f5a4e;
  --rule: #ddd6c7;
  --rule-strong: #b9b09d;
  --primary: #1d5a47;
  --primary-hover: #154536;
  --primary-ink: #fffdf8;
  --marker: #f5dd5c;
  --ok: #2e7a4c;
  --ok-bg: #e4f0e6;
  --warn: #a8640a;
  --warn-bg: #f8ecd6;
  --bad: #b3261e;
  --bad-bg: #f8e3df;

  --font-serif: Literata, Georgia, "Times New Roman", serif;
  --font-sans: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  --fs-display: 3.5rem;
  --fs-h1: 2.25rem;
  --fs-h2: 1.5rem;
  --fs-h3: 1.125rem;
  --fs-body: 1.0625rem;
  --fs-small: .875rem;
  --fs-label: .75rem;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --content: 1200px;
  --reading: 920px;
  --measure: 68ch;
  --gutter: 24px;

  --r1: 3px;
  --r2: 6px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #191814; --sheet: #211f1a; --sheet-2: #2a2822;
    --ink: #ece7db; --ink-2: #a8a192; --rule: #38352d; --rule-strong: #4e4a40;
    --primary: #7cc3a5; --primary-hover: #95d3b8; --primary-ink: #10201a;
    --marker: #6b5a12;
    --ok: #77c795; --ok-bg: #1d2e22; --warn: #e0a64e; --warn-bg: #33281a; --bad: #f08a7e; --bad-bg: #3a201c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #191814; --sheet: #211f1a; --sheet-2: #2a2822;
  --ink: #ece7db; --ink-2: #a8a192; --rule: #38352d; --rule-strong: #4e4a40;
  --primary: #7cc3a5; --primary-hover: #95d3b8; --primary-ink: #10201a;
  --marker: #6b5a12;
  --ok: #77c795; --ok-bg: #1d2e22; --warn: #e0a64e; --warn-bg: #33281a; --bad: #f08a7e; --bad-bg: #3a201c;
  color-scheme: dark;
}

/* ---------- База ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--fs-body)/1.6 var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

h1, h2, h3 { margin: 0 0 var(--s3); }
h1 { font: 600 var(--fs-h1)/1.15 var(--font-serif); letter-spacing: -.01em; }
h2 { font: 600 var(--fs-h2)/1.25 var(--font-serif); }
h3 { font: 600 var(--fs-h3)/1.35 var(--font-sans); }
p { margin: 0 0 var(--s3); }

.muted { color: var(--ink-2); }
.small { font-size: var(--fs-small); line-height: 1.45; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.label {
  font: 500 var(--fs-label)/1.3 var(--font-mono);
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2);
}
.lead { font-size: 1.125rem; color: var(--ink-2); max-width: var(--measure); }
.hl { background: linear-gradient(transparent 55%, var(--marker) 55%); padding: 0 2px; }
mark { background: linear-gradient(transparent 50%, var(--marker) 50%); color: inherit; padding: 0 1px; }

.container { width: 100%; max-width: calc(var(--content) + 2 * var(--gutter)); margin: 0 auto; padding: 0 var(--gutter); }
main.container { flex: 1; padding-top: var(--s6); padding-bottom: var(--s8); }
.footer { padding-bottom: var(--s5); font-size: var(--fs-small); }
.footer .inner { border-top: 1px solid var(--rule); padding-top: var(--s4); }

/* ---------- Шапка ---------- */
.topbar { border-bottom: 1px solid var(--rule); background: var(--paper); }
.topbar .container { display: flex; align-items: center; gap: var(--s5); min-height: 60px; }
.brand { font: 600 1.25rem/1 var(--font-serif); color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand small { font: 500 var(--fs-label)/1 var(--font-mono); color: var(--ink-2); letter-spacing: .06em; text-transform: uppercase; margin-left: var(--s2); }
.topnav { display: flex; gap: var(--s5); flex: 1; overflow-x: auto; align-self: stretch; }
.topnav a {
  color: var(--ink-2); text-decoration: none; white-space: nowrap; font-size: .9375rem;
  display: flex; align-items: center; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.topnav a:hover { color: var(--ink); }
.topnav a.active { color: var(--ink); border-bottom-color: var(--primary); font-weight: 500; }
.theme-btn {
  background: none; border: 1px solid var(--rule-strong); border-radius: var(--r1); color: var(--ink-2);
  font: 500 var(--fs-label)/1 var(--font-mono); text-transform: uppercase; letter-spacing: .06em;
  padding: var(--s2) var(--s3); cursor: pointer; min-height: 32px;
}
.theme-btn:hover { color: var(--ink); border-color: var(--ink); }

/* ---------- Заголовок страницы ---------- */
.page-head { margin-bottom: var(--s6); }
.page-head .label { display: block; margin-bottom: var(--s2); }
.page-head h1 { margin-bottom: var(--s2); }
.breadcrumbs { font-size: var(--fs-small); color: var(--ink-2); margin-bottom: var(--s4); }
.breadcrumbs a { color: var(--ink-2); }
.meta { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--fs-small); color: var(--ink-2); }

.section { margin-top: var(--s7); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3);
  border-bottom: 1px solid var(--ink); padding-bottom: var(--s2); margin-bottom: 0;
}
.section-head h2 { margin: 0; }
.section-head .aside { font-size: var(--fs-small); color: var(--ink-2); }

/* ---------- Сводка (главная) ---------- */
.summary { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.summary > * { padding: var(--s5) var(--s5) var(--s5) 0; color: inherit; text-decoration: none; display: block; }
.summary > * + * { border-left: 1px solid var(--rule); padding-left: var(--s5); }
a.summary-cell:hover .big { color: var(--primary); }
.big { font: 600 var(--fs-display)/1 var(--font-serif); letter-spacing: -.02em; margin: var(--s2) 0; font-variant-numeric: tabular-nums; }
.big .unit { font-size: 1.25rem; font-weight: 400; color: var(--ink-2); letter-spacing: 0; margin-left: var(--s1); }

/* ---------- Таблицы и линованные списки ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.table th {
  font: 500 var(--fs-label)/1.3 var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2);
  text-align: left; padding: var(--s3) var(--s3) var(--s2) 0; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.table td { padding: var(--s4) var(--s3) var(--s4) 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table tr.past td { color: var(--ink-2); }
.table .num { text-align: right; padding-right: 0; }
.subject-name { display: flex; gap: var(--s3); align-items: flex-start; font-weight: 600; }
.subject-name a { color: var(--ink); text-decoration: none; }
.subject-name a:hover { color: var(--primary); text-decoration: underline; }
.swatch { flex: none; width: 4px; align-self: stretch; min-height: 1.4em; background: var(--subject, var(--rule-strong)); border-radius: 1px; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; align-items: flex-start; gap: var(--s4);
  padding: var(--s4) var(--s2); border-bottom: 1px solid var(--rule); color: inherit; text-decoration: none;
}
a.row:hover { background: var(--sheet); text-decoration: none; }
a.row:hover .row-title { color: var(--primary); }
.row > .grow { flex: 1; min-width: 0; }
.row-num { flex: none; width: 2.5em; font: 500 var(--fs-small)/1.6 var(--font-mono); color: var(--ink-2); }
.row-title { font-weight: 600; }
.row-sub { font-size: var(--fs-small); color: var(--ink-2); margin-top: 2px; }
.row-end { flex: none; text-align: right; font-size: var(--fs-small); color: var(--ink-2); }
.tick { font-family: var(--font-mono); color: var(--ok); font-weight: 600; }

/* ---------- Тег ---------- */
.tag {
  display: inline-block; font: 500 var(--fs-label)/1 var(--font-mono); text-transform: uppercase; letter-spacing: .06em;
  padding: 4px 6px; border: 1px solid var(--rule-strong); border-radius: var(--r1); color: var(--ink-2); white-space: nowrap;
  vertical-align: 2px;
}
.tag.ok { color: var(--ok); border-color: currentColor; }
.tag.warn { color: var(--warn); border-color: currentColor; }
.tag.bad { color: var(--bad); border-color: currentColor; }
.tag.primary { color: var(--primary); border-color: currentColor; }

/* ---------- Прогресс ---------- */
.progress-row { display: flex; align-items: center; gap: var(--s3); font: 500 var(--fs-small)/1 var(--font-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.progress { flex: 1; height: 4px; background: var(--sheet-2); border-radius: 2px; overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: var(--primary); transition: width .3s; }
.table .progress-row > span:last-child { min-width: 3.5em; text-align: right; }
.head-progress { max-width: 320px; margin-top: var(--s3); }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: var(--s2) var(--s4); border-radius: var(--r1);
  border: 1px solid var(--rule-strong); background: transparent; color: var(--ink);
  font: 500 .9375rem/1.2 var(--font-sans); cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.ok { border-color: var(--ok); color: var(--ok); }
.btn.ok.on, .btn.ok:hover { background: var(--ok-bg); }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.warn.on, .btn.warn:hover { background: var(--warn-bg); }
.btn.bad { border-color: var(--bad); color: var(--bad); }
.btn.bad.on, .btn.bad:hover { background: var(--bad-bg); }
.btn.quiet { border-color: transparent; color: var(--primary); padding-left: 0; padding-right: 0; text-decoration: underline; text-underline-offset: 3px; }
.btn.quiet:hover { text-decoration-thickness: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { min-height: 32px; padding: var(--s1) var(--s3); font-size: var(--fs-small); }
.btn.quiet.sm { padding-left: 0; padding-right: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s5); align-items: center; }

.tabs { display: flex; flex-wrap: wrap; gap: var(--s4); box-shadow: inset 0 -1px 0 var(--rule); margin-bottom: var(--s4); }
.tabs button {
  flex: none; white-space: nowrap;
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: var(--s2) 0; color: var(--ink-2); font: 500 .9375rem/1.4 var(--font-sans); cursor: pointer;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--primary); }
.tabs .count { font-family: var(--font-mono); font-size: var(--fs-label); color: var(--ink-2); margin-left: var(--s1); }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: flex-end; justify-content: space-between; margin-bottom: var(--s4); }
.toolbar .tabs { margin-bottom: 0; flex: 1; }

/* ---------- Лист ---------- */
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); padding: var(--s6); }
.sheet-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s4); margin-top: var(--s7); }
a.sheet { display: block; color: inherit; text-decoration: none; }
a.sheet:hover { border-color: var(--rule-strong); }
a.sheet:hover h3 { color: var(--primary); }
.sheet h3 { margin-bottom: var(--s2); }

/* ---------- Конспект ---------- */
.prose { max-width: var(--measure); overflow-wrap: break-word; }
.prose.sheet { max-width: none; }
.prose.sheet > * { max-width: var(--measure); }
/* Страницы для чтения (конспект, квиз) — узкая колонка, даже на широкой сетке */
#app > div:has(> article.prose), #app > div:has(> .quiz-head), #app > div:has(> .sheet.result) { max-width: var(--reading); }
.nowrap { white-space: nowrap; }
.prose > :first-child { margin-top: 0; }
.prose h1 { font-size: var(--fs-h1); }
.prose h2 { margin-top: var(--s6); }
.prose h3 { margin-top: var(--s5); }
.prose p, .prose ul, .prose ol { margin: 0 0 var(--s4); }
.prose li { margin-bottom: var(--s1); }
.prose img { max-width: 100%; border: 1px solid var(--rule); border-radius: var(--r2); }
.prose pre { background: var(--sheet-2); padding: var(--s3) var(--s4); border-radius: var(--r1); overflow-x: auto; font-size: .875rem; }
.prose code { font-family: var(--font-mono); background: var(--sheet-2); padding: 1px 5px; border-radius: var(--r1); font-size: .85em; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; margin-bottom: var(--s4); max-width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--rule); padding: var(--s2) var(--s4) var(--s2) 0; text-align: left; }
.prose th { font: 500 var(--fs-label)/1.3 var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.prose blockquote { margin: var(--s5) 0; padding: var(--s1) 0 var(--s1) var(--s4); border-left: 3px solid var(--marker); }
.prose blockquote p { margin: 0; }
/* position: relative — чтобы скрытая MathML формул подрезалась прокруткой и не расширяла страницу */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: var(--s1) 0; position: relative; }
.prose table { position: relative; }

.pager { display: flex; justify-content: space-between; gap: var(--s4); margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--rule); flex-wrap: wrap; }
.pager a { text-decoration: none; color: var(--ink); max-width: 48%; }
.pager a:hover .pager-title { color: var(--primary); text-decoration: underline; }
.pager .label { display: block; margin-bottom: var(--s1); }
.pager .next { text-align: right; margin-left: auto; }
.pager-title { font-weight: 600; }

/* ---------- Квиз ---------- */
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); margin-bottom: var(--s3); }
.quiz-progress { height: 2px; background: var(--rule); margin-bottom: var(--s5); }
.quiz-progress > span { display: block; height: 100%; background: var(--primary); }
.question { font-size: 1.1875rem; line-height: 1.5; margin-bottom: var(--s5); }
.question p { margin: 0 0 var(--s2); }
.options { display: flex; flex-direction: column; gap: var(--s2); }
.option {
  display: flex; gap: var(--s4); align-items: flex-start; text-align: left; width: 100%;
  padding: var(--s3) var(--s4); border: 1px solid var(--rule-strong); border-radius: var(--r1);
  background: var(--sheet); color: var(--ink); font: inherit; cursor: pointer;
}
.option p { margin: 0; }
.option .key { flex: none; font: 600 var(--fs-small)/1.75 var(--font-mono); color: var(--ink-2); width: 1.25em; }
.option:hover:not(:disabled) { border-color: var(--ink); }
.option.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.option.selected .key { color: var(--primary); }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.correct .key { color: var(--ok); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option.wrong .key { color: var(--bad); }
.option:disabled { cursor: default; }
.text-answer {
  width: 100%; padding: var(--s3) var(--s4); border: 1px solid var(--rule-strong); border-radius: var(--r1);
  background: var(--sheet); color: var(--ink); font: inherit;
}
.text-answer:focus { outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.feedback { margin-top: var(--s5); padding: var(--s1) 0 var(--s1) var(--s4); border-left: 3px solid; }
.feedback.ok { border-color: var(--ok); }
.feedback.bad { border-color: var(--bad); }
.feedback .verdict { font-weight: 600; }
.feedback.ok .verdict { color: var(--ok); }
.feedback.bad .verdict { color: var(--bad); }
.feedback p { margin: var(--s1) 0; }
.hint { font-size: var(--fs-small); color: var(--ink-2); margin-top: var(--s4); }
kbd { font: 500 .75rem/1 var(--font-mono); border: 1px solid var(--rule-strong); border-bottom-width: 2px; border-radius: var(--r1); padding: 2px 5px; background: var(--sheet); }

.result { display: grid; grid-template-columns: auto 1fr; gap: var(--s6); align-items: center; }
.result .big { margin: 0; }
.mistake { padding: var(--s4) 0; border-bottom: 1px solid var(--rule); }
.mistake .question { font-size: var(--fs-body); margin-bottom: var(--s2); }
.answer-line { font-size: var(--fs-small); display: flex; gap: var(--s3); align-items: baseline; margin-top: var(--s1); }
.answer-line .label { width: 6.5em; flex: none; }

/* ---------- Карточки для запоминания ---------- */
.flashcard { perspective: 1400px; cursor: pointer; margin: var(--s3) 0; max-width: 640px; }
.flashcard-inner { position: relative; min-height: 300px; transition: transform .45s ease; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  /* Текст пишется по линовке: строка 32px, первая строка начинается под шапкой (44px). */
  padding: 44px var(--s6) var(--s5); border-radius: var(--r2);
  border: 1px solid var(--rule); border-top: 3px solid var(--bad);
  background:
    linear-gradient(var(--sheet), var(--sheet)) top / 100% 44px no-repeat,
    repeating-linear-gradient(transparent 0 31px, var(--rule) 31px 32px) 0 44px / 100% 100%,
    var(--sheet);
  overflow: auto; font-size: 1.25rem; line-height: 32px;
}
.flashcard-face p, .flashcard-face ul, .flashcard-face ol { margin: 0; }
.flashcard-face .katex-display { margin: 0; padding: 0; }
.flashcard-face.back { transform: rotateY(180deg); border-top-color: var(--primary); }
.flashcard-face .label { position: absolute; top: var(--s3); left: var(--s6); line-height: 1.3; }
.flashcard-actions { display: flex; flex-wrap: wrap; gap: var(--s2); max-width: 640px; }
.flashcard-actions .spacer { flex: 1; }

/* ---------- Вопросы к экзамену ---------- */
details.qa { border-bottom: 1px solid var(--rule); }
details.qa summary { list-style: none; cursor: pointer; padding: var(--s4) var(--s2); display: flex; gap: var(--s4); align-items: flex-start; }
details.qa summary::-webkit-details-marker { display: none; }
details.qa summary:hover { background: var(--sheet); }
details.qa[open] summary { background: var(--sheet); }
details.qa summary .grow { flex: 1; min-width: 0; }
details.qa summary .grow p { margin: 0; }
details.qa .answer { padding: var(--s2) var(--s2) var(--s5) calc(2.5em + var(--s4) + var(--s2)); background: var(--sheet); }
details.qa .chev { flex: none; font-family: var(--font-mono); color: var(--ink-2); transition: transform .15s; }
details.qa[open] .chev { transform: rotate(90deg); }
.status-btns { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s4); }

/* ---------- Поиск ---------- */
.search-input {
  width: 100%; padding: var(--s3) 0; border: 0; border-bottom: 2px solid var(--ink); background: transparent;
  color: var(--ink); font: 400 1.5rem/1.3 var(--font-serif);
}
.search-input::placeholder { color: var(--ink-2); }
.search-input:focus { outline: none; border-bottom-color: var(--primary); }

/* ---------- Расписание занятий ---------- */
.week { border-top: 1px solid var(--ink); }
.day { display: grid; grid-template-columns: 180px 1fr; gap: var(--s5); padding: var(--s4) 0; border-bottom: 1px solid var(--rule); }
.day-name { font-weight: 600; }
.day-date { font: 500 var(--fs-small)/1.5 var(--font-mono); color: var(--ink-2); }
.day.today .day-name .hl { font-weight: 600; }
.day.off { color: var(--ink-2); }
.lessons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.lesson { display: flex; gap: var(--s4); }
.lesson.past { opacity: .5; }
.lesson-time { flex: none; width: 7.5em; font: 500 var(--fs-small)/1.6 var(--font-mono); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lesson .swatch { min-height: 2.6em; }
.lesson > .grow { flex: 1; min-width: 0; }
.lesson-title { font-weight: 600; }
.lesson-title a { color: var(--ink); text-decoration: none; }
.lesson-title a:hover { color: var(--primary); text-decoration: underline; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); align-items: center; font-size: var(--fs-small); color: var(--ink-2); margin-top: 2px; }

/* ---------- Аккаунт и формы ---------- */
.account-link {
  color: var(--ink); text-decoration: none; font-size: .9375rem; font-weight: 500; white-space: nowrap;
  max-width: 14em; overflow: hidden; text-overflow: ellipsis; display: inline-flex; align-items: center; min-height: 32px;
}
.account-link:hover { color: var(--primary); text-decoration: underline; }
.account-link.active { color: var(--primary); }
.form { display: flex; flex-direction: column; gap: var(--s4); max-width: 420px; }
.field { display: flex; flex-direction: column; gap: var(--s2); }
.input {
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3); border: 1px solid var(--rule-strong); border-radius: var(--r1);
  background: var(--sheet); color: var(--ink); font: inherit;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.check-field { display: flex; gap: var(--s3); align-items: center; min-height: 44px; cursor: pointer; }
.check-field input { width: 20px; height: 20px; accent-color: var(--primary); }
textarea.input { min-height: 96px; resize: vertical; line-height: 1.5; }
.note-box { margin-top: var(--s4); }
.note-box .label { display: block; margin-bottom: var(--s2); }
.table .rank { font-family: var(--font-mono); color: var(--ink-2); width: 2.5em; }
.table tr.me td { background: var(--sheet); }
.rating-table .num { padding-right: var(--s5); white-space: nowrap; }
.rating-table td .muted { font-size: var(--fs-label); }

/* Длинные слова при крупном тексте переносятся, а не раздвигают страницу */
body { overflow-wrap: break-word; hyphens: auto; }
h1, h2, .big, .row > .grow, details.qa summary .grow, .summary > *, .section-head > *, .lesson .grow, .subject-name { overflow-wrap: anywhere; }
.section-head { flex-wrap: wrap; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tabs + .week { border-top: 0; }

.notice { border-left: 3px solid var(--marker); padding: var(--s1) 0 var(--s1) var(--s4); margin-bottom: var(--s5); }
.error-box { border-left: 3px solid var(--bad); padding: var(--s1) 0 var(--s1) var(--s4); margin-bottom: var(--s5); }
.empty { padding: var(--s6) 0; color: var(--ink-2); border-bottom: 1px solid var(--rule); }

.sm-only { display: none; }

/* ---------- Сенсорные экраны: цели касания не меньше 44px ---------- */
@media (pointer: coarse), (max-width: 720px) {
  .btn, .btn.sm, .theme-btn { min-height: 44px; }
  .tabs button { min-height: 44px; }
  .topnav a { min-height: 44px; }
}

/* ---------- Телефон ---------- */
@media (max-width: 720px) {
  :root { --gutter: 16px; --fs-h1: 1.75rem; --fs-display: 2.75rem; }
  main.container { padding-top: var(--s5); }
  .sm-only { display: inline; }
  div.sm-only { display: block; }

  /* Шапка: логотип и тема в первой строке, меню целиком во второй */
  .topbar .container { flex-wrap: wrap; gap: 0 var(--s4); padding-top: var(--s2); }
  .brand { flex: 1; }
  .brand small { display: none; }
  .topnav { order: 3; flex: 1 0 100%; flex-wrap: wrap; overflow: visible; gap: 0 var(--s3); }
  .topnav a { font-size: .875rem; }

  /* Сводка: «Сегодня» во всю ширину, экзамен и готовность рядом */
  .summary { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  .summary > * { padding: var(--s4) var(--s3) var(--s4) 0; min-width: 0; }
  .summary > * + * { border-left: 0; padding-left: 0; }
  .summary > .wide { grid-column: 1 / -1; border-bottom: 1px solid var(--rule); }
  .summary > :last-child:not(:first-child) { border-left: 1px solid var(--rule); padding-left: var(--s3); }
  .summary .big { font-size: 2.25rem; }
  .summary .big .unit { font-size: 1rem; }

  /* Таблица предметов: строки вместо колонок */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody { display: block; }
  .table.stack tr { display: grid; grid-template-columns: 1fr; gap: var(--s2); padding: var(--s4) 0; border-bottom: 1px solid var(--rule); }
  .table.stack td { display: block; padding: 0 0 0 calc(4px + var(--s3)); border: 0; }
  .table.stack td.cell-main { padding-left: 0; }
  .table.stack .hide-sm { display: none; }
  .table.stack .progress-row { max-width: 320px; }
  .table.stack .progress-row > span:last-child { min-width: 0; }

  /* Фильтры в одну строку с прокруткой, кнопка отдельной строкой */
  .toolbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .toolbar .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .toolbar .tabs::-webkit-scrollbar { display: none; }
  .toolbar > .btn { align-self: flex-start; }

  /* Пара: время над названием */
  .day { grid-template-columns: 1fr; gap: var(--s2); }
  .lesson { flex-wrap: wrap; column-gap: var(--s3); row-gap: 0; }
  .lesson-time { width: 100%; }

  .pager { flex-direction: column; }
  .pager a { max-width: 100%; overflow-wrap: anywhere; }
  .pager .next { text-align: left; margin-left: 0; }

  .sheet { padding: var(--s5) var(--s4); }
  .sheet-grid { grid-template-columns: 1fr; }
  .table .hide-sm { display: none; }
  details.qa .answer { padding-left: var(--s2); }
  .result { grid-template-columns: 1fr; gap: var(--s3); }
  .flashcard-inner { min-height: 268px; }
  .flashcard-face { padding-left: var(--s4); padding-right: var(--s4); font-size: 1.125rem; }
  .flashcard-face .label { left: var(--s4); }
}

.tab-link { display: inline-flex; align-items: center; min-height: 44px; padding: var(--s2) 0; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500; font-size: .9375rem; white-space: nowrap; }
.tab-link:hover { color: var(--ink); text-decoration: none; }
.tab-link.active { color: var(--ink); border-bottom-color: var(--primary); }
