/*
  «Поля»: the app is a ruled notebook. Lists are ruled lines, not cards.
  The navigation sits in the notebook margin behind the red margin line.
  A sheet is a squared page, and marks (+, ±, −) are written in its margin.
  Green, amber and red are used only for results: the marks (+, ±, −) and, in the lesson grid,
  whether a held lesson is paid for (green) or still owed (red).
*/

:root {
  --paper: #fbfcfe;
  --sheet: #ffffff;
  --ink: #1b2a4a;
  --ink-2: #55627d;
  --rule: #d5deea;
  --rule-strong: #8393ae;
  --grid: #e3eaf4;
  --wash: #eef2f8;
  --pen: #2447b8;
  --red-line: #d9505c;
  --red: #b5303d;
  --green: #23704b;
  --amber: #8a5a0b;
  --amber-line: #c98a12;

  --font-ui: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --font-task: "Literata", Georgia, "Times New Roman", serif;
  --r: 6px;
  --rail-w: 13.5rem;
  --tab-h: 3.75rem;
  --control-h: 2.75rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--font-ui);
}

h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
h1 { font: 600 1.75rem/1.2 var(--font-ui); letter-spacing: -0.01em; }
h2 { font: 600 1.1875rem/1.3 var(--font-ui); }
h3 { font: 600 1rem/1.4 var(--font-ui); }

a { color: var(--pen); text-underline-offset: 0.18em; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
[hidden] { display: none !important; }

/* A utility class: !important so that general rules for fields (input[type="file"] { width: 100% })
   cannot make a hidden element visible or wider than the page. */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.muted { color: var(--ink-2); }

/* ---------- shell ---------- */

.rail {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--sheet);
  border-top: 2px solid var(--red-line);
  padding-bottom: env(safe-area-inset-bottom);
}

.brand, .rail-note { display: none; }

.rail-nav { display: grid; grid-template-columns: repeat(5, 1fr); }

.rail-nav a {
  display: grid;
  place-items: center;
  min-height: var(--tab-h);
  color: var(--ink-2);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 3px solid transparent;
}

.rail-nav a[aria-current] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--ink);
}

/* Backup reminder. Ink blue on purpose: green, amber and red are kept for marks. */
.rail-nav a[data-due] {
  grid-auto-flow: column;
  justify-content: center;
  gap: 0.375rem;
}

.rail-nav a[data-due]::after {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--pen);
}

.view {
  max-width: 70rem;
  padding: 1.25rem 1rem calc(var(--tab-h) + 2.5rem);
}

@media (min-width: 60rem) {
  .app {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    min-height: 100dvh;
  }

  .rail {
    position: sticky;
    top: 0;
    left: auto;
    right: auto;
    bottom: auto;
    align-self: start;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding: 1.75rem 1rem 1.25rem 1.5rem;
    background: transparent;
    border-top: 0;
    border-right: 2px solid var(--red-line);
  }

  .brand {
    display: block;
    color: var(--ink);
    font: italic 500 2rem/1 var(--font-task);
    text-decoration: none;
  }

  .rail-nav { display: flex; flex-direction: column; gap: 0.125rem; }

  .rail-nav a {
    display: block;
    min-height: 0;
    margin-left: -0.75rem;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: var(--r);
    font-size: 1rem;
  }

  .rail-nav a:hover { background: var(--wash); }
  .rail-nav a[aria-current] { background: var(--wash); }
  .rail-nav a[data-due]::after { margin-left: 0.375rem; vertical-align: 0.0625rem; }

  .rail-note {
    display: block;
    margin-top: auto;
    color: var(--ink-2);
    font-size: 0.8125rem;
    line-height: 1.4;
  }

  .view { padding: 2rem 2.5rem 4rem; }
}

.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.back {
  display: inline-block;
  margin-bottom: 0.375rem;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.section { margin-top: 2.5rem; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.prose { max-width: 42rem; }
.prose > * + * { margin-top: 0.75rem; }
.prose ul { padding-left: 1.25rem; }
.prose li + li { margin-top: 0.375rem; }

.danger-zone { margin-top: 3rem; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-h);
  padding: 0 1rem;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  background: var(--sheet);
  color: var(--ink);
  font: 500 0.9375rem/1.2 var(--font-ui);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { background: var(--wash); }
.btn--primary { background: var(--ink); color: #fff; }
.btn--primary:hover { background: #2a3e6b; }
.btn--danger { border-color: var(--red); color: var(--red); }
.btn--danger:hover { background: #fbe9eb; }
.btn--small { min-height: 2.25rem; padding: 0 0.75rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* A label-button around a hidden file input: show the focus on the button the person sees. */
.btn:has(> input.visually-hidden:focus-visible) { outline: 2px solid var(--pen); outline-offset: 2px; }

.picker, .picker-preview { display: grid; gap: 0.5rem; justify-items: start; }
.picker .task-img { max-height: 16rem; width: auto; }

.btn-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--pen);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.btn-link--danger { color: var(--red); }

.btn-icon {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: none;
  color: var(--ink);
  font: 400 1rem/1 var(--font-ui);
  cursor: pointer;
}

.btn-icon:hover { background: var(--wash); }
.btn-icon:disabled { opacity: 0.3; cursor: not-allowed; }

@media (pointer: coarse) {
  .btn--small { min-height: var(--control-h); }
  .btn-icon { width: var(--control-h); height: var(--control-h); }
  .btn-link { min-height: var(--control-h); }
}

input[type="text"], input[type="search"], input[type="date"], input[type="time"], input[type="number"],
input[type="file"], select, textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
}

textarea { display: block; resize: vertical; line-height: 1.5; }
::placeholder { color: #7a869d; opacity: 1; }

.form { display: grid; gap: 1rem; }
.form-grid { display: grid; gap: 1rem; }
@media (min-width: 36rem) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.field { display: grid; gap: 0.25rem; align-content: start; min-width: 0; }
.field-label { font-size: 0.9375rem; font-weight: 500; }
.field-hint { color: var(--ink-2); font-size: 0.875rem; }
.field-error { color: var(--red); font-weight: 500; }
.field-error:empty, .status:empty { display: none; }
.status { color: var(--ink-2); }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--control-h);
  font-weight: 500;
  cursor: pointer;
}

.check input { width: 1.125rem; height: 1.125rem; margin: 0; accent-color: var(--ink); }

.seg {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r);
  background: var(--sheet);
  overflow: hidden;
}

.seg-opt { position: relative; cursor: pointer; }
.seg-opt + .seg-opt { border-left: 1px solid var(--rule-strong); }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span {
  display: grid;
  place-items: center;
  min-height: calc(var(--control-h) - 2px);
  padding: 0 0.75rem;
  font-size: 0.9375rem;
}
.seg-opt input:checked + span { background: var(--ink); color: #fff; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--pen); outline-offset: -3px; }

.filters {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

@media (min-width: 44rem) {
  .filters { grid-template-columns: minmax(12rem, 2fr) repeat(3, minmax(0, 1fr)); align-items: center; }
  .filters .check { grid-column: 1 / -1; }
}

/* ---------- ruled lists ---------- */

.rows { border-top: 1px solid var(--rule); }
.rows--bare { border-top: 0; }

.row {
  display: block;
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}

.row--link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  color: inherit;
  text-decoration: none;
}

.row--link:hover { background: var(--wash); box-shadow: -0.75rem 0 0 var(--wash), 0.75rem 0 0 var(--wash); }
.row--link:hover .row-title { text-decoration: underline; text-underline-offset: 0.18em; }
.row-title { font-size: 1.0625rem; font-weight: 600; }
.row-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; color: var(--ink-2); font-size: 0.9375rem; }

.row--mark { display: grid; grid-template-columns: 2.5rem minmax(0, 1fr); gap: 0.5rem; align-items: start; }
.row--mark .mark { font-size: 2.25rem; justify-self: center; }
.row--picked { background: var(--wash); box-shadow: -0.75rem 0 0 var(--wash), 0.75rem 0 0 var(--wash); }

.row-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 0.625rem;
}

.row-actions { display: flex; gap: 1.25rem; }

.row--split {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
}

/* ---------- lessons ---------- */

.week-range { font-size: 1.0625rem; font-weight: 500; }
.week { max-width: 52rem; }
.day { margin-top: 1.75rem; }

.day-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 1.0625rem;
}

.day-head > span:first-child::first-letter { text-transform: uppercase; }
.day-add { margin-left: auto; font-weight: 400; font-size: 0.9375rem; }
.day-empty { padding: 0.5rem 0; border-top: 1px solid var(--rule); font-size: 0.9375rem; }
.day--today .day-head { color: var(--pen); }

.lesson {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr);
  gap: 0.5rem 0.75rem;
  align-items: start;
}

.lesson-time { font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.6; }
.lesson-main { display: grid; gap: 0.125rem; min-width: 0; }
.lesson-main .row-title a { color: inherit; }
.lesson-main .row-title::first-letter { text-transform: uppercase; }
.lesson-main .muted { font-size: 0.9375rem; overflow-wrap: anywhere; }

.lesson-side {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

.lesson-marks { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.lesson--off .lesson-time, .lesson--off .row-title { color: var(--ink-2); text-decoration: line-through; }

@media (min-width: 44rem) {
  .lesson { grid-template-columns: 3.25rem minmax(0, 1fr) auto; align-items: center; }
  .lesson-side { grid-column: 3; justify-content: flex-end; }
}

/* The week as a grid by hour. On a narrow screen it scrolls sideways under a fixed hour column. */
.week--grid { max-width: none; }

.grid-scroll {
  position: relative;
  margin-top: 0.75rem;
  overflow-x: auto;
  border: 1px solid var(--rule);
  background: var(--sheet);
}

.grid {
  --hour: 3.5rem;
  display: grid;
  grid-template-columns: 3.25rem repeat(7, minmax(7.25rem, 1fr));
  min-width: max-content;
}

.grid-corner, .grid-gutter {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--sheet);
  border-right: 1px solid var(--rule);
}

.grid-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  padding: 0.125rem 0.125rem 0.125rem 0.5rem;
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule-strong);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.grid-corner { border-bottom: 1px solid var(--rule-strong); }
.grid-weekday { color: var(--ink-2); font-weight: 500; }
.grid-day-head--today, .grid-day-head--today .grid-weekday { color: var(--pen); }
.grid-add { width: 2rem; height: 2rem; color: var(--pen); font-size: 1.125rem; }

.grid-hour-label {
  height: var(--hour);
  padding: 0.125rem 0.375rem 0 0;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.grid-gutter--untimed {
  padding: 0.375rem 0.375rem 0.375rem 0.125rem;
  border-bottom: 1px solid var(--rule-strong);
  color: var(--ink-2);
  font-size: 0.6875rem;
  line-height: 1.2;
  text-align: right;
}

.grid-untimed {
  display: grid;
  gap: 2px;
  align-content: start;
  padding: 2px;
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule-strong);
}

.grid-col { position: relative; height: calc(var(--hours) * var(--hour)); border-left: 1px solid var(--rule); }
.grid-col--today { background: var(--wash); }
.grid-hour { height: var(--hour); }
.grid-hour + .grid-hour { border-top: 1px solid var(--grid); }

.slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.1875rem 0.375rem;
  overflow: hidden;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  background: var(--sheet);
  color: var(--ink-2);
  font: 400 0.75rem/1.3 var(--font-ui);
  text-align: left;
  cursor: pointer;
}

.grid-col .slot { position: absolute; }
.slot:hover { border-color: var(--ink); }
.slot-time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.slot-name { color: var(--ink); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-state { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.slot--short .slot-time { display: none; }

.swatch { width: 0.875rem; height: 0.875rem; border: 1px solid var(--rule-strong); border-radius: 3px; background: var(--sheet); }

.slot--paid { border-color: var(--green); background: #e4f3ea; color: var(--green); }
.slot--due { border-color: var(--red); background: #fbe6e8; color: var(--red); }
.slot--paid .slot-name, .slot--due .slot-name { color: inherit; }
.slot--off { border-style: dashed; background: var(--paper); }
.slot--off .slot-name { color: var(--ink-2); text-decoration: line-through; }

.grid-legend { display: flex; flex-wrap: wrap; gap: 0.375rem 1.25rem; font-size: 0.875rem; }
.grid-legend-item { display: inline-flex; align-items: center; gap: 0.375rem; }

.seg--wrap { flex-wrap: wrap; }
.dialog-foot-left { margin-right: auto; }
.section-note { margin-bottom: 0.75rem; font-size: 0.9375rem; }
.balance { font-size: 1.1875rem; font-weight: 600; }
.more { margin-top: 0.75rem; }

.task-body { display: grid; gap: 0.5rem; min-width: 0; }

.task-text {
  max-width: 44rem;
  font: 400 1.0625rem/1.6 var(--font-task);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.task-img {
  display: block;
  max-width: min(100%, 36rem);
  height: auto;
  border: 1px solid var(--rule);
  background: var(--sheet);
}

.task-body--clamp .task-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  font-size: 0.9375rem;
  line-height: 1.5;
}

.task-body--clamp .task-img { max-height: 6rem; width: auto; }

.task-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 0.875rem;
  color: var(--ink-2);
  font-size: 0.875rem;
}

.task-source { font-style: italic; }

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.0625rem 0.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--sheet);
  color: var(--ink);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.chip--warn { border-color: var(--amber-line); color: var(--amber); }
.chip--new { border-color: var(--green); color: var(--green); }

.dots { display: inline-flex; gap: 0.1875rem; }
.dot { width: 0.5rem; height: 0.5rem; border: 1px solid var(--ink-2); border-radius: 50%; }
.dot--on { background: var(--ink-2); }

.given { display: inline-flex; align-items: center; gap: 0.375rem; }

.empty {
  display: grid;
  justify-items: start;
  gap: 0.75rem;
  max-width: 36rem;
  padding: 2rem 0;
}

.notice {
  max-width: 44rem;
  padding: 0.625rem 0.875rem;
  border-left: 3px solid var(--amber-line);
  background: #fdf6e7;
  font-size: 0.9375rem;
}

.view > .notice { margin-bottom: 1rem; }

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.25rem 1.25rem;
  max-width: 44rem;
}

.kv dt { color: var(--ink-2); }

/* ---------- marks ---------- */

.mark {
  display: inline-block;
  font: italic 700 3rem/0.9 var(--font-task);
  transform: rotate(-7deg);
}

.mark-inline { font: italic 600 1.25rem/1 var(--font-task); }

.mark--self { color: var(--green); }
.mark--help { color: #a86c0a; }
.mark--error { color: var(--red); }

.tally { display: inline-flex; gap: 0.875rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tally-item { display: inline-flex; gap: 0.25rem; }

.topics { border-top: 1px solid var(--rule); max-width: 44rem; }

.topic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name tally" "bar bar";
  gap: 0.375rem 1rem;
  align-items: center;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--rule);
}

.topic-name { grid-area: name; }
.topic .tally { grid-area: tally; }
.bar { grid-area: bar; display: flex; gap: 2px; height: 0.5rem; }
.bar-part { min-width: 0.375rem; border-radius: 1px; }
.bar-part--self { background: var(--green); }
.bar-part--help { background: var(--amber-line); }
.bar-part--error { background: var(--red); }

.topics-note { max-width: 44rem; margin-bottom: 0.75rem; font-size: 0.9375rem; }

/* Every mark of the topic in lesson order, written the way they stand in the margin. */
.topic-trail {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.375rem;
}

.topic-trail .mark-inline { width: 0.875rem; text-align: center; }
.trail-gap { align-self: stretch; width: 1px; margin: 0.125rem 0.125rem; background: var(--rule-strong); }
.topic-fixed { margin-left: 0.5rem; font-size: 0.875rem; }

@media (min-width: 44rem) {
  .topic {
    grid-template-columns: minmax(8rem, 15rem) minmax(4rem, 1fr) auto;
    grid-template-areas: "name bar tally";
  }

  .topic-trail { grid-column: 2 / -1; }
}

/* ---------- the squared page ---------- */

.page {
  --cell: 1.375rem;
  --mw: 3.25rem;
  position: relative;
  border: 1px solid var(--rule);
  background-color: var(--sheet);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  box-shadow: 0 14px 30px -22px rgba(27, 42, 74, 0.55);
}

.sheet {
  max-width: 50rem;
  margin-top: 1rem;
  padding: 1.5rem 0 2rem 0.75rem;
}

.sheet::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: var(--mw);
  width: 2px;
  background: var(--red-line);
}

.sheet-head { margin-bottom: 1rem; padding-right: calc(var(--mw) + 1rem); }
.sheet-title { font: 500 1.5rem/1.25 var(--font-task); }
.sheet-sub { color: var(--ink-2); }

.sheet-tasks { margin: 0; padding: 0; list-style: none; }

.sheet-task {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr) var(--mw);
  padding: 0.875rem 0;
}

.sheet-task-main { padding-right: 0.875rem; }
.sheet-margin { display: grid; justify-items: center; align-content: start; }
.num { color: var(--ink-2); font: 500 1.0625rem/1.6 var(--font-task); }

.mark-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

.mark-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  min-height: var(--control-h);
  padding: 0 0.875rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--sheet);
  color: var(--ink);
  font: 500 0.9375rem/1 var(--font-ui);
  cursor: pointer;
}

.mark-btn:hover { background: var(--wash); }
.mark-btn-sym { font: italic 600 1.25rem/1 var(--font-task); }
.mark-btn[aria-pressed="true"][data-mark="self"] { border-color: var(--green); background: #e4f3ea; color: var(--green); }
.mark-btn[aria-pressed="true"][data-mark="help"] { border-color: var(--amber-line); background: #fbf0d9; color: var(--amber); }
.mark-btn[aria-pressed="true"][data-mark="error"] { border-color: var(--red); background: #fbe6e8; color: var(--red); }

.answers {
  margin: 1.5rem calc(var(--mw) + 1rem) 0 0;
  padding-top: 1rem;
  border-top: 1px dashed var(--rule-strong);
}

.answers ol { margin-top: 0.5rem; padding-left: 1.75rem; font-family: var(--font-task); }

@media (min-width: 44rem) {
  .page { --mw: 4.5rem; }
  .sheet { padding-left: 1.75rem; }
}

.summary { max-width: 50rem; }
.summary h3 { margin: 1.5rem 0 0.5rem; }
.summary .actions { margin-top: 0.75rem; }
.summary .field-hint { margin-top: 0.375rem; }

.totals { display: flex; flex-wrap: wrap; gap: 0.75rem 2.5rem; margin-top: 0.75rem; }
.total { display: grid; }
.total-num { font: italic 600 1.75rem/1.2 var(--font-task); font-variant-numeric: tabular-nums; }

.repeat { padding: 0; list-style: none; }
.repeat li { display: flex; align-items: center; gap: 0.625rem; padding: 0.25rem 0; }
.repeat .mark-inline { width: 1rem; text-align: center; }

/* ---------- sheet builder ---------- */

.builder { display: grid; gap: 1.5rem; }
.builder > * { min-width: 0; }

.page--draft { padding: 1.25rem 1rem; }
.page--draft .muted { margin-top: 1rem; }

.mini-list { margin: 1rem 0 0; padding: 0; list-style: none; }

.mini {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto;
  gap: 0.375rem;
  align-items: start;
  padding: 0.625rem 0;
  border-top: 1px solid var(--rule);
  background: var(--sheet);
}

.mini .num { font-size: 0.9375rem; line-height: 1.5; }
.mini-actions { display: flex; }

@media (min-width: 72rem) {
  .builder { grid-template-columns: minmax(0, 1fr) minmax(20rem, 25rem); gap: 2rem; align-items: start; }
  .builder-pick { grid-column: 1; grid-row: 1; }
  .builder-sheet {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: 1rem;
    max-height: calc(100dvh - 7rem);
    overflow: auto;
  }
}

.savebar {
  position: sticky;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.5rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.savebar-count { font-weight: 500; }

@media (min-width: 60rem) {
  .savebar { bottom: 0; }
}

/* ---------- add materials ---------- */

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.75rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
  counter-reset: step;
  color: var(--ink-2);
}

.steps li { counter-increment: step; }
.steps li::before { content: counter(step) ". "; }
.steps li[aria-current] { color: var(--ink); font-weight: 600; }

.import-source, .review, .crop { display: grid; gap: 1rem; max-width: 52rem; }

.dropzone {
  display: grid;
  gap: 0.25rem;
  justify-items: center;
  padding: 2rem 1rem;
  border: 2px dashed var(--rule-strong);
  border-radius: var(--r);
  background: var(--sheet);
  text-align: center;
  cursor: pointer;
}

.dropzone span { max-width: 30rem; color: var(--ink-2); font-size: 0.9375rem; }
.dropzone:hover, .dropzone--over { border-color: var(--pen); background: #f1f5fe; }
.dropzone:focus-within { outline: 2px solid var(--pen); outline-offset: 2px; }

.or { color: var(--ink-2); text-align: center; }

.crop-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.pager { display: flex; align-items: center; gap: 0.75rem; }

.crop-stage {
  position: relative;
  border: 1px solid var(--rule-strong);
  background: var(--sheet);
  user-select: none;
  -webkit-user-select: none;
}

.crop-stage img { display: block; width: 100%; height: auto; }
.crop-overlay { position: absolute; inset: 0; cursor: crosshair; touch-action: none; }
.crop-rect { position: absolute; border: 2px solid var(--pen); background: rgba(36, 71, 184, 0.12); }
.crop-rect--drawing { pointer-events: none; border-style: dashed; }

.crop-num {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0 0.375rem;
  background: var(--pen);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
}

.crop-del {
  position: absolute;
  top: -0.875rem;
  right: -0.875rem;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.75rem;
  cursor: pointer;
}

.bulk { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem; }
.bulk .field { flex: 1 1 14rem; }

.cands { border-top: 1px solid var(--rule); }

.cand {
  display: grid;
  gap: 0.625rem;
  padding: 1rem 0 1.25rem;
  border-bottom: 1px solid var(--rule);
}

.cand--off > :not(.check) { opacity: 0.4; }
.cand-text { font: 400 1.0625rem/1.6 var(--font-task); }
.cand-fields { display: grid; gap: 0.75rem; align-items: start; }
.cand .btn-link { justify-self: start; }

@media (min-width: 48rem) {
  .cand-fields { grid-template-columns: minmax(0, 1.2fr) auto minmax(0, 1fr); }
}

/* ---------- tables, dialogs, toasts ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.table th, .table td { padding: 0.375rem 0.75rem 0.375rem 0; border-bottom: 1px solid var(--rule); text-align: left; white-space: nowrap; }
.table th { color: var(--ink-2); font-weight: 500; }

.dialog {
  width: min(38rem, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 60px -20px rgba(27, 42, 74, 0.6);
}

.dialog::backdrop { background: rgba(27, 42, 74, 0.45); }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0 1.25rem;
}

.dialog-body { padding: 1rem 1.25rem 1.25rem; }
.dialog-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 100;
  display: grid;
  gap: 0.5rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 0.625rem 1rem;
  border-radius: var(--r);
  background: var(--ink);
  color: #fff;
  font-size: 0.9375rem;
  box-shadow: 0 10px 24px -12px rgba(27, 42, 74, 0.7);
}

@media (min-width: 60rem) {
  .toasts { bottom: 1.5rem; }
}

/* ---------- print: the student gets a clean sheet without marks ---------- */

@media print {
  body { background: #fff; }
  .rail, .toasts, .view-head, .mark-row, .sheet-margin, .summary, .danger-zone, .no-print { display: none !important; }
  .grid-scroll { overflow: visible; }
  .app { display: block; }
  .view { max-width: none; padding: 0; }
  .page { border: 0; background: none; box-shadow: none; }
  .sheet { max-width: none; margin: 0; padding: 0; }
  .sheet::after { display: none; }
  .sheet-head { padding-right: 0; }
  .sheet-task { grid-template-columns: 1.75rem minmax(0, 1fr); break-inside: avoid; }
  .sheet-task-main { padding-right: 0; }
  .answers { margin-right: 0; break-before: page; border-top: 0; }
}
