/* trivium · graphite dark + amber highlights.
 *
 * Surface is warm graphite (#161519) — near-black with a slight warm
 * tilt so it reads as aged paper rather than clinical charcoal. Body
 * text is off-white with a faint warm cast (#e6e0d6), never pure #fff.
 * Highlights, brand, links, primary buttons, and roles use a softened
 * gold-amber (#d4af6a) — descaled from the previous mustard so it sits
 * next to the warm graphite without going neon. Top and bottom strips
 * share the same graphite; the amber lives in the foreground.
 *
 * Previously this was a chalkboard-green slate (#1d3329 + #c8a84b
 * mustard) — replaced because the green-on-amber read as casino-felt
 * rather than scholarly.
 *
 * Type system follows the t34ch.tech presentation deck: Bebas Neue for
 * the trivium brand, page titles, h3 section labels, and badges. Libre
 * Baskerville for body prose (anything markdown-rendered — feedback,
 * assignment description). IBM Plex Sans for the dense form/table
 * chrome. IBM Plex Mono for sha-256s, JWS, code, signal names, table
 * data, form inputs.
 *
 * @font-face declarations point at /static/fonts/. Run
 * scripts/fetch-fonts.sh after a fresh checkout to populate them; if any
 * file is missing, the stack falls back to system serif/sans/mono. */

@font-face {
  font-family: "IBM Plex Sans";
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/IBMPlexSans-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Sans";
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/IBMPlexMono-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/IBMPlexMono-Medium.woff2") format("woff2");
}
@font-face {
  font-family: "Bebas Neue";
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/BebasNeue-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Libre Baskerville";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("/static/fonts/LibreBaskerville-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Libre Baskerville";
  font-weight: 400;
  font-style: italic;
  font-display: swap;
  src: url("/static/fonts/LibreBaskerville-Italic.woff2") format("woff2");
}
@font-face {
  font-family: "Libre Baskerville";
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url("/static/fonts/LibreBaskerville-Bold.woff2") format("woff2");
}

:root {
  /* Graphite dark + amber highlights. Warm near-black canvas, off-white
   * body, softened gold-amber accents. Replaces the prior chalkboard-
   * green slate (the green read as casino-felt rather than scholarly).
   *
   * Two themes ship: graphite (default, dark) and Linen (light, applied
   * via prefers-color-scheme: light). color-scheme is set to `light
   * dark` so the user agent renders form controls + scrollbars in the
   * correct mode for whichever theme is active.
   *
   * Contrast: every text colour pairs ≥4.5:1 against the surfaces it
   * lives on (AA), and every link/badge colour ≥4.5:1 against the
   * darkest card it can appear in. */
  color-scheme: light dark;
  --bg:        #161519;   /* deepest — warm near-black */
  --bg-soft:   #1d1c21;   /* panels, top bar */
  --bg-card:   #232228;   /* cards, raised surfaces */
  --line:      rgba(228, 222, 213, 0.07);
  --line-2:    rgba(228, 222, 213, 0.18);
  --text:      #e6e0d6;   /* primary off-white, faint warm cast */
  --text-dim:  #b1aaa0;   /* secondary text — AA on bg-soft + bg-card */
  --text-mute: #948e83;   /* tertiary — meta, crumbs (AA on bg/bg-soft) */
  --amber:     #d4af6a;   /* brand accent, links, primary buttons */
  --amber-2:   #e8c182;   /* hover state */
  --blue:      #7da7d4;   /* info / role-grader */
  --orange:    #db9a68;   /* terracotta — warn / late */
  --good:      #8fb87a;   /* sage success — no longer the chalkboard green */
  --warn:      #db9a68;
  --err:       #e89090;   /* salmon */
  --link:      #d4af6a;
  /* RGB triplets for rgba(...) tints. Theme-switched alongside the named
   * variables above so opacity-blended highlights track the active palette. */
  --accent-rgb:  212, 175, 106;  /* amber */
  --warn-rgb:    219, 154, 104;  /* orange / terracotta */
  --success-rgb: 143, 184, 122;  /* sage — used by the grade-cell flash */
  /* Text-on-amber colour. Stays as the page bg so the contrast inverts
   * cleanly when the palette flips to Linen. */
  --on-amber: var(--bg);
  --mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --sans:    "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif:   "Libre Baskerville", Georgia, "Times New Roman", serif;
  --display: "Bebas Neue", "IBM Plex Sans Condensed", "Inter", system-ui, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Linen: cool stone paper + sepia ink. Replaces an earlier
     * Vellum draft that was too yellow-cream. Paper hex stays in
     * the neutral-warm-grey range (low chroma); accent shifts from
     * mustard to sepia-brown so amber tints stop reading as cream. */
    --bg:        #e8e6df;
    --bg-soft:   #d6d3cb;
    --bg-card:   #f1eee7;
    --line:      rgba(40, 32, 22, 0.12);
    --line-2:    rgba(40, 32, 22, 0.26);
    --text:      #1c1a14;
    --text-dim:  #5a5447;
    --text-mute: #5e594b;  /* bumped from #8a8478 to hit WCAG AA on bg-soft */
    --amber:     #5e4a14;
    --amber-2:   #6c5719;  /* hover — darkened from #76601f to hit AA on bg-soft */
    --blue:      #2a4a6b;
    --orange:    #8a3a0e;
    --good:      #3e5a22;
    --warn:      #8a3a0e;
    --err:       #762020;
    --link:      #2a4a6b;
    --accent-rgb:  94, 74, 20;
    --warn-rgb:    138, 58, 14;
    --success-rgb: 100, 138, 70;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--amber-2); text-decoration: underline; }

code, pre, .sha, .jws { font-family: var(--mono); }
pre {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12px;
}
.sha { font-size: 11px; color: var(--text-dim); }
.sha.tiny { font-size: 10px; }
.jws { font-size: 11px; word-break: break-all; }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.brand {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--amber);
  font-size: 18px;
}
.brand:hover { color: var(--amber-2); text-decoration: none; }
.topnav { display: flex; gap: 14px; align-items: center; }
.topnav a { font-size: 12px; color: var(--amber); }
.topnav a:hover { color: var(--amber-2); }
.topnav .inline { margin: 0; padding: 0; }
.topnav .link {
  background: none; border: 0; padding: 0;
  color: var(--link); font: inherit; cursor: pointer;
  font-size: 12px;
}
.topnav .link:hover { color: var(--amber-2); text-decoration: underline; }

/* ── Layout ── */
.container {
  max-width: 1100px;
  margin: 28px auto;
  padding: 0 22px 80px;
}
h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 34px;
  margin: 0 0 14px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--amber);
}
h2 { font-size: 16px; font-weight: 600; margin: 18px 0 10px; }
h3 {
  font-family: var(--display);
  font-size: 15px;
  font-weight: 400;
  margin: 14px 0 6px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.dim, .muted { color: var(--text-dim); }
.empty { color: var(--text-mute); font-style: italic; }

.crumbs { font-size: 11px; color: var(--text-mute); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--text-dim); margin: 4px 0 18px; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 16px 18px;
  margin: 18px 0;
}
.card h2:first-child { margin-top: 0; }
.flash {
  padding: 8px 12px;
  background: rgba(var(--accent-rgb), 0.08);
  border-left: 2px solid var(--amber);
  font-size: 13px;
}
.dev-banner {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(var(--warn-rgb), 0.08);
  border-left: 2px solid var(--warn);
  font-size: 12px;
}
.dev-banner a { word-break: break-all; }
.alt { font-size: 12px; margin-top: 14px; color: var(--text-dim); }

/* ── Forms ── */
form { margin: 0; }
form.inline { display: inline; }
label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 12px 0 4px;
}
input[type=text], input[type=email], input[type=url], input[type=number], select, textarea {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line-2);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  padding: 8px 10px;
}
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 1px solid var(--amber); outline-offset: -1px; }

button, .btn {
  display: inline-block;
  background: var(--amber);
  color: var(--on-amber);
  border: 0;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  margin-top: 14px;
}
button:hover { background: var(--amber-2); }
button.link {
  background: none;
  color: var(--link);
  font: inherit;
  padding: 0;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
button.link:hover { color: var(--amber-2); text-decoration: underline; }

/* ── Tables / Grids ── */
table.grid {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  margin: 14px 0;
  font-size: 13px;
}
table.grid th, table.grid td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
table.grid th {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: var(--bg-soft);
}
table.grid tbody tr:hover { background: rgba(var(--accent-rgb), 0.04); }

/* ── Badges / status ── */
.role, .status {
  display: inline-block;
  font-family: var(--display);
  font-size: 11px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 2px 7px 1px;
  border: 1px solid var(--line-2);
  color: var(--text-dim);
}
.role-instructor { color: var(--amber); border-color: var(--amber); }
.role-grader     { color: var(--blue);  border-color: var(--blue); }
.role-student    { color: var(--text);  border-color: var(--line-2); }

.status-graded     { color: var(--amber);  border-color: var(--amber); }
.status-submitted  { color: var(--blue);   border-color: var(--blue); }
.status-missing    { color: var(--orange); border-color: var(--orange); }
.status-open       { color: var(--text-dim); }
.status-ungraded   { color: var(--text-mute); }

/* ── Course header ── */
.course-header { margin-bottom: 18px; }
.subnav {
  display: flex;
  gap: 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  margin-bottom: 18px;
}
.subnav a { color: var(--text); }
.subnav a:hover { color: var(--amber); }

/* ── Video player ── */
.video-player {
  width: 100%;
  max-width: 1080px;
  background: #000;
  display: block;
  margin: 16px 0;
}

/* ── Files ── */
ul.files {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
}
ul.files li {
  padding: 6px 0;
  border-bottom: 1px dotted var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ── Quiz form ── */
fieldset.quiz-q {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  padding: 12px 16px;
  margin: 12px 0;
}
fieldset.quiz-q legend {
  font-family: var(--display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--amber);
  padding: 0 8px;
}
.quiz-opt {
  display: block;
  margin: 4px 0;
  padding: 4px 6px;
  cursor: pointer;
}
.quiz-opt:hover { background: rgba(var(--accent-rgb), 0.04); }
.quiz-short { width: 100%; max-width: 360px; }

/* ── Late badge ── */
.late-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 6px;
  margin-left: 8px;
  border: 1px solid var(--orange);
  color: var(--orange);
  background: rgba(var(--warn-rgb), 0.08);
}

/* ── Class gradebook (inline-editable cells) ── */
.grade-cell-td {
  text-align: center;
  padding: 4px 6px !important;
  position: relative;
}
.grade-cell-form {
  display: inline-block;
  margin: 0;
}
.grade-cell-input {
  width: 56px;
  padding: 3px 6px;
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
}
.grade-cell-input:focus {
  outline: 1px solid var(--amber);
  outline-offset: -1px;
  background: var(--bg-card);
}
.grade-cell-input::-webkit-outer-spin-button,
.grade-cell-input::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.grade-cell-input { -moz-appearance: textfield; }
.grade-cell-link {
  font-size: 9px;
  margin-left: 3px;
  color: var(--text-mute);
  text-decoration: none;
  vertical-align: middle;
}
.grade-cell-link:hover { color: var(--amber); }
/* Brief flash after a successful save. The "saved" class is applied
 * server-side on the response fragment; the animation runs once. */
.gc-saved .grade-cell-input {
  animation: gc-flash 0.9s ease-out;
}
@keyframes gc-flash {
  0%   { background: rgba(var(--success-rgb), 0.45); }
  100% { background: var(--bg-soft); }
}

/* ── Accessibility: skip link + focus ring ── */
.skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  background: var(--amber);
  color: var(--bg-card);
  padding: 8px 14px;
  z-index: 1000;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 8px; outline: 2px solid var(--text); }
/* High-contrast focus ring everywhere; browsers' default is too faint
 * on the dark chalkboard background. */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── Markdown live preview ── */
.md-preview-wrap {
  margin: -8px 0 14px;
  border: 1px solid var(--line);
  border-top: none;
  background: var(--bg-soft);
  padding: 10px 14px;
  font-size: 13px;
}
.md-preview-wrap::before {
  content: "preview";
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.md-preview { color: var(--text); }
.md-preview > :first-child { margin-top: 0; }
.md-preview > :last-child { margin-bottom: 0; }

/* ── SpeedGrader nav ── */
.speedgrader-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  font-size: 13px;
  flex-wrap: wrap;
}
.speedgrader-nav a { font-weight: 600; }
.speedgrader-nav .sg-disabled { color: var(--text-mute); }
.speedgrader-nav .sg-pos { font-family: var(--mono); }
.speedgrader-nav .sg-shortcuts { margin-left: auto; font-size: 11px; }
.speedgrader-nav kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  border-radius: 2px;
}
.grader-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; }
.grader-actions button { margin: 0; }

/* ── Grader layout ── */
.grader-grid {
  display: grid;
  grid-template-columns: 1fr 360px 200px;
  gap: 18px;
}
.grader-grid section, .grader-grid aside { min-width: 0; }
.grader-grid .files-pane { background: var(--bg-card); border: 1px solid var(--line); padding: 14px 16px; }
.grader-grid .grade-pane { background: var(--bg-card); border: 1px solid var(--line); padding: 14px 16px; }
.grader-grid .queue-pane { background: var(--bg-soft); border: 1px solid var(--line); padding: 12px 14px; font-size: 12px; }
ul.queue { list-style: none; padding: 0; margin: 0; }
ul.queue li { padding: 4px 0; border-bottom: 1px dotted var(--line); }
ul.queue li.active { background: rgba(var(--accent-rgb), 0.06); padding-left: 6px; margin-left: -6px; }

ul.annotations { list-style: none; padding: 0; margin: 8px 0 14px; }
.annotation {
  border-left: 2px solid var(--amber);
  padding: 6px 10px;
  margin: 8px 0;
  background: rgba(var(--accent-rgb), 0.04);
  font-size: 12px;
}
.ann-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.annotation-form { background: var(--bg-soft); border: 1px solid var(--line); padding: 10px 12px; }

/* ── Markdown body prose ── feedback, rendered assignment descriptions,
 * anything that's actually paragraphs of writing rather than UI chrome.
 * Libre Baskerville reads at body sizes the way the slide deck reads
 * Baskerville on screen — generous, slightly old-fashioned, classroom. */
.feedback, .prose {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}
.feedback p:first-child, .prose p:first-child { margin-top: 0; }
.feedback code, .prose code {
  font-family: var(--mono);
  background: var(--bg-soft);
  padding: 1px 5px;
  font-size: 12px;
}
.feedback pre code, .prose pre code { background: none; padding: 0; }

/* ── Course list ── */
ul.course-list { list-style: none; padding: 0; margin: 0; }
ul.course-list li { padding: 6px 0; border-bottom: 1px dotted var(--line); font-size: 13px; }

/* ── Footer ── */
.footbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  text-align: center;
  padding: 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--amber);
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  letter-spacing: 0.06em;
}

/* ── Error page ── */
main.err { max-width: 720px; margin: 60px auto; padding: 30px; background: var(--bg-card); border: 1px solid var(--err); }
main.err h1 { color: var(--err); margin: 0 0 12px; font-family: var(--mono); font-size: 18px; letter-spacing: 0.04em; }
main.err pre { color: var(--text-dim); font-size: 12px; }

/* The chalkboard palette applies regardless of prefers-color-scheme.
 * An earlier light-mode variant lived here (whiteboard with green
 * marker); removed because users on light-mode OSes were getting that
 * by default and reading it as "the theme didn't change". Chalkboard
 * everywhere is the right call — the surface IS dark by design. */

/* ── Utility classes — used to drop CSP `style-src 'unsafe-inline'`.
 * Templates previously sprinkled `style="…"` attributes for one-off
 * spacing/typography. Each recurring pattern now has a class here so
 * the CSP can stay strict. */

/* font sizes */
.fs-10 { font-size: 10px; }
.fs-11 { font-size: 11px; }
.fs-12 { font-size: 12px; }

/* mono variants */
.mono-10 { font-family: var(--mono); font-size: 10px; }
.mono-12 { font-family: var(--mono); font-size: 12px; }

/* margins (vertical) */
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-24 { margin-top: 24px; }
.mb-14 { margin-bottom: 14px; }
.ml-14 { margin-left: 14px; }
.m-0   { margin: 0; }

/* flex layout */
.row-between {
  display: flex;
  justify-content: space-between;
}
.row-between-center {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.row-gap-14 {
  display: flex;
  gap: 14px;
}

/* misc */
.fw-normal       { font-weight: normal; }
.pl-18           { padding-left: 18px; }
.bg-soft         { background: var(--bg-soft); }
.overflow-x-auto { overflow-x: auto; }
.clickable       { cursor: pointer; }
.text-clip-340 {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* themed surfaces (used in flashes + my-message highlight) */
.flash-amber {
  background: rgba(var(--accent-rgb), 0.08);
  border-color: var(--amber);
}
.text-amber {
  border-color: var(--amber);
  color: var(--amber);
}
.message-mine {
  background: rgba(var(--accent-rgb), 0.04);
}
.check-row {
  display: block;
  font-weight: normal;
}
.text-error {
  color: var(--err);
}
.box-input {
  border: 1px solid var(--line);
  padding: 8px 12px;
  background: var(--bg-soft);
  min-height: 80px;
}
.card-padded {
  background: var(--bg-card);
  border: 1px solid var(--line);
  padding: 24px 32px;
}

/* htmx loading indicators — equivalent of the styles htmx would otherwise
 * inject at runtime via document.head.insertAdjacentHTML. We disable that
 * runtime injection (meta htmx-config includeIndicatorStyles:false) so the
 * CSP can keep style-src 'self' with no inline-style escape hatch. */
.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }
.htmx-request.htmx-indicator { opacity: 1; transition: opacity 200ms ease-in; }

/* ─────────────────────────────────────────────────────────────────────────
 * Tablet / touch surface (iPad-first, also benefits all hand-held use).
 *
 * Three things in one pass:
 *   1. Tap targets ≥44pt — Apple's accessibility minimum for touch.
 *      Anything tappable (links in nav, buttons, list rows, form fields)
 *      grows to that target on touch viewports without changing the
 *      desktop look.
 *   2. Body text bumped to 16px on tablet+ so iOS Safari does not
 *      auto-zoom on input focus (it zooms whenever input font-size
 *      <16px), and reading on a 10–13" panel doesn't squint.
 *   3. Safe-area-inset clearance for the iPad Pro home-indicator and
 *      side bezels in landscape (and notched iPads/iPhones, harmless
 *      elsewhere).
 *
 * Strategy: a `pointer: coarse` media-feature override (any touch
 * primary input) plus a viewport-min-width override for tablet+.
 * Desktop pointer:fine viewports keep the original tight density. */

html { -webkit-tap-highlight-color: rgba(var(--accent-rgb), 0.18); }

/* Smooth corners — applied everywhere by default, no breakpoint. */
.card,
.flash, .dev-banner,
button, .btn,
input[type=text], input[type=email], input[type=url], input[type=number],
select, textarea,
.role, .status, .late-badge,
fieldset.quiz-q,
table.grid,
pre,
.skip-link {
  border-radius: 10px;
}
table.grid { overflow: hidden; }   /* contain rounded corners */
.grade-cell-input { border-radius: 6px; }
.brand { border-radius: 6px; }

/* Safe-area gutters on top bar + main container. max() falls back to the
 * original numeric padding on browsers without env() support. */
.topbar {
  padding-left:  max(22px, env(safe-area-inset-left));
  padding-right: max(22px, env(safe-area-inset-right));
  padding-top:    max(10px, env(safe-area-inset-top));
}
.container {
  padding-left:  max(22px, env(safe-area-inset-left));
  padding-right: max(22px, env(safe-area-inset-right));
  padding-bottom: max(80px, calc(env(safe-area-inset-bottom) + 80px));
}

/* prefers-reduced-motion: respect the OS hint. The grade-cell flash is
 * informative not decorative, so we keep the colour change but drop
 * the timed animation (it ends in the same final state either way). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Touch-pointer pass: applied any time the primary input is coarse
 * (finger, pencil, stylus) regardless of viewport size. */
@media (pointer: coarse) {
  html, body { font-size: 16px; line-height: 1.55; }

  /* Form fields: 16px font kills iOS focus-zoom; 12px vertical padding
   * pushes height past the 44pt minimum (16 line-height ≈ 25, +24
   * padding = 49). Same look applies to textareas. */
  input[type=text], input[type=email], input[type=url], input[type=number],
  select, textarea {
    font-size: 16px;
    padding: 12px 14px;
    min-height: 44px;
  }
  textarea { font-size: 15px; line-height: 1.5; }

  /* Buttons: 14px label, 12px/22px padding, 44pt min height.
   * .btn-sm escape hatch left at the old size for crowded toolbars. */
  button, .btn {
    font-size: 14px;
    padding: 12px 22px;
    min-height: 44px;
  }
  button.link { min-height: 0; padding: 0; }   /* inline link-style stays inline */
  .btn-sm { font-size: 12px; padding: 8px 14px; min-height: 0; }

  /* Top + sub nav links become real tap targets with vertical padding
   * (the previous 12px font with no padding gave a ~14px tall hit area
   * — well below 44pt). */
  .topnav a, .topnav .link {
    font-size: 14px;
    padding: 10px 6px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .subnav { gap: 4px; padding: 4px 0; }
  .subnav a {
    font-size: 14px;
    padding: 10px 12px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    border-radius: 8px;
  }
  .subnav a:hover { background: rgba(var(--accent-rgb), 0.08); text-decoration: none; }

  /* File-list rows — were 6px vertical padding (≈22px tall); bump to
   * a finger-friendly hit area. */
  ul.files li { padding: 12px 0; gap: 14px; }
  ul.files { font-size: 14px; }

  /* Quiz options become tappable rows, not text-spans. */
  .quiz-opt {
    padding: 12px 14px;
    margin: 6px 0;
    border: 1px solid var(--line);
    border-radius: 8px;
  }
  .quiz-opt:hover { background: rgba(var(--accent-rgb), 0.08); }

  /* Tables: bigger row height for inline-editable gradebook cells. */
  table.grid th, table.grid td { padding: 12px 14px; font-size: 14px; }
  .grade-cell-input { width: 72px; padding: 8px 10px; font-size: 14px; }

  /* Cards breathe a little more. */
  .card { padding: 20px 22px; }

  /* Inline label sizes are still small for hierarchy, but the
   * smallest copy gets a small bump too. */
  label { font-size: 12px; }
  .crumbs { font-size: 12px; }
  .meta { font-size: 13px; gap: 18px; }
}

/* Tablet+ viewport (≥ 768px) — also applies on laptop touch screens.
 * Keep container max-width 1100px, but widen interior gutter so
 * full-bleed never looks cramped against the rounded corners. */
@media (min-width: 768px) {
  .container { padding-top: 24px; }
  h1 { font-size: 38px; }
}

/* Stage Manager / multi-window aware: when the viewport is very
 * narrow (single-pane on iPad multitasking), drop side gutter and
 * stack the topbar contents. */
@media (max-width: 480px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .container { padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 28px; }
}

/* ─────────────────────────────────────────────────────────────────────────
 * Pencil annotation (ink.js)
 *
 * .ink-figure  — outer figure wrapping image + caption
 * .ink-frame   — flex/positioning host; the .ink-host class gets added
 *                by JS once the canvas mounts; this provides a fallback
 *                style before the JS has run.
 * .ink-host    — image's parent at runtime; relatively positioned so
 *                the canvas can overlay absolutely.
 * .ink-layer   — the canvas; absolute, exactly atop the image, with
 *                touch-action:none so the browser doesn't steal Pencil
 *                strokes for page scroll.
 * .ink-toolbar — pill row above the image with tool + undo + save.
 */

.ink-figure { margin: 18px 0; }
.ink-figure figcaption {
  font-size: 12px;
  margin-bottom: 6px;
}

.ink-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px 10px 0 0;
  border-bottom: 0;
}
.ink-toolbar .ink-btn { margin: 0; }
.ink-toolbar .ink-btn.active {
  background: var(--amber-2);
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}
.ink-toolbar .ink-save { margin-left: auto; }

.ink-frame {
  position: relative;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  line-height: 0;            /* kill descender gap under <img> */
}
.ink-frame img,
.ink-host img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.ink-host { position: relative; }
.ink-layer {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;        /* required for Pencil + finger capture */
  cursor: crosshair;
}
.ink-layer.erase { cursor: cell; }

/* ─────────────────────────────────────────────────────────────────────────
 * Course shell — sticky vertical sidebar pattern (iPadOS-style left rail).
 *
 * On tablet+ widths (≥ 900px) the shell is a 240px sidebar + flexible
 * content area. The sidebar is `position: sticky` so it stays in view
 * while the content scrolls. On narrow viewports the sidebar collapses
 * behind a hamburger button (.drawer-toggle); JS (initDrawerToggles)
 * flips the .open class.
 *
 * No layout shift on initial paint: the sidebar element is in normal
 * flow on narrow widths and stacks above the content. CSS grid handles
 * both states with a single `grid-template-columns` rule per breakpoint.
 */

.course-shell { display: block; }
.drawer-toggle { display: inline-flex; margin: 6px 0 12px; }

.course-shell-nav {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 14px;
  margin-bottom: 14px;
}
.course-shell-nav.open { display: block; }

.course-shell-brand { margin-bottom: 12px; }
.course-shell-title {
  font-family: var(--display);
  font-size: 18px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--amber);
}
.course-shell-meta {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-dim);
}

.course-shell-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
}
.course-shell-links a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  border: 1px solid transparent;
}
.course-shell-links a:hover {
  background: rgba(var(--accent-rgb), 0.06);
  color: var(--amber);
  text-decoration: none;
}
.course-shell-links a.active {
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--amber);
  border-color: rgba(var(--accent-rgb), 0.25);
  font-weight: 600;
}
.course-shell-section {
  font-family: var(--display);
  letter-spacing: 0.10em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--text-dim);
  margin: 14px 0 4px;
  padding: 0 12px;
}
.course-shell-admin { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 4px; }
.course-shell-foot { margin-top: 12px; padding: 8px 12px; font-size: 12px; }

/* Tablet+ — pin the sidebar to the left as a sticky rail. */
@media (min-width: 900px) {
  .drawer-toggle { display: none; }
  .course-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }
  .course-shell-nav {
    display: block;
    position: sticky;
    top: 16px;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    margin-bottom: 0;
  }
  .course-shell-main { min-width: 0; }   /* let tables shrink */
  .course-shell-main .course-header h1 { margin-top: 0; }
}

/* Wide desktop — extra room for the table. */
@media (min-width: 1280px) {
  .course-shell { grid-template-columns: 260px minmax(0, 1fr); gap: 32px; }
}

/* ── Module item rows ───────────────────────────────────────────────── */
.module-items { list-style: none; padding: 0; margin: 12px 0 0; }
.module-items .module-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.module-items .module-item:last-child { border-bottom: 0; }
.module-items .module-item a { flex: 1 1 auto; }
.module-items .module-item .role { font-size: 10px; opacity: 0.7; }
