:root {
  --primary: #1a5276;
  --primary-dark: #12384f;
  --accent: #2e86c1;
  --bg: #f4f7fa;
  --card: #ffffff;
  --text: #22303c;
  --muted: #6b7b8a;
  --border: #dfe6ec;
  --good: #1e8449;
  --bad: #c0392b;
  --warn: #b9770e;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  /* The palette is light-only. Without this a browser in dark mode gives
     fields a light UA text colour while our CSS keeps the white background,
     and the student ends up typing invisible text. */
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1200px; }

.topbar {
  background: var(--primary);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 1.1rem; margin: 0; font-weight: 600; }
.topbar .right { font-size: .9rem; opacity: .95; }

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

h2 { margin: 0 0 6px; font-size: 1.25rem; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: .92rem; }

label { display: block; font-weight: 600; margin: 12px 0 6px; font-size: .9rem; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--muted); -webkit-text-fill-color: var(--muted); opacity: 1; }
/* Chrome paints its own background over an autofilled field; keep ours. */
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 30px #fff inset;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
textarea { font-family: ui-monospace, "Cascadia Code", monospace; font-size: .9rem; resize: vertical; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .col { flex: 1 1 160px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: var(--primary); }
.btn:disabled { background: #9fb3c0; cursor: not-allowed; }
.btn.secondary { background: #eef3f7; color: var(--primary); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e2ebf2; }
.btn.danger { background: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; font-size: .85rem; }
.btn.xs { padding: 4px 9px; font-size: .78rem; }

.hidden { display: none !important; }

.notice { padding: 10px 14px; border-radius: 8px; font-size: .9rem; margin: 10px 0; }
.notice.err { background: #fdecea; color: var(--bad); border: 1px solid #f5c6cb; }
.notice.ok { background: #eafaf1; color: var(--good); border: 1px solid #b7e4c7; }
.notice.warn { background: #fff6e5; color: var(--warn); border: 1px solid #f5d78e; }

/* ---- Quiz taking ---- */
.quiz-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 8px;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 1.3rem;
  padding: 4px 12px; border-radius: 8px;
  background: #eef3f7; color: var(--primary);
}
.timer.low { background: #fdecea; color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.switch-badge { font-size: .85rem; color: var(--muted); }
.switch-badge b { color: var(--bad); }

.q-block { margin-bottom: 4px; }
.q-num { color: var(--accent); font-weight: 700; font-size: .85rem; letter-spacing: .04em; }
.q-text { font-weight: 600; margin: 4px 0 12px; }
.opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--accent); background: #f7fbfe; }
.opt input { margin-top: 3px; }
.opt.checked { border-color: var(--accent); background: #eaf4fb; }
.opt .key { font-weight: 700; color: var(--primary); }

.progress-dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.dot {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; font-size: .8rem; cursor: pointer; color: var(--muted);
}
.dot.answered { background: var(--accent); color: #fff; border-color: var(--accent); }
.dot.current { outline: 2px solid var(--primary); }

/* watermark shown during quiz to discourage screenshots */
.wm { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; color: rgba(26,82,118,0.05); font-weight: 800;
  transform: rotate(-24deg); user-select: none; }

/* ---- Admin table ---- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f0f5f9; color: var(--primary); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #f9fbfd; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.pill.live { background: #fff6e5; color: var(--warn); }
.pill.done { background: #eafaf1; color: var(--good); }
.pill.flag { background: #fdecea; color: var(--bad); }
/* Faculty granted something: extra time, or a resume the student has not taken yet. */
.pill.warnpill { background: #eef3f7; color: var(--primary); border: 1px solid var(--border); }

.row-actions { white-space: nowrap; }
.row-actions .btn { margin-right: 5px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: #f6f9fb; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.stat .n { font-size: 1.7rem; font-weight: 700; color: var(--primary); }
.stat .l { font-size: .8rem; color: var(--muted); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Code", monospace; }
.right-align { text-align: right; }
.no-select { user-select: none; -webkit-user-select: none; }

/* ---- Proctoring ---- */

/* Content is blurred the instant focus is lost, so anything captured while
   switching away (screenshot, screen share, second monitor) is unreadable. */
body.screen-hidden .wrap { filter: blur(22px); pointer-events: none; }

.proctor-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(18, 56, 79, .97);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.proctor-box {
  background: #fff; border-radius: 14px; padding: 30px;
  max-width: 560px; width: 100%; text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.proctor-icon { font-size: 2.6rem; color: var(--bad); line-height: 1; }
.proctor-box h2 { margin: 10px 0 8px; color: var(--bad); font-size: 1.5rem; }
.proctor-body { color: var(--text); font-size: 1.02rem; margin: 0 0 14px; }
.proctor-count {
  display: inline-block; background: #fdecea; color: var(--bad);
  border: 1px solid #f5c6cb; border-radius: 8px;
  padding: 6px 14px; font-size: 1rem; margin-bottom: 10px;
}
.proctor-timer { font-size: .92rem; color: var(--muted); margin: 0 0 16px; }
.proctor-foot { font-size: .82rem; color: var(--muted); margin: 12px 0 0; }

.rules-box {
  background: #f6f9fb; border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px; margin: 16px 0;
}
.rules-box h3 { margin: 0 0 10px; font-size: 1rem; color: var(--primary); }
.rules-box ol { margin: 0; padding-left: 20px; font-size: .93rem; }
.rules-box li { margin-bottom: 7px; }

/* Compulsory reading time on the instructions screen */
.read-gate {
  background: #eef3f7;
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 16px 0;
  text-align: center;
}
.read-gate-label {
  font-size: .78rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--primary);
}
.read-gate-time {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 2.4rem; font-weight: 700; line-height: 1.1;
  color: var(--primary); font-variant-numeric: tabular-nums;
}
.read-gate-note { font-size: .86rem; color: var(--muted); margin: 4px 0 0; }
.read-gate.unlocked {
  background: #eafaf1; border-color: var(--good);
}
.read-gate.unlocked .read-gate-label,
.read-gate.unlocked .read-gate-time { color: var(--good); }

.agree {
  display: flex; align-items: flex-start; gap: 10px;
  font-weight: 500; font-size: .95rem; margin: 4px 0 16px;
  cursor: pointer;
}
.agree input { margin-top: 4px; width: 18px; height: 18px; }

.net-chip {
  position: fixed; top: 60px; right: 16px; z-index: 9998;
  background: var(--warn); color: #fff; font-size: .82rem; font-weight: 600;
  padding: 6px 14px; border-radius: 20px; box-shadow: var(--shadow);
}
.saved-chip {
  margin-left: 8px; font-size: .74rem; color: var(--good);
  opacity: 0; transition: opacity .25s;
}
.saved-chip.flash { opacity: 1; }

/* Printing an exam paper is never legitimate. */
@media print {
  body * { display: none !important; }
  body::after {
    content: "Printing is disabled during this assessment.";
    display: block !important; font-size: 20pt; padding: 40pt;
  }
}

/* ===========================================================================
   Descriptive test — additions on top of the shared quiz styling
   =========================================================================== */

/* The paper is unselectable, but an answer box must not be: a student has to be
   able to sweep a sentence to make it bold. proctor.js refuses selection
   everywhere else. */
#examView { --ed-sticky: 74px; }

.ed-body, .ed-body * , .modal, .modal * {
  user-select: text;
  -webkit-user-select: text;
}

/* A descriptive question carries its own layout: (a)/(b)/(c) parts, an OR
   branch, the mark split on its own line. Keep the line breaks the paper had,
   and drop the weight a little — a 120-word question set entirely in bold is a
   wall. Applies to the student's paper and the faculty's marking view alike. */
.q-text {
  white-space: pre-wrap;
  font-weight: 500;
}

.q-marks {
  float: right;
  background: #eef3f7;
  color: var(--primary);
  border-radius: 20px;
  padding: 1px 10px;
  font-size: .78rem;
  letter-spacing: 0;
}
.q-guide {
  font-size: .88rem;
  color: var(--muted);
  border-left: 3px solid var(--border);
  padding: 2px 0 2px 10px;
  margin: 0 0 12px;
}

/* ---- Answer editor ---- */
.ed {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  /* Deliberately no overflow. "overflow: hidden" would turn .ed into its own
     scroll container, and the sticky toolbar below would then take its 74px
     offset from the top of .ed instead of from the page — parking it on top of
     the first three lines the student typed. The corners are rounded on the
     toolbar and the footer instead. */
}
.ed:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(46,134,193,.15); }

.ed-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px;
  padding: 6px 8px;
  background: #f4f8fb;
  border-bottom: 1px solid var(--border);
  border-radius: 9px 9px 0 0;
  /* Sits under the exam's own sticky header; 0 anywhere else (selftest). */
  position: sticky; top: var(--ed-sticky, 0px); z-index: 6;
}
.ed-toolbar button {
  min-width: 32px; height: 30px;
  padding: 0 7px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  font-size: .95rem; line-height: 1;
  color: var(--text);
  cursor: pointer;
}
.ed-toolbar button:hover { background: #e4eef6; border-color: var(--border); }
.ed-toolbar button.on { background: #d9e9f5; border-color: var(--accent); color: var(--primary); }
.ed-toolbar .tb-b { font-weight: 800; }
.ed-toolbar .tb-i { font-style: italic; font-family: Georgia, serif; }
.ed-toolbar .tb-u { text-decoration: underline; }
.ed-toolbar .tb-s { text-decoration: line-through; }
.ed-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.ed-style {
  width: auto; height: 30px; padding: 0 6px;
  font-size: .85rem; border-radius: 6px; margin-right: 4px;
}

.ed-body {
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  caret-color: var(--accent);
  background: #fff;
  min-height: 220px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 1rem;
  line-height: 1.65;
  outline: none;
}
.ed-body:empty::before {
  content: "Start typing your answer here…";
  color: #9aa8b5;
}
.ed-body p { margin: 0 0 10px; }
.ed-body h2 { font-size: 1.15rem; margin: 14px 0 6px; color: var(--primary); }
.ed-body h3 { font-size: 1.02rem; margin: 12px 0 5px; color: var(--primary); }
.ed-body h4 { font-size: .95rem; margin: 10px 0 4px; }
.ed-body ul, .ed-body ol { margin: 0 0 10px; padding-left: 26px; }
.ed-body blockquote {
  margin: 0 0 10px; padding: 6px 14px;
  border-left: 3px solid var(--accent); background: #f4f9fd; color: #445;
}
.ed-body pre {
  background: #f5f7f9; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; overflow-x: auto;
  font-family: ui-monospace, "Cascadia Code", monospace; font-size: .9rem;
}
.ed-body table { margin: 0 0 12px; width: auto; min-width: 60%; }
.ed-body td, .ed-body th { border: 1px solid var(--border); padding: 6px 9px; }
.ed-body th { background: #f0f5f9; }
.ed-body hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.ed-foot {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: #fafcfd;
  border-radius: 0 0 9px 9px;
  font-size: .8rem; color: var(--muted);
}
.ed-count b { color: var(--primary); }
.ed-target.warn { color: var(--warn); font-weight: 600; }
.ed-tip { margin-left: auto; opacity: .8; }

/* ---- Diagrams inside an answer ---- */
figure.dgm {
  margin: 12px 0; padding: 8px;
  border: 1px dashed var(--accent); border-radius: 8px;
  background: #f7fbfe; text-align: center;
}
figure.dgm img { max-width: 100%; max-height: 420px; border-radius: 6px; display: block; margin: 0 auto 6px; }
figure.dgm figcaption { font-size: .85rem; color: var(--muted); font-style: italic; }

/* ---- Equations ---- */
.mathx {
  display: inline-block;
  padding: 0 2px;
  background: #f4f9fd;
  border-bottom: 1px dotted var(--accent);
}
.katex { font-size: 1.05em; }

/* ---- Modals (symbols, equations, evaluation) ---- */
.modal {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(18, 56, 79, .55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 14px; padding: 22px;
  max-width: 720px; width: 100%; max-height: 88vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal-box.wide { max-width: 980px; }
.modal-box h3 { margin: 0 0 4px; color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.m-src { font-family: ui-monospace, "Cascadia Code", monospace; font-size: .95rem; }
.m-preview {
  min-height: 64px; margin: 12px 0;
  border: 1px solid var(--border); border-radius: 8px; background: #fafcfd;
  padding: 12px; text-align: center; overflow-x: auto;
}
.m-err { color: var(--bad); font-size: .85rem; }
.m-templates { display: flex; flex-wrap: wrap; gap: 6px; }
.m-t {
  border: 1px solid var(--border); background: #f4f8fb; border-radius: 20px;
  padding: 4px 12px; font-size: .82rem; cursor: pointer; color: var(--primary);
}
.m-t:hover { background: #e4eef6; }

.sym-group { margin-bottom: 12px; }
.sym-title {
  font-size: .75rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 5px;
}
.sym-row { display: flex; flex-wrap: wrap; gap: 4px; }
button.sym {
  width: 36px; height: 34px;
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  font-size: 1.05rem; cursor: pointer;
}
button.sym:hover { background: #eaf4fb; border-color: var(--accent); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 10001;
  background: var(--primary-dark); color: #fff;
  padding: 9px 18px; border-radius: 22px; font-size: .88rem;
  box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.toast.err { background: var(--bad); }
.toast.warn { background: var(--warn); }
.toast.ok { background: var(--good); }

/* ---- Faculty: reading and marking a paper ---- */
.paper-q { border-top: 1px solid var(--border); padding-top: 14px; margin-top: 18px; }
.paper-q:first-child { border-top: none; margin-top: 0; }
.paper-ans {
  background: #fafbfc; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; line-height: 1.6;
}
.paper-ans img { max-width: 100%; border: 1px solid var(--border); border-radius: 6px; }
.paper-ans figure.dgm { background: #fff; }
.paper-ans table { width: auto; min-width: 50%; }
.paper-ans td, .paper-ans th { border: 1px solid var(--border); }
.mark-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 10px;
}
.mark-row .mk { width: 110px; }
.mark-row .fb { flex: 1 1 260px; }
.mark-row label { margin: 0 0 4px; }
.mark-row input, .mark-row textarea { padding: 7px 10px; font-size: .9rem; }
.mark-row textarea { font-family: inherit; min-height: 38px; }
.rubric {
  background: #fff8e8; border: 1px solid #f0dca8; border-radius: 8px;
  padding: 10px 14px; font-size: .88rem; margin: 10px 0 0;
}
.score-bar {
  position: sticky; bottom: 0; background: var(--card);
  border-top: 2px solid var(--accent); padding: 12px 0 4px;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px;
}
.score-bar .tot { font-size: 1.2rem; font-weight: 700; color: var(--primary); }

.qbuild-row {
  display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px;
  background: #fafcfd;
}
.qbuild-row .qtext { flex: 1 1 320px; }
.qbuild-row .qnum {
  font-weight: 700; color: var(--accent); min-width: 26px; padding-top: 30px;
}
.qbuild-row .small { width: 78px; }
.qbuild-row label { font-size: .75rem; margin: 0 0 3px; }

/* ---- Table dialog ---------------------------------------------------------
   Replaces window.prompt(), which is browser chrome and therefore blurs the
   page and can drop full screen. Everything here is inside the document. */
.modal .small { width: 92px; }
.tbl-row { display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; }
.tbl-row label { margin: 0 0 4px; }
.tbl-head {
  display: flex; align-items: center; gap: 8px;
  font-weight: 500; font-size: .9rem; padding-bottom: 9px; cursor: pointer;
}
.tbl-head input { width: 17px; height: 17px; margin: 0; }
.tbl-preview {
  margin: 14px 0 0; padding: 12px; overflow: auto; max-height: 220px;
  background: #fafcfd; border: 1px solid var(--border); border-radius: 8px;
}
.tbl-preview table { border-collapse: collapse; width: auto; }
.tbl-preview td, .tbl-preview th {
  border: 1px solid var(--border); padding: 5px 14px; font-size: .82rem;
  min-width: 52px; color: var(--muted);
}
.tbl-preview th { background: #f0f5f9; }

/* ---- Drawing pad ----------------------------------------------------------
   Lets a diagram be drawn in the exam rather than photographed and uploaded,
   which means no file chooser, no focus loss and no violation. */
.draw-tools {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 8px; margin-bottom: 10px;
  background: #f4f8fb; border: 1px solid var(--border); border-radius: 8px;
}
.draw-group { display: inline-flex; gap: 4px; align-items: center; }
.draw-btn {
  height: 30px; padding: 0 10px;
  border: 1px solid var(--border); background: #fff; border-radius: 6px;
  font-size: .84rem; color: var(--text); cursor: pointer; line-height: 1;
}
.draw-btn:hover { background: #e4eef6; }
.draw-btn.on { background: #d9e9f5; border-color: var(--accent); color: var(--primary); font-weight: 600; }
.draw-swatch {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0;
}
.draw-swatch.on { box-shadow: 0 0 0 2px var(--accent); transform: scale(1.12); }
.draw-hint { margin-left: auto; font-size: .78rem; color: var(--muted); }

.draw-wrap {
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; overflow: hidden; line-height: 0;
}
.draw-canvas {
  display: block; width: 100%; height: auto;
  cursor: crosshair;
  /* Stops a touch drag from scrolling the page instead of drawing a line. */
  touch-action: none;
}
.draw-count { margin-right: auto; font-size: .82rem; }
