:root {
  --bg: #f4f1ea;
  --paper: #fbf9f4;
  --ink: #1d1b17;
  --muted: #6d675d;
  --faint: #a39c90;
  --line: #ddd6c9;
  --line-strong: #c4bba9;
  --accent: #2d5a86;
  --accent-ink: #ffffff;
  --accent-soft: #e3eaf1;
  --good: #3b7a4c;
  --bad: #b0442e;
  --warn: #9a6a12;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513;
    --paper: #1d1c19;
    --ink: #ebe6dc;
    --muted: #a29b8f;
    --faint: #6f695f;
    --line: #34312c;
    --line-strong: #4a4640;
    --accent: #8fb2d6;
    --accent-ink: #10202f;
    --accent-soft: #22303d;
    --good: #7fbf8e;
    --bad: #e48b76;
    --warn: #d8ae5c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 3px; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 34px; }
h2 { font-size: 23px; }
h3 { font-size: 18px; }
p { margin: 0 0 12px; }
.boot { padding: 40px 16px; color: var(--muted); }

/* ---------- каркас ---------- */
.top {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.top-in {
  max-width: 1040px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 28px; min-height: 60px;
}
.brand { font-family: var(--serif); font-style: italic; font-size: 20px; font-weight: 500; color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 22px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 18px 0 16px; border-bottom: 2px solid transparent;
}
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--ink); border-bottom-color: var(--ink); }
.nav .count { color: var(--bad); font-variant-numeric: tabular-nums; margin-left: 4px; }
.who { color: var(--muted); font-size: 14px; white-space: nowrap; text-decoration: none; }
.who:hover { color: var(--ink); }

main { max-width: 1040px; margin: 0 auto; padding: 36px 20px 80px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.head p { color: var(--muted); margin: 6px 0 0; }
.crumb { font-size: 14px; color: var(--muted); margin-bottom: 10px; display: inline-block; text-decoration: none; }
.crumb:hover { color: var(--ink); }
section + section { margin-top: 44px; }
section > h2 { margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 18px 0; border-top: 1px solid var(--line); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link.danger { color: var(--bad); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  background: var(--paper); border: 1px solid var(--line-strong); border-radius: 6px;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.55; }
textarea.answer { min-height: 280px; font-size: 17px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.short { max-width: 140px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { flex: 1 1 160px; }
.hint { font-size: 14px; color: var(--muted); margin-top: 6px; }
.error { color: var(--bad); margin: 0 0 14px; }
.ok { color: var(--good); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 9px 16px; cursor: pointer; border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.checks { border-top: 1px solid var(--line); }
.checks label { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.checks input { width: 18px; height: 18px; accent-color: var(--ink); }

/* ---------- таблицы ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; font-size: 13px; color: var(--muted);
  padding: 0 12px 8px 0; border-bottom: 1px solid var(--line-strong);
}
.table td { padding: 13px 12px 13px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.go { cursor: pointer; }
.table tr.go:hover td { background: color-mix(in srgb, var(--paper) 70%, transparent); }
.table .r { text-align: right; padding-right: 0; }
.table td a.title { color: var(--ink); text-decoration: none; font-weight: 500; }
.table td a.title:hover { text-decoration: underline; }
.st { font-size: 14px; white-space: nowrap; }
.st.todo { color: var(--ink); }
.st.returned, .st.late { color: var(--bad); }
.st.submitted { color: var(--warn); }
.st.graded { color: var(--muted); }
.up { color: var(--good); }
.down { color: var(--bad); }
.same { color: var(--muted); }

@media (max-width: 680px) {
  .table.stack thead { display: none; }
  .table.stack tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .table.stack td { display: block; border: 0; padding: 2px 0; text-align: left; }
  .table.stack td[data-l]::before { content: attr(data-l) " · "; color: var(--muted); font-size: 13px; }
}

/* ---------- задание и ответ ---------- */
.task {
  font-size: 17px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere;
  padding: 20px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.task.plain { border: 0; padding: 0; }
.meta { display: flex; gap: 6px 20px; flex-wrap: wrap; color: var(--muted); font-size: 14px; margin-top: 8px; }
.files { list-style: none; padding: 0; margin: 14px 0 0; }
.files li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.files li:first-child { border-top: 1px solid var(--line); }
.files .fname { flex: 1 1 200px; overflow-wrap: anywhere; }
.files audio { width: 100%; max-width: 420px; height: 40px; }
.files img { display: block; max-width: 100%; max-height: 520px; border: 1px solid var(--line); border-radius: 4px; }
.files .imgwrap { flex-basis: 100%; }

.note {
  border-left: 3px solid var(--line-strong); padding: 4px 0 4px 16px; margin: 20px 0;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.note.bad { border-color: var(--bad); }
.note.good { border-color: var(--good); }
.note b { display: block; font-weight: 500; margin-bottom: 4px; }

.words { font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; flex-wrap: wrap; }
.words .out { color: var(--bad); }
.words .in { color: var(--good); }

.rec { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 16px 0; }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.rec .time { font-variant-numeric: tabular-nums; font-size: 20px; min-width: 60px; }
.upbar { height: 3px; background: var(--line); margin-top: 8px; }
.upbar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.answer-view { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 17px; line-height: 1.65; padding: 18px 20px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px; align-items: start; }
.aside { position: sticky; top: 84px; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; gap: 36px; } .aside { position: static; } }

.grade { border-top: 2px solid var(--ink); padding-top: 18px; }
.grade .scorein { display: flex; align-items: baseline; gap: 10px; font-size: 18px; }
.grade .scorein .input { width: 90px; font-size: 24px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- прогресс ---------- */
.big { font-family: var(--serif); font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; }
.big small { font-size: 20px; color: var(--muted); }
.prog { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 44px 48px; }
@media (max-width: 760px) { .prog { grid-template-columns: 1fr; } }
.prog-item { border-top: 2px solid var(--ink); padding-top: 14px; }
.prog-item .line1 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.prog-item .delta { font-size: 15px; margin-top: 8px; min-height: 22px; }
.chart { width: 100%; height: auto; display: block; margin-top: 14px; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--faint); font-size: 11px; font-family: var(--sans); }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .pt { fill: var(--paper); stroke: var(--accent); stroke-width: 2; }
.chart .pt.last { fill: var(--accent); }
.chart .lbl { fill: var(--ink); font-size: 12px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.attempts { list-style: none; margin: 12px 0 0; padding: 0; font-size: 14px; }
.attempts li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.attempts li a { color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attempts li a:hover { text-decoration: underline; }
.cell-score { white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell-score .d { font-size: 13px; margin-left: 6px; }

/* ---------- вход ---------- */
.auth { max-width: 400px; margin: 0 auto; padding: 12vh 20px 60px; }
.auth h1 { margin-bottom: 8px; }
.auth .lead { color: var(--muted); margin-bottom: 28px; }
.auth .btn { width: 100%; }

.creds {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 15px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; white-space: pre-wrap;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 6px; font-size: 15px;
  z-index: 20; max-width: calc(100% - 32px);
}

@media (max-width: 600px) {
  h1 { font-size: 28px; }
  main { padding: 26px 16px 70px; }
  .top { position: static; }
  .top-in { padding: 0 16px; gap: 16px; flex-wrap: wrap; min-height: 0; padding-top: 12px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; gap: 18px; }
  .nav a { padding: 10px 0 10px; }
}
