/* Своя компактная таблица стилей вместо внешнего фреймворка: страница одна, а
   бейджи «кто проверил» — смысловой центр, и их читаемостью хочется управлять точно. */

:root {
  --bg: #fbfaf7;
  --fg: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0da;
  --card: #fff;
  --ok: #1a7f43;
  --ok-bg: #e8f6ed;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --warn: #8a5a00;
  --warn-bg: #fdf3e0;
  --code-bg: #f4f2ec;
  --accent: #2f5fa8;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
  max-width: 96rem;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; color: var(--accent); }
header { margin-bottom: 1.25rem; }

section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.1rem;
}

.muted { color: var(--muted); font-size: .875rem; }

code {
  background: var(--code-bg);
  padding: .1em .35em;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .875em;
}

pre.code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  max-height: 26rem;
}

label { display: block; margin-bottom: .6rem; font-size: .9rem; }
label.checkbox { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  margin-top: .25rem;
  padding: .45rem .6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}
input[type="text"]:focus, input[type="number"]:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.math-preview {
  min-height: 3.5rem;
  margin: -.2rem 0 .8rem;
  padding: .65rem .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--code-bg);
  white-space: pre-wrap;
  overflow-x: auto;
}
.math-preview[hidden] { display: none; }
.katex-display { overflow-x: auto; overflow-y: hidden; }

button {
  padding: .45rem .9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }

nav.templates { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
nav.templates a {
  padding: .3rem .7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  text-decoration: none;
  font-size: .875rem;
}
nav.templates a.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.toolbar { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin-bottom: .75rem; }

ol.instances { list-style: decimal; padding-left: 1.6rem; margin: 0; }
ol.instances > li { padding: .7rem 0; border-top: 1px solid var(--line); }
ol.instances > li:first-child { border-top: 0; }
.statement { font-weight: 600; margin-bottom: .4rem; }
ol.instances form { display: flex; gap: .5rem; align-items: center; }
ol.instances input[type="text"] { max-width: 18rem; margin-top: 0; }

/* --- результат проверки: вердикт + КТО проверил --- */
.result { margin-top: .5rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.result .verdict { font-weight: 700; }
.result.verdict-correct .verdict { color: var(--ok); }
.result.verdict-incorrect .verdict { color: var(--bad); }
.result.verdict-unsure .verdict,
.result.verdict-unparseable .verdict { color: var(--warn); }

.stage {
  font-size: .78rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--code-bg);
  color: var(--muted);
}
.stage-template_checker { border-color: #b7cbea; background: #eaf1fb; color: #24487d; }
.stage-llm { border-color: #d5c2ea; background: #f4ecfb; color: #5b3585; }
/* Общий сравниватель — предупреждающий цвет намеренно: это деградация проверки, и
   выглядеть она должна иначе, чем семейный чекер. */
.stage-fallback { border-color: #f0dcb4; background: var(--warn-bg); color: var(--warn); }

.result .ms { font-size: .78rem; color: var(--muted); }
.result .reason { flex-basis: 100%; font-size: .875rem; }
.result-slot:empty { display: none; }

.cross { flex-basis: 100%; font-size: .85rem; }
.cross.agree { color: var(--ok); }
.cross.disagree { color: var(--bad); font-weight: 600; }

details.peek { margin-top: .35rem; }
details.peek summary { font-size: .8rem; color: var(--muted); cursor: pointer; }

.error, .notice, .ok-banner {
  padding: .6rem .8rem;
  border-radius: 8px;
  margin-bottom: .75rem;
  font-size: .9rem;
}
.error { background: var(--bad-bg); color: var(--bad); border: 1px solid #f3c9c5; }
.ok-banner { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe3cd; }
.notice { background: var(--warn-bg); color: var(--warn); border: 1px solid #f0dcb4; }

table.fixtures { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: .5rem; }
table.fixtures th, table.fixtures td {
  text-align: left; padding: .3rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top;
}
table.fixtures th { color: var(--muted); font-weight: 600; }
tr.row-bad { background: var(--bad-bg); }
tr.row-ok td:first-child { color: var(--ok); }
tr.row-bad td:first-child { color: var(--bad); }

/* --- карточка запроса: только чтение --- */
dl.request-card { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .8rem; margin: 0; font-size: .875rem; }
dl.request-card dt { color: var(--muted); white-space: nowrap; }
dl.request-card dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
dl.request-card dd.empty { color: var(--muted); font-style: italic; }

/* --- фиксация версии --- */
.approve-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .5rem 0 .75rem; }
.approved {
  font-weight: 600; color: var(--ok);
  padding: .25rem .6rem; border: 1px solid #bfe3cd; border-radius: 999px; background: var(--ok-bg);
}

/* --- главная ученика: назначенные задания выделены --- */
section.hero { border-color: var(--accent); border-width: 2px; }
a.task-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem .9rem; margin-bottom: .5rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--fg); text-decoration: none;
}
a.task-card:hover { border-color: var(--accent); background: var(--code-bg); }
.task-title { font-weight: 600; }
.task-card-go { color: var(--accent); font-size: .875rem; white-space: nowrap; }
.why { font-size: .8rem; color: var(--warn); margin-top: .25rem; }

/* непрочитанный комментарий: галочка справа, действие одним нажатием */
.unread {
  display: flex; align-items: flex-start; gap: .7rem;
  padding: .6rem .8rem; margin-bottom: .5rem;
  border: 1px solid #f0dcb4; border-radius: 8px; background: var(--warn-bg);
}
.unread-body { flex: 1; min-width: 0; }
.message-preview { color: var(--fg); text-decoration: none; justify-content: space-between; }
.message-preview .unread-body { display: grid; gap: .2rem; }
.module-chat { scroll-margin-top: 1rem; }
.chat-history { display: flex; flex-direction: column; gap: .55rem; margin-bottom: 1rem; }
.chat-message {
  width: min(78%, 42rem); padding: .65rem .8rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--code-bg); line-height: 1.45;
}
.chat-message.mine {
  align-self: flex-end; border-color: #b8c9ea; background: #eef4ff;
}
.chat-message.theirs { align-self: flex-start; }
.chat-meta { margin-bottom: .2rem; color: var(--muted); font-size: .78rem; }
.module-chat form { margin-top: .75rem; }
@media (prefers-color-scheme: dark) {
  .chat-message.mine { border-color: #49658f; background: #1e2941; }
}
@media (max-width: 560px) {
  .chat-message { width: 92%; }
  .message-preview { align-items: flex-start; flex-direction: column; }
}
.check-btn {
  flex: none; width: 2rem; height: 2rem; padding: 0;
  font-size: 1rem; line-height: 1; border-radius: 50%;
}

/* статистика */
.stat-row { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-bottom: .9rem; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.3rem; }
.stat span { font-size: .78rem; color: var(--muted); }

/* календарь активности: недели столбцами, дни строками */
.cal-wrap { display: flex; gap: .35rem; align-items: flex-start; overflow-x: auto; padding-bottom: .3rem; }
.cal-days { display: grid; grid-template-rows: repeat(7, 11px); gap: 2px; font-size: 9px; color: var(--muted); }
.cal { display: flex; gap: 2px; }
.cal-week { display: grid; grid-template-rows: repeat(7, 11px); gap: 2px; }
.cal-cell { width: 11px; height: 11px; border-radius: 2px; background: var(--code-bg); }
.cal-empty { background: transparent; }
.lvl-0 { background: var(--code-bg); }
.lvl-1 { background: #c6e6cf; }
.lvl-2 { background: #7fce9d; }
.lvl-3 { background: #40a869; }
.lvl-4 { background: #1a7f43; }

/* история посылок */
details.submissions { margin-top: .4rem; }
details.submissions > summary { font-size: .82rem; color: var(--accent); cursor: pointer; }
.check-bar { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-top: .8rem; }
button.big { padding: .6rem 1.4rem; font-size: 1rem; font-weight: 600; }

/* --- разделы ролей --- */
div.ex { padding: .2rem 0; }
div.ex form { display: flex; gap: .5rem; align-items: center; margin: .3rem 0; }
div.ex input[type="text"] { max-width: 16rem; margin-top: 0; }
.saved { font-size: .8rem; color: var(--ok); }
select { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--card); color: var(--fg); }
section details > summary { cursor: pointer; font-weight: 600; color: var(--accent); }

/* --- шапка «кто я» и узкие страницы --- */
body.narrow-page { max-width: 46rem; }
header.whoami { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.whoami-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.whoami-right form { margin: 0; }
a.role-link { text-decoration: none; color: var(--accent); border-color: #b7cbea; background: #eaf1fb; }
a.role-link:hover { filter: brightness(.97); }

/* --- форма создания: кнопкой служит сам summary --- */
details.new-gen { margin-top: .6rem; }
summary.btn-new-sum {
  display: inline-block;
  padding: .45rem .9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
summary.btn-new-sum::-webkit-details-marker { display: none; }
summary.btn-new-sum:hover { filter: brightness(1.08); }
details.new-gen[open] > summary.btn-new-sum { margin-bottom: .6rem; }

/* --- список генераторов и раскладка --- */
#generator-list-box { padding-bottom: .6rem; }
.gen-head { display: flex; align-items: center; gap: .8rem; margin-bottom: .5rem; }
.details-box { margin-top: .4rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1.6fr; gap: .8rem; align-items: end; }
@media (max-width: 52rem) { .row-2 { grid-template-columns: 1fr; } }

/* --- «новая задача»: главное действие, поэтому заметное --- */
p.newbar { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin: 0 0 1rem; }
a.btn-new {
  padding: .45rem .9rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: .9rem;
  font-weight: 600;
}
a.btn-new:hover { filter: brightness(1.08); }
button.secondary { background: transparent; color: var(--accent); }
button.secondary:hover { background: var(--code-bg); filter: none; }
#new-task:target { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- ящик со шаблонами --- */
details.drawer { margin-bottom: 1rem; }
details.drawer > summary {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  padding: .45rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: .9rem;
  font-weight: 600;
}
.burger {
  width: .9rem; height: .7rem; flex: none;
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  position: relative;
}
.burger::after {
  content: ""; position: absolute; left: 0; right: 0; top: 50%;
  border-top: 2px solid var(--accent); transform: translateY(-1px);
}
ul.tpl-list {
  list-style: none; padding: .4rem 0 0; margin: 0;
  max-height: 24rem; overflow-y: auto;
}
ul.tpl-list li {
  display: flex; align-items: center; gap: .4rem;
  border-bottom: 1px solid var(--line);
}
ul.tpl-list li:last-child { border-bottom: 0; }
ul.tpl-list a {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: .6rem;
  padding: .4rem .5rem; color: var(--fg); text-decoration: none; font-size: .875rem;
}
ul.tpl-list a:hover { background: var(--code-bg); }
ul.tpl-list li.current a { border-left: 3px solid var(--accent); font-weight: 600; }
.tpl-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-meta { display: flex; gap: .5rem; align-items: baseline; flex: none; }
.tpl-status { font-size: .72rem; padding: .08rem .4rem; border-radius: 999px; border: 1px solid var(--line); }
.st-ready { border-color: #bfe3cd; background: var(--ok-bg); color: var(--ok); }
.st-needs_review { border-color: #f0dcb4; background: var(--warn-bg); color: var(--warn); }
.st-failed { border-color: #f3c9c5; background: var(--bad-bg); color: var(--bad); }
.st-generating { border-color: #b7cbea; background: #eaf1fb; color: #24487d; }
.tpl-del {
  flex: none; padding: .1rem .45rem; font-size: .95rem; line-height: 1;
  background: transparent; color: var(--muted); border-color: transparent;
}
.tpl-del:hover { color: var(--bad); border-color: var(--bad); filter: none; }
.tpl-arch {
  flex: none; padding: .12rem .5rem; font-size: .78rem;
  background: transparent; color: var(--muted); border-color: var(--line);
}
.tpl-arch:hover { color: var(--accent); border-color: var(--accent); filter: none; }
details.archive { margin-top: .5rem; }
details.archive > summary { cursor: pointer; font-size: .82rem; color: var(--muted); }
.st-archived { border-color: var(--line); background: var(--code-bg); color: var(--muted); }

/* --- итерации и образцы задач --- */
details.iterations > summary { cursor: pointer; font-size: .85rem; color: var(--accent); margin: .5rem 0; }
.s-statement { font-weight: 600; font-size: .875rem; margin-top: .3rem; }
details.s-block > summary { cursor: pointer; font-size: .82rem; color: var(--accent); }
ol.s-list { padding-left: 1.2rem; margin: .3rem 0 0; }
ol.s-list > li { padding: .25rem 0; }

details.models {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .7rem;
  margin-bottom: 1.1rem;
  background: var(--card);
}
details.models > summary { cursor: pointer; font-size: .9rem; color: var(--accent); }
table.profiles { width: 100%; border-collapse: collapse; font-size: .85rem; margin: .6rem 0; }
table.profiles th, table.profiles td { text-align: left; padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
table.profiles th { color: var(--muted); font-weight: 600; }
table.profiles select, table.profiles input { padding: .25rem .35rem; font: inherit; max-width: 11rem; }

/* --- две колонки: управление слева, результат справа --- */
.studio {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.1rem;
  align-items: start;
}
.col { min-width: 0; }
.studio.one-col { grid-template-columns: minmax(0, 1fr); }
/* Правая колонка прилипает и скроллится сама: код слева бывает на 400 строк, а
   задачи справа нужны перед глазами всё это время. */
.col-right { position: sticky; top: 1rem; }
.col-right section.sandbox {
  margin-bottom: 0;
  max-height: calc(100vh - 2.5rem);
  overflow-y: auto;
}
@media (max-width: 74rem) {
  .studio { grid-template-columns: minmax(0, 1fr); }
  .col-right { position: static; }
  .col-right section.sandbox { max-height: none; overflow-y: visible; margin-bottom: 1.1rem; }
}

/* --- решение --- */
details.solution { margin-top: .4rem; }
details.solution > summary { font-size: .82rem; color: var(--accent); cursor: pointer; }
details.solution pre, pre.solution-mini {
  margin: .35rem 0 0;
  padding: .5rem .7rem;
  background: var(--code-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-family: inherit;
  font-size: .875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-x: auto;
}
pre.solution-mini { font-size: .8rem; margin-top: .25rem; }
label.narrow input[type="number"] { max-width: 9rem; margin-right: .5rem; }
label.narrow { display: flex; flex-direction: column; gap: .2rem; }

/* --- версии генератора и редактор --- */
.versions { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.ver {
  font-size: .8rem;
  padding: .22rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}
.ver.current { border-color: var(--accent); color: var(--accent); font-weight: 600; cursor: default; }

form.editor textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .6rem .7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
  tab-size: 4;
}
.editor-bar { display: flex; gap: .5rem; align-items: center; margin-top: .6rem; }
.editor-bar input[type="text"] { margin-top: 0; }
ul.plain { list-style: none; padding-left: 0; font-size: .875rem; }
ul.plain li { padding: .12rem 0; }

/* --- живой лог агентного цикла --- */
.run-log {
  max-height: 22rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .6rem .75rem;
  background: var(--code-bg);
  font-size: .875rem;
  margin: .5rem 0;
}
/* Строка статуса прогона: тикающие часы и вращающийся кружок — единственное, что
   отличает «работает» от «повисло», пока писатель молчит минуты. */
.run-status {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem .75rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--code-bg);
  font-size: .9rem;
  font-weight: 600;
}
.run-status .elapsed { font-weight: 400; font-variant-numeric: tabular-nums; margin-left: auto; }
.run-status .spinner {
  width: .8rem;
  height: .8rem;
  flex: none;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: run-spin .8s linear infinite;
}
.run-status.done .spinner { display: none; }
.run-status.done { border-color: var(--line); font-weight: 400; }
.run-status.ok { border-color: var(--ok); color: var(--ok); }
.run-status.bad { border-color: var(--bad); color: var(--bad); }
@keyframes run-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .run-status .spinner { animation: none; } }

.run-log:empty { display: none; }
.log-line { padding: .18rem 0; }
.log-line.ok { color: var(--ok); }
.log-line.bad { color: var(--bad); }
.log-line.muted { color: var(--muted); }
.run-code { margin-top: .5rem; }
form.refine { display: flex; gap: .5rem; align-items: flex-end; margin-top: .75rem; }
form.refine label { flex: 1; margin: 0; }

@media (prefers-color-scheme: dark) {
  .lvl-1 { background: #1e4a30; }
  .lvl-2 { background: #2c7048; }
  .lvl-3 { background: #3f9c63; }
  .lvl-4 { background: #6ede9a; }
  :root {
    --bg: #17171a; --fg: #ececf0; --muted: #9a9aa2; --line: #33333a;
    --card: #1f1f24; --code-bg: #26262c; --accent: #7aa8f0;
    --ok: #6ede9a; --ok-bg: #17351f; --bad: #ff9b93; --bad-bg: #3a1b18;
    --warn: #ffcd76; --warn-bg: #3a2c12;
  }
  input[type="text"], input[type="number"], textarea { background: #26262c; color: var(--fg); }
  button { color: #14141a; }
  .stage-template_checker { border-color: #3c5686; background: #1e2941; color: #b7cbea; }
  .stage-llm { border-color: #5d4680; background: #2a2036; color: #d5c2ea; }
}


/* --- конструктор заданий Студии --- */
select {
  width: 100%; margin-top: .25rem; padding: .45rem .6rem;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; font: inherit;
}
.library-card { padding: .75rem 0; border-top: 1px solid var(--line); }
.library-card:first-of-type { border-top: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.task-composition { margin: 0; padding-left: 1.6rem; }
.task-composition > li {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .65rem 0; border-top: 1px solid var(--line);
}
.task-composition > li:first-child { border-top: 0; }
.task-item-main { flex: 1; min-width: 0; }
.inline-form { display: flex; align-items: end; gap: .6rem; }
.inline-form label { margin: 0; }
.inline-form input[type="number"] { width: 7rem; }
button.secondary { background: #fff; color: var(--accent); }
button.danger { background: #fff; color: var(--bad); border-color: var(--bad); }
.studio-sections { margin-bottom: 1.1rem; }
@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .task-composition > li { align-items: flex-start; flex-direction: column; }
}


/* --- версии и линейная цепочка модуля --- */
.module-versions { display: flex; flex-direction: column; gap: .6rem; }
.module-version-row {
  display: flex; align-items: center; gap: .7rem; flex-wrap: wrap;
  padding: .7rem; border: 1px solid var(--line); border-radius: 8px;
}
.module-version-row.current { border-color: var(--accent); }
.module-version-actions { display: flex; gap: .45rem; flex-wrap: wrap; margin-left: auto; }
.module-version-actions form { margin: 0; }
.module-version-actions button { font-size: .82rem; }
.module-chain { display: flex; align-items: stretch; gap: .7rem; overflow-x: auto; padding: .4rem 0 .8rem; }
.module-chain-part { display: flex; align-items: center; gap: .7rem; flex: none; }
.module-node {
  width: 17rem; min-height: 12rem; padding: .8rem; border: 2px solid var(--line);
  border-radius: 10px; background: var(--card); display: flex; flex-direction: column; gap: .55rem;
}
.module-node form { margin: 0; }
.chain-arrow { font-size: 1.8rem; color: var(--accent); }
.chain-arrow.chain-paused { color: var(--warn); }
.transition-badge {
  display: inline-block; width: fit-content; padding: .15rem .5rem; border-radius: 999px;
  background: var(--code-bg); color: var(--muted); font-size: .8rem;
}
.transition-next { background: #eaf1fb; color: #24487d; }
.transition-teacher_decides { background: var(--warn-bg); color: var(--warn); }
.transition-finish { background: var(--ok-bg); color: var(--ok); }
.subchain-preview { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.subchain-preview span { padding: .45rem .7rem; border: 1px solid var(--line); border-radius: 7px; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* --- фактическая индивидуальная траектория --- */
.trajectory {
  display: flex; align-items: stretch; gap: .65rem; overflow-x: auto;
  padding: .45rem 0 1rem;
}
.trajectory-node {
  flex: 0 0 16rem; min-height: 8rem; padding: .8rem;
  border: 2px solid var(--line); border-radius: 10px; background: var(--card);
  display: flex; flex-direction: column; gap: .4rem;
}
.trajectory-current { border-color: var(--accent); box-shadow: 0 0 0 2px #e8f0ff; }
.trajectory-redirected { opacity: .68; border-style: dashed; }
.trajectory-arrow {
  flex: none; align-self: center; color: var(--accent); font-size: .8rem;
  font-weight: 700; text-align: center;
}
.trajectory-decision {
  margin-top: auto; padding: .55rem; border-radius: 7px;
  background: var(--warn-bg); color: var(--warn); font-size: .85rem;
}
.trajectory-canonical .trajectory-node { min-height: 6rem; background: var(--code-bg); }
.route-plan-section { border-color: #b8c9ea; background: #f8faff; }
.trajectory-plan { padding-top: .7rem; }
.route-plan-node { background: #f5f6f8; border-style: dashed; color: #596273; }
.route-plan-current {
  background: var(--card); border-style: solid; border-color: var(--accent);
  color: var(--text); box-shadow: 0 0 0 2px #e8f0ff;
}
.route-plan-completed { background: var(--ok-bg); border-color: #78b68a; color: var(--text); }
.route-plan-assigned { background: var(--card); border-style: solid; color: var(--text); }
.route-plan-redirected { opacity: .65; }
.route-plan-end { border-style: solid; border-color: var(--warn); box-shadow: 0 0 0 2px var(--warn-bg); }
.route-plan-arrow { color: #6c7890; }
.route-plan-decision-arrow { color: var(--warn); max-width: 7rem; }
.route-plan-outcome { border-color: var(--warn); background: var(--warn-bg); color: var(--text); }
.route-builder { margin-top: 1rem; }
.route-builder-preview { margin: .7rem 0; }
.trajectory-actions {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem; margin-top: 1rem;
}
.trajectory-actions form { padding: .8rem; border: 1px solid var(--line); border-radius: 8px; }
@media (max-width: 760px) {
  .module-version-actions { width: 100%; margin-left: 0; }
  .trajectory-actions { grid-template-columns: 1fr; }
}

/* --- теоретические материалы --- */
.card-list, .resource-links { display: grid; gap: .65rem; }
.card-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 0; border-top: 1px solid var(--line);
}
.card-row:first-child { border-top: 0; }
.card-row form { margin: 0; }
.compact-section { padding-block: .8rem; }
.assignment-actions { display: flex; justify-content: flex-end; margin-bottom: .75rem; }
.button-link {
  display: inline-flex; align-items: center; min-height: 2.5rem; padding: .5rem .9rem;
  border: 1px solid var(--accent); border-radius: 7px; text-decoration: none;
  font-weight: 600;
}
.button-link.secondary { background: var(--card); color: var(--accent); }
.resource-links { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }
.resource-link {
  display: flex; justify-content: space-between; gap: .75rem; padding: .75rem .85rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  text-decoration: none; font-weight: 600;
}
.resource-link span { color: var(--muted); font-size: .85rem; font-weight: 400; }
.theory-content { font-size: 1.02rem; line-height: 1.7; }
.theory-content h1, .theory-content h2, .theory-content h3 { line-height: 1.25; }
.theory-content img { display: block; max-width: 100%; height: auto; margin: 1rem auto; }
.theory-content pre { max-width: 100%; overflow-x: auto; }
.theory-content table { display: block; max-width: 100%; overflow-x: auto; }
@media (max-width: 560px) {
  .card-row { align-items: flex-start; flex-direction: column; }
  .resource-links { grid-template-columns: 1fr; }
}

/* --- простой интерфейс ученика --- */
body.student-ui {
  max-width: 68rem;
  padding: 1.4rem 1.4rem 4rem;
  font-size: 16px;
  line-height: 1.55;
}
.student-ui h1 { font-size: clamp(1.55rem, 3vw, 2rem); letter-spacing: -.025em; }
.student-ui h2 { margin: 0; color: var(--fg); font-size: 1.08rem; }
.student-ui section { padding: 1.2rem 1.3rem; margin-bottom: 1rem; border-radius: 14px; }
.student-header {
  align-items: center; flex-wrap: nowrap; margin-bottom: 1.4rem; padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.student-header > div:first-child { min-width: 0; }
.student-header .whoami-right { gap: .75rem; }
.student-header button {
  display: inline-flex; align-items: center; min-height: 2.75rem; padding: .5rem .8rem;
}
.student-name { color: var(--muted); font-size: .88rem; }
.student-section-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin-bottom: .85rem;
}
.student-count {
  min-width: 1.7rem; padding: .12rem .48rem; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: .78rem; font-weight: 700;
  text-align: center;
}
.student-inbox { border-color: #e8ce91; background: var(--warn-bg); }
.student-inbox-item {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 3.6rem; padding: .7rem 0; border-top: 1px solid #e8ce91;
  color: var(--fg); text-decoration: none;
}
.student-inbox-item:first-of-type { border-top: 0; }
.student-inbox-item > a, .student-inbox-item > span:first-child {
  display: grid; flex: 1; min-width: 0; gap: .15rem; color: var(--fg); text-decoration: none;
}
.student-item-meta {
  display: block; color: var(--muted); font-size: .78rem; font-weight: 500;
}
.student-item-text { display: block; overflow-wrap: anywhere; }
.student-arrow { color: var(--accent); font-size: 1.2rem; }
.student-done {
  display: inline-grid; place-items: center; min-width: 2.75rem; min-height: 2.75rem;
  padding: 0; border-radius: 50%;
}
.student-next { border: 2px solid var(--accent); }
.student-task-list { display: grid; gap: .7rem; }
.student-task-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1.2rem;
  min-height: 6.2rem; padding: 1rem; border: 1px solid var(--line); border-radius: 11px;
  background: var(--card); color: var(--fg); text-decoration: none;
}
.student-task-card:hover { border-color: var(--accent); }
.student-next .student-task-card {
  min-height: 5.4rem; padding: 1rem 0; border: 0; border-top: 1px solid var(--line);
  border-radius: 0;
}
.student-next .student-task-card:first-child { border-top: 0; }
.student-task-main { display: grid; min-width: 0; gap: .18rem; }
.student-task-title { font-size: 1.12rem; font-weight: 700; }
.student-task-note { color: var(--muted); font-size: .86rem; }
.student-retry-note { margin-top: .2rem; color: var(--warn); font-size: .82rem; }
.student-primary-action {
  flex: none; min-height: 2.75rem; padding: .62rem .85rem; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: .9rem; font-weight: 700;
}
.student-empty { display: grid; gap: .25rem; color: var(--muted); }
.student-empty b { color: var(--fg); }
.student-overview { background: var(--code-bg); }
.student-stat-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem;
  margin-top: .9rem;
}
.student-stat-grid > div {
  display: grid; gap: .1rem; padding: .8rem; border-radius: 10px; background: var(--card);
}
.student-stat-grid b { font-size: 1.35rem; }
.student-stat-grid span { color: var(--muted); font-size: .78rem; }
.student-last-activity { margin: .8rem 0 0; color: var(--muted); font-size: .8rem; }
.student-module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-top: .9rem; }
.student-module-card {
  display: grid; min-width: 0; gap: .65rem; padding: 1rem;
  border: 1px solid var(--line); border-radius: 11px; color: var(--fg); text-decoration: none;
}
.student-module-card:hover { border-color: var(--accent); }
.student-module-top, .student-module-facts {
  display: flex; justify-content: space-between; gap: .8rem;
}
.student-module-top b { overflow-wrap: anywhere; }
.student-module-status {
  flex: none; width: fit-content; padding: .16rem .48rem; border-radius: 999px;
  background: var(--code-bg); color: var(--muted); font-size: .72rem; white-space: nowrap;
}
.student-progress-track { height: .35rem; overflow: hidden; border-radius: 999px; background: var(--code-bg); }
.student-progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--ok); }
.student-module-facts { color: var(--muted); font-size: .78rem; }
.student-page-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  min-height: 2.75rem; margin-bottom: .85rem;
}
.student-page-nav > a, .student-page-actions > a { color: var(--accent); font-weight: 600; text-decoration: none; }
.student-page-actions { display: flex; align-items: center; gap: 1rem; }
.student-module-now { border-color: var(--accent); }
.student-waiting { color: var(--warn); }
.student-task-card-single { margin-top: .9rem; }
.student-stat-grid-compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.student-trajectory {
  display: flex; align-items: stretch; gap: .6rem; overflow-x: auto;
  margin-top: .9rem; padding: .1rem 0 .5rem;
}
.student-trajectory-node {
  display: grid; flex: 0 0 12.5rem; align-content: start; gap: .45rem; min-height: 8.5rem;
  padding: .85rem; border: 1px solid var(--line); border-radius: 11px;
  color: var(--fg); text-decoration: none;
}
.student-trajectory-node.current { border: 2px solid var(--accent); }
.student-trajectory-node:only-child { flex-basis: 100%; min-height: 0; }
.student-trajectory-node.redirected { border-style: dashed; opacity: .72; }
.student-trajectory-state { margin-top: auto; color: var(--ok); font-size: .8rem; font-weight: 700; }
.student-trajectory-arrow {
  flex: none; align-self: center; max-width: 4rem; color: var(--muted);
  font-size: .72rem; text-align: center;
}
.student-teacher-decision {
  padding: .45rem; border-radius: 7px; background: var(--warn-bg);
  color: var(--warn); font-size: .75rem;
}
.student-module-chat textarea, .student-standalone-chat textarea { min-height: 5.5rem; }
.student-module-chat button, .student-standalone-chat button { min-height: 2.75rem; margin-top: .3rem; }
.student-ui .chat-message { border-radius: 14px; }
.student-ui .chat-message.mine { border-bottom-right-radius: 4px; }
.student-ui .chat-message.theirs { border-bottom-left-radius: 4px; }
.student-feedback-item { display: grid; gap: .25rem; padding: .65rem 0; border-top: 1px solid var(--line); }
.student-feedback-item:first-of-type { border-top: 0; }
.student-resources .resource-links { margin-top: .8rem; }
.student-ui .resource-link { min-height: 3.4rem; align-items: center; }
.student-assignment-rule { margin: -.2rem 0 1rem; color: var(--muted); font-size: .86rem; }
.student-attempt { color: var(--muted); font-size: .82rem; }
.student-exercises { margin: 0; padding: 0; list-style: none; counter-reset: exercise; }
.student-exercises > li { padding: 1.2rem 0; border-top: 1px solid var(--line); }
.student-exercises > li:first-child { border-top: 0; }
.student-exercise-label { margin-bottom: .35rem; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.student-ui .student-answer { min-height: 3rem; margin-top: .7rem; font-size: 1rem; }
.student-ui button, .student-ui .button-link { min-height: 44px; }
.student-carried-answer { display: grid; gap: .15rem; margin-top: .65rem; color: var(--ok); font-size: .84rem; }
.student-inline-feedback { margin-top: .65rem; padding: .65rem; border-radius: 8px; background: var(--warn-bg); color: var(--warn); }
.student-submit-bar { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.student-submit-bar button { min-height: 3rem; }
.student-submit-bar span { color: var(--muted); font-size: .8rem; }
.student-assignment-state { text-align: center; }
.student-assignment-state form { margin-top: .8rem; }
.student-success-mark {
  display: grid; place-items: center; width: 3rem; height: 3rem; margin: 0 auto .6rem;
  border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: 1.4rem; font-weight: 800;
}
.student-result { max-width: 42rem; margin: 3rem auto 0; padding: 2.2rem; text-align: center; }
.student-result-kicker {
  margin: 0; color: var(--ok); font-size: .78rem; font-weight: 800;
  letter-spacing: .04em; text-transform: uppercase;
}
.student-result h2 { margin: .3rem 0; font-size: clamp(1.8rem, 6vw, 2.8rem); }
.student-result-note { max-width: 31rem; margin: 0 auto; color: var(--muted); }
.student-result-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem;
  margin: 1.6rem 0;
}
.student-result-stats > div {
  display: grid; gap: .2rem; padding: 1rem .6rem; border-radius: 10px; background: var(--code-bg);
}
.student-result-stats b { font-size: 1.5rem; }
.student-result-stats span { color: var(--muted); font-size: .78rem; }
.student-result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.student-result-actions .button-link { justify-content: center; min-height: 3rem; }
.student-result-actions .button-link:first-child {
  border-color: var(--accent); background: var(--accent); color: #fff;
}
.student-ui a:focus-visible, .student-ui button:focus-visible,
.student-ui input:focus-visible, .student-ui textarea:focus-visible,
.student-ui select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, white); outline-offset: 2px;
}
.student-history details > summary, .student-answer-key details > summary { min-height: 2.75rem; padding: .55rem 0; }
.student-history-list { display: grid; gap: 1rem; margin-top: .7rem; }
.student-history-task { display: grid; gap: .45rem; }
.student-history-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem 1rem;
  padding: .6rem; border-radius: 8px; background: var(--code-bg); font-size: .84rem;
}
.student-history-row .student-item-meta { grid-column: 1 / -1; }
.student-history-result { font-weight: 700; }
.student-answer-key ol { display: grid; gap: .8rem; padding-left: 1.4rem; }
.student-answer-key li { padding-left: .3rem; }
.student-answer-key li > span, .student-answer-key li > b { display: block; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 700px) {
  body.student-ui { padding: 1rem .8rem 3rem; }
  .student-ui section { padding: 1rem; border-radius: 12px; }
  .student-name { display: none; }
  .student-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .student-stat-grid-compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .student-module-grid { grid-template-columns: 1fr; }
  .student-task-card { align-items: flex-start; flex-direction: column; }
  .student-primary-action { width: 100%; text-align: center; }
  .student-module-facts { flex-direction: column; gap: .1rem; }
  .student-trajectory { flex-direction: column; overflow-x: visible; }
  .student-trajectory-node { flex-basis: auto; min-height: 0; }
  .student-trajectory-arrow { align-self: flex-start; max-width: none; padding-left: .85rem; }
  .student-submit-bar { align-items: stretch; flex-direction: column; }
  .student-submit-bar button { width: 100%; }
  .student-history-row { grid-template-columns: 1fr; }
  .student-history-row .student-item-meta { grid-column: auto; }
  .student-result { margin-top: 1rem; padding: 1.4rem 1rem; }
  .student-result-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
  .student-result-stats > div { padding: .8rem .3rem; }
  .student-result-stats span { font-size: .7rem; }
  .student-result-actions { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .student-header { align-items: center; }
  .student-page-actions { width: 100%; justify-content: space-between; }
  .student-page-actions .button-link { justify-content: center; }
  .student-inbox-item { align-items: flex-start; }
}
