:root {
  --brand: #275c50;
  --brand-dark: #1c463d;
  --brand-tint: #e8f0ee;
  --ink: #1d2b28;
  --muted: #5d6b68;
  --line: #d6dedc;
  --bg: #f3f5f4;
  --card: #ffffff;
  --warn: #b25e00;
  --warn-bg: #fff4e5;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok: #1e7b45;
  --ok-bg: #e7f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 34, .06), 0 4px 16px rgba(16, 40, 34, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* Header */
.topbar { background: var(--brand); color: #fff; display: flex; align-items: center; gap: 14px; padding: 10px 20px; min-height: 60px; position: sticky; top: 0; z-index: 20; }
.topbar img { width: 38px; height: 38px; border-radius: 6px; }
.topbar .title { font-weight: 600; font-size: 16px; line-height: 1.2; }
.topbar .subtitle { font-size: 12.5px; opacity: .85; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; text-align: right; }

/* Layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.narrow { max-width: 760px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card + .card { margin-top: 16px; }
h1 { font-size: 24px; margin: 0 0 6px; }
h2 { font-size: 19px; margin: 0 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* Forms */
label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid #b9c5c2; border-radius: 8px; padding: 9px 11px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(39, 92, 80, .35); border-color: var(--brand); }
.field { margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--brand); }
.btn.secondary:hover { background: var(--brand-tint); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.danger { background: #fff; color: var(--danger); border-color: #e4b4b0; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.lg { padding: 12px 22px; font-size: 16px; }
.error { background: var(--danger-bg); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.notice { background: var(--brand-tint); border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.warnbox { background: var(--warn-bg); color: #6a3b00; border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }

/* Instructions */
.instructions ul { padding-left: 20px; }
.instructions li { margin: 6px 0; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.fact { background: var(--brand-tint); border-radius: 8px; padding: 12px; text-align: center; }
.fact b { display: block; font-size: 22px; color: var(--brand); }
.fact span { font-size: 12.5px; color: var(--muted); }
@media (max-width: 600px) { .facts { grid-template-columns: 1fr; } }

/* Test screen */
.testbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 60px; z-index: 15; }
.testbar .inner { max-width: 1280px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; padding: 6px 14px; border-radius: 8px; background: var(--brand-tint); color: var(--brand); min-width: 112px; text-align: center; }
.timer.low { background: var(--warn-bg); color: var(--warn); }
.timer.critical { background: var(--danger-bg); color: var(--danger); }
.savestate { font-size: 13px; color: var(--muted); }
.savestate.bad { color: var(--danger); font-weight: 600; }
.test-layout { max-width: 1280px; margin: 0 auto; padding: 20px; display: grid; grid-template-columns: 230px 1fr; gap: 20px; }
@media (max-width: 860px) { .test-layout { grid-template-columns: 1fr; } }
.qnav { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 860px) { .qnav { flex-direction: row; overflow-x: auto; } }
.qbtn { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; min-width: 150px; }
.qbtn .qn { font-weight: 700; }
.qbtn .qt { font-size: 12.5px; color: var(--muted); display: block; }
.qbtn .qc { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.qbtn .dot { width: 8px; height: 8px; border-radius: 50%; background: #c4ccca; display: inline-block; }
.qbtn.answered .dot { background: var(--ok); }
.qbtn.active { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); background: var(--brand-tint); }
.viewtoggle { margin-top: 10px; font-size: 13px; }
.qsection { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.qsection + .qsection { margin-top: 18px; }
.qhead { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--brand); font-weight: 700; margin-bottom: 6px; }
.qprompt { font-size: 16px; margin: 0 0 14px; }
.answer { width: 100%; min-height: 330px; resize: vertical; font-size: 16px; line-height: 1.6; padding: 14px; border-radius: 8px; border: 1px solid #b9c5c2; }
.answer:disabled { background: #f4f6f5; }
.counter { text-align: right; font-size: 13px; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.counter.near { color: var(--warn); font-weight: 600; }
.counter.full { color: var(--danger); font-weight: 700; }
.qfoot { display: flex; justify-content: space-between; margin-top: 14px; }
.pse-layout { max-width: 1320px; margin: 0 auto; padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 960px) { .pse-layout { grid-template-columns: 1fr; } }
.pse-prompt { max-height: calc(100vh - 170px); overflow: auto; position: sticky; top: 140px; }
.pse-prompt table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.pse-prompt th, .pse-prompt td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.pse-prompt th { background: var(--brand-tint); }
.pse-answer .answer { min-height: 520px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 30, 26, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; max-width: 560px; width: 100%; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); max-height: 90vh; overflow: auto; }
.modal.wide { max-width: 900px; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.review-list { list-style: none; padding: 0; margin: 12px 0; }
.review-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.review-list .empty { color: var(--danger); font-weight: 600; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2b28; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-weight: 600; }
.toast.warn { background: var(--warn); }

.bigtimer { font-size: 56px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; text-align: center; margin: 10px 0; }
.center { text-align: center; }
.check { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); display: flex; align-items: center; justify-content: center; font-size: 34px; margin: 0 auto 12px; }

/* Admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tab { background: none; border: none; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
table.data { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
table.data th, table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfb; }
table.data tr:hover td { background: #fafcfb; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b-gray { background: #eceff0; color: #4b5856; }
.b-blue { background: #e3eefc; color: #1d4f91; }
.b-amber { background: var(--warn-bg); color: var(--warn); }
.b-green { background: var(--ok-bg); color: var(--ok); }
.b-purple { background: #efe8fb; color: #5b2ea6; }
.chars { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); }
.setup { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1000px) { .setup { grid-template-columns: 1fr; } }
.slot { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fff; }
.slot .slothead { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.slot textarea { min-height: 86px; }
.bank { max-height: 75vh; overflow: auto; }
.bankitem { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #fff; }
.bankitem .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bankitem .text { margin: 6px 0; font-size: 14px; white-space: pre-wrap; }
.bankitem .text.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bankitem .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.scorecard { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; background: #fff; }
.scorecard .resp { white-space: pre-wrap; background: #f7f9f8; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: Georgia, serif; font-size: 15px; max-height: 360px; overflow: auto; }
.rubric-row { display: grid; grid-template-columns: 190px 70px 1fr; gap: 10px; align-items: start; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.rubric-row textarea { min-height: 52px; font-size: 13.5px; }
.saor { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
@media (max-width: 900px) { .saor { grid-template-columns: 1fr 1fr; } .rubric-row { grid-template-columns: 1fr 70px; } .rubric-row textarea { grid-column: 1 / -1; } }
.saor .cell { border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 13px; }
.total { font-size: 18px; font-weight: 700; color: var(--brand); }
.issues { width: 100%; border-collapse: collapse; font-size: 13px; }
.issues td, .issues th { border: 1px solid var(--line); padding: 5px 7px; text-align: left; }
.split { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
.studentlist { max-height: 75vh; overflow: auto; }
.studentlist button { width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.studentlist button.active { border-color: var(--brand); background: var(--brand-tint); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.btn.secondary .spinner { border-color: rgba(39,92,80,.3); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.pse-layout .qsection + .qsection { margin-top: 0; }
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 60; pointer-events: none; }
.toasts .toast { position: static; transform: none; }
@media (max-width: 640px) {
  .btn { white-space: normal; text-align: center; }
  .topbar .subtitle { display: none; }
  .topbar { padding: 8px 16px; }
  .wrap { padding: 16px 16px 48px; }
  .card { padding: 18px; }
  .testbar { top: 56px; }
  .testbar .inner { padding: 8px 16px; gap: 10px; }
  .test-layout, .pse-layout { padding: 16px; }
  .qsection { padding: 16px; }
  .answer { min-height: 260px; }
  .qbtn { min-width: 128px; }
  .pse-prompt { position: static; max-height: none; }
  .bigtimer { font-size: 44px; }
}
.test-layout > *, .pse-layout > * { min-width: 0; }
@media (max-width: 640px) { .topbar .who .small { display: none; } }
/* Single-page exam */
.examnav { position: sticky; top: 140px; align-self: start; }
@media (max-width: 860px) { .examnav { position: static; } }
.parthead { margin: 6px 0 12px; }
.parthead h2 { margin: 0; }
.parthead + .qsection { margin-top: 0; }
.qsection + .parthead { margin-top: 28px; }
.pse-text table { border-collapse: collapse; margin: 10px 0; font-size: 14px; }
.pse-text th, .pse-text td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.pse-text th { background: var(--brand-tint); }
.answer.pse-answer { min-height: 480px; }
.qsection { scroll-margin-top: 140px; }
