:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1c1a;
  --muted: #6f6b64;
  --line: #e2ded7;
  --accent: #1f5f57;
  --accent-soft: #e6f0ee;
  --red: #d92b2b;
  --amber: #c88a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(29, 28, 26, 0.06), 0 8px 24px rgba(29, 28, 26, 0.06);
  /* Marks and notes on the page. Plain Arial: small and still easy to read. */
  --pen: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 14px;
  transition: background 120ms, border-color 120ms, transform 60ms;
}
button:hover:not(:disabled) { background: #faf9f7; border-color: #cdc7bd; }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: #1a524b; border-color: #1a524b; }
button.danger { color: var(--red); border-color: #f0cccc; }
button.danger:hover:not(:disabled) { background: #fdf1f1; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover:not(:disabled) { background: rgba(0,0,0,0.05); }
button.sm { padding: 5px 10px; font-size: 13px; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 90px; font-family: inherit; }

label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #eae7e0, var(--bg));
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.login-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.hint {
  margin-top: 16px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------- shell ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  height: 56px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.crumb { color: var(--muted); font-size: 14px; }
.crumb b { color: var(--ink); font-weight: 600; }
.spacer { flex: 1; }
.pill {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.page { max-width: 1240px; margin: 0 auto; padding: 26px 20px 60px; }
.page.wide { max-width: 1600px; }

h2.section { font-size: 20px; margin: 0 0 2px; letter-spacing: -0.02em; }
p.section-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.row { display: flex; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* ---------- exam list ---------- */

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.exam-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 120ms, transform 100ms;
  position: relative;
}
.exam-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.exam-card h3 { margin: 0 0 4px; font-size: 16px; letter-spacing: -0.01em; }
.exam-card .meta { color: var(--muted); font-size: 13px; }
.exam-card .stats {
  margin-top: 14px;
  display: flex;
  gap: 16px;
  font-size: 13px;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
}
.exam-card .stats b { display: block; font-size: 17px; font-weight: 700; }
.exam-card .del { position: absolute; top: 10px; right: 10px; opacity: 0; }
.exam-card:hover .del { opacity: 1; }

.banner {
  background: #fff6e5;
  border-bottom: 1px solid #f0dcb4;
  color: #7a5600;
  padding: 11px 20px;
  font-size: 13.5px;
}
.banner code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

/* ---------- exam workspace ---------- */

.workspace { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }

.students {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  position: sticky;
  top: 76px;
}
.students header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.student-item {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.student-item:hover { background: #faf9f7; }
.student-item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.student-item .nm { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-item .sc { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #cdc7bd; flex: none; }
.dot.marked { background: var(--accent); }
.dot.partial { background: var(--amber); }
.dot.error { background: var(--red); }

.students footer { padding: 12px 14px; }

.detail { min-width: 0; }
.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.detail-head h2 { margin: 0; font-size: 21px; letter-spacing: -0.02em; }
.score-badge {
  font-weight: 700;
  font-size: 15px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ---------- annotated page ---------- */

.page-block { margin-bottom: 26px; }
.page-block > header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.page-block > header .t { font-weight: 600; font-size: 14px; }

.sheet {
  --sw: 900px;
  position: relative;
  display: inline-block;
  /* Readable, not wall-sized: a page never grows past about A4-on-screen. */
  max-width: min(100%, 860px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  line-height: 0;
}
.sheet img { max-width: 100%; height: auto; display: block; }

.ann {
  position: absolute;
  transform: translate(-50%, -50%);
  color: var(--red);
  font-family: var(--pen);
  user-select: none;
  touch-action: none;
  cursor: grab;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 0 2px rgba(255,255,255,0.7);
}
.ann.editing { cursor: grabbing; }
.editable .ann:hover { outline: 1px dashed rgba(217,43,43,0.6); outline-offset: 3px; }
.ann.mark { font-weight: 700; }
/* Outcome marks: met is green, not met is red. */
.ann.mark.tick { color: #1f7a3f; }
.ann.mark.cross { color: var(--red); }
/* A comment starts at (x, y) with its first line centred on y, and wraps before
   the page edge — max-width is set per note from where it starts. */
.ann.comment {
  font-weight: 600;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: left;
  line-height: 1.2;
  transform: translate(0, -0.6em);
}
.ann.shape { border: 2.5px solid var(--red); transform: translate(-50%, -50%); background: transparent; }
.ann.shape.circle { border-radius: 50%; }
.ann.shape.underline { border: none; border-bottom: 2.5px solid var(--red); transform: translate(0, -50%); }

/* The delete button sits fully outside the note, above its right-hand end, so
   grabbing the note to drag it can't land on the ×. */
.ann-del {
  position: absolute;
  top: -22px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  font-size: 11px;
  line-height: 14px;
  padding: 0;
  display: none;
  cursor: pointer;
  font-family: ui-sans-serif, sans-serif;
}
.editable .ann:hover .ann-del { display: block; z-index: 2; }
.ann.mark .ann-del { top: -16px; right: -18px; }
/* An invisible halo around every mark so the cursor can travel from the mark
   to its × without the × disappearing on the way. */
.editable .ann::before {
  content: '';
  position: absolute;
  inset: -26px -24px -8px -8px;
}
.ann.mark::before { inset: -20px -22px -6px -6px; }

.job-card { margin-bottom: 16px; }
.job-card .progress { margin: 10px 0 6px; }

.grade-stamp {
  position: absolute;
  top: 14px;
  right: 18px;
  font-family: var(--pen);
  color: var(--red);
  font-weight: 700;
  font-size: 30px;
  text-shadow: 0 0 3px rgba(255,255,255,0.8);
}

.qtable { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 12px; }
.qtable th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.qtable td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.qtable tr:last-child td { border-bottom: none; }
.qtable.outcomes { margin-top: 14px; }
.qtable.outcomes td:nth-child(2) { font-weight: 500; }
.omark {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 13px;
}
.omark.met { background: var(--accent-soft); color: #1f7a3f; }
.omark.not { background: #fdecec; color: var(--red); }

.verdict { font-weight: 700; font-size: 12px; }
.verdict.correct { color: var(--accent); }
.verdict.partial { color: var(--amber); }
.verdict.incorrect, .verdict.blank { color: var(--red); }

.summary-note {
  margin-top: 12px;
  padding: 12px 14px;
  background: #fffaf0;
  border: 1px solid #f0e2c4;
  border-radius: 8px;
  font-size: 14px;
}

.progress {
  height: 6px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0;
}
.progress > div { height: 100%; background: var(--accent); transition: width 300ms; }
.log { font-size: 12.5px; color: var(--muted); font-family: ui-monospace, monospace; max-height: 120px; overflow: auto; }

/* ---------- modal & toast ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(29, 28, 26, 0.4);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-height: 90vh;
  overflow: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 19px; letter-spacing: -0.02em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  max-width: 380px;
}
.toast.err { background: var(--red); }

.spin {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: sp 0.7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes sp { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .students { position: static; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- class summary ---------- */

.student-item.summary { border-bottom: 1px solid var(--line); }
.dot.summary { background: var(--accent); border-radius: 2px; }
h3.section { font-size: 16px; margin: 0 0 6px; letter-spacing: -0.01em; }
.meta { color: var(--muted); font-size: 12.5px; }
.nowrap { white-space: nowrap; }

.bar {
  display: inline-block;
  vertical-align: middle;
  width: 90px;
  height: 8px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
  margin-right: 8px;
}
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.mid > span { background: var(--amber); }
.bar.low > span { background: var(--red); }
.bar-label { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  margin: 1px 0;
}
.chip.wrong { background: #fdecec; color: #a32020; }
.chip.wrong b { font-weight: 700; }

.insight-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--panel);
}
.insight-card h4 { margin: 0; font-size: 15.5px; }
.insight-card p { margin: 8px 0 6px; font-size: 14px; }
.insight-n {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}
.insight-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--muted); }
.insight-meta b { color: var(--ink); font-weight: 600; margin-right: 4px; }
.insight-tip { margin-top: 8px; font-size: 13.5px; padding: 8px 10px; background: #fffaf0; border-radius: 6px; }
.strengths { margin: 0; padding-left: 20px; font-size: 14px; }
.strengths li { margin-bottom: 4px; }

/* ---------- "⋯" menus: the rarely used actions, out of the way ---------- */

details.menu { position: relative; }
details.menu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 15px;
  line-height: 1;
  font-weight: 700;
  color: var(--muted);
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover { background: #faf9f7; border-color: #cdc7bd; color: var(--ink); }
details.menu[open] > summary { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
details.menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  padding: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
details.menu > div > button {
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
}
details.menu > div > button:hover:not(:disabled) { background: #f3f1ec; border-color: transparent; }
details.menu > div > button.danger { color: var(--red); }

/* ---------- page tabs ---------- */

.pager { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
/* One row that scrolls sideways when a paper has many pages; the active tab is
   kept in view by the script. */
.pager .tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; padding: 4px 2px; scrollbar-width: thin; }
.pager .tab { flex: none; }
.pager .tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  color: var(--muted);
}
.pager .tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager .tab.active .dot { background: rgba(255,255,255,0.7); }
.pager .tab .dot { width: 7px; height: 7px; }
.pager .meta { margin-left: 4px; }

.page-block > header .meta { font-size: 12.5px; }
.page-block > header button.ghost.danger { border-color: transparent; }

details.fold { margin-top: 14px; }
details.fold > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 0;
  color: var(--ink);
  list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '▸'; display: inline-block; width: 16px; color: var(--muted); transition: transform 120ms; }
details.fold[open] > summary::before { transform: rotate(90deg); }

/* ---------- exam dialog: marks checkboxes ---------- */

.check-group { margin: -8px 0 14px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

/* ---------- student overview tab ---------- */

.overview .qtable button.ghost.sm { padding: 2px 8px; font-size: 12.5px; color: var(--accent); }
