/* Timetable: the look of a printed exam schedule. Text is Source Sans 3 (OFL, in fonts/), a face made for
   reading on screens; Barlow Condensed (signage) is kept for the big figures: countdowns, clocks and scores. */
@font-face { font-family: "Source Sans 3"; src: url("fonts/SourceSans3.ttf"); font-weight: 200 900; }
@font-face { font-family: "Atkinson Hyperlegible Next"; src: url("fonts/AtkinsonHyperlegibleNext.ttf"); font-weight: 200 800; }
@font-face { font-family: "Barlow Condensed"; src: url("fonts/BarlowCondensed-SemiBold.ttf"); font-weight: 600; }
@font-face { font-family: "Barlow Condensed"; src: url("fonts/BarlowCondensed-Bold.ttf"); font-weight: 700; }

:root {
  --bg: #e9eae6;
  --surface: #fafaf8;
  --surface-2: #f0f1ed;
  --text: #17191c;
  --muted: #5d6166;
  --faint: #969a9e;
  --border: #dcded9;
  --track: #e3e5e0;
  --accent: #17191c;
  --accent-text: #ffffff;
  --accent-soft: #e9eae7;
  --warn: #b06d08;
  --warn-soft: #f6ead3;
  --danger: #c4202f;
  --danger-soft: #f8e1e1;
  --ok: #1f7546;
  --ok-soft: #e0efe5;
  --shadow: none;
  --radius: 6px;  /* buttons, fields and rows */
  --sheet-radius: 8px;
  --sans: "Source Sans 3", -apple-system, "Segoe UI", system-ui, sans-serif;
  --figures: "Barlow Condensed", "Arial Narrow", sans-serif;
  /* Research time in the week chart: a hue between the accent and red, so it follows every theme. */
  --research: color-mix(in srgb, var(--accent) 50%, var(--danger));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #19191b;
    --surface: #242527;
    --surface-2: #2c2d30;
    --text: #ecebe6;
    --muted: #a6a59f;
    --faint: #706f6b;
    --border: #3a3b3d;
    --track: #343537;
    --accent: #ecebe6;
    --accent-text: #1e1f20;
    --accent-soft: #333436;
    --warn: #e3a43a;
    --warn-soft: #3a301f;
    --danger: #f0625c;
    --danger-soft: #3e2425;
    --ok: #62c48c;
    --ok-soft: #1f3529;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 0.9688rem/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea, select { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font: 700 1.625rem/1.2 var(--sans); letter-spacing: -.01em; }
h2 { font: 700 1.0312rem/1.3 var(--sans); color: var(--text); }
h3 { font-weight: 600; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.loading { color: var(--muted); padding: 40px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 28px 10px;
  background: var(--bg);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 4px 0; cursor: pointer;
  font: 700 1.125rem/1 var(--sans); letter-spacing: -.01em;
}
.brand-mark {
  width: 16px; height: 16px; border-radius: 2px;
  background: var(--text);
}
.today { color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- sidebar ---------- */
.shell { flex: 1; min-height: 0; display: flex; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#sidebar {
  width: 15rem; flex: none; display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px 14px; background: var(--bg);
  transition: width .15s ease;
}
.side-toggle { flex: none; }
.side-top { display: flex; align-items: center; gap: 4px; }
.side-top .side-item { flex: 1; min-width: 0; }
#side-nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px; }
.side-head {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  margin: 14px 0 2px; padding-left: 8px; min-height: 26px;
  font: 700 0.8125rem/1.2 var(--sans); color: var(--muted);
}
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; min-height: 36px;
  border: 0; border-radius: var(--radius); background: transparent; cursor: pointer; text-align: left;
}
.side-item:hover { background: color-mix(in srgb, var(--surface) 55%, transparent); }
.side-item.active { background: var(--surface); }
.side-item.active .side-label { font-weight: 600; }
.side-badge {
  width: 30px; height: 22px; border-radius: 2px; flex: none; display: inline-grid; place-items: center;
  color: #fff; font: 700 0.8125rem/1 var(--figures); letter-spacing: .03em; overflow: hidden; white-space: nowrap;
}
.side-badge.plain { background: none; color: var(--muted); }
.side-item.active .side-badge.plain { color: var(--accent); }
.side-text { display: flex; flex-direction: column; min-width: 0; }
.side-label, .side-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-sub { font-size: 0.8125rem; color: var(--muted); }
.side-empty { margin: 2px 0; padding-left: 8px; color: var(--faint); font-size: 0.8125rem; }
.side-foot { display: flex; align-items: center; gap: 6px; padding-top: 10px; }
.side-foot #account { flex: 1; min-width: 0; }
.side-foot .sync-chip { width: 100%; max-width: 100%; }
.side-foot .chip-email { flex: 1; min-width: 0; max-width: none; text-align: left; }
.side-foot .chip-status { display: none; }

body.side-collapsed #sidebar { width: 60px; padding-left: 8px; padding-right: 8px; }
body.side-collapsed .side-top { flex-direction: column-reverse; align-items: stretch; }
body.side-collapsed .side-toggle { align-self: center; }
body.side-collapsed .side-text,
body.side-collapsed .side-head > span,
body.side-collapsed .side-head .icon-btn,
body.side-collapsed .side-empty { display: none; }
body.side-collapsed .side-head { margin: 8px 4px; padding: 0; min-height: 0; border-top: 1px solid var(--border); }
body.side-collapsed .side-item { justify-content: center; padding: 6px 0; }
body.side-collapsed .side-foot { flex-direction: column; }
body.side-collapsed .side-foot .sync-chip { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; position: relative; }
body.side-collapsed .side-foot .chip-email { display: none; }
body.side-collapsed .side-foot .sync-dot { position: absolute; right: 1px; bottom: 1px; box-shadow: 0 0 0 2px var(--surface); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; white-space: nowrap;
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: none; background: color-mix(in srgb, var(--accent) 86%, var(--bg)); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { height: 26px; padding: 0 10px; font-size: 0.8125rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.icon-btn.small { width: 26px; height: 26px; }
.link { background: none; border: 0; padding: 0; color: var(--text); cursor: pointer; font-weight: 500; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--faint); }
.link:hover { text-decoration: underline; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- running timer / banner ---------- */
.running {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 24px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
}
.running.break { background: var(--ok-soft); }
.running.overtime .clock { color: var(--ok); }
.running.overtime .pulse { background: var(--ok); }
.running .clock { font: 700 1.75rem/1 var(--figures); min-width: 80px; }
.running .what { display: flex; flex-direction: column; line-height: 1.25; }
.running .what small { color: var(--muted); }
.running .actions { margin-left: auto; display: flex; gap: 8px; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
.running.break .pulse { background: var(--ok); }
.running.paused .pulse { animation: none; opacity: .4; }
@keyframes pulse { 50% { opacity: .3; } }

.banner {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 24px;
  background: var(--danger-soft); color: var(--danger);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.banner.soon { background: var(--warn-soft); color: var(--warn); }

/* ---------- layout ---------- */
main { flex: 1; overflow-y: auto; padding: 20px 28px 40px; outline: none; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 21.25rem; gap: 24px; max-width: 1280px; margin: 0 auto; }
.grid > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 20px; }
.section-head h2 { white-space: nowrap; }
.section-head .muted { font-size: 0.8125rem; text-align: right; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; min-height: 28px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

/* Sections are lighter sheets on the shaded page: separated by tone and space, not lines or shadows. */
.panel { background: var(--surface); border: 0; border-radius: var(--sheet-radius); box-shadow: none; padding: 6px 0 10px; }
.panel-body { padding: 14px 20px; }
.panel .section-head { padding: 12px 20px 2px; margin-bottom: 4px; }
.panel .list { padding: 0 8px 4px; }
.panel .list .row { padding: 9px 12px; border-radius: var(--radius); }
.panel .list .row:hover { background: var(--surface-2); }
.empty-small { color: var(--muted); padding: 4px 20px 14px; }

/* ---------- subject cards: rows of a timetable ---------- */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  position: relative; display: grid; grid-template-columns: 64px minmax(0, 1fr); column-gap: 16px;
  background: var(--surface); border: 0; border-radius: var(--sheet-radius);
  box-shadow: none; padding: 18px 22px 18px 14px; cursor: pointer;
}
.card:hover { background: color-mix(in srgb, var(--surface) 70%, var(--surface-2)); }
/* The course's colour as a bar down the left edge, as in the previous look. */
.card::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--course); }
.card > :not(.tt-when):not(.drag-handle) { grid-column: 2; }
.tt-when { grid-column: 1; grid-row: 1 / span 6; display: flex; flex-direction: column; align-items: flex-end; padding-top: 2px; }
.tt-num { font: 700 2.875rem/.9 var(--figures); letter-spacing: -.01em; }
.tt-unit { font: 500 0.8125rem/1.3 var(--sans); color: var(--muted); }
.tt-when.close .tt-num, .tt-when.close .tt-unit { color: var(--danger); }
.tt-num:not(:only-child) { white-space: nowrap; }
.tt-when .tt-num:only-child { font-size: 1.5rem; }
.tt-when.over .tt-num { font-size: 1.5rem; color: var(--muted); }
.card-top { display: flex; align-items: center; gap: 12px; }
.code { font: 700 0.9688rem/1.2 var(--sans); color: var(--course); }
.card-name { font-weight: 600; font-size: 1.0625rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-exam { margin-left: auto; color: var(--muted); white-space: nowrap; font-weight: 500; }
.card-exam.close { color: var(--danger); font-weight: 600; }
.card-words { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.card-facts { color: var(--muted); margin-top: 1px; font-size: 0.875rem; }
.meta { display: inline-flex; flex-wrap: wrap; column-gap: 16px; }
.card-actions { position: absolute; right: 20px; bottom: 16px; display: flex; gap: 6px; opacity: 0; }
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; }
.behind { color: var(--warn); font-weight: 600; }

/* ---------- cram timeline ---------- */
.tl { position: relative; height: 6px; border-radius: 0; background: var(--track); margin-top: 12px; }
.tl.big { height: 12px; margin-top: 18px; }
.tl-done { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0; background: var(--course); }
.tl-behind {
  position: absolute; top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, var(--warn) 0 4px, transparent 4px 7px);
  opacity: .85;
}
.tl-today { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; border-radius: 0; background: var(--text); }
.tl.big .tl-today { top: -5px; bottom: -5px; }
.tl-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.75rem; margin-top: 8px; position: relative; }
.tl-labels .mid { position: absolute; transform: translateX(-50%); color: var(--text); font-weight: 550; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.7812rem; color: var(--muted); margin: 14px 0 0 12px; }
.legend i { display: inline-block; width: 18px; height: 6px; border-radius: 0; vertical-align: middle; margin-right: 6px; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 4px 0 8px; }
.row { position: relative; display: flex; align-items: center; gap: 10px; padding: 7px 16px; min-height: 38px; }
.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 0.875rem; color: var(--muted); }
.row .title.wrap { white-space: normal; overflow-wrap: anywhere; }
/* Edit/delete float over the right edge on hover, so they don't take room from the text. */
.row .row-actions {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px; padding: 2px; border-radius: var(--radius);
  background: var(--surface-2); box-shadow: -12px 0 12px var(--surface-2);
}
.row:hover .row-actions, .row:focus-within .row-actions { display: flex; }
.row.done .title { color: var(--faint); text-decoration: line-through; }
.clickable { cursor: pointer; }
.when { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.8125rem; }
.u-overdue { color: var(--danger); font-weight: 650; }
.u-critical { color: var(--danger); }
.u-soon { color: var(--warn); }
.u-later { color: var(--muted); }
.u-done { color: var(--faint); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--course, var(--faint)); flex: none; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 2px; font-size: 0.7812rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap;
}
.tag.high { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.tag.med { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.course { color: var(--course); }

input[type=checkbox].check {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 18px; height: 18px; border-radius: 2px; border: 1.5px solid var(--muted); background: var(--surface);
  cursor: pointer; display: grid; place-items: center;
}
input[type=checkbox].check:checked { background: var(--ok); border-color: var(--ok); }
input[type=checkbox].check:checked::after { content: ""; width: 5px; height: 9px; border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }

/* ---------- week chart ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 120px; padding: 14px 0 4px; }
.week .bar-wrap { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.week .bar { width: 100%; max-width: 28px; border-radius: 0; background: var(--text); opacity: .8; min-height: 2px; }
.week .bar.zero { background: var(--track); opacity: 1; }
.week .bar-stack { width: 100%; max-width: 28px; display: flex; flex-direction: column; gap: 1px; border-radius: 0; overflow: hidden; }
.week .bar-stack .bar { max-width: none; border-radius: 0; min-height: 0; }
.week .bar.research { background: var(--research); opacity: .9; flex: none; }
.week-legend { padding: 0 0 12px; margin-top: 0; }
.week .bar-val { font-size: 0.6875rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.week-labels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; padding: 0 0 14px; text-align: center; font-size: 0.75rem; color: var(--muted); }
.week-labels .now { color: var(--text); font-weight: 650; }

/* ---------- course banners ---------- */
.course-banner { position: relative; overflow: hidden; background: var(--course); }
.course-banner .banner-art, .course-banner .banner-img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.course-banner .banner-img { object-fit: cover; }
.course-banner.on-page { height: 96px; border-radius: var(--sheet-radius); margin-bottom: 16px; }
.course-banner.on-card { width: 34px; height: 22px; border-radius: 2px; flex: none; align-self: center; }
.h-count { font: 500 0.9375rem var(--sans); color: var(--muted); margin-left: 6px; }
.row .sub { white-space: pre-wrap; }
.banner-change { position: absolute; right: 10px; bottom: 10px; opacity: 0; transition: opacity .12s; }
.course-banner:hover .banner-change, .banner-change:focus-visible { opacity: 1; }
details.done-pane .card .course-banner { filter: grayscale(.6); }

/* ---------- subject page ---------- */
.subject-head { max-width: 1280px; margin: 0 auto 20px; }
.crumbs { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.title-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.title-line .code { font-size: 1.625rem; }
.title-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.hero { margin-top: 18px; padding: 18px 22px 16px; }
.hero-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hero-top .big { font: 700 1.25rem/1.25 var(--sans); }

.topic-row .status {
  appearance: none; -webkit-appearance: none;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 2px 22px 2px 8px; font: inherit; font-size: 0.8125rem; font-weight: 600;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center;
  color: var(--muted); cursor: pointer; min-width: 112px;
}
.status.s-in_progress { background-color: var(--surface); color: var(--text); border-color: var(--text); }
.status.s-reviewed { background-color: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status.s-confident { background-color: var(--ok); color: var(--accent-text); border-color: transparent; }
.conf { display: inline-flex; gap: 3px; }
.conf button { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--faint); background: transparent; padding: 0; cursor: pointer; }
.conf button.on { background: var(--course, var(--accent)); border-color: var(--course, var(--accent)); }
.conf button:hover { transform: scale(1.15); }
.stale { color: var(--warn); }
.reading-mini { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

/* ---------- reading list ---------- */
.source { margin-bottom: 16px; }
.source-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.source-head h3 { font-size: 1rem; }
.meter { width: 120px; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; flex: none; }
.meter > div { height: 100%; background: var(--course, var(--accent)); }
.chapter { border-top: 1px solid var(--border); }
.chapter-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.chapter-head .num { font-weight: 650; min-width: 28px; }
.chev { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; color: var(--muted); transition: transform .12s; padding: 0; }
.chev.open { transform: rotate(90deg); }
.sections { display: flex; flex-direction: column; padding: 0 16px 10px 62px; }
.sec {
  display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 3px 6px 3px 8px; border-radius: var(--radius);
  cursor: pointer; font-size: 0.8125rem;
}
.sec:hover { background: var(--surface-2); }
.sec-box {
  width: 16px; height: 16px; flex: none; border-radius: 4px; border: 1.5px solid var(--faint);
  display: grid; place-items: center;
}
.sec.read .sec-box { background: var(--ok); border-color: var(--ok); }
.sec.read .sec-box::after { content: ""; width: 4px; height: 8px; border: solid var(--accent-text); border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.sec .sec-num { min-width: 36px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sec .sec-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sec.read .sec-num, .sec.read .sec-title { color: var(--muted); }
.sec .sec-note { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
/* Optional reading doesn't count toward progress, so it steps back visually. */
.sec.optional { opacity: .6; }
.sec.optional:hover { opacity: .85; }
.sec .sec-menu { opacity: 0; }
.sec:hover .sec-menu { opacity: 1; }

/* ---------- empty state ---------- */
.welcome { max-width: 560px; margin: 8vh auto; text-align: center; }
.welcome h1 { font-size: 1.75rem; margin-bottom: 10px; }
.welcome p { color: var(--muted); font-size: 0.9375rem; margin: 0 0 24px; }
.welcome .steps { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px; margin: 0 0 24px; }
.welcome .steps li { margin: 6px 0; }

/* ---------- modal ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(15, 16, 20, .38);
  display: grid; place-items: center; padding: 24px; z-index: 20;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 480px; max-height: calc(100vh - 48px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18); padding: 24px 26px;
  animation: rise .14s ease-out;
}
.modal.wide { max-width: 640px; }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }
.modal h3 { font: 700 1.1875rem/1.25 var(--sans); margin-bottom: 6px; }
.modal .intro { color: var(--muted); margin: 0 0 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; }
.field > span { font-weight: 550; font-size: 0.8125rem; }
.field small { color: var(--muted); font-size: 0.75rem; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select.input, textarea {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font: inherit; width: 100%;
}
textarea { height: auto; min-height: 120px; padding: 8px 10px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8125rem; }
input:focus, select.input:focus, textarea:focus { border-color: var(--text); outline: none; box-shadow: inset 0 0 0 1px var(--text); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 2px var(--surface); }
.swatch.on { border-color: var(--text); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice b { display: block; }
.choice small { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg label { padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.modal-actions .left { margin-right: auto; }
.form-error { color: var(--danger); margin-top: 12px; font-weight: 500; }
.form-error:empty { display: none; }

/* ---------- menu ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.menu button { display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none; border-radius: var(--radius); cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 40; align-items: center; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: rise .15s ease-out; max-width: 520px;
}
.toast.error { background: var(--danger); color: #fff; }

details.done-pane { margin-top: 20px; }
details.done-pane summary { cursor: pointer; color: var(--muted); font-weight: 550; padding: 6px 0; }
details.done-pane .card { opacity: .7; }

/* Topic rows have controls on the right (confidence), so their buttons sit inline instead of floating. */
.topic-row .row-actions { position: static; transform: none; display: flex; visibility: hidden; background: none; box-shadow: none; padding: 0; }
.topic-row:hover .row-actions, .topic-row:focus-within .row-actions { visibility: visible; }

/* ---------- account ---------- */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer;
  color: var(--muted); font-size: 0.8125rem; white-space: nowrap;
}
.sync-chip:hover { border-color: var(--faint); color: var(--text); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.s-syncing .sync-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.s-offline .sync-dot { background: var(--faint); }
.s-error .sync-dot { background: var(--warn); }
.menu-label { padding: 7px 10px; color: var(--muted); font-size: 0.8125rem; }
.welcome-account p { margin-bottom: 14px; font-size: 0.875rem; }
.welcome-buttons { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
input[type=email], input[type=password] {
  height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font: inherit; width: 100%;
}

/* ---------- greeting and overall progress ---------- */
.greeting { max-width: 1280px; margin: 0 auto 20px; }
.greeting h1 { font-size: 1.75rem; }
.greeting p { margin: 4px 0 0; color: var(--muted); font-size: 0.9375rem; }
#overall {
  display: flex; align-items: center; gap: 14px; flex: none;
  padding: 12px 28px 14px; background: var(--bg);
}
#overall[hidden] { display: none; }
.overall-label { font: 700 0.8438rem/1 var(--sans); color: var(--text); }
.overall-bar { flex: 1; min-width: 0; }
.overall-bar .tl { margin-top: 0; }
.overall-percent { font: 700 1.375rem/1 var(--figures); min-width: 44px; text-align: right; }
/* Keep toasts clear of the bar. */
body:has(#overall:not([hidden])) #toasts { bottom: 64px; }
.tag.mood-behind { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.mood-ahead, .tag.mood-on_track { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* ---------- literature: topics and references ---------- */
.view-toggle { font-size: 0.8125rem; }
.view-toggle label { padding: 5px 12px; }
.topic-tag { margin-left: 6px; color: var(--course, var(--accent)); }
.cite-btn { color: var(--muted); }
.check-gap { width: 18px; flex: none; }
.lits { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.lit {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 2px 2px 10px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border); font-size: 0.8125rem; max-width: 100%;
}
.lit-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
[data-only][hidden] { display: none; }
.apa-preview { margin-top: 16px; padding: 10px 12px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.apa-preview > span { display: block; font-size: 0.75rem; font-weight: 550; color: var(--muted); margin-bottom: 4px; }
.apa-preview .apa-text { font-size: 0.8125rem; line-height: 1.5; user-select: text; -webkit-user-select: text; padding-left: 1.5em; text-indent: -1.5em; min-height: 1.5em; }

/* ---------- folding books and chapters ---------- */
.chev-gap { width: 22px; flex: none; }
.source-head.foldable { cursor: pointer; }
.source-head.foldable:hover h3 { color: var(--course, var(--accent)); }
.source:not(.open) .source-head { padding-top: 12px; padding-bottom: 12px; }
.source { margin-bottom: 10px; }
.chapter.read .chapter-head .num, .chapter.read .chapter-head .title { color: var(--muted); }

/* ---------- several accounts ---------- */
.avatar {
  width: 20px; height: 20px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  color: #fff; font-size: 0.6875rem; font-weight: 700;
}
.avatar.local { background: var(--faint); }
.sync-chip { padding-left: 6px; }
.sync-chip.s-local { padding-left: 12px; }
.s-local .sync-dot { background: var(--faint); }
.chip-email { color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.chip-status { color: var(--muted); }
.menu button.rich { display: flex; align-items: center; gap: 8px; }
.menu .menu-grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu .menu-check { color: var(--accent); flex: none; }
.menu { min-width: 240px; }

/* ---------- theme picker ---------- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
.theme-opt { display: flex; flex-direction: column; gap: 5px; cursor: pointer; font-size: 0.75rem; color: var(--muted); }
.theme-opt input { position: absolute; opacity: 0; pointer-events: none; }
.theme-opt:has(input:checked) { color: var(--text); font-weight: 600; }
.theme-opt:has(input:checked) .tp { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-opt:has(input:focus-visible) .tp { outline: 2px solid var(--accent); outline-offset: 2px; }
.tp { position: relative; display: block; height: 62px; border-radius: var(--radius); border: 1px solid; overflow: hidden; padding: 10px; }
.tp-split { position: absolute; inset: 0; }
.tp-card { position: relative; display: flex; flex-direction: column; gap: 5px; height: 100%; border-radius: 5px; border: 1px solid; padding: 6px 7px; }
.tp-line { width: 55%; height: 4px; border-radius: 2px; opacity: .85; }
.tp-bar { height: 4px; border-radius: 2px; overflow: hidden; }
.tp-bar span { display: block; width: 60%; height: 100%; }
.tp-dots { display: flex; gap: 3px; margin-top: auto; }
.tp-dots i { width: 7px; height: 7px; border-radius: 50%; }

/* ---------- exams ---------- */
.exam .counts { font-size: 0.8125rem; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.rc { font-weight: 600; }
.rc.missed { color: var(--danger); }
.rc.partial { color: var(--warn); }
.rc.ok { color: var(--ok); }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px 50px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.8125rem; cursor: pointer; max-width: 100%; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.file-chip small { color: var(--muted); }
.file-chip:hover { border-color: var(--faint); }
.file-chip.missing { opacity: .55; }
.exam-notes { margin: 0 16px 12px 50px; }
.exam-intro { margin: 0 16px 14px 50px; padding: 4px 14px; border-left: 3px solid var(--course, var(--accent)); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.qs { border-top: 1px solid var(--border); }
.q { padding: 14px 16px 14px 50px; border-bottom: 1px solid var(--border); position: relative; }
.q:last-child { border-bottom: 0; }
.q::before { content: ""; position: absolute; left: 24px; top: 16px; bottom: 16px; width: 3px; border-radius: 2px; background: var(--track); }
.q.r-ok::before { background: var(--ok); }
.q.r-partial::before { background: var(--warn); }
.q.r-missed::before { background: var(--danger); }
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-num { font-weight: 700; font-size: 0.9375rem; min-width: 22px; }
.q-res { margin-left: auto; display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.res { border: 0; border-right: 1px solid var(--border); background: transparent; color: var(--muted); font: inherit; font-size: 0.7812rem;
  padding: 3px 10px; cursor: pointer; }
.res:last-child { border-right: 0; }
.res:hover { background: var(--surface-2); color: var(--text); }
.res.ok.on { background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.res.partial.on { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.res.missed.on { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.q-why { margin-top: 6px; font-size: 0.8125rem; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.q-why svg { color: var(--course, var(--accent)); flex: none; position: relative; top: 2px; }
.q-note { margin-top: 8px; font-size: 0.8438rem; padding: 6px 10px; border-radius: var(--radius); background: var(--danger-soft); }
.q.r-partial .q-note { background: var(--warn-soft); }
.q-answer { margin-top: 8px; }
.q-answer summary { cursor: pointer; color: var(--accent); font-size: 0.8438rem; font-weight: 500; width: fit-content; }
.q-answer > .md { margin-top: 6px; padding: 2px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.md { line-height: 1.6; overflow-wrap: anywhere; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; overflow-x: auto; font-size: 0.8125rem; }
.md code { font-size: .92em; }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.md td, .md th { border: 1px solid var(--border); padding: 4px 10px; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.q-prompt { margin-top: 4px; }
.tallies .tally { display: block; padding: 8px 16px; }
.tally-top { display: flex; gap: 8px; font-size: 0.875rem; }
.tally-bar { display: flex; height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; margin-top: 6px; }
.tally-bar .m { background: var(--danger); }
.tally-bar .p { background: var(--warn); }
.ai-setup { display: flex; align-items: center; gap: 16px; }
.ai-setup p { margin: 4px 0 0; }
.file-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.875rem; }
.file-row .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row select { height: 28px; font-size: 0.8125rem; width: auto; flex: none; padding: 0 8px; }
.file-row .faint { white-space: nowrap; }
.field small a, .intro a { color: var(--accent); }
.topic-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 0.875rem; }
.pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.steps { margin: 8px 0; padding-left: 20px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.small { width: 13px; height: 13px; border-width: 2px; flex: none; }
.job { display: inline-flex; align-items: center; gap: 8px; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; }
.job-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.job-card .job { color: var(--text); font-weight: 550; }
.jobs-pill {
  display: inline-flex; align-items: center; gap: 8px; max-width: 280px; padding: 5px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); font: inherit; font-size: 0.8125rem;
  font-weight: 550; cursor: pointer;
}
.jobs-pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) {
  .q, .file-chips, .exam-notes, .exam-intro { padding-left: 16px; margin-left: 16px; }
  .q { margin-left: 0; }
  .q::before { left: 6px; }
}

/* ---------- dragging to reorder ---------- */
.drag-handle {
  display: grid; place-items: center; width: 20px; height: 28px; padding: 0; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--faint); cursor: grab; touch-action: none; opacity: 0; transition: opacity .12s;
}
.drag-handle:hover { background: var(--surface-2); color: var(--text); }
.drag-handle:focus-visible, *:hover > .drag-handle, .sorting .drag-handle { opacity: 1; }
.card > .drag-handle { position: absolute; left: -11px; top: 50%; transform: translateY(-50%); background: var(--surface); border: 1px solid var(--border); }
.row > .drag-handle { margin-left: -12px; margin-right: -6px; flex: none; }
.sorting, .sorting * { cursor: grabbing !important; user-select: none; }
.dragging { opacity: .55; box-shadow: 0 0 0 2px var(--accent) !important; }
.card.dragging { transform: scale(.99); }

/* ---------- research card ---------- */
.card.research { background: var(--surface); }
.card.research::before { background: repeating-linear-gradient(180deg, var(--course) 0 6px, transparent 6px 9px); }
.card.research.s-paused, .card.research.s-idea { opacity: .85; }
.kind-label {
  display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 1px 8px 1px 6px; border-radius: 2px;
  font-size: 0.75rem; font-weight: 600;
  color: var(--course); background: color-mix(in srgb, var(--course) 13%, transparent);
}
.kind-label svg { width: 12px; height: 12px; }
.kind-label.big { font-size: 0.75rem; padding: 3px 10px 3px 8px; }
.kind-label.big svg { width: 14px; height: 14px; }
.task-bar { display: flex; gap: 3px; height: 8px; margin-top: 12px; }
.task-bar i { flex: 1; border-radius: 0; background: var(--track); }
.task-bar i.on { background: var(--course); }
.card-tags .tag { font-size: 0.6875rem; padding: 0 6px; margin-left: 2px; }
.status-tag.st-active { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.status-tag.st-paused { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.status-tag.st-done { color: var(--muted); }

/* ---------- research page ---------- */
.research-head .title-line h1 { overflow-wrap: anywhere; }
.status-pick {
  appearance: none; -webkit-appearance: none; font: inherit; font-size: 0.75rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 3px 24px 3px 10px; color: var(--muted);
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 9px center;
}
.status-pick.st-active, .status-pick.rs-read { background-color: var(--ok-soft); color: var(--ok); border-color: transparent; }
.status-pick.st-paused { background-color: var(--warn-soft); color: var(--warn); border-color: transparent; }
.status-pick.rs-reading { background-color: var(--accent-soft); color: var(--accent); border-color: transparent; }
.row .status-pick { flex: none; min-width: 92px; }
.research-hero .tags-line { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.project-description { margin-top: 8px; }
.link-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.link-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--radius); font: inherit; font-size: 0.8125rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; max-width: 240px;
}
.link-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-chip:hover { border-color: var(--course, var(--accent)); }
.link-chip.add { color: var(--muted); border-style: dashed; }
.link-chip .link-icon { color: var(--course, var(--accent)); flex: none; }
.research-body { max-width: 1280px; margin: 0 auto; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 550; padding: 8px 14px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: none; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--course); }
.tab .count { font-size: 0.75rem; color: var(--faint); font-weight: 500; margin-left: 2px; }
.tab-panel { min-height: 320px; }
.tab-head { padding: 12px 16px 0; }
.small-seg label { padding: 3px 10px; font-size: 0.8125rem; }
.filter-line { padding: 0 16px 6px; }

.notes { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 460px; }
.note-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.note-tools { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--border); }
.note-tools input { flex: 1; min-width: 0; height: 30px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.8125rem; }
.note-tools input:focus { border-color: var(--accent); outline: none; }
.note-list ul { list-style: none; margin: 0; padding: 6px; overflow-y: auto; max-height: 640px; }
.note-item { padding: 8px 10px; border-radius: var(--radius); cursor: pointer; }
.note-item:hover { background: var(--surface-2); }
.note-item.on { background: color-mix(in srgb, var(--course) 12%, transparent); }
.note-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-snip { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-when { font-size: 0.6875rem; color: var(--faint); margin-top: 2px; }
.note-none { padding: 12px 16px; margin: 0; }
.note-editor { display: flex; flex-direction: column; min-width: 0; padding: 12px 16px 10px; }
.note-bar { display: flex; align-items: center; gap: 10px; }
.note-title { flex: 1; min-width: 0; font: inherit; font-size: 1.25rem; font-weight: 650; border: 0; background: none; color: var(--text); padding: 4px 0; }
.note-title:focus { outline: none; box-shadow: none; }
.note-body {
  flex: 1; min-height: 380px; margin-top: 8px; border: 1px solid transparent !important; background: var(--surface-2);
  font-size: 0.875rem; line-height: 1.6; resize: none;
}
.note-body:focus { border-color: var(--border) !important; box-shadow: none !important; }
.note-preview { flex: 1; min-height: 380px; margin-top: 8px; padding: 2px 10px; cursor: text; }
.note-about { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 0.8125rem; }
.note-about select.input, .note-tools select.input { width: auto; max-width: 100%; height: 30px; font-size: 0.8125rem; padding: 0 8px; }
.note-tools select.input { flex: 1; }
.note-topic-tag { font-size: 0.75rem; color: var(--course, var(--accent)); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-notes { max-width: 1280px; margin: 0 auto; }
.topic-notes {
  display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 2px 6px; border: 0; border-radius: var(--radius);
  background: none; color: var(--muted); font: inherit; font-size: 0.8125rem; cursor: pointer;
}
.topic-notes:hover { background: var(--surface-2); color: var(--course, var(--text)); }
.note-foot { display: flex; justify-content: space-between; gap: 12px; font-size: 0.75rem; color: var(--faint); padding-top: 8px; }
.note-empty { margin: auto; max-width: 420px; text-align: center; color: var(--muted); }

.journal { list-style: none; margin: 0; padding: 4px 16px 12px; }
.entry { position: relative; display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 16px; padding: 10px 0; border-top: 1px solid var(--border); }
.entry:first-child { border-top: 0; }
.entry-day { font-weight: 600; font-size: 0.8125rem; padding-top: 9px; color: var(--course); white-space: nowrap; }
.entry-body > :first-child { margin-top: 6px; }
.entry .row-actions { position: absolute; right: 0; top: 8px; display: none; gap: 2px; background: var(--surface); }
.entry:hover .row-actions, .entry:focus-within .row-actions { display: flex; }

.task-add { padding: 4px 16px 6px; }
.task-add input { width: 100%; height: 36px; padding: 0 12px; border: 1px dashed var(--border); border-radius: var(--radius); background: transparent; color: var(--text); font: inherit; }
.task-add input:focus { border-style: solid; border-color: var(--accent); outline: none; }
.annotation { font-size: 0.8125rem; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }
.source-row, .task-row { align-items: flex-start; }
.source-row .status-pick, .task-row .check { margin-top: 2px; }
.source-row > .drag-handle, .task-row > .drag-handle { margin-top: -4px; }
.link-badge { display: grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius); flex: none;
  color: var(--course); background: color-mix(in srgb, var(--course) 12%, transparent); }
.suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 16px 16px; }

@media (max-width: 760px) {
  .notes { grid-template-columns: 1fr; }
  .note-list { border-right: 0; border-bottom: 1px solid var(--border); }
  .note-list ul { max-height: 220px; }
  .entry { grid-template-columns: 1fr; gap: 0; }
}
.q-type { font-size: 0.75rem; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.q-noanswer { margin: 8px 0 0; font-size: 0.8125rem; }

/* ---------- an exam's own page, taking it and the results ---------- */
.exam-card { cursor: pointer; margin-bottom: 10px; }
.exam-card:hover { border-color: var(--faint); }
.exam-card:hover h3 { color: var(--course, var(--accent)); }
.exam-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.exam-go { color: var(--faint); display: inline-grid; place-items: center; width: 22px; }
.attempt-words { font-size: 0.8125rem; color: var(--muted); margin-top: 2px; }
.exam-meta { margin: 6px 0 0; }
.exam-page { padding-top: 14px; }
.exam-page > .qs:first-child { border-top: 0; }
.exam-page .file-chips, .exam-page .exam-notes, .exam-page .exam-intro { margin-left: 0; padding-left: 16px; }
.exam-page .exam-intro { margin-left: 16px; padding-left: 14px; }
.small-text { font-size: 0.7812rem; }
.attempts .attempt-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; }
.attempts .attempt-row:hover { background: var(--surface-2); }
.attempt-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.attempt-score.good, .attempt-big.good { color: var(--ok); }
.attempt-score.mid, .attempt-big.mid { color: var(--warn); }
.attempt-score.low, .attempt-big.low { color: var(--danger); }

.take { max-width: 900px; margin: -24px auto 0; }
.take-bar {
  position: sticky; top: -24px; z-index: 5; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 4px 12px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.take-title { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.take-title b { font-size: 0.9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.take-title .muted { font-size: 0.7812rem; }
.take-nav { display: flex; gap: 4px; flex-wrap: wrap; max-width: 360px; }
.take-dot {
  min-width: 26px; height: 24px; padding: 0 5px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 0.7188rem; font-weight: 600; cursor: pointer;
}
.take-dot.done { background: var(--course, var(--accent)); border-color: transparent; color: #fff; }
.take-clock {
  font: 700 1.625rem/1 var(--figures); min-width: 72px; text-align: right;
  padding: 2px 10px; border-radius: var(--radius);
}
.take-clock.low { color: var(--danger); background: var(--danger-soft); }
.take-qs { display: flex; flex-direction: column; gap: 14px; padding: 18px 0 40px; }
.take-q { background: var(--surface); border-radius: var(--sheet-radius); padding: 18px 22px; scroll-margin-top: 90px; }
.take-answer {
  width: 100%; margin-top: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); resize: vertical;
  background: var(--surface-2); color: var(--text); font: 0.875rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.take-answer:focus { outline: 2px solid var(--course, var(--accent)); outline-offset: 0; border-color: transparent; }
.take-preview { margin-top: 8px; padding: 2px 12px; border-left: 3px solid var(--border); }
.take-end { display: flex; justify-content: flex-end; }
.take-choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.take-choices.tf { flex-direction: row; }
.take-choice {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.take-choices.tf .take-choice { justify-content: center; min-width: 110px; font-weight: 600; }
.take-choice:hover { border-color: var(--course, var(--accent)); }
.take-choice:focus-visible { outline: 2px solid var(--course, var(--accent)); outline-offset: 1px; }
.take-choice.on { border-color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--text); }
.take-choice .opt-key {
  flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 4px;
  border: 1px solid var(--border); font-size: 0.75rem; font-weight: 700; color: var(--muted);
}
.take-choice.on .opt-key { background: var(--text); border-color: transparent; color: var(--bg); }
.take-choice .md > :first-child { margin-top: 0; }
.take-choice .md > :last-child { margin-bottom: 0; }
.take-choice-hint { margin: 2px 0 0; font-size: 0.7812rem; }

.attempt-page { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.attempt-hero { display: flex; align-items: center; gap: 20px; padding: 18px 20px; }
.attempt-big { font: 700 3.25rem/1 var(--figures); min-width: 96px; text-align: center; font-variant-numeric: tabular-nums; }
.attempt-points { font-size: 1rem; font-weight: 600; margin-bottom: 2px; }
.attempt-hint { margin: 6px 0 0; color: var(--muted); }
.attempt-summary { display: flex; gap: 10px; align-items: flex-start; }
.attempt-summary > svg { color: var(--course, var(--accent)); flex: none; margin-top: 10px; }
.attempt-summary .md p:first-child { margin-top: 6px; }
.attempt-q-points { font-weight: 650; font-variant-numeric: tabular-nums; }
.your-answer { margin-top: 10px; padding: 4px 14px 6px; border: 1px solid var(--border); border-radius: var(--radius); }
.your-answer .label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); margin-top: 6px; }
.your-answer > .faint { margin: 6px 0; }
.attempt-feedback { color: var(--text); font-size: 0.8438rem; }
.attempt-feedback .md p { margin: 0; }

/* ---------- phones: one column, the sidebar as a drawer, nothing that needs a mouse ---------- */
.drawer-btn { display: none; }
@media (max-width: 700px) {
  .topbar { gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .drawer-btn { display: inline-grid; margin-left: -6px; }
  .today { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 0 10px; font-size: 0.875rem; }
  #jobs .jobs-pill { max-width: 120px; }

  #sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(84vw, 300px);
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: none;
  }
  body.drawer-open #sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  body.drawer-open .shell::after { content: ""; position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, .3); }
  .side-toggle { display: none; }
  .side-item { min-height: 44px; }

  main { padding: 12px 12px calc(28px + env(safe-area-inset-bottom)); }
  #overall { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); gap: 10px; }
  .greeting h1 { font-size: 1.5rem; }

  /* Cards: a narrower countdown, and the code, name and exam date wrap instead of squeezing. */
  .card { grid-template-columns: 44px minmax(0, 1fr); column-gap: 12px; padding: 14px 14px 14px 10px; }
  .tt-num { font-size: 2.25rem; }
  .card-top { flex-wrap: wrap; column-gap: 8px; row-gap: 0; }
  .card-name { white-space: normal; flex-basis: 100%; order: 2; }
  .card-exam { margin-left: auto; order: 1; font-size: 0.8125rem; }
  .card-actions, .drag-handle { display: none; }

  /* Topics: the name on its own line, then the status, reading and confidence, with the buttons. */
  .topic-row { flex-wrap: wrap; row-gap: 6px; padding-top: 10px; padding-bottom: 10px; }
  .topic-row .grow { order: -2; flex: 1 1 calc(100% - 150px); }
  .topic-row .status { min-width: 104px; }
  .topic-row { column-gap: 8px; }
  .topic-row .title { white-space: normal; }
  .topic-row .row-actions { order: -1; visibility: visible; align-self: flex-start; }
  .tl-labels .mid { display: none; }
  .conf { gap: 5px; }
  .conf button { width: 18px; height: 18px; }
  .meta { column-gap: 10px; }

  .section-head, .title-line { flex-wrap: wrap; }
  .panel .section-head { padding: 12px 14px 2px; }
  .title-actions { margin-left: 0; width: 100%; }
  .title-line .code { font-size: 1.375rem; }
  .course-banner.on-page { height: 72px; }
  .banner-change { opacity: 1; }

  /* Forms open as a sheet from the bottom, with fields big enough that iOS doesn't zoom in on them. */
  .backdrop { padding: calc(40px + env(safe-area-inset-top)) 0 0; place-items: end stretch; }
  .backdrop .modal { max-width: none; max-height: 100%;
    border-radius: 12px 12px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-width: 1px 0 0; }
  input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
  select, select.input, textarea, .take-answer { font-size: 16px; }
  .field-row { flex-direction: column; gap: 0; }
  #toasts { left: 12px; right: 12px; transform: none; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
/* Touch screens have no hover, so what hover shows is always there (or left out). */
@media (hover: none) {
  .row.touched .row-actions, .entry.touched .row-actions { display: flex; }
  .banner-change { opacity: 1; }
  .card:hover { background: var(--surface); }
}
