/* DexiMath — локальный интерфейс.

   Визуальный язык заимствован у сайта кафедры ФН-1 (фн1.рф): фиолетовый
   акцент #8C2CFF, тёмно-фиолетовый #39126A, чернила #1A1A19, шапка со
   скруглением нижних углов 28px, карточки радиусом 12px с мягкой тенью,
   волосяная граница rgba(26,26,25,.19), гарнитура als-sector с системным
   запасным вариантом.

   Цвета серий на графиках — #8C2CFF и #EB6834 (в тёмном режиме #9B4DFF и
   #D95926): пара проверена на разделимость при дальтонизме и на контраст
   относительно обеих поверхностей. */

:root {
  color-scheme: light;
  --page:        #f5f3f8;
  --surface:     #ffffff;
  --surface-2:   #f7f5fa;
  --ink:         #1a1a19;
  --ink-2:       #4d4d55;
  --muted:       #86868c;
  --line:        rgba(26, 26, 25, .19);
  --line-soft:   rgba(26, 26, 25, .10);
  --accent:      #8c2cff;
  --accent-deep: #39126a;
  --accent-soft: #f2e8ff;
  --accent-ink:  #ffffff;
  --series-1:    #8c2cff;
  --series-2:    #eb6834;
  --good:        #0ca30c;
  --good-bg:     #eaf6ea;
  --bad:         #d03b3b;
  --bad-bg:      #fbecec;
  --shadow:      0 4px 8px rgba(0, 0, 0, .10);
  --r-card:      12px;
  --r-pill:      28px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:        #131215;
    --surface:     #1e2127;
    --surface-2:   #262a32;
    --ink:         #f1eff4;
    --ink-2:       #bcbac4;
    --muted:       #8b8f98;
    --line:        rgba(255, 255, 255, .16);
    --line-soft:   rgba(255, 255, 255, .09);
    --accent:      #9b4dff;
    --accent-deep: #c9a6ff;
    --accent-soft: #2a2036;
    --accent-ink:  #ffffff;
    --series-1:    #9b4dff;
    --series-2:    #d95926;
    --good:        #0ca30c;
    --good-bg:     #14251a;
    --bad:         #e66767;
    --bad-bg:      #2a1a1c;
    --shadow:      0 4px 8px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 "als-sector", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ------------------------------------------------------------------ шапка */

.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: var(--accent);
  color: #fff;
  border-radius: 0 0 var(--r-pill) var(--r-pill);
}
.brand { font-weight: 700; font-size: 19px; color: #fff; text-decoration: none; letter-spacing: -.01em; }
.bar-sub { color: rgba(255, 255, 255, .78); font-size: 14px; }
.grow { flex: 1; }
.bar .link { color: #fff; text-decoration: none; font-size: 15px; white-space: nowrap; font-weight: 700; }
.bar .link:hover { text-decoration: underline; }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; color: rgba(255, 255, 255, .78); }
.who input { width: 160px; background: rgba(255, 255, 255, .16); border-color: transparent; color: #fff; }
.who input::placeholder { color: rgba(255, 255, 255, .6); }
.who input:focus { background: #fff; color: var(--ink); outline-color: var(--accent-deep); }

/* ------------------------------------------------------------- карточки */

main { max-width: 900px; margin: 0 auto; padding: 26px 22px 60px; }
main.wide { max-width: 1120px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-deep);
}
.card-head > :nth-child(2):not(h2) { margin-left: auto; }
.counter { margin-left: auto; font-size: 13px; color: var(--muted); }
.hint { margin: 0 0 12px; font-size: 14px; color: var(--muted); }

.task { font-size: 24px; padding: 8px 0 4px; overflow-x: auto; min-height: 42px; }

/* --------------------------------------------------------------- кнопки */

button {
  font: inherit;
  font-size: 15px;
  padding: 9px 18px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
button.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }
button.ghost { background: var(--surface-2); }
button.small { padding: 6px 13px; font-size: 14px; }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 18px; }

/* ----------------------------------------------------------------- чипы */

.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  padding: 8px 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 15px;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* ------------------------------------------------------------------ поля */

.row-wide { margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px 16px; }

.field label.cap { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type=text] {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
input::placeholder { color: var(--muted); opacity: .7; }

.pair { display: flex; align-items: center; gap: 6px; }
.pair .paren { color: var(--muted); font-size: 16px; }
.pair input { text-align: center; }

.tex { font-size: 14px; color: var(--ink-2); margin-top: 5px; overflow-x: auto; }
.tex:empty { display: none; }
.sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* --------------------------------------------------------------- вердикт */

.verdict { display: none; margin-top: 18px; padding: 12px 16px; border-radius: 10px; font-weight: 700; font-size: 15px; }
.verdict.show { display: block; }
.verdict.ok  { background: var(--good-bg); color: var(--good); }
.verdict.err { background: var(--bad-bg);  color: var(--bad); }

/* -------------------------------------------------------------- отладка */

.debug { margin-left: auto; font-size: 14px; }
.debug summary { color: var(--muted); cursor: pointer; list-style: none; }
.debug summary::-webkit-details-marker { display: none; }
.debug summary::before { content: "⋯ "; }
.debug-body { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 12px; }
pre {
  flex-basis: 100%;
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 12px;
  font-size: 12.5px;
  overflow-x: auto;
  max-height: 320px;
  display: none;
}
pre.show { display: block; }

/* -------------------------------------------------------------- таблицы */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: none; }
td.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: 14px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.ok  { color: var(--good); }
.pill.err { color: var(--bad); }

/* ---------------------------------------------------------------- модалка */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(26, 18, 40, .5);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.overlay.show { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  max-width: 540px;
}
.modal h2 { margin: 0 0 14px; font-size: 18px; font-weight: 700; color: var(--accent-deep); }
.modal p { margin: 8px 0; font-size: 15px; color: var(--ink-2); }
code { font-family: ui-monospace, Consolas, monospace; background: var(--accent-soft); color: var(--accent-deep); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

/* ------------------------------------------------- преподавательская часть */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.tile .k { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.tile .v { font-size: 30px; font-weight: 700; line-height: 1.15; margin-top: 6px; letter-spacing: -.02em; }
.tile .u { font-size: 13px; color: var(--muted); margin-left: 3px; font-weight: 400; }

.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.filters label { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--muted); }
select {
  font: inherit;
  font-size: 14px;
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  max-width: 100%;
}
select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Внутри формы поле занимает свою ячейку целиком. Без этого select берёт
   ширину по самому длинному пункту: с длинными названиями комплектов он
   вылезал на соседнюю колонку, а с пустым списком схлопывался до кнопки. */
.field select,
.field input,
.field textarea { width: 100%; box-sizing: border-box; }

.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .charts { grid-template-columns: 1fr; } }

.legend { display: flex; gap: 16px; align-items: center; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(96px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.bar-row .name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; gap: 2px; height: 16px; }
.bar-seg { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-seg:first-child { border-radius: 4px 4px 4px 4px; }
.bar-row .val { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }

.tip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px 11px;
  font-size: 13px;
  display: none;
  max-width: 260px;
}
.tip.show { display: block; }
.tip b { display: block; margin-bottom: 3px; }

tr.expandable { cursor: pointer; }
tr.expandable:hover td { background: var(--accent-soft); }
tr.detail > td { background: var(--surface-2); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 8px 18px; font-size: 13.5px; }
.detail-grid div { display: flex; gap: 8px; }
.detail-grid .dk { color: var(--muted); min-width: 118px; }
.detail-grid .dv { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; word-break: break-word; }

@media (max-width: 620px) {
  .bar { flex-wrap: wrap; border-radius: 0 0 18px 18px; }
  .who input { width: 120px; }
  main { padding: 18px 14px 50px; }
}

/* ------------------------------------------------------------- тренажёр */

.step { padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.step:last-child { border-bottom: none; }
.step h3 { margin: 0 0 8px; font-size: 15px; font-weight: 700; color: var(--accent-deep); }
.step-formula { overflow-x: auto; padding: 4px 0 6px; }
.step-text { margin: 0; font-size: 14px; color: var(--ink-2); }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { border-color: var(--line); color: var(--ink); }

/* --------------------------------------------------------------- график */

.plot-box { display: flex; flex-direction: column; align-items: center; }
.plot { max-width: 480px; }
.plot-grid line { stroke: var(--line-soft); stroke-width: 1; }
.plot-axes line { stroke: var(--muted); stroke-width: 1.1; color: var(--muted); }
.plot-labels text { fill: var(--muted); font-size: 10px; }

/* Подписи набраны KaTeX внутри foreignObject: та же гарнитура, что у формул. */
.plot-tex { display: flex; align-items: center; height: 100%; font-size: 11px; color: var(--muted); }
.plot-tex-center { justify-content: center; }
.plot-tex-left { justify-content: flex-start; }
.plot-tex-right { justify-content: flex-end; }
.plot-axis-name .plot-tex { color: var(--ink-2); font-size: 12.5px; }
.plot-point-label .plot-tex { color: var(--ink-2); font-size: 12px; }
.plot foreignObject { overflow: visible; }

/* Послойное появление элементов графика. */
.plot-layer { opacity: 0; transition: opacity .3s ease; }
.plot-layer.shown { opacity: 1; }
.plot-border { stroke: var(--line-soft); stroke-width: 1; }
.plot-caption { margin-top: 8px; text-align: center; color: var(--muted); }
.plot-note { text-align: center; }

/* Кривая прорисовывается, а не возникает целиком. */
.plot-layer-curve polyline,
.plot-layer-line polyline { stroke-dasharray: 3000; stroke-dashoffset: 3000; }
.plot-layer-curve.shown polyline,
.plot-layer-line.shown polyline { animation: plot-draw 1s ease forwards; }
@keyframes plot-draw { to { stroke-dashoffset: 0; } }

/* ------------------------------------------------------ состав комплекта */

.variant-pick { margin: 16px 0 20px; }
.variant-pick .field { max-width: 150px; }

.composition { border-top: 1px solid var(--line); }
.composition-row {
  display: grid;
  grid-template-columns: 28px 1fr auto 34px;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.composition-row:hover { background: var(--surface-2); }
.composition-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.composition-no { color: var(--muted); font-variant-numeric: tabular-nums; }
.composition-marks { color: var(--muted); font-size: 13px; }
.composition-score { color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.composition-row.is-current { background: var(--accent-soft); border-radius: 8px; }
.composition-row.is-current .composition-title { font-weight: 700; color: var(--accent-deep); }

/* ------------------------------------------------- отметка у поля ответа */

.field .mark { float: right; font-weight: 700; font-size: 12px; }
.field.ok  .mark { color: var(--good); }
.field.err .mark { color: var(--bad); }
.field.ok  input[type=text] { border-color: var(--good); }
.field.err input[type=text] { border-color: var(--bad); }
#answer-fields .field + .field { margin-top: 16px; }

/* ------------------------------------------------- условие задачи абзацем */

.task-text {
  font-size: 17px;
  line-height: 1.65;
  min-height: 0;
  padding: 4px 0 2px;
}
.task-text .katex-display { margin: 12px 0; }
.task-text .katex { font-size: 1.05em; }

/* ------------------------------------------------------------- вход в роли */

.entry { max-width: 900px; }
.entry-lead { color: var(--ink-2); font-size: 16px; line-height: 1.6; margin: 4px 0 26px; }

.doors { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }

.door {
  display: block;
  padding: 22px 24px 20px;
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--ink);
  transition: border-color .15s, transform .15s;
}
.door:hover { border-color: var(--accent); transform: translateY(-2px); }
.door-role { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.door h2 { margin: 6px 0 10px; font-size: 22px; }
.door p { color: var(--ink-2); line-height: 1.55; margin: 0 0 14px; }
.door-go { color: var(--accent); font-weight: 700; }
.door-teacher .door-role, .door-teacher .door-go { color: var(--series-2); }
.door-teacher:hover { border-color: var(--series-2); }

/* ------------------------------------------------------- плитки на главной */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

.tile {
  display: block;
  padding: 16px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  text-decoration: none;
  color: var(--ink);
  transition: border-color .15s;
}
.tile:hover { border-color: var(--accent); }
.tile h3 { margin: 0 0 2px; font-size: 17px; }
.tile-sub { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.tile-text { margin: 0 0 12px; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
.tile-go { color: var(--accent); font-weight: 700; font-size: 14px; }

/* ------------------------------------------------- признаки текущей страницы */

.link.is-here { color: var(--accent-ink); border-bottom: 2px solid currentColor; }
.muted-link { opacity: .72; }
.bar-teacher { background: linear-gradient(90deg, #d2551f, #eb6834); }

.composition-row.is-static { cursor: default; }
.composition-row.is-static:hover { background: none; }
.chip.is-static { cursor: default; font-weight: 400; }

/* ------------------------------------------------------ таблица вариантов */

.table-scroll { overflow-x: auto; }
.grid-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.grid-table th, .grid-table td { padding: 6px 10px; border-bottom: 1px solid var(--line-soft); text-align: right; }
.grid-table th { color: var(--muted); font-weight: 600; font-size: 13px; white-space: nowrap; }
.grid-table th:first-child, .grid-table .row-head { text-align: left; }
.grid-table .row-head { color: var(--muted); font-variant-numeric: tabular-nums; }
.grid-table tbody tr:hover { background: var(--surface-2); }

.code {
  margin: 10px 0 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  font-size: 13px;
  overflow-x: auto;
  white-space: pre;
}

/* ------------------------------------------------- группы и персональная ссылка */

.who-line { margin: 4px 0 0; font-size: 16px; font-weight: 500; }
.token-link { font-family: var(--font-mono, monospace); font-size: 13px; }
.new-group { margin-top: 14px; }
.new-group summary { cursor: pointer; color: var(--accent); font-size: 14px; }
textarea {
  width: 100%; font: inherit; font-size: 15px; padding: 8px 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); resize: vertical;
}

.sub-inline { margin-left: 8px; font-size: 12px; color: var(--muted); font-weight: 400; }

/* ------------------------------------------------------- состояние выдачи */

.state {
  display: inline-block;
  padding: 1px 9px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
}
.state-pending { background: var(--accent-soft); color: var(--accent-deep); }
.state-open    { background: var(--good-bg);    color: var(--good); }
.state-closed  { background: var(--bad-bg);     color: var(--bad); }

/* --------------------------------------------- разбор ответов в журнале */

.chip-small { padding: 2px 9px; font-size: 12px; margin: 0 4px 4px 0; }
.chip-ok { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.ok-cell { color: var(--good); font-weight: 700; }
.bad-cell { color: var(--bad); font-weight: 700; }
.muted-cell { color: var(--muted); }

/* ------------------------------------------------------------------ маскот */

/* Ро сидит в левом поле страницы, целиком ниже шапки и целиком на экране.

   Отступы посчитаны, а не подобраны на глаз. Поворот идёт вокруг левого
   верхнего угла слоя, поэтому рисунок съезжает относительно рамки: правый
   верхний край поднимается примерно на 13 px, левый — уходит вправо на 14.
   Плюс в самой картинке сверху и слева есть прозрачные поля. С учётом
   всего этого чернила занимают полосу 54–177 px по горизонтали и
   начинаются в 55 px от верха — то есть ниже шапки высотой около 51 px. */
.mascot {
  position: fixed;
  left: 40px;
  top: 68px;
  width: 124px;
  height: 132px;
  background: url("mascot.png") no-repeat left top / contain;
  transform: rotate(-7deg);
  transform-origin: top left;
  pointer-events: none;
  z-index: 30;
}

@media (prefers-color-scheme: dark) {
  .mascot { background-image: url("mascot-dark.png"); }
}

/* Ро помещается только там, где поле слева от карточек шире его самого.
   Содержимое центрировано и ограничено по ширине, поэтому порог считается
   от неё: обычная страница — 900 px плюс отступы, широкая — 1120 px. На
   узком экране Ро налезал бы на карточки, поэтому просто убирается. */
@media (max-width: 1280px) {
  .mascot { display: none; }
}
@media (max-width: 1500px) {
  body:has(main.wide) .mascot { display: none; }
}
