/* Two themes over one set of tokens. Light is the default; dark is chosen
   inside the site and set on <html> by theme.js as data-theme="dark".
   Components use the tokens only — never a colour of their own. */

@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-sans@5.3.0/files/ibm-plex-sans-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: italic; font-weight: 400; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-sans@5.3.0/files/ibm-plex-sans-latin-400-italic.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-sans@5.3.0/files/ibm-plex-sans-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-sans@5.3.0/files/ibm-plex-sans-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-mono@5.3.0/files/ibm-plex-mono-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap;
  src: url(https://cdn.jsdelivr.net/npm/@fontsource/ibm-plex-mono@5.3.0/files/ibm-plex-mono-latin-500-normal.woff2) format("woff2"); }

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --field: #ffffff;
  --ink: #14171c;
  --muted: #5d6572;
  --line: #dde0e6;
  --line-strong: #c3c8d1;
  --accent: #4b2fd0;
  --accent-dark: #3a22ab;
  --accent-soft: #b4a8ec;
  --on-accent: #ffffff;
  --link: #3a22ab;
  --tint: #f1eefc;
  --tint-strong: #e6e0fb;
  --code-bg: #f1f3f6;
  --ok: #117a4b;
  --ok-bg: #e8f5ee;
  --ok-line: #b9e0c9;
  --warn: #a35f00;
  --warn-bg: #fdf1e0;
  --bad: #c0271e;
  --bad-bg: #fcebea;
  --bad-line: #f1c1bc;
  --on-status: #ffffff;
  --info: #1f4f86;
  --info-bg: #eaf1fb;
  --info-line: #c6d7ef;
  --neutral-bg: #eef0f3;
  --img-bg: transparent;
  --shadow: #14171c22;
  --backdrop: #14171c88;
  --grid: #eef0f3;
  --grid-noise: #dde1e7;
  --radius: 0;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 22'%3E%3Cpath d='M0 11 L3 4 L6 17 L9 2 L12 19 L15 6 L18 15 L21 8 L24 13 L27 9.5 L30 12.2 L33 10.2 L36 11.6 L39 10.6 L42 11.2 L46 11 L64 11' fill='none' stroke='%23000' stroke-width='1.4' stroke-linejoin='round'/%3E%3C/svg%3E");
  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark: an oscilloscope screen — near-black with a blue-green cast and a
   phosphor-cyan trace. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1012; --panel: #11171a; --field: #0e1417; --ink: #d9e2e4; --muted: #86949a;
  --line: #223036; --line-strong: #34464d; --accent: #5fd0e6; --accent-dark: #8fe0ef; --accent-soft: #2d6673;
  --on-accent: #0c1012; --link: #5fd0e6; --tint: #12262c; --tint-strong: #173640; --code-bg: #0f1a1e;
  --ok: #4fc98a; --ok-bg: #0f2419; --ok-line: #1f4a33; --warn: #f0b050; --warn-bg: #2a1e0c;
  --bad: #ff6b5e; --bad-bg: #2a1311; --bad-line: #5a2622; --on-status: #0c1012;
  --info: #8cc8ea; --info-bg: #10222e; --info-line: #1f4052; --neutral-bg: #172024;
  --img-bg: #eef2f3; --shadow: #00000088; --backdrop: #000000aa; --grid: #151e22; --grid-noise: #2b3f46;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
}
a { color: var(--link); text-decoration: none; }
/* The background field, drawn by theme.js in the --grid colours. */
#field { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
/* Labels, numbers and controls speak in the mono face. */
.panel > h3, table.list th, .filter-label, .badge, .msg-head, button, .btn, .chip,
.topbar .brand small, .draft-save-state { font-family: var(--mono); }
a:hover { text-decoration: underline; }

/* Keyboard users see where they are; the skip link appears only on focus. */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: var(--ink); color: var(--bg); padding: 0.65rem 1rem; border-radius: var(--radius); }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.environment-banner {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 0.28rem 1rem;
  background: #8a4b00;
  color: #fff;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}
.environment-development .topbar { top: 1.7rem; }

/* ---------------------------------------------------------------- layout */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 600; letter-spacing: 0.01em; display: grid; grid-template-columns: auto 1fr; column-gap: 0.75rem; align-items: center; }
.topbar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.08em; }
/* The mark: noise settling into silence. Drawn as a mask so it takes the
   accent colour of either theme and survives pages rewriting the brand. */
.topbar .brand::before {
  content: "";
  grid-row: span 2;
  width: 3.4rem;
  height: 1.4rem;
  background: var(--accent);
  -webkit-mask: var(--mark) center / contain no-repeat;
          mask: var(--mark) center / contain no-repeat;
}
/* It sweeps in, briefly, every time a page opens. */
.topbar .brand::before { animation: trace 0.9s linear 0.1s both; }
@keyframes trace { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
:root[data-theme="dark"] .topbar .brand::before { filter: drop-shadow(0 0 2px var(--accent)); }
@media (prefers-reduced-motion: reduce) { .topbar .brand::before { animation: none; } }
.theme-toggle { min-width: 4.2rem; }

/* The masthead on pages outside any course (sign-in, invitations). */
.masthead { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1.6rem; }
.masthead::before {
  content: ""; flex: none; width: 4.2rem; height: 1.7rem; background: var(--accent);
  -webkit-mask: var(--mark) center / contain no-repeat;
          mask: var(--mark) center / contain no-repeat;
}
.masthead h1 { margin: 0; font-size: 1.45rem; line-height: 1.2; }
.masthead::before { animation: trace 0.9s linear 0.1s both; }
:root[data-theme="dark"] .masthead::before { filter: drop-shadow(0 0 2px var(--accent)); }
@media (prefers-reduced-motion: reduce) { .masthead::before { animation: none; } }
.topbar nav { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0.4rem 1rem; font-size: 0.95rem; }
/* Items wrap whole onto a second row rather than breaking mid-label. */
.topbar nav > * { white-space: nowrap; }
.topbar .who { color: var(--muted); font-size: 0.85rem; }
/* "Edit my Personal Information" reads like the nav links, not a button. */
.topbar button.profile-link { background: none; border: 0; padding: 0; font: inherit; letter-spacing: 0; text-transform: none; color: var(--ink); }
.topbar button.profile-link:hover, .topbar button.profile-link:focus-visible { color: var(--link); text-decoration: underline; background: none; }
/* An admin's "View as" select (api.js ViewAs), small beside the profile link. */
.topbar label.view-as { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; font-size: 0.8rem; }
.topbar label.view-as select { width: auto; padding: 0.15rem 0.4rem; font-size: 0.8rem; }
.view-as-banner { padding: 0.35rem 1rem; background: var(--warn-bg); color: var(--warn); text-align: center; font-size: 0.85rem; font-weight: 600; }
.view-as-banner button { margin-left: 0.6rem; }
.topbar nav a { color: var(--ink); }
.topbar nav a:hover { color: var(--link); }
.topbar nav a[aria-current="page"] { color: var(--link); text-decoration: underline; text-underline-offset: 0.25em; }

.page { max-width: 52rem; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.page.wide { max-width: 68rem; }
.page.drafts-wide { max-width: 88rem; }

h1 { font-size: 1.55rem; font-weight: 600; margin: 0 0 0.25rem; text-wrap: balance; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 1.5rem 0 0.6rem; }
h2 .discover { vertical-align: middle; margin-left: 0.6rem; }
p.lead { color: var(--muted); margin-top: 0.25rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 0.5rem; font-size: 1.02rem; font-weight: 600; }
/* course.html: a box hidden from students, as its professors still see it. */
.panel.section-hidden { border-style: dashed; opacity: 0.65; }
.panel .section-toggle { float: right; margin: -0.35rem 0 0 0.6rem; }
.panel > h3 { font-size: 0.72rem; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 0.75rem; }
.panel > h3 .muted { text-transform: none; letter-spacing: 0; }
/* Corner ticks mark the object of study — the matrix — and nothing else. */
.panel:has(> .matrix) {
  --tick: linear-gradient(var(--accent), var(--accent));
  background: var(--tick) top left / 10px 2px, var(--tick) top left / 2px 10px,
              var(--tick) top right / 10px 2px, var(--tick) top right / 2px 10px,
              var(--tick) bottom left / 10px 2px, var(--tick) bottom left / 2px 10px,
              var(--tick) bottom right / 10px 2px, var(--tick) bottom right / 2px 10px,
              var(--panel);
  background-repeat: no-repeat;
  background-origin: border-box;
}

/* ---------------------------------------------------------------- forms */

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.9rem 0 0.3rem; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  font: inherit;
  color: var(--ink);
}
input[type="date"], input[type="number"] {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  font: inherit;
  color: var(--ink);
}
textarea { min-height: 7rem; font-family: var(--mono); font-size: 0.9rem; line-height: 1.5; }
/* admin.html: the group of each student, in a narrow column; at 100% the number had no room. */
#experimentTable select { width: auto; min-width: 3.5rem; padding: 0.3rem 0.5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.6rem 1.05rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 90ms linear, border-color 90ms linear;
}
button:hover, .btn:hover { background: var(--accent-dark); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.ghost:hover, .btn.ghost:hover { border-color: var(--muted); background: transparent; }
button.danger, .btn.danger { background: var(--bad); color: var(--on-status); }
button.danger:hover, .btn.danger:hover { background: color-mix(in srgb, var(--bad) 82%, var(--ink)); }
button.small, .btn.small { padding: 0.35rem 0.7rem; font-size: 0.68rem; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; align-items: center; }
.editor-tools { flex-wrap: wrap; }
.editor-tools button { white-space: nowrap; }
.editor-tools [aria-live] { flex-basis: 100%; }
.editor-tools [aria-live]:empty { display: none; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.7rem; align-items: end; }
.filter-grid label { margin: 0; }
.filter-grid input, .filter-grid select { width: 100%; }
.check-stack { display: grid; gap: 0.35rem; margin: 0.6rem 0; }
.check-stack label { margin: 0; }

.error { background: var(--bad-bg); border: 1px solid var(--bad-line); color: var(--bad); padding: 0.6rem 0.85rem; border-radius: var(--radius); margin: 0.8rem 0; }
.ok-msg { background: var(--ok-bg); border: 1px solid var(--ok-line); color: var(--ok); padding: 0.6rem 0.85rem; border-radius: var(--radius); margin: 0.8rem 0; }
.hidden { display: none !important; }
/* Optional subsystems: hidden until Session.load() confirms they are on. */
[data-feature]:not(.feature-on) { display: none !important; }

/* -------------------------------------------------------------- messages */

/* One message in the inbox or the sent list. Unread rows carry a soft tint
   so a glance at the list shows what is still waiting. */
.message { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 0.9rem; margin-bottom: 0.5rem; }
.message.unread { background: var(--info-bg); border-color: var(--info-line); }
.message-head { display: flex; gap: 0.7rem; align-items: baseline; flex-wrap: wrap; }
.message-body { margin-top: 0.5rem; color: var(--ink); }
.message .muted a { color: var(--bad); }


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

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card h4 { margin: 0 0 0.25rem; font-size: 1.02rem; }
.card .meta { color: var(--muted); font-size: 0.82rem; display: flex; gap: 0.8rem; flex-wrap: wrap; align-items: center; }

/* The general dashboard's course boxes: one card per membership. */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0.8rem; }
.course-grid .card { display: block; margin-bottom: 0; text-decoration: none; color: inherit; cursor: pointer; }
.course-grid .card:hover { border-color: var(--accent); }

/* One challenge's standing on the dashboard's progress box. */
.progress-row { display: flex; gap: 0.7rem; align-items: baseline; padding: 0.3rem 0; }
.progress-row .badge { flex: none; }

/* PDF documents are the primary layer — they get the highlight. */
.card.doc { border-left: 2px solid var(--accent); padding: 1rem 1.2rem; }
.card.doc h4 { font-size: 1.08rem; }
.btnrow { display: flex; gap: 0.6rem; margin-bottom: 1rem; }

/* Tag chips (multi-select) and the tag management row */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.35rem 0 0.6rem; }
.chip {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: none;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tag-add-row { display: flex; gap: 0.6rem; align-items: center; }
.tag-add-row input { flex: 1; }
.pdf-frame {
  width: 100%;
  height: 75vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.pdf-loading { display: flex; align-items: center; justify-content: center; background: var(--panel); }
input[type="file"] { width: 100%; padding: 0.6rem 0; font: inherit; color: var(--ink); }
input[type="file"]::file-selector-button {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.4rem 0.9rem;
  margin-right: 0.8rem;
  font: inherit;
  cursor: pointer;
}

.badge {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.14rem 0.45rem;
  border-radius: var(--radius);
}
.badge.note { background: var(--tint-strong); color: var(--link); }
.badge.reference { background: var(--info-bg); color: var(--info); }
.badge.pdf { background: var(--warn-bg); color: var(--warn); }
.badge.ch { background: var(--neutral-bg); color: var(--muted); }
.badge.status { text-transform: none; letter-spacing: 0.02em; font-weight: 500; }
.badge.status.sent, .badge.status.pending { background: var(--info-bg); color: var(--info); }
.badge.status.accepted { background: var(--ok-bg); color: var(--ok); }
.badge.status.expired, .badge.status.revoked { background: var(--bad-bg); color: var(--bad); }

.content-filters {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 0.8rem;
  padding: 0.75rem 0.85rem;
  background: color-mix(in srgb, var(--panel) 75%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filter-row { display: flex; gap: 0.7rem; align-items: flex-start; }
.filter-label { flex: 0 0 3.2rem; padding-top: 0.35rem; color: var(--muted); font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; }
.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.filters button { padding: 0.35rem 0.7rem; font-size: 0.7rem; background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.filters button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

@media (max-width: 520px) {
  .filter-row { display: block; }
  .filter-label { display: block; padding: 0 0 0.35rem; }
}

/* ---------------------------------------------------------------- content */

.content-body { line-height: 1.7; }
.content-body img { max-width: 100%; background: var(--img-bg); }
/* Line drawings (theme.js marks them) are inverted in the dark theme: the
   ink turns light, the white paper turns black, and "lighten" lets the panel
   show through the black, so the figure sits on the page with no box. */
:root[data-theme="dark"] .content-body img[data-ink="line"] {
  background: transparent;
  filter: invert(1) hue-rotate(180deg) brightness(0.88);
  mix-blend-mode: lighten;
}
/* Figures are centred here because the sanitiser strips authored style="". */
.content-body figure { margin: 1.2rem 0; text-align: center; }
.content-body figcaption { color: var(--muted); font-size: 0.88rem; margin-top: 0.35rem; }
.content-body pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; overflow-x: auto; font-family: var(--mono); font-size: 0.88rem; }
.content-body code { font-family: var(--mono); font-size: 0.9em; background: var(--code-bg); padding: 0.1rem 0.3rem; }
.content-body blockquote { margin: 0; padding: 0 1rem; border-left: 2px solid var(--line-strong); color: var(--muted); }

.comment { border-top: 1px solid var(--line); padding: 0.8rem 0; }
.comment .meta { font-size: 0.8rem; color: var(--muted); display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }

/* ---------------------------------------------------------------- tables */

table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.list th { text-align: left; color: var(--muted); font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line-strong); }
table.list td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
table.list tr:last-child td { border-bottom: 0; }
.table-scroll { overflow-x: auto; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 720px) { .split { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 0.4rem; margin-bottom: 1.2rem; }
.tabs button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.tabs button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
/* Sortable column headers: the button looks like the plain header text.
   Each label stays on one line with its arrow on a line of its own below,
   and the headers align to the top so every label sits on the same row. */
table.list:has(button.sort) th { vertical-align: top; white-space: nowrap; }
table.list th button.sort {
  display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.15rem;
  background: none; border: 0; padding: 0; color: inherit; font: inherit;
  letter-spacing: inherit; text-transform: inherit; text-align: left; cursor: pointer;
}
table.list th button.sort:hover { background: none; color: var(--ink); }
table.list th button.sort::after { content: "\2195"; opacity: 0.35; }
table.list th[aria-sort="ascending"] button.sort::after { content: "\2191"; opacity: 1; }
table.list th[aria-sort="descending"] button.sort::after { content: "\2193"; opacity: 1; }
table.list th[aria-sort] { color: var(--ink); }
table.list caption { text-align: left; font-weight: 600; padding: 0.4rem 0; }
.table-scroll { overflow-x: auto; }
.list-status { min-height: 1.4em; margin: 0.65rem 0; }
.nowrap { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 0.8rem; margin-top: 1rem; }

/* ui.js: the live status region and the confirm dialog. */
.notifications { position: fixed; right: 1rem; bottom: 1rem; z-index: 30; max-width: min(32rem, calc(100vw - 2rem)); padding: 0.8rem 1rem; border: 1px solid var(--line); border-left: 2px solid var(--accent); border-radius: var(--radius); background: var(--panel); box-shadow: 0 4px 18px var(--shadow); overflow-wrap: anywhere; }
.notifications:empty { display: none; }
.notifications.error { border-left-color: var(--bad); }
.confirm-dialog { max-width: min(30rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; color: var(--ink); background: var(--panel); }
.confirm-dialog::backdrop { background: var(--backdrop); }
.confirm-dialog h2 { margin-top: 0; }

.results { margin: 0.9rem 0; max-height: 20rem; overflow-y: auto; font-size: 0.88rem; font-family: var(--mono); }
.results .ok { color: var(--ok); }
.results .bad { color: var(--bad); }

.preview { border: 1px dashed var(--line); border-radius: var(--radius); padding: 0.9rem 1.1rem; margin-top: 0.8rem; background: var(--panel); }

/* -------------------------------------------------------------- drafts */

.draft-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.draft-heading .lead { margin-bottom: 0; }
.draft-shell { display: grid; grid-template-columns: minmax(13rem, 17rem) minmax(0, 1fr); gap: 1rem; align-items: start; }
.draft-sidebar { position: sticky; top: 4.8rem; max-height: calc(100vh - 6rem); overflow-y: auto; }
.draft-list-item { display: block; width: 100%; text-align: left; color: var(--ink); background: transparent; border: 1px solid var(--line); margin-top: 0.45rem; padding: 0.65rem 0.7rem; font-family: var(--font); font-size: 0.9rem; letter-spacing: 0; text-transform: none; }
.draft-list-item:hover { color: var(--ink); background: var(--tint); border-color: var(--accent); }
.draft-list-item.active { background: var(--tint-strong); border-color: var(--accent); }
.draft-list-item strong, .draft-list-item span { display: block; }
.draft-list-item strong { overflow-wrap: anywhere; }
.draft-list-item span { color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; }
.draft-title-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 1rem; }
.draft-save-state { color: var(--muted); font-size: 0.8rem; padding-bottom: 0.6rem; }
.draft-save-state.unsaved { color: var(--warn); font-weight: 600; }
.draft-editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; margin-top: 0.4rem; }
.draft-body { min-height: 31rem; resize: vertical; }
textarea.drop-ready { outline: 2px dashed var(--accent); outline-offset: 2px; }
.draft-preview-label { margin: 0.9rem 0 0.3rem; }
.draft-preview { min-height: 31rem; max-height: 50rem; overflow: auto; margin-top: 0; }
.draft-primary-actions { justify-content: space-between; }
.markdown-guide summary { cursor: pointer; font-weight: 600; }
.markdown-guide pre { overflow-x: auto; white-space: pre-wrap; }

@media (max-width: 900px) {
  .draft-shell, .draft-editor-grid { grid-template-columns: 1fr; }
  .draft-sidebar { position: static; max-height: 18rem; }
  .draft-body, .draft-preview { min-height: 20rem; }
}

@media (max-width: 520px) {
  .draft-heading, .draft-title-row { display: block; }
  .draft-heading button { margin-top: 0.7rem; }
  .draft-save-state { padding: 0.45rem 0 0; }
}

footer { margin-top: 3rem; color: var(--muted); font-size: 0.8rem; text-align: center; }

/* ------------------------------------------------------------ challenges */

/* The matrix, as the machine reads it. */
/* The instance matrix, typeset as a matrix, not a table. */
.matrix { display: block; text-align: center; padding: 0.5rem 0 0.6rem; overflow-x: auto; font-variant-numeric: tabular-nums; }
.matrix mjx-container { font-size: 1.15rem; }

/* The machine's claim, quoted verbatim. */
.claim {
  margin: 0 0 0.6rem;
  padding: 0.9rem 1.1rem;
  border-left: 2px solid var(--accent);
  background: var(--tint);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--ink);
}

/* The session transcript: two clearly separated sides. */
.chat { display: flex; flex-direction: column; gap: 1.15rem; max-height: 55vh; overflow-y: auto; padding: 0.25rem 0.4rem 0.25rem 0; }
.msg { display: flex; flex-direction: column; gap: 0.2rem; max-width: 94%; }
.msg.student { align-self: flex-end; align-items: flex-end; }
.msg.machine { align-self: flex-start; align-items: flex-start; }
.msg-head { display: flex; align-items: baseline; gap: 0.55rem; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-variant-numeric: tabular-nums; }
.msg.student .msg-head { justify-content: flex-end; }
.msg-who { font-weight: 700; }
.msg.student .msg-who { color: var(--accent); }
.msg-at { opacity: 0.75; font-size: 0.62rem; }
.msg-engine { text-transform: none; background: var(--neutral-bg); padding: 0.08rem 0.5rem; font-size: 0.6rem; letter-spacing: 0.02em; }
.msg-bubble { padding: 0.65rem 0.95rem 0.75rem; border-radius: var(--radius); font-size: 0.95rem; line-height: 1.55; }
.msg.student .msg-bubble { background: var(--tint); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); }
.msg.machine .msg-bubble { background: var(--panel); border: 1px solid var(--line); border-left: 2px solid var(--accent); }
.msg-bubble mjx-container { margin: 0.1rem 0; }

.chat-input { margin-top: 0.9rem; }

/* Figures and the Python sandbox. */
.figs { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 900px) { .figs { grid-template-columns: 1fr; } }
.fig h4 { margin: 0 0 0.25rem; font-size: 0.95rem; }
.figure { border: 1px solid var(--line); border-radius: var(--radius); background: var(--field); max-width: 100%; }
.pycode { min-height: 24rem; font-family: var(--mono); font-size: 0.92rem; line-height: 1.5; tab-size: 4; resize: vertical; }

/* The verdict panel. */
.verdict-btns { display: flex; gap: 0.6rem; margin-bottom: 0.4rem; }
.verdict-btns button { flex: 1; text-transform: none; letter-spacing: 0.03em; font-size: 0.8rem; }
.verdict-btns .picked { outline: 3px solid var(--accent); outline-offset: 1px; }
button.okbtn, .btn.okbtn { background: var(--ok); color: var(--on-status); }
button.okbtn:hover, .btn.okbtn:hover { background: color-mix(in srgb, var(--ok) 82%, var(--ink)); }
button.badbtn, .btn.badbtn { background: var(--bad); color: var(--on-status); }
button.badbtn:hover, .btn.badbtn:hover { background: color-mix(in srgb, var(--bad) 82%, var(--ink)); }

/* The spectrum, on the outcome screen. */
.spectrum { display: flex; gap: 1.6rem; align-items: flex-end; padding: 0.9rem 0 0.4rem; }
.spec-col { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.spec-col .bar { width: 1.5rem; background: var(--accent); }
.spec-lbl { font-family: var(--mono); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* admin.html, Traffic tab: the weekly line chart. Two series colours checked
   for colour-blind separation and contrast on each theme's panel. */
:root { --viz-visits: #4b2fd0; --viz-students: #c2410c; }
:root[data-theme="dark"] { --viz-visits: #2a9fb5; --viz-students: #c97a3a; }
.traffic-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.2rem; margin: 0.8rem 0 0.4rem; font-size: 0.85rem; color: var(--muted); }
.traffic-legend span { display: inline-flex; align-items: center; gap: 0.45rem; }
.traffic-legend .key { display: inline-block; width: 1.3rem; height: 0; border-top: 2px solid; }
.traffic-legend .key.visits { border-color: var(--viz-visits); }
.traffic-legend .key.students { border-color: var(--viz-students); }
.traffic-legend .key.enrolled { border-top: 1px dashed var(--muted); }
.traffic-chart { position: relative; margin: 0; }
.traffic-chart svg { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.traffic-chart .grid { stroke: var(--grid-noise); stroke-width: 1; }
.traffic-chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.traffic-chart .band { fill: var(--neutral-bg); }
.traffic-chart .band-label { fill: var(--muted); font-size: 11px; }
.traffic-chart .enrolled { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.traffic-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.traffic-chart .line.estimated { stroke-dasharray: 5 4; }
.traffic-chart .s-visits { stroke: var(--viz-visits); fill: var(--viz-visits); }
.traffic-chart .s-students { stroke: var(--viz-students); fill: var(--viz-students); }
.traffic-chart .dot { stroke: var(--panel); stroke-width: 2; }
.traffic-chart .label { font-size: 11px; font-weight: 600; stroke: none; }
.traffic-chart .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.traffic-tip { position: absolute; top: 0; z-index: 2; pointer-events: none; min-width: 11rem; padding: 0.5rem 0.7rem; background: var(--panel); border: 1px solid var(--line-strong); box-shadow: 0 4px 14px var(--shadow); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.traffic-tip b { display: block; margin-bottom: 0.25rem; }
.traffic-tip .row { display: flex; justify-content: space-between; gap: 1rem; }
.traffic-tip .row i { display: inline-block; width: 0.8rem; border-top: 2px solid; margin-right: 0.35rem; vertical-align: middle; }
table.list th.num, table.list td.num { text-align: right; }
