:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #64748b;
  --line: #d7dde5;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --ok: #15803d;
  --err: #b91c1c;
  --warn: #b45309;
  --shape: #fbfbfd;
  --entity: #1e3a8a;
  --rel: #7c3aed;
  --weak: #0f766e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* The browser hides [hidden] with `display: none`, but any author rule that
   sets `display` beats it - which silently turned every `el.hidden = true` on
   a flex banner or toolbar into a no-op (a student's name stayed on screen
   after leaving their work).  Say it once, with the weight to hold. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  display: flex; flex-direction: column; font-size: 14px;
}

/* ---- top bar ---- */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .2px; color: var(--accent); }
.project-controls { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.project-controls .spacer { flex: 1; }
.project-controls label { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
select, input[type=text], textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
}
button {
  font: inherit; cursor: pointer; border-radius: 6px; padding: 5px 11px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.ghost:hover { border-color: var(--accent); color: var(--accent); }
button.danger { color: var(--err); border-color: #f0c9c9; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 2px 8px; font-size: 12px; }

/* ---- tabs ---- */
#tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 14px; font-weight: 600;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- staleness banner ---- */
#staleBanner {
  padding: 6px 16px; background: #fff7ed; color: var(--warn);
  border-bottom: 1px solid #fed7aa; font-size: 13px;
}
#staleBanner button { margin-left: 10px; }

#changeBanner {
  padding: 6px 16px; background: #eef2ff; color: #3730a3;
  border-bottom: 1px solid #c7d2fe; font-size: 13px;
}
#changeBanner button { margin-left: 10px; }
.presence-chip { align-self: center; font-size: 12px; color: var(--muted);
  background: #eef2f7; border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 9px; white-space: nowrap; }

/* ---- main view ---- */
#view { flex: 1; overflow: auto; position: relative; }
.stage { padding: 16px 20px; max-width: 1200px; }
.stage h2 { margin: 0 0 4px; font-size: 18px; }
.stage .lede { color: var(--muted); margin: 0 0 16px; max-width: 70ch; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }

/* ---- ER editor ---- */
#erWrap { position: absolute; inset: 0; display: flex; overflow: hidden; }
#erCanvasCol { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#erToolbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
#erToolbar .hint { color: var(--muted); font-size: 12px; }
#erSvg { flex: 1; background:
  linear-gradient(90deg, rgba(0,0,0,.035) 1px, transparent 1px) 0 0 / 24px 24px,
  linear-gradient(rgba(0,0,0,.035) 1px, transparent 1px) 0 0 / 24px 24px, #fff;
  cursor: grab; user-select: none; }
#erSvg.panning { cursor: grabbing; }

.node { cursor: move; }
.node .shape { fill: var(--shape); stroke: var(--entity); stroke-width: 2; }
.node.weak .shape { stroke: var(--weak); }
.node.rel .shape { fill: #faf5ff; stroke: var(--rel); }
.node.sel .shape { stroke: var(--accent); filter: drop-shadow(0 0 0 2px var(--accent-soft)); }
.node .label { font-size: 13px; font-weight: 600; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.node.rel .label { font-weight: 600; }

.edge { stroke: #94a3b8; stroke-width: 1.5; fill: none; }
.edge.total { stroke-width: 1.5; }
.edge-card { font-size: 11px; fill: var(--muted); font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.spec-tri { fill: #eef2ff; stroke: var(--rel); stroke-width: 1.5; }
.spec-letter { font-size: 11px; font-weight: 700; fill: var(--rel); text-anchor: middle; dominant-baseline: middle; }

.attr { cursor: move; }
.attr:hover .attr-ellipse { stroke: var(--accent); }

/* teammate cursors */
.peers { pointer-events: none; }
.peer-outline { fill: none; stroke-width: 2; stroke-dasharray: 5 3; opacity: .9; }
.peer-cursor { stroke: #fff; stroke-width: 1.2; paint-order: stroke; }
.peer-pill { }
.peer-name { fill: #fff; font-size: 10px; font-weight: 600; dominant-baseline: middle; }
.attr-ellipse { fill: #fff; stroke: #9aa7b6; stroke-width: 1.2; }
.attr-ellipse.mv { stroke-width: 1.2; }
.attr-ellipse.derived { stroke-dasharray: 4 3; }
.attr-line { stroke: #b8c2ce; stroke-width: 1; }
.attr-text { font-size: 10px; fill: #475569; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.attr-underline { stroke: #475569; stroke-width: 1; pointer-events: none; }
.attr-underline.partial { stroke-dasharray: 2.5 2; }  /* weak-entity discriminator */

/* ---- properties panel ---- */
#erPanel { flex: 0 0 340px; width: 340px; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 14px; }
#erWrap.panel-anim #erPanel { transition: transform .25s ease, margin-right .25s ease; }
#erWrap.panel-collapsed #erPanel { transform: translateX(100%); margin-right: -340px; }
#erPanel h3 { margin: 0 0 10px; font-size: 14px; }
#erPanel .empty { color: var(--muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.field > label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; gap: 6px; align-items: center; }
.checkbox-row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 13px; }
.sublist { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; }
.sublist .item { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.sublist .item:last-child { border-bottom: none; }
.sublist .item .line { display: flex; gap: 4px; }
.sublist .item input[type=text] { flex: 1; min-width: 0; }
.sublist .item select { flex: 1; min-width: 0; }
.mini { font-size: 11px; color: var(--muted); }

/* What is actually in the built database: one chip per table with its row
   count.  The shape of the schema is drawn at stage 2, so this is only ever
   about how full it is. */
.fill-counts { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.fill-count { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
  background: #fff; color: var(--muted); }
.fill-count b { color: var(--ink); font-variant-numeric: tabular-nums; }
.fill-count.none { color: var(--muted); border-style: dashed; }
.fill-count.none b { color: var(--muted); }

/* ---- schema cards / mapping log ---- */
.cards { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-width: 240px; max-width: 340px; overflow: hidden; }
.card > header { background: #f8fafc; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.card > header .tname { font-weight: 700; }
.card > header .src { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.card table { width: 100%; border-collapse: collapse; font-size: 12px; }
.card td { padding: 4px 12px; border-bottom: 1px solid #eef1f5; }
.card tr:last-child td { border-bottom: none; }
.card .col-name { font-weight: 600; }
.card .col-type { color: var(--muted); }
.badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 4px; }
.badge.pk { background: #fef9c3; color: #854d0e; }
.badge.fk { background: #dbeafe; color: #1e40af; }
.badge.u  { background: #ede9fe; color: #5b21b6; }
.badge.nn { background: #f1f5f9; color: #475569; }
.card .fkline { padding: 4px 12px; font-size: 11px; color: var(--muted); border-top: 1px dashed var(--line); }

/* ---- editable schema cards (stage 2) ---- */
.card.edit { max-width: 440px; }
.card.edit > header { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.card.edit > header .src { flex-basis: 100%; margin-top: 3px; }
.card.edit .tname-input { flex: 1; min-width: 0; font-weight: 700; font-size: 13px;
  border: 1px solid transparent; background: transparent; border-radius: 4px; padding: 2px 4px; }
.card.edit .tname-input:hover { border-color: var(--line); }
.card.edit .tname-input:focus { border-color: var(--accent); background: #fff; }
.card.edit table.cols { width: 100%; border-collapse: collapse; }
.card.edit table.cols th { text-align: left; font-size: 9.5px; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase; color: var(--muted); padding: 5px 4px; border-bottom: 1px solid var(--line); }
.card.edit table.cols td { padding: 3px 4px; border-bottom: 1px solid #eef1f5; }
.card.edit table.cols td.ck, .card.edit table.cols th.ck { text-align: center; width: 24px; padding-left: 0; padding-right: 0; }
.card.edit input:not([type=checkbox]), .card.edit select {
  font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--line);
  border-radius: 4px; background: #fff; max-width: 100%; }
.card.edit .c-name { width: 96px; }
.card.edit .c-type { width: 100%; }
.card.edit .c-def { width: 66px; }
.card.edit .fk-cols { width: 74px; }
.card.edit .chk { width: 160px; }
.card.edit .x { border: none; background: transparent; color: var(--err); font-size: 15px;
  line-height: 1; padding: 0 3px; cursor: pointer; }
.card.edit .x:hover { color: #7f1d1d; }
.card.edit .card-actions, .card.edit .sec { padding: 6px 10px; border-top: 1px dashed var(--line); }
.card.edit .sec-h { font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; }
.card.edit .fk-row { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; margin-bottom: 4px; }

.spec-strategies { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin: 10px 0; }
.spec-strategies .row { margin-top: 6px; gap: 8px; }
.log-wrap { margin-top: 20px; }
.log-wrap > summary { cursor: pointer; font-weight: 600; color: var(--ink); margin-bottom: 6px; }

.log { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; margin-top: 8px; }
.log .step { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.log .step:last-child { border-bottom: none; }
.log .rule { font-weight: 700; color: var(--accent); }
.log .kv { font-size: 12px; margin-top: 3px; }
.log .kv b { color: var(--muted); font-weight: 600; }
.warnbox { background: #fff7ed; border: 1px solid #fed7aa; color: var(--warn); border-radius: 8px; padding: 8px 12px; margin: 10px 0; font-size: 13px; }
.warnbox ul { margin: 4px 0 0 18px; }

/* ---- code / results ---- */
textarea.code { width: 100%; min-height: 340px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; line-height: 1.5; tab-size: 2; }
.stmtlist { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 10px; background: var(--panel); }
.stmtlist .stmt { padding: 7px 12px; border-bottom: 1px solid var(--line); font-family: ui-monospace, monospace; font-size: 12px; white-space: pre-wrap; }
.stmtlist .stmt:last-child { border-bottom: none; }
.stmt .mark { font-weight: 700; margin-right: 8px; }
.stmt.ok .mark { color: var(--ok); }
.stmt.bad { background: #fef2f2; }
.stmt.bad .mark { color: var(--err); }
.stmt .err { display: block; color: var(--err); margin-top: 4px; }

.grid-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-height: 60vh; }
/* room under the last row for the horizontal scrollbar, which otherwise sits
   on top of the `+ add` line and its button */
.grid-scroll { padding-bottom: 14px; }
/* a refusal is meant to be read and copied, so it wraps and selects */
.row-refusal { white-space: pre-wrap; word-break: break-word; user-select: text;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.grid th, table.grid td { border: 1px solid #e5e9ef; padding: 4px 8px; text-align: left; white-space: nowrap; }
table.grid th { background: #f8fafc; position: sticky; top: 0; z-index: 1; }
table.grid td.pk { background: #fffef2; }
table.grid input { width: 100%; min-width: 90px; border: 1px solid transparent; background: transparent; padding: 2px 4px; }
table.grid input:focus { border-color: var(--accent); background: #fff; }
/* The row's controls lead it and stay put.  Moving them from the far end to
   the front puts them on screen at rest; pinning them keeps them there when a
   wide table is scrolled sideways, which is the same complaint one scroll
   later - at 375px, scrolled right, they sat at -384px. */
table.grid td.actions { white-space: nowrap; position: sticky; left: 0;
  z-index: 2; background: #fff; }
table.grid th.actions-h { position: sticky; left: 0; z-index: 3; }
/* an opaque background, or the columns scroll through underneath it */
table.grid tr.add-row td.actions { background: #f3f8ff; }
.msg { font-size: 13px; margin: 8px 0; }
.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); white-space: pre-wrap; font-family: ui-monospace, monospace; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }

.saved-queries { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.saved-queries .chip { font-size: 12px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; }
.saved-queries .chip:hover { border-color: var(--accent); }

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #1d2733; color: #fff; padding: 8px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 50;
}
#toast.err { background: var(--err); }

/* ---- hosted-mode sign in ---- */
.user-chip { font-size: 12px; color: var(--muted); padding: 0 6px; align-self: center; white-space: nowrap; }
.backlink { align-self: center; font-size: 12px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; white-space: nowrap; }
.backlink:hover { border-color: var(--accent); color: var(--accent); }

/* ---- instructor portal ---- */
.stage-admin { max-width: 1000px; }
.admin-add { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.admin-add textarea { width: 100%; }
.assignment-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  margin-bottom: 8px; }
.assignment-card .toolbar { flex-wrap: wrap; gap: 6px; }
.assignment-card p.mini { margin: 4px 0 0; }
.subs-panel { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.subs-panel input.bad { border-color: var(--err); background: #fef2f2; }
.new-codes { background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.new-codes h4 { margin: 0 0 6px; font-size: 13px; }
.new-codes .pair { font-size: 12.5px; line-height: 1.8; }
table.roster { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
table.roster th { text-align: left; background: #f8fafc; padding: 8px 10px; border-bottom: 1px solid var(--line);
  font-size: 10px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.roster td { padding: 7px 10px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
table.roster tr:last-child td { border-bottom: none; }
table.roster tr.inactive td { opacity: .5; }
.code-chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: #f1f5f9;
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 12px;
  white-space: nowrap; }
.code-chip.flash { background: #fde68a; }
.code-chip.masked { color: var(--muted); letter-spacing: 2px; }
.code-cell { display: inline-flex; align-items: center; gap: 5px; }
.code-cell .reveal { border: 0; background: none; color: var(--muted); padding: 2px; margin: 0;
  cursor: pointer; border-radius: 4px; display: inline-flex; align-items: center; }
.code-cell .reveal:hover { color: var(--ink); }
.code-cell .reveal svg { display: block; }
.roster-actions { display: flex; gap: 4px; flex-wrap: wrap; }
/* the material toggle on a class meeting, with its reason beside it */
.sess-material { display: inline-flex; gap: 6px; align-items: center; }
.role-tag { font-size: 9px; font-weight: 700; text-transform: uppercase; padding: 1px 5px;
  border-radius: 4px; background: #ede9fe; color: #5b21b6; margin-left: 6px; vertical-align: 1px; }
.role-tag.student { background: #e0f2fe; color: #075985; }

.portal-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.ptab { background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  color: var(--muted); font-weight: 600; padding: 8px 12px; }
.ptab:hover { color: var(--ink); }
.ptab.active { color: var(--accent); border-bottom-color: var(--accent); }
/* the pages inside a page: which part of a section you are building or marking */
.portal-subnav { display: flex; gap: 4px; margin: 4px 0 14px; }
.portal-subnav .ptab { border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px; font-size: 13px; }
.portal-subnav .ptab.active { background: var(--accent-soft); border-color: var(--accent); }

/* ---- marking one submission: the work beside the mark ---- */
.grade-split { display: flex; gap: 14px; align-items: stretch; min-height: 62vh; }
.grade-frame { flex: 1 1 auto; min-width: 0; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; }
.grade-side { flex: 0 0 340px; width: 340px; display: flex; flex-direction: column;
  gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  background: var(--panel); overflow: auto; }
.grade-head { display: flex; flex-direction: column; gap: 2px; }
.mark-box { width: 80px; font-size: 16px; font-weight: 700; }
/* one chip per thing that carries a mark, so the whole submission is in view */
.grade-steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.step-chip { border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 3px 11px; font-size: 12px; color: var(--muted); }
.step-chip.done { color: var(--ok); border-color: #bbf7d0; background: #f0fdf4; }
.step-chip.active { border-color: var(--accent); color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft); }
.grade-comments { border-top: 1px solid var(--line); padding-top: 8px; }
.grade-comments textarea { width: 100%; }
.comment-row { align-items: flex-start; gap: 8px; }
.mark-chip { background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  padding: 3px 12px; font-size: 13px; }
.role-tag.warn { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
.course-head h3 { margin: 0 0 6px; }
.teams-grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.team-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 260px; }
.team-card.new { background: transparent; border-style: dashed; }
.team-card-h { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
.team-card-h .spacer { flex: 1; }
.member-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; min-height: 20px; }
.member-chip { font-size: 12px; background: #eef2f7; border: 1px solid var(--line); border-radius: 999px; padding: 1px 4px 1px 8px; display: inline-flex; align-items: center; gap: 2px; }
.member-chip .x { border: none; background: transparent; color: var(--err); cursor: pointer; font-size: 13px; line-height: 1; padding: 0 3px; }
.team-card select { width: 100%; font-size: 12px; }
.enrol-picks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 6px 0 10px; }
.enrol-pick { display: inline-flex; align-items: center; gap: 4px; }

.proj-groups { display: flex; flex-direction: column; gap: 10px; }
.proj-group { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.proj-group-h { background: #f8fafc; padding: 6px 12px; font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--line); }
.proj-row { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid #eef1f5; font-size: 13px; }
.proj-row:last-child { border-bottom: none; }
.proj-row .spacer { flex: 1; }
.proj-name { font-weight: 600; }
.lineage { color: var(--muted); }

/* ---- instructor inspect banner (main app) ---- */
#inspectBanner { padding: 6px 16px; font-size: 13px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line); }
#inspectBanner.inspecting { background: #eff6ff; color: #1e40af; border-bottom-color: #bfdbfe; }
#inspectBanner.editing-other { background: #fef2f2; color: #991b1b; border-bottom-color: #fecaca; }
/* ---- show & tell: high contrast, it goes on a projector ---- */
#showTellBanner { padding: 8px 16px; font-size: 14px; font-weight: 600; display: flex;
  align-items: center; gap: 10px; background: #faf5ff; color: #6b21a8;
  border-bottom: 1px solid #e9d5ff; }
dialog.show-tell { max-width: min(560px, 94vw); width: min(560px, 94vw); }
dialog.show-tell .proj-groups { max-height: 50vh; overflow-y: auto; margin-top: 8px; }
.login-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: var(--bg); }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 26px 30px 22px; width: min(360px, 92vw); box-shadow: 0 12px 44px rgba(15,23,42,.14); }
.login-card h1 { margin: 0 0 2px; font-size: 20px; color: var(--accent); }
.login-card p.mini { margin: 0 0 6px; }
.login-card input { width: 100%; margin: 12px 0 2px; padding: 8px 10px; font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.login-code { position: relative; margin: 12px 0 2px; }
.login-code input { margin: 0; padding-right: 42px; }
.login-code .reveal { position: absolute; right: 4px; top: 0; bottom: 0; width: 34px;
  margin: 0; padding: 0; background: none; border: 0; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; }
.login-code .reveal:hover { color: var(--ink); }
.login-card .row { margin-top: 12px; }
.login-card button { width: 100%; padding: 9px; font-size: 14px; }
.login-err { color: var(--err); font-size: 12px; min-height: 15px; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 18px; max-width: 420px; }
dialog::backdrop { background: rgba(15,23,42,.35); }
dialog h3 { margin: 0 0 12px; }
dialog .row { justify-content: flex-end; margin-top: 14px; }
dialog.wide { max-width: min(640px, 94vw); width: min(640px, 94vw); }
dialog.wide .proj-groups { max-height: 60vh; overflow-y: auto; margin-top: 4px; }
/* stacked label/field pairs for the course-material dialog */
.field-grid { display: flex; flex-direction: column; gap: 10px; }
.field-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px;
  color: var(--muted); }
.field-grid label input, .field-grid label select { font-size: 13px; }
.field-grid .mini { margin: -2px 0 0; }
.proj-row select.small { max-width: 150px; }
#scopeNote { padding: 6px 16px; font-size: 13px; background: #f0fdfa; color: #115e59;
  border-bottom: 1px solid #99f6e4; }
.scope-picks { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
/* a phase, its tick and its points on one line - `.field-grid label` stacks
   its children, and these are the exception */
.field-grid .scope-pick, .scope-pick { display: flex; flex-direction: row;
  align-items: center; gap: 6px; font-size: 12px; color: var(--fg); }
.scope-pick > span { flex: 1; min-width: 0; }
.scope-pick > input[type=checkbox] { flex: 0 0 auto; margin: 0; }
/* what a phase is worth, beside the phase itself */
.scope-pts { width: 58px; flex: 0 0 auto; }
.scope-pts:disabled { opacity: .45; }

/* ---- what an exercise assesses, in the portal ---- */
.phase-row > span:first-child { min-width: 170px; font-weight: 600; }
.phase-list { display: flex; flex-direction: column; gap: 2px; margin: 10px 0; }
.phase-line { display: flex; align-items: center; gap: 8px; font-size: 13px;
  padding: 3px 4px; border-radius: 5px; }
.phase-line:hover { background: var(--accent-soft); }
.phase-line > span { flex: 1; min-width: 0; }
/* a gradebook column group: the exercise, with its phases beneath */
.subs-panel { overflow-x: auto; }
th.ex-group { text-align: center; border-bottom: 1px solid var(--line); }
th.phase-head { font-weight: 600; white-space: nowrap; }
/* the box and the two buttons onto the work belong on one line */
td.score-cell { white-space: nowrap; }
/* ---- instructor feedback dock: comment while reading the work ---- */
#fbDock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; max-height: 46vh;
  display: flex; flex-direction: column; background: var(--panel);
  border-top: 2px solid #c4b5fd; box-shadow: 0 -6px 18px rgba(15,23,42,.12); }
#fbDock .fb-head { display: flex; align-items: center; gap: 10px; padding: 7px 14px;
  background: #faf5ff; border-bottom: 1px solid var(--line); }
#fbDock .fb-items { overflow-y: auto; padding: 4px 14px; }
#fbDock .fb-item { display: flex; align-items: center; gap: 8px; padding: 5px 0;
  border-bottom: 1px solid var(--line); }
#fbDock .fb-compose { display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  border-top: 1px solid var(--line); }
#fbDock .fb-compose textarea { flex: 1; font-size: 13px; resize: vertical; }
#fbDock .fb-comment { flex: 1; font-size: 13px; }
.feedback-block { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
.feedback-block .fb-comment { flex: 1; font-size: 13px; }
.role-tag.issue { background: #fef2f2; color: #991b1b; }
.role-tag.suggestion { background: #fffbeb; color: #92400e; }
.role-tag.praise { background: #f0fdf4; color: #166534; }
dialog.feedback { max-width: min(640px, 94vw); width: min(640px, 94vw); }
dialog.feedback .proj-groups { max-height: 40vh; overflow-y: auto; margin-bottom: 10px; }
dialog.feedback textarea { width: 100%; font-size: 13px; }
.assignment-block { border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; }
.assignment-block .proj-row.sub { padding-left: 22px; background: var(--bg-soft, transparent); }
.assignment-block .proj-row.sub .mini { color: var(--muted); }
.proj-toolbar { display: flex; gap: 6px; margin: 0 0 12px; }
.proj-row .proj-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* per-row Shared toggle in the projects manager */
.share-ctl { display: inline-flex; align-items: center; gap: 6px; }
.share-ctl select.small { max-width: 120px; }
.rs-switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  user-select: none; font-size: 12px; font-weight: 600; color: var(--muted); }
.rs-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.rs-slider { position: relative; flex: none; width: 34px; height: 18px; border-radius: 999px;
  background: var(--line); transition: background .15s; }
.rs-slider::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.rs-switch input:checked + .rs-slider { background: var(--accent); }
.rs-switch input:checked + .rs-slider::before { transform: translateX(16px); }
.rs-switch input:checked ~ span:last-child { color: var(--accent); }
.rs-switch input:disabled + .rs-slider { opacity: .4; }
.rs-switch input:disabled { cursor: not-allowed; }
.rs-switch input:focus-visible + .rs-slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- stage 7: star schema ---- */
.dw-wrap { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-top: 12px; }
.dw-panel { flex: 1 1 420px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.dw-side { flex: 0 1 330px; display: flex; flex-direction: column; gap: 10px; }
.dw-side-h { font-weight: 600; font-size: 12px; color: var(--muted); }
.dw-card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; }
.dw-card-h { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 8px; }
.dw-card-h input { font-weight: 600; }
.dw-card .x { border: none; background: transparent; color: var(--err); font-size: 15px;
  line-height: 1; padding: 0 4px; cursor: pointer; }
.dw-card-h .x { margin-left: auto; }
.dw-sub-h { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  margin: 12px 0 5px; }
.dw-field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.dw-field > label { font-size: 11px; color: var(--muted); }
.dw-field select, .dw-field input { width: 100%; }
.dw-line { display: flex; gap: 6px; align-items: center; margin-bottom: 5px; }
.dw-line select, .dw-line input { flex: 1; min-width: 0; }
.dw-measure { border-left: 2px solid var(--line); padding-left: 8px; margin-bottom: 8px; }
.dw-inl { flex: 0 0 auto; font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); }
.dw-checks { display: flex; flex-wrap: wrap; gap: 3px 12px; }
.dw-check { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; }
.dw-hop { margin-top: 4px; }
.dw-hop > summary { font-size: 11px; color: var(--muted); cursor: pointer; }
.dw-hop .dw-checks { padding: 4px 0 4px 14px; }
.dw-sql { max-height: 300px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; line-height: 1.45; background: #0f172a; color: #e2e8f0; padding: 10px 12px;
  border-radius: 6px; white-space: pre; }
.dw-star { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 6px; }
.dw-star-svg { width: 100%; height: auto; display: block; }
.dw-star-fact { fill: var(--accent); }
.dw-star-dim { fill: #eef2ff; stroke: var(--line); }
.dw-star-edge { stroke: var(--line); stroke-width: 1.5; }
.dw-star-t { font-size: 9px; text-anchor: middle; fill: var(--ink); pointer-events: none; }
.dw-star-ft { fill: #fff; font-weight: 600; }
/* a degenerate dimension is a column on the fact, so it is drawn inside it */
.dw-star-deg { fill: #dbeafe; font-size: 8px; }

/* ---- stage 2 as a diagram: table boxes + foreign-key links ---- */
/* Mirrors the ER canvas so the second diagram in the sequence handles the
   same way; the stage keeps its heading and toolbar above it. */
.stage.sd-stage { height: 100%; max-width: none; display: flex; flex-direction: column;
  padding-bottom: 16px; }
.stage.sd-stage > div:last-child { flex: 1; position: relative; min-height: 360px; }
#sdWrap { position: absolute; inset: 0; display: flex; overflow: hidden;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
#sdCanvasCol { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#sdToolbar { display: flex; gap: 8px; align-items: center; padding: 7px 10px;
  border-bottom: 1px solid var(--line); background: #f8fafc; flex-wrap: wrap; }
#sdToolbar .hint { color: var(--muted); font-size: 12px; }
#sdSvg { flex: 1; width: 100%; background:
  radial-gradient(circle at 1px 1px, #e2e8f0 1px, transparent 0) 0 0/22px 22px; cursor: default; }
#sdSvg.panning { cursor: grabbing; }
#sdPanel { flex: 0 0 320px; width: 320px; border-left: 1px solid var(--line);
  background: var(--panel); overflow: auto; padding: 14px; }
#sdWrap.panel-anim #sdPanel { transition: transform .25s ease, margin-right .25s ease; }
#sdWrap.panel-collapsed #sdPanel { transform: translateX(100%); margin-right: -320px; }
#sdPanel h3 { margin: 0 0 10px; font-size: 14px; }
#sdPanel .empty { color: var(--muted); font-size: 13px; }
#sdPanel .sd-col-item { display: flex; gap: 6px; align-items: center; cursor: pointer;
  padding: 5px 4px; border-radius: 4px; }
#sdPanel .sd-col-item:hover { background: var(--accent-soft); }
#sdPanel .sd-col-item-n { font-weight: 600; font-size: 12.5px; }

/* table box */
.sd-box { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; }
.sd-head, .sd-head-sq { fill: #eef2f7; stroke: none; }
.sd-table.sel .sd-box { stroke: var(--accent); stroke-width: 2; }
.sd-table.sel .sd-head, .sd-table.sel .sd-head-sq { fill: var(--accent-soft); }
.sd-tname { font-size: 13px; font-weight: 700; fill: var(--entity); }
.sd-col-hit { fill: transparent; }
.sd-col:hover .sd-col-hit { fill: var(--accent-soft); }
.sd-col.sel .sd-col-hit { fill: #dbeafe; }
.sd-cname { font-size: 12px; fill: var(--ink); }
.sd-cname.pk { font-weight: 700; }
.sd-ctype { font-size: 11px; fill: var(--muted); }
.sd-badge { font-size: 8.5px; font-weight: 700; }
.sd-badge.pk { fill: #b45309; }
.sd-badge.fk { fill: #7c3aed; }
.sd-badge.u { fill: var(--muted); }
.sd-port { fill: #cbd5e1; stroke: var(--panel); stroke-width: 1.5; cursor: crosshair; }
.sd-col:hover .sd-port { fill: var(--accent); }

/* foreign-key link: a line into the key it references */
.sd-edge { fill: none; stroke: #94a3b8; stroke-width: 1.6; }
.sd-edge.sel { stroke: var(--accent); stroke-width: 2.4; }
.sd-edge.linking { stroke: var(--accent); stroke-dasharray: 5 4; }
.sd-arrowhead { fill: #94a3b8; }
.sd-edge-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; }
.sd-table { cursor: grab; }
/* crow's foot: the glyphs sit on the line, so the circle has to mask it */
.sd-foot { stroke: #64748b; stroke-width: 1.5; fill: none; }
.sd-foot-o { fill: var(--panel); }
.sd-foot.sel { stroke: var(--accent); stroke-width: 2; }

/* ---- stage 0: the requirements brief ---- */
.req-body { max-width: 78ch; }
textarea.req-edit { width: 100%; min-height: 58vh; line-height: 1.5; }
.req-read { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 24px; line-height: 1.6; }
.req-read h2 { font-size: 17px; margin: 18px 0 8px; }
.req-read h3 { font-size: 15px; margin: 16px 0 6px; }
.req-read h4, .req-read h5 { font-size: 13.5px; margin: 14px 0 6px; color: var(--muted); }
.req-read > :first-child { margin-top: 0; }
.req-read p { margin: 0 0 10px; }
.req-read ul, .req-read ol { margin: 0 0 12px; padding-left: 24px; }
.req-read li { margin: 3px 0; }
.req-read code { background: #f1f5f9; border-radius: 4px; padding: 1px 5px;
  font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.req-read blockquote { margin: 0 0 12px; padding: 4px 14px; color: var(--muted);
  border-left: 3px solid var(--line); }
.req-read hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.req-read a { color: var(--accent); }

/* A workspace embedded in the portal's grading pages: no chrome, because the
   page around it is doing the navigating. */
body.bare #topbar, body.bare #tabs, body.bare #staleBanner, body.bare #scopeNote,
body.bare #changeBanner, body.bare #inspectBanner, body.bare #showTellBanner,
body.bare #classMismatch,
body.bare #fbDock { display: none !important; }
body.bare #view { border-top: none; }

/* ---- header: three segments in one row ---- */
/* What you are working on | what the class is doing | who you are. Separated by
   a rule rather than by spacing, and every part allowed to shrink, so a narrow
   window truncates instead of pushing controls off the edge. */
#topbar { flex-wrap: nowrap; }
#topbar button, #topbar summary, #topbar label, #topbar .presence-chip,
#topbar .user-chip, .class-now { white-space: nowrap; }
.project-controls > .seg { display: flex; align-items: center; gap: 8px; }
.project-controls > .seg + .seg,
.project-controls > .spacer + .seg { border-left: 1px solid var(--line);
  padding-left: 12px; }
/* Only the work segment gives ground, and all of it comes out of the project
   <select>: the select carries the explicit min-width that is the floor, while
   the segments keep the default `auto` so a button is never squeezed under its
   neighbour.  Without this the row ran straight past the right edge. */
#workSeg { flex: 0 1 auto; }
#classSeg, #acctSeg { flex: 0 0 auto; }
/* The 230px is a flex-basis, not a width: a definite `width` would become the
   select's minimum size and the segment would refuse to narrow at all. */
#workSeg label { flex: 0 1 230px; min-width: 88px; }
#projectSelect { width: 100%; min-width: 0; }
#courseChip { overflow: hidden; text-overflow: ellipsis; max-width: 230px; }

/* Under a narrow window, in this order: the word "Project" (the select beside
   it already names one), the breathing room, and the second half of the
   wordmark - so the class and account segments never have to go. */
@media (max-width: 1120px) {
  #workSeg label > .lbl { display: none; }
  #topbar { gap: 10px; padding-left: 10px; padding-right: 10px; }
  .project-controls { gap: 6px; }
  .project-controls > .seg { gap: 6px; }
  .project-controls > .seg + .seg,
  .project-controls > .spacer + .seg { padding-left: 8px; }
}
/* Last to go, and only once the row genuinely cannot hold it: the headcount,
   and the project select down to a stub.  Everything left in the row is a
   control somebody has to be able to reach. */
@media (max-width: 960px) {
  #classChip { display: none; }
  #workSeg label { min-width: 64px; }
}
/* Past that there is nothing left to give, so the row wraps onto a second
   line.  Clipping would put "Sign out" off the edge; wrapping only costs
   height. */
@media (max-width: 880px) {
  #topbar, .project-controls { flex-wrap: wrap; row-gap: 6px; }
  /* whichever segment drops to the second line still hugs the right edge,
     and loses the separator, which only reads as one on a shared row */
  #acctSeg { margin-left: auto; }
  .project-controls > .spacer + .seg { border-left: none; padding-left: 0; }
}
/* a menu is a <details>, so open/close needs no script */
#topbar details.menu { position: relative; }
#topbar details.menu > summary { list-style: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px;
  background: #fff; font-size: 14px; display: flex; align-items: center; gap: 5px; }
#topbar details.menu > summary::-webkit-details-marker { display: none; }
#topbar details.menu > summary::after { content: "▾"; color: var(--muted); font-size: 11px; }
#topbar details.menu > summary:hover { border-color: var(--accent); color: var(--accent); }
#topbar details.menu[open] > summary { border-color: var(--accent); color: var(--accent); }
#topbar .menu-items { position: absolute; right: 0; top: calc(100% + 5px); z-index: 70;
  min-width: 190px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px; display: flex; flex-direction: column;
  box-shadow: 0 8px 26px rgba(15,23,42,.14); }
#topbar .menu-items > * { text-align: left; background: none; border: none;
  color: var(--ink); font: inherit; padding: 7px 10px; border-radius: 5px;
  text-decoration: none; cursor: pointer; }
#topbar .menu-items > *:hover { background: var(--accent-soft); color: var(--accent); }

/* ---- a class in progress ---- */
.class-now { font-weight: 700; color: var(--rel); display: flex; align-items: center;
  gap: 6px; font-size: 13px; }
.class-now::before { content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--rel); box-shadow: 0 0 0 3px #ede9fe; }
#classBtn { border-color: var(--rel); color: var(--rel); background: #faf5ff; }
#classAgenda { flex: 0 1 auto; max-width: 230px; min-width: 110px; }
#classMismatch { padding: 6px 16px; font-size: 13px; display: flex;
  align-items: center; gap: 10px; background: #fff7ed; color: #9a3412;
  border-bottom: 1px solid #fed7aa; }

#classOffer { padding: 8px 16px; font-size: 14px; font-weight: 600; display: flex;
  align-items: center; gap: 10px; background: #f5f3ff; color: #5b21b6;
  border-bottom: 1px solid #ddd6fe; }
.class-agenda-h { margin-top: 14px; }
.class-agenda-h:first-of-type { margin-top: 0; }

/* A folder's name inside "My own work" — quieter than a group heading, since
   it sits under one. */
.proj-subgroup-h {
  padding: 8px 12px 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted, #667);
}

/* A foldable group: the heading is its own control, so it needs to look like
   one without turning into a button. */
details.proj-group > summary.proj-group-h {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
details.proj-group > summary.proj-group-h::-webkit-details-marker { display: none; }
details.proj-group > summary.proj-group-h::before {
  content: "\25B8";
  display: inline-block;
  width: 1em;
  font-size: 10px;
  transition: transform .12s ease;
}
details.proj-group[open] > summary.proj-group-h::before { transform: rotate(90deg); }

/* ---- the normalization workbench ---- */
/* Its own pane rather than a numbered stage, so it reads as a workshop beside
   the pipeline: sections stacked, and one panel at the bottom that whatever you
   last asked for writes into. */
.nf-badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px;
  border-radius: 4px; margin-left: 6px; background: #f1f5f9; color: #475569; }
.nf-badge.ok   { background: #dcfce7; color: var(--ok); }
.nf-badge.warn { background: #fef3c7; color: var(--warn); }
.nf-badge.bad  { background: #fee2e2; color: var(--err); }
.nf-badge.mute { background: #f1f5f9; color: var(--muted); }

.nf-section { margin-top: 18px; }
.nf-section h3 { margin: 0 0 4px; font-size: 14px; }

.nf-fd { border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  padding: 8px 12px; margin-bottom: 6px; }
.nf-fd-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nf-fd code { font-size: 12.5px; }
.nf-fd .mini { margin-top: 4px; color: var(--muted); line-height: 1.5; }

.nf-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px;
  padding: 8px 12px; border: 1px dashed var(--line); border-radius: 8px; }
.nf-add select { min-width: 150px; }

.nf-node { border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px; background: var(--panel); padding: 8px 12px; margin-bottom: 6px; }
/* a table that has been split is kept in view - it is what its two halves get
   rejoined and compared against - but it is no longer one of your tables */
.nf-node.spent { border-left-color: var(--line); opacity: .6; }
.nf-node > div { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nf-node .cols { display: block; color: var(--muted); margin-top: 4px; }

.nf-panel { margin-top: 18px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); }
.nf-panel h4 { margin: 0 0 8px; font-size: 14px; }
.nf-panel p { line-height: 1.55; margin: 8px 0; }
.nf-panel pre.code { background: var(--shape); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; overflow-x: auto; white-space: pre; }

.nf-anom { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.nf-anom > strong { text-transform: capitalize; }
/* the point of the whole demonstration is the difference between two grids, so
   the second one is marked rather than left for the reader to diff by eye */
.nf-panel table.grid.after { outline: 2px solid #fecaca; }

.nf-match { padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.nf-match:last-child { border-bottom: 0; }
/* one pass of the minimal cover: its reason once, its changes under it */
.nf-pass { margin-top: 8px; padding-left: 10px; border-left: 2px solid var(--line); }
.nf-pass .cols { margin: 2px 0; }

/* DB-Publish: the Publish dialog.  The published site itself has its own
   stylesheet under static/pub/ - this is only the door to it. */
dialog.publish-dlg { max-width: min(560px, 94vw); width: min(560px, 94vw); }
dialog.publish-dlg .field { display: flex; flex-direction: column; gap: 4px;
  margin: 10px 0; font-size: 12px; color: var(--muted); }
dialog.publish-dlg .field input { padding: 7px 9px; font-size: 14px; }
dialog.publish-dlg label.preset { display: flex; gap: 8px; align-items: flex-start;
  padding: 9px 10px; margin-top: 8px; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; }
dialog.publish-dlg label.preset:hover { border-color: var(--accent); }
dialog.publish-dlg label.preset input { margin-top: 3px; }
/* the per-preset consequence of a stage-4 rebuild: the one thing in this
   dialog a student must read before they click */
dialog.publish-dlg .mini.warn { margin-top: 10px; padding: 8px 10px;
  border-left: 3px solid var(--warn); background: #fff7ed; color: #7c4a03;
  border-radius: 0 6px 6px 0; }
dialog.publish-dlg .site-row { padding: 10px 0; border-top: 1px solid var(--line); }
dialog.publish-dlg .site-row:first-of-type { border-top: 0; }
dialog.publish-dlg .site-row .row { justify-content: flex-start; margin-top: 0; }
dialog.publish-dlg .site-row label.mini { display: flex; gap: 6px; align-items: center;
  margin-top: 4px; }
/* name, font and colour side by side, with the result shown underneath */
dialog.publish-dlg .site-row .look {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  margin: 8px 0 6px;
}
dialog.publish-dlg .site-row .look label.mini {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: stretch;
  margin-top: 0;
}
dialog.publish-dlg .site-row .look input,
dialog.publish-dlg .site-row .look select {
  padding: 5px 7px;
  font-size: 13px;
}
dialog.publish-dlg .title-preview-wrap {
  padding: 10px 8px;
  margin-bottom: 6px;
  text-align: center;
  background: #f6f7f9;
  border: 1px solid var(--line);
  border-radius: 8px;
}
dialog.publish-dlg .title-preview { font-size: 22px; font-weight: 700; line-height: 1.2; }
@media (max-width: 520px) {
  dialog.publish-dlg .site-row .look { grid-template-columns: 1fr; }
}

/* deleting hangs off "may add and correct", because it is gated on both */
dialog.publish-dlg .site-row label.mini.indent { margin-left: 20px; }
dialog.publish-dlg .site-row label.mini input:disabled { opacity: .45; }
dialog.publish-dlg .site-row label.mini:has(input:disabled) { opacity: .55; }
dialog.publish-dlg .url { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all; margin: 2px 0 6px; }

/* ---- bug reports: the form, and the queue behind it ---- */
/* The form is a column of short questions, so it wants the width a dialog
   does not have by default - four textareas at 420px is a keyhole. */
dialog.bug-report { max-width: min(560px, 94vw); width: min(560px, 94vw); }
dialog.bug-report textarea, dialog.bug-report input[type="text"] {
  width: 100%; font: inherit; font-size: 13px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; resize: vertical;
}
dialog.bug-report .field-grid { margin-top: 4px; }
dialog.bug-report p.mini { margin: 4px 0 0; }
/* what rides along with the report, said out loud rather than collected quietly */
.bug-ctx { margin-top: 10px; color: var(--muted); word-break: break-word; }
.bug-mine { margin: 10px 0 4px; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; background: var(--shape); }
.bug-mine summary { cursor: pointer; }
.bug-mine-row { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px;
  padding: 4px 0; border-top: 1px solid var(--line); }
.bug-mine-sum { flex: 1; min-width: 0; }

/* A ticket's state, wherever it is shown - the reporter's own list and the
   queue read the same words off the same class. */
.bug-state { font-size: 11px; border-radius: 999px; padding: 1px 8px;
  border: 1px solid var(--line); white-space: nowrap; }
.bug-state.new { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.bug-state.open { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.bug-state.closed { background: #eef2f7; color: var(--muted); }

.bug-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; margin-bottom: 8px; }
/* the colour is the severity, on the edge where it reads down a list */
.bug-card { border-left: 4px solid var(--line); }
.bug-card.sev-blocked { border-left-color: var(--err); }
.bug-card.sev-wrong { border-left-color: var(--warn); }
.bug-card.sev-annoying { border-left-color: var(--accent); }
.bug-card.sev-idea { border-left-color: var(--ok); }
.bug-card > summary { display: flex; gap: 10px; align-items: baseline; cursor: pointer;
  font-size: 13px; }
.bug-card .bug-sev { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bug-card .bug-sum { flex: 1; min-width: 0; font-weight: 600; }
.bug-card .bug-para { margin-top: 10px; }
.bug-card .sec-h { font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); }
.bug-card .bug-para p { margin: 2px 0 0; white-space: pre-wrap; font-size: 13px; }
.bug-card textarea { width: 100%; }
.bug-card .danger { color: var(--err); }
@media (max-width: 560px) {
  .bug-card > summary { flex-wrap: wrap; }
}

/* ---- the textbook reader ------------------------------------------------ */
/* Two columns: the contents, and one chapter.  The chapter scrolls on its own
   so the contents stay put - a book you read by scrolling past its own index
   loses the index exactly when you want it. */
#tbWrap { display: flex; align-items: stretch; height: calc(100vh - 52px); }
#tbContents { width: 280px; flex: 0 0 280px; overflow-y: auto; padding: 14px 10px 30px;
  border-right: 1px solid var(--line); background: var(--panel); }
#tbChapter { flex: 1 1 auto; overflow-y: auto; padding: 26px 34px 80px;
  max-width: 46rem; line-height: 1.62; }
.tb-toc-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 10px 8px; }
.tb-toc-ch { display: block; width: 100%; text-align: left; border: 0; background: none;
  font: inherit; font-weight: 600; color: var(--ink); padding: 6px 8px; border-radius: 6px;
  cursor: pointer; }
.tb-toc-ch:hover { background: var(--accent-soft); }
.tb-toc-ch.on { background: var(--accent-soft); color: var(--accent); }
.tb-toc-secs { list-style: none; margin: 2px 0 10px; padding: 0 0 0 8px; }
.tb-toc-sec { display: block; width: 100%; text-align: left; border: 0; background: none;
  font: inherit; font-size: 13px; color: var(--muted); padding: 3px 8px; border-radius: 5px;
  cursor: pointer; }
.tb-toc-sec:hover { background: var(--bg); color: var(--ink); }

#tbChapter h2 { font-size: 26px; margin: 0 0 18px; }
#tbChapter h3 { font-size: 19px; margin: 30px 0 10px; }
#tbChapter h4 { font-size: 15px; margin: 20px 0 8px; }
#tbChapter blockquote { margin: 14px 0; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line); color: var(--muted); }

/* The recurring devices.  Each is a box a reader learns the shape of, so the
   heading is drawn by the renderer and never typed by the author. */
.tb-block { margin: 20px 0; padding: 12px 16px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); }
.tb-block-h { margin: 0 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted); }
.tb-block > :last-child { margin-bottom: 0; }
.tb-activity { border-color: #bfdbfe; background: #f5f9ff; }
.tb-activity .tb-block-h { color: var(--accent); }
.tb-studio { border-color: #ddd6fe; background: #faf8ff; }
.tb-studio .tb-block-h { color: #6d28d9; }
.tb-predict { border-color: #fed7aa; background: #fffbf5; }
.tb-predict .tb-block-h { color: var(--warn); }
.tb-log { border-color: var(--line); background: var(--shape); }
.tb-aside { border-style: dashed; background: var(--bg); }
.tb-other { border-color: var(--err); }

/* The cells do not wrap, so `2019-06-03` and `541-555-0201` cannot break at
   their hyphens.  Chapter 1 turns on two phone numbers differing in the last
   digit; split across two lines, the difference the reader is asked to find is
   the thing hardest to see.  Too wide to fit, the table scrolls instead. */
.tb-tablewrap { overflow-x: auto; margin: 16px 0; }
.tb-table { border-collapse: collapse; margin: 0; font-size: 14px; width: 100%; }
.tb-table th, .tb-table td { border: 1px solid var(--line); padding: 6px 10px;
  text-align: left; white-space: nowrap; }
/* A predict's question, which is the whole point of the block */
.tb-q { margin: 0 0 10px; font-weight: 600; line-height: 1.5; }
/* The options, before anything has been chosen: clickable, and looking it.
   A control that does something has to look like one - the book already had a
   button that refused the pointer while working, and this is the same trap. */
.tb-predict ul { list-style: none; padding: 0; margin: 0 0 10px; }
.tb-opt { border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 8px 12px; margin: 6px 0; cursor: pointer; line-height: 1.45; }
.tb-opt:hover, .tb-opt:focus { border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft); }
/* Once chosen, nothing is clickable and the cursor says so before the click */
.tb-opt[tabindex="-1"] { cursor: default; box-shadow: none; }
.tb-opt[tabindex="-1"]:hover { border-color: var(--line); }
/* Text that only a screen reader reads.  The ✓ below is `::after` generated
   content, which is not in the DOM and is announced inconsistently at best -
   so the meaning of each mark is also carried as real text, hidden this way
   rather than with `display: none`, which would hide it from everybody. */
.tb-sr { position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; border: 0; overflow: hidden; white-space: nowrap;
  clip: rect(0 0 0 0); clip-path: inset(50%); }
/* which was right, and which they picked - a reader who was wrong needs to
   see both, and a reader who was right should see them coincide */
.tb-right { border-color: var(--ok); background: #f2fbf5; }
.tb-right::after { content: " ✓"; color: var(--ok); font-weight: 700; }
.tb-picked { border-width: 2px; }
.tb-picked:not(.tb-right) { border-color: var(--warn); background: #fffbf5; }
/* an option already tried and wrong: out of play, and visibly so */
.tb-wrong { border-color: var(--err); background: #fef6f6; color: var(--muted);
  text-decoration: line-through; }
.tb-wait { color: var(--warn); font-weight: 600; }
.tb-predict-told:empty { display: none; }
/* a block answered in words rather than by picking */
.tb-written { margin: 0 0 10px; }
.tb-answer { flex: 1; min-width: 160px; padding: 7px 10px; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; }
/* The row grid's filter: one control on its own line, so it is obviously
   about the grid below it rather than part of the import toolbar above. */
.grid-filter { gap: 10px; }
.grid-find { flex: 0 1 260px; padding: 5px 9px; font-size: 13px;
  border: 1px solid var(--line); border-radius: 7px; }
.grid-find:focus { border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft); }
/* Restart sits beside Open and must not compete with it: this is the way
   back, not the way on. */
.tb-restart { margin-left: 6px; background: #fff; color: var(--muted);
  border: 1px solid var(--line); }
.tb-restart:hover { color: var(--err); border-color: var(--err); }
.tb-answer:focus { border-color: var(--accent); outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft); }
.tb-verdict:empty { display: none; }
.tb-verdict { margin: 0 0 8px; font-weight: 600; font-size: 13.5px; }
.tb-predict-foot:empty { display: none; }
.tb-predict-foot { margin-bottom: 4px; }
.tb-skip { font-size: 13px; }
/* aria-disabled rather than disabled: still focusable, so it can explain
   itself to somebody who arrived by keyboard.  It has to LOOK unavailable
   anyway, or it is the cursor:not-allowed lie the other way round. */
button[aria-disabled="true"] { opacity: .55; cursor: default; }
button[aria-disabled="true"]:hover { filter: none; }
/* a Section the reader cannot open yet - the contents said nothing at all,
   so 2.3 looked exactly like 1.1 until you clicked it */
.tb-toc-sec.locked { color: var(--muted); opacity: .7; }
.tb-toc-sec.locked::before { content: "· "; }
.tb-table th { background: var(--shape); }
.tb-code { margin: 16px 0; padding: 12px 14px; border-radius: 8px; overflow-x: auto;
  background: var(--shape); border: 1px solid var(--line); font-size: 13px; }
/* An action the book offers.  The dashed border and not-allowed cursor here
   were written while every one of these was inert, and outlived that by a
   commit: the buttons worked and still refused the pointer, which is a worse
   lie than the disabled one they replaced. */
.tb-action { font: inherit; font-size: 13px; padding: 4px 11px; border-radius: 6px;
  border: 1px solid var(--accent); background: var(--accent-soft);
  color: var(--accent); cursor: pointer; }
.tb-action:hover { background: var(--accent); color: #fff; }
/* one the app cannot honour yet keeps the old look, which now means what it says */
.tb-action[disabled] { border-style: dashed; cursor: not-allowed; opacity: .6; }
.tb-action[disabled]:hover { background: var(--accent-soft); color: var(--accent); }

@media (max-width: 820px) {
  #tbWrap { flex-direction: column; height: auto; }
  #tbContents { width: auto; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  #tbChapter { padding: 18px 16px 60px; }
}

/* What the last edit on the Cards view did, and a way back from it.  A
   chapter that asks the reader to READ their schema sends them into this
   editor, so a mis-click has to be recoverable rather than silent. */
.schema-undo { display: flex; align-items: center; gap: 10px; margin: 0 0 10px;
  padding: 7px 11px; border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 7px; background: #fffbf5; font-size: 13px; }
.schema-undo[hidden] { display: none; }

/* A table the sample carries that the design does not, currently absent */
.carried-gone { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 10px; padding: 8px 11px; border: 1px solid var(--line);
  border-left: 3px solid var(--warn); border-radius: 7px; background: #fffbf5;
  font-size: 13px; }

/* ---- participation ------------------------------------------------------ */
/* `table.grid td` sets the alignment, so these have to be at least as specific
   or they quietly do nothing - which is what the first version of this did. */
table.part-grid th.sortable { cursor: pointer; user-select: none; }
table.part-grid th.sortable:hover { background: var(--accent-soft); }
table.part-grid th.up::after { content: " ▲"; font-size: 9px; color: var(--muted); }
table.part-grid th.down::after { content: " ▼"; font-size: 9px; color: var(--muted); }
/* numbers line up on the right, where a column of them can be read down */
table.part-grid td { text-align: right; }
table.part-grid td:first-child { text-align: left; }
/* somebody who has never been here at all: the row worth finding */
table.part-grid tr.never td { color: var(--muted); }

/* ---- the reading gate --------------------------------------------------- */
/* A locked Section keeps its heading and says what opens it: a reader should
   know what is there and why it is shut, which is not the same as hiding it. */
.tb-locked { border-style: dashed; border-color: var(--warn); background: #fffbf5; }
.tb-locked .tb-block-h { color: var(--warn); }
.tb-act-foot { margin-top: 12px; padding-top: 10px; border-top: 1px solid #dbeafe; }
.tb-act-foot .row { flex-wrap: wrap; gap: 8px; }
.tb-done { color: var(--ok); font-weight: 600; font-size: 13px; }
/* got past it, but what it asks for is not there now */
.tb-stale { color: var(--warn); font-weight: 600; font-size: 13px; }
.tb-skipped { color: var(--warn); font-size: 13px; }
.tb-check-out { margin-top: 10px; }
.tb-check-out .msg { margin: 0 0 6px; }
/* the reasons are the useful part, so they are readable rather than terse */
.tb-why { margin: 0; padding-left: 20px; font-size: 13px; line-height: 1.5; }
.tb-why li { margin: 3px 0; }
#tbToast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 14px; z-index: 60; box-shadow: 0 6px 20px rgba(15,23,42,.25); }
/* a skip is not a failure, but it is worth the eye finding it */
table.part-grid td.part-skip { color: var(--warn); font-weight: 600; }
table.part-grid tr.part-worry td { background: #fffbf5; }
.part-acts { margin-top: 26px; }
.part-acts h3 { margin: 0 0 4px; font-size: 15px; }
/* a row that has something behind it says so before it is clicked, and while
   it is open stays marked - an expander that looks identical open and shut
   leaves you clicking it twice to find out which it is */
table.part-acts-grid tr.part-open { cursor: pointer; }
table.part-acts-grid tr.part-open:hover td { background: var(--accent-soft); }
table.part-acts-grid tr.part-open td:first-child::before {
  content: "▸ "; color: var(--muted); }
table.part-acts-grid tr.part-shown td:first-child::before { content: "▾ "; }
/* `>` matters: the drill row holds a table of its own, and without it these
   reach into that table's cells and overrule its alignment from outside. */
table.part-acts-grid tr.part-drill > td { text-align: left; background: #f8fafc; }
table.part-acts-grid tr.part-drill > td > p { margin: 0 0 6px; }
/* the section number belongs beside the activity it numbers; this column is
   text, and the grid right-aligns by default because the rest of it is counts */
table.part-acts-grid > tbody > tr > td:nth-child(2) { text-align: left; }
/* the predicates themselves, verbatim: the instructor has to be able to find
   the line in the manuscript, and a prettified version of it would not match.
   `table.grid th, table.grid td` is (0,1,2) and beat the first version of the
   cell rules here, which were (0,1,1) and did nothing at all. */
table.part-preds { border-collapse: collapse; font-size: 13px; }
table.part-preds td { padding: 2px 18px 2px 0; border: 0; white-space: normal; }
table.part-preds td:first-child { text-align: left; color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
table.part-preds td:last-child { text-align: right; color: var(--muted); }
/* an instructor reading the book: a statement about students, not about them */
.tb-ungated { color: var(--muted); font-size: 13px; }
