/* Site stylesheet: design tokens, self-hosted fonts and shared components.
   Fonts are declared in fonts.css: Cormorant SC (headings) and Cactus Classical Serif (body, one weight only). */

:root {
  color-scheme: light; /* native controls (dropdown lists) stay light even when the OS is dark */
  /* Owner's palette */
  --navy: #3B5183;
  --butter: #F5E283;
  --rust: #833514;
  /* Derived neutrals and states */
  --cream: #FBF7EC;
  --ink: #2B2420;
  --white: #FFFFFF;
  --green: #2F6B4F;
  --navy-tint: #E3E8F3;
  --butter-tint: #FCF6D4;
  --rust-tint: #F6E4DC;
  --green-tint: #E4F1E9;
  --line: #D9D2C3;
  --muted-ink: #6B645D;

  --font-display: "Cormorant SC", Georgia, "Times New Roman", serif;
  --font-body: "Cactus Classical Serif", Georgia, "Times New Roman", serif;
  --radius: 22px;
  --radius-small: 14px;
  --shadow: 0 6px 20px rgba(59, 81, 131, 0.12);
}

* { box-sizing: border-box; }

html { font-size: 18px; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  font-synthesis: none; /* the body font has one weight: never fake bold or italic */
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4, th, .brand, .num {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
h1 { font-size: 2.4rem; color: var(--navy); margin: 0 0 0.6rem; }
h2 { font-size: 1.7rem; color: var(--rust); margin: 1.6rem 0 0.6rem; }
/* A subheading sits close to its own content and further from the block above it. */
h3 { font-size: 1.3rem; color: var(--navy); margin: 1.4rem 0 0.5rem; }
h2 + .stack > h3:first-child { margin-top: 0; }
.stack > h3 + * { margin-top: 0.5rem; }
strong, b { font-weight: 400; color: var(--navy); }
a { color: var(--navy); text-underline-offset: 3px; }
a:hover { color: var(--rust); }
p { margin: 0.6rem 0; }
ol, ul { padding-left: 1.4rem; }

.page { max-width: 62rem; margin: 0 auto; padding: 1.2rem; }
.page-narrow { max-width: 26rem; margin: 2rem auto; }
.muted { color: var(--muted-ink); font-size: 0.85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1.2rem;
  background: var(--navy); color: var(--white);
  border-radius: var(--radius); padding: 0.9rem 1.4rem; margin-bottom: 1.4rem;
}
.topbar .brand { font-size: 1.7rem; color: var(--white); text-decoration: none; }
.topbar .brand { display: inline-flex; align-items: center; gap: 0.6rem; }
.brand-logo { height: 2.2rem; width: auto; max-width: 8rem; object-fit: contain; }
.footer-contacts { display: flex; flex-wrap: wrap; gap: 0.2rem 1.2rem; margin: 0 0 0.4rem; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 1.2rem; }
.topbar nav a { color: var(--butter); }
.topbar nav a:hover { color: var(--white); }
.topbar form { margin: 0; }
.topbar nav a[aria-current="page"] { color: var(--white); text-decoration-thickness: 3px; }
/* Tutor menu: one row on a wide screen, a «Меню» button that opens the list on a phone. */
.nav-narrow { display: none; }
.nav-narrow summary { list-style: none; }
.nav-narrow summary::-webkit-details-marker { display: none; }
@media (max-width: 767px) {
  .topbar .nav-wide { display: none; }
  .nav-narrow { display: block; }
  .nav-narrow[open] { flex-basis: 100%; }
  .nav-narrow nav { flex-direction: column; align-items: flex-start; gap: 0.8rem; margin-top: 0.8rem; }
}
.crumbs { margin: 0 0 0.3rem; font-size: 0.9rem; }
/* Footer: set apart from the last block of the page. */
footer { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px solid var(--line); }
footer > :first-child { margin-top: 0; }

/* Flash messages */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { background: var(--butter-tint); border: 1px solid var(--butter); border-radius: var(--radius-small); padding: 0.7rem 1rem; margin-bottom: 0.5rem; }
.messages li.error { background: var(--rust-tint); border-color: var(--rust); }
.messages li.success { background: var(--green-tint); border-color: var(--green); }

/* Cards and layout */
.card { background: var(--white); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1rem; }
/* Even padding: the first and last element of a card add no margin of their own (a CSRF field comes first in forms). */
.card > :first-child, .card > input[type="hidden"]:first-child + * { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
/* Related lines inside a card sit closer than on the open page; :where keeps it weaker than .stack. */
.card :where(p) { margin: 0.4rem 0; }
.grid .card { margin-bottom: 0; }
/* A card with a plain list of names (the students page). */
.name-list { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.name-list li { padding: 0.5rem 0; border-top: 1px solid #EFE8D8; }
.name-list .row { margin-top: 0.4rem; }
/* Dashboard tiles: a tinted panel with framed cards, so each tile reads as its own block. */
.tiles { background: var(--navy-tint); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem; }
.tiles > .card { border: 1px solid #BFCAE0; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; }
/* Margins of a text inside a flex row do not collapse and doubled the space between rows. */
.row > p { margin: 0; }
.row:has(> p) { row-gap: 0.3rem; } /* on a phone the button wraps under its own text, not towards the next row */
.row + .row { margin-top: 0.8rem; }
.row + .btn { margin-top: 0.8rem; }
/* A button row above cards or a table: the buttons must not stick to the content below. */
.row + :is(.grid, .card, .table-scroll, .tiles) { margin-top: 1.5rem; }
.row > .field { width: auto; flex: 1 1 10rem; } /* a select next to its button shares the line */
.text-block { white-space: pre-line; }

/* Buttons */
/* A page title with a small round action next to it (a smaller heading than the default h1). */
.title-row { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.6rem; }
.title-row h1 { font-size: 1.9rem; margin: 0; }  /* still above the h2 group names (1.7rem) */
.btn-round {
  display: inline-flex; align-items: center; justify-content: center; flex: none; width: 2.2rem; height: 2.2rem;
  font-size: 1.5rem; line-height: 1; text-decoration: none; color: var(--white); background: var(--navy); border-radius: 50%;
}
.btn-round:hover { background: #2F4269; color: var(--white); }
.btn {
  display: inline-block; min-height: 2.6rem; padding: 0.6rem 1.5rem;
  font: inherit; font-size: 1rem; line-height: 1.4; text-align: center; text-decoration: none; cursor: pointer;
  border: 2px solid transparent; border-radius: 999px;
}
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { background: #2F4269; color: var(--white); }
.btn-accent { background: var(--butter); color: var(--navy); }
.btn-accent:hover { background: #EBD767; color: var(--navy); }
.btn-ghost { background: transparent; color: var(--navy); border-color: var(--navy); }
.btn-ghost:hover { background: var(--navy-tint); color: var(--navy); }
.btn-danger { background: var(--rust); color: var(--white); }
.btn-danger:hover { background: #6B2B10; color: var(--white); }
.btn-small { min-height: 2rem; padding: 0.2rem 1rem; font-size: 0.85rem; }
.topbar .btn-ghost { color: var(--white); border-color: var(--butter); }
.topbar .btn-ghost:hover { background: var(--butter); color: var(--navy); }
.btn-block { display: block; width: 100%; }
.btn:focus-visible, a:focus-visible, .field:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.topbar a:focus-visible, .topbar .btn:focus-visible { outline-color: var(--butter); }

/* Badges and tabs */
.badge { display: inline-block; padding: 0.15rem 0.9rem; border-radius: 999px; font-size: 0.85rem; }
.badge-butter { background: var(--butter); color: var(--navy); }
.badge-navy { background: var(--navy-tint); color: var(--navy); }
.badge-rust { background: var(--rust-tint); color: var(--rust); }
.badge-green { background: var(--green-tint); color: var(--green); }
/* A badge pinned to the top right corner of a card (e.g. «ИИ» on a bank task). */
.card-marked { position: relative; padding-right: 4rem; }
.badge-corner { position: absolute; top: 0.8rem; right: 0.8rem; }
.tabs { display: inline-flex; background: var(--white); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.tabs a, .tabs span { padding: 0.5rem 1.3rem; border-radius: 999px; color: var(--navy); text-decoration: none; }
.tabs .on { background: var(--navy); color: var(--white); }

/* Forms */
label { display: block; font-size: 0.9rem; color: var(--muted-ink); margin-bottom: 0.25rem; }
.field, .card input[type="text"], .card input[type="password"], .card input[type="number"], .card input[type="datetime-local"],
.card select, .card textarea {
  width: 100%; min-height: 2.8rem; padding: 0.6rem 0.9rem;
  font: inherit; color: var(--ink); background: var(--white);
  border: 2px solid var(--line); border-radius: var(--radius-small);
}
.field:focus, .card input:focus, .card select:focus, .card textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 4px var(--navy-tint); outline: none; }
/* Dropdown lists: the site is light-only (color-scheme in :root), so the list is never black on a dark OS.
   Where the browser supports it (Chrome 135+), the list itself is styled in the site look; elsewhere the
   native list is used with the same font size and colors. Multi-line selects keep their native look. */
select, select option { font-family: var(--font-body); font-size: 0.9rem; }
select option { background: var(--white); color: var(--ink); }
@supports (appearance: base-select) {
  select:not([multiple]):not([size]), select:not([multiple]):not([size])::picker(select) { appearance: base-select; }
  select:not([multiple]):not([size]) { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; cursor: pointer; }
  select:not([multiple]):not([size])::picker-icon { color: var(--navy); }
  select:not([multiple]):not([size])::picker(select) {
    background: var(--white); color: var(--ink);
    border: 2px solid var(--navy); border-radius: var(--radius-small);
    box-shadow: var(--shadow); padding: 0.3rem; margin-top: 4px; max-height: 18rem;
  }
  select:not([multiple]):not([size]) option { display: flex; padding: 0.4rem 0.8rem; border-radius: 10px; cursor: pointer; }
  select:not([multiple]):not([size]) option:hover, select:not([multiple]):not([size]) option:focus { background: var(--butter-tint); }
  select:not([multiple]):not([size]) option:checked { background: var(--navy-tint); color: var(--navy); }
  select:not([multiple]):not([size]) option::checkmark { content: none; }
}
.form-row { margin-bottom: 1rem; }
.errorlist { list-style: none; padding: 0; margin: 0.3rem 0; color: var(--rust); font-size: 0.85rem; }
.helptext { color: var(--muted-ink); font-size: 0.85rem; }

/* Answer states */
.answer { font-size: 1.1rem; margin-top: 0.8rem; }
.answer-ok { border-color: var(--green) !important; background: var(--green-tint) !important; }
.answer-bad { border-color: var(--rust) !important; background: var(--rust-tint) !important; }
.task-ok { border-left: 6px solid var(--green); }
.task-bad { border-left: 6px solid var(--rust); }
.task-neutral { border-left: 6px solid var(--line); }
.label-ok { color: var(--green); }
.label-bad { color: var(--rust); }
.solution { background: var(--butter-tint); border-radius: var(--radius-small); padding: 0.9rem 1.1rem; margin-top: 0.8rem; white-space: pre-line; }

/* Progress bar and numbers */
.bar { height: 0.9rem; border-radius: 999px; background: var(--butter-tint); border: 1px solid #EADF9E; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--navy); border-radius: 999px; }
.num { font-size: 1.35rem; color: var(--navy); line-height: 1.1; margin: 0.3rem 0 0.6rem; }
.badge.num { margin: 0; } /* a count inside a line of text: no block margins that make the line taller */

/* Tables */
.table-scroll { overflow-x: auto; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.5rem; }
.table-scroll table { border-collapse: collapse; min-width: 100%; }
.table-scroll th, .table-scroll td { padding: 0.6rem 0.9rem; text-align: left; vertical-align: top; border-bottom: 1px solid #EFE8D8; }
.table-scroll th { color: var(--navy); font-size: 1.1rem; }
.table-scroll .badge { white-space: nowrap; }

@media (max-width: 640px) {
  html { font-size: 17px; }
  .page { padding: 0.8rem; }
  .topbar { padding: 0.8rem 1rem; }
  h1 { font-size: 2rem; }
  .card { padding: 1.1rem; }
  .table-scroll th, .table-scroll td { padding: 0.5rem 0.6rem; }
  .btn { width: 100%; }
  .topbar .btn, .row .btn-small { width: auto; }
}

/* Builder page (tutor): pick tasks from the whole bank */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.9rem; }
.builder-layout { display: grid; grid-template-columns: 1fr 20rem; gap: 1.2rem; align-items: start; }
.builder-side { position: sticky; top: 1rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.9rem; margin-bottom: 1rem; }
.filters > div { flex: 1; min-width: 10rem; }
.pick { cursor: pointer; border: 2px solid transparent; box-shadow: var(--shadow); }
.pick:hover { border-color: var(--navy-tint); }
.pick.on { border-color: var(--navy); background: var(--navy-tint); }
.pick[hidden] { display: none; }
.picked-list { padding-left: 1.4rem; margin: 0.6rem 0; }
.picked-list li { margin-bottom: 0.4rem; }
.picked-list button { font: inherit; font-size: 0.85rem; padding: 0 0.5rem; margin-left: 0.3rem; cursor: pointer; background: var(--white); border: 1px solid var(--line); border-radius: 8px; color: var(--navy); }
@media (max-width: 900px) {
  .builder-layout { grid-template-columns: 1fr; }
  .builder-side { position: static; }
}

/* Mastery levels (progress by line): 1-2 rust, 3 butter, 4 navy, 5-6 green */
.level-1, .level-2 { background: var(--rust-tint); color: var(--rust); }
.level-3 { background: var(--butter); color: var(--navy); }
.level-4 { background: var(--navy-tint); color: var(--navy); }
.level-5, .level-6 { background: var(--green-tint); color: var(--green); }
.bar-level-1 > i, .bar-level-2 > i { background: var(--rust); }
.bar-level-3 > i { background: #CDB43A; }
.bar-level-4 > i { background: var(--navy); }
.bar-level-5 > i, .bar-level-6 > i { background: var(--green); }

/* «ДЗ и результаты» (tutor): one folding card per homework, its students inside */
.results-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.8rem 1.4rem; }
.results-filters > div { flex: 1; min-width: 12rem; }
.results-filters > .results-exam { flex: 0 1 10rem; min-width: 8rem; }
.results-filters label.check { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.4rem; font-size: 1rem; color: var(--ink); cursor: pointer; }
.card.hw { padding: 1rem 1.4rem; margin-bottom: 0.7rem; }
.hw > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr); gap: 0.4rem 1.2rem; align-items: center; }
.hw > summary::-webkit-details-marker { display: none; }
.hw-title { display: flex; flex-direction: column; }
.hw-name { color: var(--navy); font-size: 1.15rem; }
.hw-name::before { content: "▸ "; display: inline-block; transition: transform 0.15s; }
.hw[open] .hw-name::before { content: "▾ "; }
.hw[open] > summary { padding-bottom: 0.8rem; border-bottom: 1px solid #EFE8D8; }
.hw-students { list-style: none; padding: 0; margin: 0.2rem 0 0.6rem; }
.hw-students li { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.5fr) auto; gap: 0.3rem 1rem; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid #EFE8D8; }
.hw-actions { display: flex; gap: 1rem; justify-content: flex-end; }
@media (max-width: 640px) {
  .card.hw { padding: 0.9rem 1rem; }
  .hw > summary { grid-template-columns: 1fr 1fr; }
  .hw-title { grid-column: 1 / -1; }
  .hw-students li { grid-template-columns: 1fr auto; }
  .hw-actions { justify-content: flex-start; }
}

/* Checkboxes (lesson marks): big enough to tap, in the site color */
input[type="checkbox"] { width: 1.5rem; height: 1.5rem; accent-color: var(--navy); cursor: pointer; }
/* A checkbox with its text on one line */
label.check { display: flex; align-items: center; gap: 0.6rem; font-size: 1rem; color: var(--ink); cursor: pointer; margin: 0.8rem 0; }

/* Schedule: a lesson is a link; a tap opens its actions under it */
.lesson-menu + .lesson-menu { margin-top: 1rem; }
.lesson-menu summary { list-style: none; cursor: pointer; }
.lesson-menu summary::-webkit-details-marker { display: none; }
.lesson-menu .lesson-who { color: var(--navy); text-decoration: underline; text-underline-offset: 3px; }
.lesson-menu summary:hover .lesson-who { color: var(--rust); }
.lesson-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; margin-top: 0.7rem; padding-left: 0.8rem; border-left: 3px solid var(--navy-tint); }
.lesson-actions form { margin: 0; }

/* A window over the page (popover), e.g. «Добавить урок» */
.modal { width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); overflow-y: auto; margin: auto; border: none; color: var(--ink); }
.modal::backdrop { background: rgba(27, 33, 51, 0.45); }

/* Rating: the student's own row */
.table-scroll tr.row-me td { background: var(--butter-tint); color: var(--navy); }

/* Shop: reward cards */
.reward-photo { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: var(--radius-small); margin-bottom: 0.8rem; background: var(--butter-tint); }
.reward-photo-empty { display: flex; align-items: center; justify-content: center; color: var(--muted-ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* Picture of a task (a reaction scheme). Wide schemes scroll sideways inside the card on a phone and open full size on tap. */
.task-image-wrap { overflow-x: auto; max-width: 560px; margin: 0.75rem 0; }
.task-image { display: block; width: 100%; min-width: 480px; max-width: none; height: auto; }

/* A student's free-form answer: keeps the line breaks and wraps long lines. */
.answer-text { white-space: pre-wrap; overflow-wrap: break-word; background: var(--cream); border: 1px solid var(--line); border-radius: var(--radius-small); padding: 0.6rem 0.9rem; margin: 0 0 0.75rem; }
.comment-text { white-space: pre-line; overflow-wrap: break-word; }
.invite-link { overflow-wrap: anywhere; }
.photo-input { display: block; margin-top: 0.6rem; color: var(--muted-ink); font-size: 0.95rem; }
.photo-input input { display: block; width: 100%; max-width: 100%; margin-top: 0.3rem; font-size: 0.95rem; }
.photo-input input::file-selector-button { font: inherit; color: var(--navy); background: transparent; border: 1.5px solid var(--navy); border-radius: 999px; padding: 0.35rem 0.9rem; margin-right: 0.6rem; cursor: pointer; }
.photo-input input::file-selector-button:hover { background: var(--navy-tint); }
.answer-photos { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 0.75rem; }
.answer-photo { display: block; height: 6rem; width: auto; max-width: 100%; object-fit: cover; border-radius: var(--radius-small); border: 1px solid var(--line); }

/* Table inside a task text (lines like "| 1) A | 2) B |") */
.task-table-wrap { overflow-x: auto; margin: 0.6rem 0; }
.task-table { border-collapse: collapse; max-width: 100%; }
.task-table td { border: 1px solid var(--line); padding: 0.5rem 0.7rem; background: var(--white); overflow-wrap: break-word; }
/* Matching task: letters on the left, numbers on the right; stacked on narrow phones */
.match-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem 2rem; margin: 0.6rem 0; }
.match-col { min-width: 0; overflow-wrap: break-word; }
@media (max-width: 30rem) {
  .match-cols { grid-template-columns: 1fr; }
}
@media (max-width: 40rem) {
  .task-table { table-layout: fixed; width: 100%; font-size: 0.85rem; }
  .task-table td { padding: 0.4rem 0.3rem; }
}

/* Video player on the material page: uploaded file or YouTube / Rutube iframe, always 16:9 and never wider than the page. */
.video-frame { position: relative; width: 100%; aspect-ratio: 16 / 9; background: var(--ink); border-radius: var(--radius-small); overflow: hidden; margin-bottom: 1rem; }
.video-frame video, .video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Flashcards: a card the student turns with a tap and swipes right («знаю») or left («не знаю»). */
.flashcard {
  min-height: 14rem; margin-top: 1rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; cursor: pointer; user-select: none; touch-action: pan-y; transition: transform 0.15s ease;
}
.flashcard-flipped { background: var(--butter-tint); }
/* Body font, not the small-caps heading font: «Cu» must not turn into «CU» in a formula. */
.flashcard-term { font-size: 1.7rem; color: var(--navy); line-height: 1.25; overflow-wrap: anywhere; margin: 0; }
.flashcard-answer { font-size: 1.3rem; color: var(--rust); overflow-wrap: anywhere; margin: 0.8rem 0 0; }
.flashcard.swipe-right { transform: translateX(3rem); background: var(--green-tint); }
.flashcard.swipe-left { transform: translateX(-3rem); background: var(--rust-tint); }
.swipe-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin: 0.8rem 0; }

/* Lesson notes (/notes/<id>/): framed sections, terms by color and heading font (one weight), a print layout. */
.note-cover { text-align: center; }
.note-cover h1 { margin-bottom: 0.3rem; }
.note-section > h2 { border-left: 6px solid var(--butter); padding-left: 0.7rem; }
.note-term { color: var(--rust); font-family: var(--font-display); font-size: 1.08em; }
.note-definition { background: var(--navy-tint); border-radius: var(--radius-small); padding: 0.8rem 1rem; }
.note-definition + .note-definition { margin-top: 0.6rem; }
.note-example { background: var(--butter-tint); border-left: 6px solid var(--butter); border-radius: var(--radius-small); padding: 0.8rem 1rem; font-size: 1.05rem; }
.note-example + .note-example { margin-top: 0.6rem; }
.note-remember { background: var(--green-tint); border: 2px solid var(--green); }
.note-list { padding-left: 1.4rem; margin: 0; }
.note-list li + li { margin-top: 0.4rem; }

@media print {
  html { font-size: 12pt; }
  body { background: var(--white); }
  .topbar, footer, .no-print, .messages { display: none !important; }
  .page { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 1px solid var(--line); }
  .note-cover { min-height: 90vh; display: flex; flex-direction: column; justify-content: center; break-after: page; border: none; }
  .note-definition, .note-example, .note-list li { break-inside: avoid; }
  .note-section > h2 { break-after: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Homework library (tutor): folders on the left, the chosen folder's homework as cards */
.library {
  display: grid; grid-template-columns: 16rem minmax(0, 1fr); gap: 1.2rem; align-items: start;
  background: var(--navy-tint); border-radius: var(--radius); padding: 1rem; margin-top: 1.5rem;
}
.library .card { border: 1px solid #BFCAE0; }
.library-folders { position: sticky; top: 1rem; padding: 1.1rem 0.8rem; }
.library-folders h3 { margin: 0 0 0.5rem 0.6rem; }
.library-folders ul { list-style: none; padding: 0; margin: 0; }
.library-folders a {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  padding: 0.35rem 0.6rem; border-radius: var(--radius-small); text-decoration: none; line-height: 1.35;
}
.library-folders a:hover { background: var(--cream); }
.library-folders a.on { background: var(--navy); color: var(--white); }
.library-count { color: var(--muted-ink); font-size: 0.8rem; }
.library-folders a.on .library-count { color: var(--butter); }
.library-folders .depth-1 { padding-left: 0.9rem; }
.library-folders .depth-2 { padding-left: 1.8rem; }
.library-folders .depth-3 { padding-left: 2.7rem; }
.library-folders .depth-4, .library-folders .depth-5, .library-folders .depth-6 { padding-left: 3.6rem; }
.library-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 0.3rem 1.2rem; margin: 0.4rem 0.4rem 0.9rem; }
.library-head h2 { margin: 0; }
.library-head .muted { margin: 0; }
.library-folder-actions { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin: 0; font-size: 0.9rem; }
.card.library-hw { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 0.8rem 1.2rem; padding: 1.1rem 1.4rem; margin-bottom: 0.8rem; }
.library .library-draft { border-left: 6px solid var(--butter); }
.library-hw-info { flex: 1 1 15rem; min-width: 0; }
.library-hw-info h3 { margin: 0; font-size: 1.25rem; }
.library-hw-info h3 a { text-decoration: none; }
.library-hw-info h3 a:hover { text-decoration: underline; }
.library-hw-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.library-hw-actions form { margin: 0; }
@media (max-width: 767px) {
  .library { grid-template-columns: 1fr; padding: 0.7rem; }
  .library-folders { position: static; }
  .library-hw-actions .btn { width: auto; }
}

/* Library action windows (issue, who got it, edit): one dialog over the library, or a page of its own */
.library-window { width: min(44rem, calc(100vw - 2rem)); margin-left: auto; margin-right: auto; }
dialog.library-window { padding: 1.4rem 1.6rem; }
.window-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 0.8rem; }
.window-head h2 { margin: 0; font-size: 1.5rem; }
.window-close { font-size: 1.8rem; line-height: 1; text-decoration: none; color: var(--muted-ink); padding: 0 0.2rem; }
.window-close:hover { color: var(--rust); }
.window-note { background: var(--rust-tint); border-radius: var(--radius-small); padding: 0.6rem 0.9rem; }
.window-choices { border: 1px solid var(--line); border-radius: var(--radius-small); padding: 0.4rem 0.9rem 0.6rem; margin: 0 0 0.9rem; max-height: 15rem; overflow-y: auto; min-width: 0; }
.window-choices legend { color: var(--navy); padding: 0 0.3rem; }
.window-choices label.check { margin: 0.4rem 0; align-items: flex-start; }
.window-choices input[type="checkbox"] { flex: none; }
.window-tasks { max-height: none; overflow-y: visible; }
.window-buttons { margin-top: 1.2rem; }
.window-issue { border-top: 1px solid #EFE8D8; padding-top: 0.6rem; margin-top: 0.6rem; }
.window-issue-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.2rem 1rem; }
.window-issue-head p { margin: 0; }
.window-issue-name { color: var(--navy); font-size: 1.1rem; }
.window-students li { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.6fr); }
.window-students li:last-child { border-bottom: 0; }
@media (max-width: 640px) {
  dialog.library-window { padding: 1.1rem; }
  .window-students li { grid-template-columns: 1fr auto; }
  .window-buttons .btn { width: auto; }
}

/* Chat with the tutor: the student's corner button + panel, and the tutor's conversation page */
.chat-fab {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  width: 56px; height: 56px; border: 0; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--white); background: var(--navy); box-shadow: var(--shadow);
}
.chat-fab:focus-visible { outline: 3px solid var(--butter); outline-offset: 3px; }
.chat-dot {
  position: absolute; top: 4px; right: 4px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--rust); border: 2px solid var(--white);
}
.chat-panel {
  position: fixed; right: 16px; bottom: 84px; z-index: 51;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 110px));
  display: flex; flex-direction: column; padding: 0.8rem;
  background: var(--white); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat-panel[hidden], .chat-box [hidden], .chat-dot[hidden] { display: none; }
.chat-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.chat-panel-head h2 { margin: 0; font-size: 1.3rem; }
.chat-box { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; min-height: 0; }
.chat-feed {
  flex: 1; min-height: 8rem; overflow-y: auto; padding: 0.4rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  background: var(--cream); border-radius: var(--radius-small);
}
.chat-page .chat-feed { height: 55vh; flex: none; }
.chat-msg { max-width: 85%; padding: 0.5rem 0.8rem; border-radius: var(--radius-small); background: var(--white); }
.chat-msg-mine { margin-left: auto; background: var(--navy-tint); }
.chat-msg p { margin: 0; }
.chat-meta { font-size: 0.8rem; color: var(--muted-ink); }
.chat-meta a { color: var(--navy); }
.chat-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-photos { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.3rem; }
.chat-photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; display: block; }
.chat-reply-btn { display: block; margin-top: 0.2rem; padding: 0; border: 0; background: none; font: inherit; font-size: 0.8rem; color: var(--navy); cursor: pointer; text-decoration: underline; }
.chat-quote { margin: 0 0 0.3rem; padding: 0.2rem 0.6rem; border-left: 3px solid var(--navy); font-size: 0.85rem; color: var(--muted-ink); display: flex; flex-direction: column; }
.chat-quote-author { color: var(--navy); }
.chat-quote-text { overflow-wrap: anywhere; }
.chat-replying { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.6rem; border-left: 3px solid var(--navy); background: var(--navy-tint); border-radius: var(--radius-small); }
.chat-replying-text { margin: 0; flex: 1; min-width: 0; font-size: 0.9rem; display: flex; flex-direction: column; }
.chat-replying .btn { width: auto; flex: none; }  /* phone: .btn is full width by default */
.chat-replying-author { color: var(--navy); }
.chat-replying-snippet { overflow-wrap: anywhere; color: var(--muted-ink); }
.chat-form { display: flex; flex-direction: column; gap: 0.4rem; }
.chat-topic { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chat-topic .field { flex: 1 1 7rem; width: auto; min-width: 0; }
.chat-form textarea { resize: vertical; min-height: 3rem; }
.chat-actions { display: flex; align-items: center; gap: 0.5rem; }
.chat-actions button[type="submit"] { margin-left: auto; }
.chat-actions label { cursor: pointer; }
.chat-error { margin: 0; color: var(--rust); font-size: 0.9rem; }
.chat-count { margin-left: 0.2rem; }
body:has(.chat-widget, .pomo-widget) .page { padding-bottom: 88px; }  /* the corner button never covers the last line */
@media (max-width: 767px) {
  .chat-panel { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; }
}

/* Pomodoro timer (students): a button in the left corner, its panel and the "time is up" pop-up */
.pomo-fab {
  position: fixed; left: 16px; bottom: 16px; z-index: 50;
  min-width: 56px; height: 56px; padding: 0 15px; border: 0; border-radius: 28px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  font-family: var(--font-body); font-size: 1rem;
  color: var(--white); background: var(--navy); box-shadow: var(--shadow);
}
.pomo-fab[data-phase="rest"], .pomo-toast[data-phase="rest"] { --pomo-color: var(--green); }
.pomo-fab[data-phase="rest"] { background: var(--green); }
.pomo-fab:focus-visible { outline: 3px solid var(--butter); outline-offset: 3px; }
.pomo-fab-time[hidden], .pomo-panel[hidden], .pomo-toast[hidden] { display: none; }
.pomo-panel {
  position: fixed; left: 16px; bottom: 84px; z-index: 52;
  width: min(320px, calc(100vw - 32px)); padding: 0.8rem 1rem 1rem;
  background: var(--white); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pomo-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.pomo-head h2 { margin: 0; font-size: 1.3rem; }
.pomo-phase { margin: 0.3rem 0 0; text-align: center; }
.pomo-time { margin: 0; text-align: center; font-family: var(--font-display); font-size: 3.4rem; line-height: 1.1; color: var(--navy); }
.pomo-panel[data-phase="rest"] .pomo-time { color: var(--green); }
.pomo-actions { display: flex; justify-content: center; gap: 0.5rem; margin: 0.6rem 0 0.8rem; }
.pomo-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; align-items: end; }
.pomo-settings label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted-ink); }
.pomo-settings .field { width: 100%; }
.pomo-sound-label { grid-column: 1 / -1; flex-direction: row !important; align-items: center; gap: 0.4rem !important; cursor: pointer; }
.pomo-toast {
  position: fixed; left: 16px; bottom: 84px; z-index: 60;
  width: min(320px, calc(100vw - 32px)); padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.6rem;
  background: var(--butter-tint); color: var(--ink);
  border: 2px solid var(--pomo-color, var(--navy)); border-radius: var(--radius); box-shadow: var(--shadow);
}
.pomo-toast-text { margin: 0; font-family: var(--font-display); font-size: 1.3rem; line-height: 1.25; }
.pomo-toast .btn { align-self: flex-start; }

/* Homework check pages (tutor): the queue and one submission */
.check-tabs { margin-bottom: 1rem; }
.check-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 1.6fr); gap: 0.3rem 1.2rem; align-items: center; padding: 1rem 1.4rem; margin-bottom: 0.6rem; text-decoration: none; color: var(--ink); }
.check-row:hover { box-shadow: 0 6px 20px rgba(59, 81, 131, 0.22); }
.check-who { display: flex; flex-direction: column; }
.check-answer { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem 1.6rem; }
.check-answer .answer-photo { height: 12rem; }
.check-ai { background: var(--navy-tint); border-radius: var(--radius-small); padding: 0.6rem 0.9rem; margin: 0.8rem 0; }
.check-ai p { margin: 0 0 0.5rem; white-space: pre-line; overflow-wrap: break-word; }
.check-accept { display: inline-flex; align-items: center; gap: 0.5rem; margin: 0; cursor: pointer; }
.check-accept input { width: auto; min-height: 0; margin: 0; }
.check-comment { resize: vertical; overflow: hidden; }
.score-buttons { border: 0; padding: 0; margin: 0 0 0.8rem; min-width: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.score-buttons legend { padding: 0; margin-bottom: 0.4rem; font-size: 0.9rem; color: var(--muted-ink); }
.score-buttons label { margin: 0; }
.score-buttons input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.score-buttons span { display: inline-flex; align-items: center; justify-content: center; min-width: 3rem; min-height: 3rem; border: 2px solid var(--line); border-radius: var(--radius-small); background: var(--white); color: var(--navy); font-size: 1.2rem; cursor: pointer; }
.score-buttons input:checked + span { background: var(--navy); border-color: var(--navy); color: var(--white); }
.score-buttons input:focus-visible + span { outline: 3px solid var(--navy); outline-offset: 2px; }
.check-actions { display: flex; flex-wrap: wrap; gap: 0.8rem; justify-content: flex-end; }
@media (max-width: 900px) {
  .check-answer { grid-template-columns: 1fr; }
  .check-row { grid-template-columns: 1fr auto; }
  .check-actions { position: sticky; bottom: 0; background: var(--cream); padding: 0.7rem 0; border-top: 1px solid var(--line); justify-content: stretch; }
  .check-actions .btn { flex: 1 1 8rem; }
}
.check-name { color: var(--navy); font-size: 1.15rem; }
