:root {
  --bg: #faf9f7;
  --panel: #ffffff;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e2dc;
  --accent: #8a4baf;
  --accent-dark: #6f3890;
  --ok: #2f7d4f;
  --warn: #b26a00;
  --bad: #b3261e;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; letter-spacing: 0.01em; }
.topbar .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 0.72rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; font-size: 0.95rem; }
.topbar .who { color: var(--muted); font-size: 0.85rem; }

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

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

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

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 0.5rem; font-size: 1.02rem; }

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

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.9rem 0 0.3rem; }
input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font: inherit;
  color: var(--ink);
}
textarea { min-height: 7rem; font-family: var(--mono); font-size: 0.9rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--accent-dark); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.ghost:hover, .btn.ghost:hover { border-color: var(--muted); background: transparent; }
button.danger, .btn.danger { background: var(--bad); }
button.small, .btn.small { padding: 0.3rem 0.7rem; font-size: 0.82rem; }

.form-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; align-items: center; }

.error { background: #fdecea; border: 1px solid #f3c2bd; color: var(--bad); padding: 0.6rem 0.85rem; border-radius: var(--radius); margin: 0.8rem 0; }
.ok-msg { background: #eaf6ee; border: 1px solid #bfe3cb; color: var(--ok); padding: 0.6rem 0.85rem; border-radius: var(--radius); margin: 0.8rem 0; }
.hidden { display: none !important; }

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

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


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

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

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

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

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

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
}
.badge.note { background: #efe7f7; color: var(--accent-dark); }
.badge.reference { background: #e6f0f7; color: #245a7a; }
.badge.pdf { background: #fdeede; color: #8a5a17; }
.badge.ch { background: #f2f0ea; color: var(--muted); }
.badge.status { text-transform: none; letter-spacing: 0; font-weight: 600; }
.badge.status.sent, .badge.status.pending { background: #eaf2fb; color: #245a7a; }
.badge.status.accepted { background: #eaf6ee; color: var(--ok); }
.badge.status.expired, .badge.status.revoked { background: #fdecea; color: var(--bad); }

.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters button { padding: 0.32rem 0.75rem; font-size: 0.85rem; background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.filters button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

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

.content-body { line-height: 1.7; }
.content-body img { max-width: 100%; }
.content-body pre { background: #f5f3ef; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; overflow-x: auto; font-family: var(--mono); font-size: 0.88rem; }
.content-body code { font-family: var(--mono); font-size: 0.9em; background: #f5f3ef; padding: 0.1rem 0.3rem; border-radius: 4px; }
.content-body blockquote { margin: 0; padding: 0 1rem; border-left: 3px solid var(--line); color: var(--muted); }

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

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

table.list { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.list th { text-align: left; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0.4rem 0.6rem; border-bottom: 2px solid var(--line); }
table.list td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }

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

.tabs { display: flex; gap: 0.4rem; margin-bottom: 1.2rem; }
.tabs button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

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

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

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

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

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

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

/* The session transcript: two clearly separated sides. */
.chat { display: flex; flex-direction: column; gap: 1.15rem; max-height: 55vh; overflow-y: auto; padding: 0.25rem 0.4rem 0.25rem 0; }
.msg { display: flex; flex-direction: column; gap: 0.2rem; max-width: 94%; }
.msg.student { align-self: flex-end; align-items: flex-end; }
.msg.machine { align-self: flex-start; align-items: flex-start; }
.msg-head { display: flex; align-items: baseline; gap: 0.55rem; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.msg.student .msg-head { justify-content: flex-end; }
.msg-who { font-weight: 700; }
.msg.student .msg-who { color: var(--accent); }
.msg-at { opacity: 0.75; font-size: 0.62rem; }
.msg-engine { text-transform: none; background: var(--line); border-radius: 999px; padding: 0.08rem 0.5rem; font-size: 0.6rem; letter-spacing: 0.02em; }
.msg-bubble { padding: 0.65rem 0.95rem 0.75rem; border-radius: var(--radius); font-size: 0.95rem; line-height: 1.55; }
.msg.student .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.machine .msg-bubble { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-bottom-left-radius: 3px; }
.msg-bubble mjx-container { margin: 0.1rem 0; }

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

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

/* The verdict panel. */
.verdict-btns { display: flex; gap: 0.6rem; margin-bottom: 0.4rem; }
.verdict-btns button { flex: 1; }
.verdict-btns .picked { outline: 3px solid var(--accent); outline-offset: 1px; }
button.okbtn, .btn.okbtn { background: var(--ok); }
button.okbtn:hover, .btn.okbtn:hover { background: #256541; }
button.badbtn, .btn.badbtn { background: var(--bad); }
button.badbtn:hover, .btn.badbtn:hover { background: #8f1e17; }

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