/* Offline exam emulator. Only local system fonts (no internet in the lab). */
:root {
  --paper: #f2f4f6;
  --panel: #ffffff;
  --ink: #16202b;
  --ink-soft: #4d5967;
  --rule: #d3d9df;
  --action: #2b4c7e;
  --action-dark: #1f3a63;
  --correct: #2e7a48;
  --wrong: #b3322a;
  --idle: #98a2ad;
  --edited: #b7791f;
  --sans: "Ubuntu", "Noto Sans", "DejaVu Sans", system-ui, sans-serif;
  --mono: "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
[hidden] { display: none !important; }
button {
  font: inherit; padding: 7px 16px; border: 1px solid var(--rule); border-radius: 4px;
  background: var(--panel); color: var(--ink); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--ink-soft); }
button:disabled { opacity: .55; cursor: progress; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }
button.primary { background: var(--action); border-color: var(--action); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--action-dark); }
button.plain { border-color: transparent; background: none; color: var(--ink-soft); text-decoration: underline; }
.muted { color: var(--ink-soft); }
.error { color: var(--wrong); min-height: 1.5em; margin: 8px 0 0; }

/* ---------- gate screens (bank, login, done) ---------- */
.gate { min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: 10vh 16px; }
.gate-box { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 28px 32px; }
.gate-box.wide { max-width: 720px; }
.gate h1 { font-size: 24px; margin: 0 0 8px; font-weight: 500; }
.gate-help { color: var(--ink-soft); margin: 0 0 18px; }
.field { display: block; margin-bottom: 16px; font-weight: 500; }
.field input { display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; padding: 7px 9px; border: 1px solid var(--rule); border-radius: 4px; }
.gate .primary { width: 100%; padding: 9px; }
.gate .plain { width: 100%; margin-top: 6px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 28px;
  padding: 10px 20px; background: var(--ink); color: #e9eef3;
}
.tb-who { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.tb-who strong { color: #fff; }
.tb-who span { font-size: 13px; color: #b9c3cd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-stats { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; flex: 1; }
.tb-stats b { color: #fff; font-variant-numeric: tabular-nums; }
.count i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.count.correct i { background: #5cc07f; }
.count.wrong i { background: #ef6a5f; }
.count.idle i { background: var(--idle); }
.tb-clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.tb-clock-label { font-size: 12px; color: #b9c3cd; }
#tb-left { font: 600 26px/1.1 var(--mono); font-variant-numeric: tabular-nums; color: #fff; letter-spacing: .02em; }
#tb-left.soon { color: #f2c14e; }
#tb-left.urgent { color: #ff7b70; }
button.submit { background: var(--wrong); border-color: var(--wrong); color: #fff; font-weight: 500; }
button.submit:hover:not(:disabled) { background: #922820; }

/* ---------- layout ---------- */
#screen-exam { display: flex; flex-direction: column; height: 100%; }
.body { flex: 1; display: flex; min-height: 0; }
nav { width: 290px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--rule); background: var(--panel); padding: 8px 0; }
main { flex: 1; overflow-y: auto; padding: 22px 36px 60px; }
main > * { max-width: 980px; }

/* ---------- navigation ---------- */
nav a {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px; color: var(--ink);
  text-decoration: none; border-left: 3px solid transparent;
}
nav a:hover { background: var(--paper); }
nav a.current { background: #e4eaf1; border-left-color: var(--action); font-weight: 500; }
nav .num {
  flex-shrink: 0; width: 28px; height: 24px; border-radius: 4px; display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff; background: var(--idle); font-variant-numeric: tabular-nums;
}
nav .correct .num { background: var(--correct); }
nav .wrong .num { background: var(--wrong); }
nav .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
nav .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--edited); flex-shrink: 0; visibility: hidden; }
nav a.edited .dot { visibility: visible; }
.legend { padding: 10px 14px 4px; font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--rule); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; margin-right: 10px; }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ---------- question ---------- */
.q-head { display: flex; align-items: baseline; gap: 14px; }
.q-head h2 { font-size: 22px; font-weight: 500; margin: 0 0 10px; }
.qtext { line-height: 1.6; max-width: 80ch; }
.qtext code, .qtext pre { font-family: var(--mono); font-size: 15px; }
.qtext code { background: #e8ecf0; padding: 0 3px; border-radius: 3px; }
.qtext pre { background: #e8ecf0; padding: 8px 12px; border-radius: 4px; overflow-x: auto; }
.qtext pre code { background: none; padding: 0; }
h3 { font-size: 15px; font-weight: 600; margin: 22px 0 6px; }

table.io { border-collapse: collapse; margin: 4px 0 8px; font-size: 14px; }
table.io th, table.io td { border: 1px solid var(--rule); padding: 5px 10px; text-align: left; vertical-align: top; }
table.io th { background: #e8ecf0; font-weight: 600; }
table.io td pre { margin: 0; font: 15px/1.35 var(--mono); white-space: pre-wrap; word-break: break-word; }
table.io tr.pass td { background: #e5f3ea; }
table.io tr.fail td { background: #fbe7e5; }
table.io td.mark { font-weight: 700; text-align: center; width: 28px; }
tr.pass td.mark { color: var(--correct); }
tr.fail td.mark { color: var(--wrong); }
td.hidden-row { color: var(--ink-soft); font-style: italic; }

/* ---------- editor ---------- */
#editor .CodeMirror {
  height: 380px; border: 1px solid var(--rule); border-radius: 4px;
  font: 16px/1.4 var(--mono); resize: vertical; overflow: hidden;
}
.actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.hint { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; }

/* ---------- results ---------- */
#result { margin-top: 18px; }
.res { border: 1px solid var(--rule); border-radius: 4px; padding: 12px 16px; background: var(--panel); }
.res.ok { border-color: #9cd0ae; background: #f1f9f4; }
.res.bad { border-color: #e6aaa5; background: #fdf3f2; }
.res h4 { margin: 0 0 8px; font-size: 15px; }
.res pre.err { font: 14px/1.4 var(--mono); background: #fbe7e5; padding: 8px 12px; border-radius: 4px; white-space: pre-wrap; margin: 0; }
.res p { margin: 8px 0 0; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(22, 32, 43, .55); display: grid; place-items: center; z-index: 20; }
.modal-box { background: var(--panel); border-radius: 6px; padding: 24px 28px; max-width: 480px; width: calc(100% - 32px); }
.modal-box h2 { margin: 0 0 10px; font-size: 20px; font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- done ---------- */
.done-total { font-size: 28px; font-weight: 600; margin: 10px 0 16px; }
table.summary { width: 100%; border-collapse: collapse; font-size: 14px; }
table.summary th, table.summary td { border-bottom: 1px solid var(--rule); padding: 6px 8px; text-align: left; }
table.summary td.r-correct { color: var(--correct); font-weight: 500; }
table.summary td.r-wrong { color: var(--wrong); font-weight: 500; }
table.summary td.r-not_attempted { color: var(--ink-soft); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- v2 additions ---------- */
.modebar {
  display: flex; align-items: center; gap: 16px; padding: 6px 20px; font-size: 13px;
  background: #e4eaf1; border-bottom: 1px solid var(--rule); color: var(--ink-soft);
}
.modebar .penalty-on { color: #8a3b12; font-weight: 500; }
.mb-tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
button.small { padding: 3px 10px; font-size: 13px; }
#tb-left.nolimit { font-size: 18px; }
.nav-heading {
  padding: 12px 14px 4px; font-size: 13px; font-weight: 600; color: var(--ink-soft);
  border-top: 1px solid var(--rule); margin-top: 6px;
}
nav .nav-heading:first-child { border-top: none; margin-top: 0; padding-top: 6px; }
.notice { background: #fff4d6; border: 1px solid #ecd28c; padding: 8px 12px; border-radius: 4px; }
.gate-help.or { margin-top: 18px; }
.bank-list { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 8px; }
.bank-item { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; }
.bank-item:hover { background: #f5f8fb; }
.bank-title { font-weight: 500; }
.done-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.gate .done-actions .primary { width: auto; padding: 7px 22px; }
button.fill { margin-left: auto; border-style: dashed; color: #8a3b12; }

/* ---------- question list toggle, current question, prev/next ---------- */
.navtoggle { white-space: nowrap; }
.mb-current { font-weight: 500; color: var(--ink); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.nav-collapsed nav { display: none; }
.nav-backdrop { display: none; }
.res, #q-examples, .qtext { overflow-x: auto; }
.qnav { display: flex; align-items: center; gap: 12px; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--rule); }
.qnav button { max-width: 42%; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 8px 14px; }
.qnav .qnext { margin-left: auto; }
.qnav-pos { color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.qnav button:disabled { visibility: hidden; }

button.more { display: none; }
.modebar { position: relative; }

/* ---------- matplotlib figures under the results ---------- */
.figs { margin-top: 14px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; }
.figs h4 { margin: 0 0 8px; font-size: 15px; }
.figs img { display: block; max-width: 100%; height: auto; margin: 0 0 8px; }

/* ---------- tries / penalty chip next to Check ---------- */
.try-chip {
  font-size: 13px; padding: 3px 10px; border-radius: 12px; white-space: nowrap; cursor: help;
  background: #e8ecf0; color: var(--ink-soft); border: 1px solid var(--rule);
}
.try-chip.warn { background: #fff4d6; border-color: #ecd28c; color: #8a3b12; }
.try-chip.solved { background: #e5f3ea; border-color: #9cd0ae; color: var(--correct); }

/* ---------- time extension box on the submitted screen ---------- */
.ext-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 12px 0 4px; padding: 10px 12px;
  background: #fff4d6; border: 1px solid #ecd28c; border-radius: 4px; font-size: 14px;
}
.ext-box input { font: inherit; padding: 5px 8px; border: 1px solid var(--rule); border-radius: 4px; flex: 1; min-width: 150px; }
.modal-box .field { margin: 12px 0 0; }

/* ---------- set description ---------- */
.tb-who .tb-desc { max-width: 60ch; font-style: italic; }

/* ---------- web home page (practice site): quiet, on the grey page ---------- */
.gate-box.home { max-width: 760px; padding: 0; background: none; border: none; }
.intro { padding-bottom: 14px; margin-bottom: 20px; border-bottom: 1px solid var(--rule); }
.gate .intro h1 { font-size: 28px; font-weight: 600; margin: 0 0 12px; display: flex; align-items: center; gap: 12px; }
.intro-mark {
  font: 700 14px/1 var(--mono); color: #f2c14e; background: var(--ink);
  padding: 6px 8px; border-radius: 4px;
}
.intro p { margin: 0 0 10px; color: var(--ink-soft); max-width: 72ch; }
.intro b { color: var(--ink); font-weight: 600; }
.intro .intro-credit { font-size: 14px; }
.home #choose-title { font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.home .gate-help { margin-bottom: 12px; }
.home .bank-item {
  gap: 3px; padding: 11px 16px; border: 1px solid var(--rule); border-left: 4px solid var(--action);
  border-radius: 4px; background: var(--panel);
}
.home .bank-item:hover:not(:disabled), .home .bank-item:focus-visible { background: #f7f9fb; border-color: var(--action); }
.bank-head { display: flex; align-items: baseline; gap: 12px; width: 100%; }
.home .bank-title { font-size: 16px; font-weight: 600; color: var(--action-dark); }
.bank-meta { margin-left: auto; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.bank-desc {                                   /* one faint line; full text on hover */
  width: 100%; font-size: 14px; color: #7a8591; line-height: 1.45;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bank-item:hover .bank-desc, .bank-item:focus-visible .bank-desc { white-space: normal; color: var(--ink-soft); }
@media (hover: none) { .bank-desc { white-space: normal; } }   /* touch screens cannot hover */

/* ---------- phones and narrow windows ---------- */
@media (max-width: 800px) {
  .tb-stats .lbl { display: none; }                  /* counts keep their coloured dots */
  #mb-penalty:not(.penalty-on) { display: none; }    /* only show the line when a penalty applies */
  button.more:not([hidden]) { display: inline-block; margin-left: auto; }
  .mb-tools {
    display: none; position: absolute; right: 12px; top: 100%; z-index: 12; flex-direction: column;
    background: var(--panel); border: 1px solid var(--rule); border-radius: 4px; padding: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
  }
  body.tools-open .mb-tools { display: flex; }
  .mb-tools button { text-align: left; padding: 8px 12px; }
  body { font-size: 15px; }
  .topbar { flex-wrap: wrap; gap: 4px 12px; padding: 8px 12px; }
  .tb-who { order: 1; flex: 1; }
  .tb-who span { font-size: 12px; }
  #tb-student, #tb-start-wrap { display: none; }
  .tb-clock { order: 2; }
  .tb-clock-label { font-size: 11px; }
  #tb-left { font-size: 20px; }
  #tb-left.nolimit { font-size: 15px; }
  #btn-submit { order: 3; padding: 5px 10px; font-size: 14px; }
  .tb-stats { order: 4; flex-basis: 100%; font-size: 13px; gap: 2px 14px; flex-wrap: nowrap; }
  .modebar { flex-wrap: wrap; gap: 6px 10px; padding: 6px 12px; }
  .mb-current { flex: 1; }
  #mb-penalty { order: 5; flex-basis: 100%; font-size: 12px; }
  /* question list becomes a slide-in drawer */
  nav {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 15; width: min(86vw, 330px);
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 4px 0 18px rgba(0, 0, 0, .18);
  }
  body.nav-collapsed nav { display: block; }
  body.nav-open nav { transform: none; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 14; background: rgba(22, 32, 43, .45); }
  nav a { padding: 9px 14px; }
  main { padding: 14px 14px 40px; }
  .q-head { flex-wrap: wrap; gap: 4px 12px; }
  .q-head h2 { font-size: 19px; margin-bottom: 4px; }
  #editor .CodeMirror { height: 300px; font-size: 15px; }
  .actions { flex-wrap: wrap; }
  .actions button { padding: 9px 14px; }
  button.fill { margin-left: 0; }
  .hint { display: none; }
  .qnav button { max-width: 44%; padding: 10px 12px; }
  .gate { padding: 5vh 12px; }
  .gate-box { padding: 20px 18px; }
  .modal-box { padding: 18px; }
  #tb-desc { display: none; }
  .gate .intro h1 { font-size: 23px; }
  .bank-head { flex-wrap: wrap; gap: 0 12px; }
  .bank-meta { margin-left: 0; }
}
