:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ef;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --p2: #7b3fd0;
  --p2-soft: #f1e9fd;
  --ok: #2b8a3e;
  --ok-soft: #e6f6ea;
  --mid: #b07400;
  --mid-soft: #fff4d6;
  --bad: #c92a2a;
  --bad-soft: #fdecec;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: .4em 0 .5em; line-height: 1.25; }
h2 { font-size: 1.25rem; margin: 1.6em 0 .6em; }
h3 { font-size: 1.05rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
code { background: #f0f2f7; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }

/* top bar */
.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand.big { font-size: 1.5rem; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.user { display: flex; gap: 12px; align-items: center; font-size: .9rem; }
.user form { margin: 0; }
.linklike { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.linklike:hover { color: var(--bad); }

/* cards and layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.card.narrow { max-width: 460px; }
.grid { display: grid; gap: 14px; }
.cards3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.card.action { display: block; color: var(--text); transition: border-color .15s, transform .15s; }
.card.action:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.action-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; color: var(--accent); }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* flash */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; }
.flash-ok { background: var(--ok-soft); border-color: #b7e4c0; color: #1e5e2b; }
.flash-error { background: var(--bad-soft); border-color: #f5c2c2; color: #8a1f1f; }
.flash-secret { background: #fff8e1; border-color: #f3d27a; font-family: ui-monospace, Consolas, monospace; font-size: .95rem; }

/* forms */
label { display: block; margin-bottom: 12px; font-size: .92rem; color: var(--muted); }
label.inline, label.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); margin: 0 10px 0 0; }
label.check { margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; color: var(--text);
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
label.inline select, label.check input { width: auto; display: inline-block; margin: 0; }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-block; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: .875rem; }
.btn.big { padding: 13px 26px; font-size: 1.05rem; }
.btn.wide { width: 100%; }
.btn.disabled { opacity: .45; pointer-events: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form, .inline-form { display: inline; margin: 0; }

/* login */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }

/* number badges & pills */
.num {
  display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .9rem;
}
.num.p2 { background: var(--p2-soft); color: var(--p2); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.pill.good { background: var(--ok-soft); color: var(--ok); }
.pill.mid { background: var(--mid-soft); color: var(--mid); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.none { background: #f0f2f7; color: var(--muted); }

.progress-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.progress-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; color: var(--text);
}
a.progress-item:hover { border-color: var(--accent); text-decoration: none; }

/* practice */
.number-list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.number-row { display: grid; grid-template-columns: 34px 1fr auto auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.number-row:last-child { border-bottom: 0; }
.number-topic { color: var(--text); font-weight: 500; }

.task-list { display: flex; flex-direction: column; gap: 8px; }
.task-item { display: flex; gap: 12px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--text); }
.task-item:hover { border-color: var(--accent); text-decoration: none; }
.task-preview { flex: 1; min-width: 0; }
.rich.clamp { font-size: .98rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rich.clamp p { margin: 0; display: inline; }
.rich.clamp .katex-display { display: inline; margin: 0; }
.status { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-weight: 700; flex-shrink: 0; font-size: .9rem; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.bad { background: var(--bad-soft); color: var(--bad); }
.status.new { background: #f0f2f7; color: var(--muted); }

.task-card { padding: 22px 24px; }
.task-head { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.rich { font-size: 1.05rem; overflow-wrap: anywhere; }
.rich p { margin: .5em 0; }
.rich img { max-width: 100%; }
.rich .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.task-img { display: block; max-width: 100%; max-height: 380px; margin: 12px 0; border-radius: 8px; }
.answer-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.answer-form input { width: 220px; margin: 0; }
.verdict { margin-top: 16px; padding: 10px 14px; border-radius: 10px; font-weight: 600; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict.mid { background: var(--mid-soft); color: var(--mid); }
.verdict-inline.ok { color: var(--ok); font-weight: 600; }
.verdict-inline.bad { color: var(--bad); font-weight: 600; }
.pager { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.pager form { margin: 0; }
details summary { cursor: pointer; font-weight: 600; }
details[open] summary { margin-bottom: 10px; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { background: #fafbfd; font-size: .85rem; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; }
.matrix th, .matrix td { text-align: center; padding: 7px 6px; }
.matrix td:first-child, .matrix th:first-child { text-align: left; padding-left: 12px; }
.cell-ok { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.cell-mid { background: var(--mid-soft); color: var(--mid); font-weight: 600; }
.cell-bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }

/* variants */
.variant-list { display: flex; flex-direction: column; gap: 0; }
.variant-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.variant-title { font-weight: 600; font-size: 1.05rem; }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 4px 16px; margin: 10px 0 16px; }
.variant-row { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--text); }
.variant-row select { margin: 0; }

.exam-bar {
  position: sticky; top: 52px; z-index: 10; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; box-shadow: 0 4px 14px rgba(20, 30, 60, .06);
}
.exam-title { font-weight: 600; }
.exam-nav, .result-strip { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.result-strip { margin: 14px 0; }
.exam-dot {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); color: var(--muted); font-size: .82rem; font-weight: 600; background: #fff;
}
.exam-dot:hover { text-decoration: none; border-color: var(--accent); }
.exam-dot.p2 { border-style: dashed; }
.exam-dot.filled { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); }
.exam-dot.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-soft); }
.exam-dot.mid { background: var(--mid-soft); color: var(--mid); border-color: var(--mid-soft); }
.exam-dot.bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-soft); }
.exam-timer { font: 700 1.25rem ui-monospace, Consolas, monospace; }
.exam-timer.warn { color: var(--bad); }
.exam-task { scroll-margin-top: 130px; }
.finish-form { text-align: center; margin: 24px 0; }

.score-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.score-big { font-size: 2.6rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.score-mid { font-size: 1.6rem; font-weight: 700; line-height: 1.3; }

/* admin */
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 5px 10px; border-radius: 99px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: .9rem; }
.chip small { color: var(--muted); margin-left: 2px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active small { color: #dfe5ff; }
.chip.empty { opacity: .6; }
.chip:hover { text-decoration: none; border-color: var(--accent); }

.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.editor-preview { position: sticky; top: 70px; min-height: 200px; }
.help { margin: 4px 0 16px; font-size: .9rem; }
.help ul { margin: 6px 0; padding-left: 20px; }
.current-image { margin-bottom: 12px; }
.inline-create { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.inline-create label { margin: 0; flex: 1; min-width: 150px; }
ul.plain { margin: 0; padding-left: 20px; }
ul.plain li { margin: 4px 0; }
.article h1 { margin-top: .2em; }

@media (max-width: 760px) {
  h1 { font-size: 1.4rem; }
  .editor { grid-template-columns: 1fr; }
  .editor-preview { position: static; }
  .row2 { grid-template-columns: 1fr; }
  .variant-grid { grid-template-columns: 1fr; }
  .number-row { grid-template-columns: 34px 1fr auto; }
  .number-row .muted.small, .number-row .btn { display: none; }
  .task-card { padding: 16px; }
  .answer-form input { width: 100%; }
  .exam-bar { top: 0; position: sticky; }
  .topbar { position: static; }
  .table th, .table td { padding: 7px 8px; }
}

/* --- ДЗ, фото решений, проверка --- */
h2.flush { margin-top: 0; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--bad); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 18px; }
.pill.p2 { background: var(--p2-soft); color: var(--p2); }
.overdue { color: var(--bad); font-weight: 600; }
.upload { margin-top: 12px; }
.upload input[type=file] { padding: 8px; background: #fafbfd; border-style: dashed; cursor: pointer; }
.upload-form { margin-top: 14px; }
.upload-form .btn { margin-top: 4px; }
.solution { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: #fcfcfe; }
.solution-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.comment { margin-top: 8px; padding: 8px 12px; background: var(--accent-soft); border-radius: 8px; white-space: pre-wrap; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.photos img { height: 150px; max-width: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.review-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; align-items: start; }
.review-layout .photos img { height: auto; max-height: 520px; width: 100%; object-fit: contain; }
.review-layout .photos a { flex: 1 1 100%; }
.score-pick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; font-weight: 600; }
.score-option { margin: 0; }
.score-option input { position: absolute; opacity: 0; width: 1px; }
.score-option span { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 10px; font-size: 1.1rem; font-weight: 700; color: var(--text); cursor: pointer; }
.score-option input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.score-option input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.hw-group { border-top: 1px solid var(--line); padding: 8px 0; }
.hw-group summary { font-weight: 500; display: flex; gap: 8px; align-items: center; }
.task-check { display: flex !important; gap: 10px; align-items: flex-start; padding: 6px 0 6px 36px; margin: 0 !important; }
.task-check input { margin-top: 4px !important; flex-shrink: 0; }
.task-check .rich { flex: 1; }
.student-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }
.hw-item { color: var(--text); }
.hw-item:hover { text-decoration: none; border-color: var(--accent); }
.hw-due-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.hw-due-row:last-child { border-bottom: 0; }
select.compact { padding: 5px 8px; margin: 0; width: auto; min-width: 140px; }
@media (max-width: 760px) {
  .review-layout { grid-template-columns: 1fr; }
  .task-check { padding-left: 0; }
}
