:root {
  --bg: #f3f4f7; --card: #fff; --ink: #161a23; --muted: #5d6677; --line: #dfe3ea;
  --brand: #1f4fd8; --brand-ink: #fff; --ok: #12805c; --warn: #b26a00; --bad: #c0362c;
  --ok-bg: #e2f4ec; --warn-bg: #fdf0d5; --bad-bg: #fbe3e0;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Thonburi", "Leelawadee UI", sans-serif;
  background: var(--bg); color: var(--ink);
}
h1 { font-size: 1.45rem; margin: 0 0 .6rem; line-height: 1.25; }
h1 span { display: block; font-size: 1.05rem; font-weight: 500; color: var(--muted); }
h2 { font-size: .95rem; margin: 0 0 .5rem; }
button, input { font: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: .6rem 1rem; border-radius: 8px; cursor: pointer;
}
button:hover { border-color: #b9c0cc; }
button:focus-visible, input:focus-visible { outline: 3px solid #9db5f5; outline-offset: 1px; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button.small { padding: .4rem .8rem; }
button:disabled { opacity: .45; cursor: default; }

.center { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.narrow { width: 100%; max-width: 620px; }
.meta { color: var(--muted); margin: 0 0 1rem; }
label { display: block; font-weight: 600; margin: .8rem 0; }
label input:not([type=checkbox]):not([type=radio]) {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem;
  border: 1px solid var(--line); border-radius: 8px; font-weight: 400;
}
label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; }
label.check input { margin-top: .3rem; width: 1.1rem; height: 1.1rem; }
.notice { background: #f6f8fc; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; font-size: .9rem; }
.notice ul { margin: .4rem 0; padding-left: 1.2rem; }
.notice p { margin: .4rem 0; }
.err { color: var(--bad); font-weight: 600; }
form .primary { width: 100%; margin-top: .6rem; padding: .8rem; }

/* exam */
#exam { min-height: 100%; user-select: none; -webkit-user-select: none; }
header {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.who span { color: var(--muted); margin-left: .6rem; }
.status { display: flex; align-items: center; gap: 14px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.15rem; min-width: 5.2ch; text-align: right; }
.timer.low { color: var(--bad); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; padding: 18px 20px; max-width: 1200px; margin: 0 auto; }
.qhead { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-weight: 600; margin-bottom: .5rem; }
.hint { color: var(--warn); }
.q-en { font-size: 1.15rem; font-weight: 600; margin: 0 0 .35rem; }
.q-th { font-size: 1.05rem; color: #333c4d; margin: 0 0 1.1rem; padding-left: 1.4rem; }
.opts { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 12px; align-items: flex-start; margin: 0; font-weight: 400;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.opt:hover { border-color: #b9c0cc; }
.opt.sel { border-color: var(--brand); background: #eef3ff; }
.opt input { margin-top: .3rem; width: 1.05rem; height: 1.05rem; flex: none; }
.opt b { flex: none; width: 1.4rem; }
.nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 1.3rem; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid button { padding: .35rem 0; font-size: .85rem; border-radius: 6px; }
.grid button.answered { background: var(--ok-bg); border-color: #9fd3bd; }
.grid button.flagged { box-shadow: inset 0 -4px 0 var(--warn); }
.grid button.cur { outline: 2px solid var(--brand); }
.legend { font-size: .8rem; color: var(--muted); margin: .8rem 0 0; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 4px 0 8px; vertical-align: -1px; border: 1px solid var(--line); }
.lg.answered { background: var(--ok-bg); border-color: #9fd3bd; }
.lg.flagged { box-shadow: inset 0 -4px 0 var(--warn); }
#flagBtn.on { border-color: var(--warn); color: var(--warn); }

#watermark {
  position: fixed; inset: -20%; z-index: 4; pointer-events: none; overflow: hidden;
  display: flex; flex-wrap: wrap; gap: 46px 60px; align-content: flex-start;
  transform: rotate(-24deg); opacity: .07; font-size: .85rem; font-weight: 700; white-space: nowrap;
}
body.shielded #exam { filter: blur(18px); pointer-events: none; }
#shield, .modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(22, 26, 35, .72);
}
.score { font-size: 2rem; font-weight: 700; margin: .4rem 0; }

@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } .grid { grid-template-columns: repeat(10, 1fr); } }
@media print { body * { display: none !important; } }

/* proctor dashboard */
.admin { max-width: 1400px; margin: 0 auto; padding: 18px 20px; }
.admin .bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.open { background: #f1f4fb; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-weight: 700; font-size: .8rem; }
.badge.low { background: var(--ok-bg); color: var(--ok); }
.badge.medium { background: var(--warn-bg); color: var(--warn); }
.badge.high { background: var(--bad-bg); color: var(--bad); }
.split { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: .6rem 0; }
.chip { background: #eef0f5; border-radius: 6px; padding: 2px 8px; font-size: .8rem; }
.chip.hot { background: var(--bad-bg); color: var(--bad); font-weight: 600; }
.timeline { max-height: 55vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; font-size: .85rem; }
.timeline div { display: grid; grid-template-columns: 5.5rem 11rem 1fr 2.5rem; gap: 8px; padding: 4px 10px; border-bottom: 1px solid #eef0f4; }
.timeline div.hot { background: #fff6f5; }
.timeline div.warm { background: #fffaf0; }
.timeline .t { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .d { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline .w { text-align: right; color: var(--bad); font-weight: 600; }
.answers { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; margin-top: .5rem; }
.answers span { text-align: center; font-size: .75rem; padding: 3px 0; border-radius: 4px; background: #eef0f5; }
.answers span.ok { background: var(--ok-bg); color: var(--ok); }
.answers span.no { background: var(--bad-bg); color: var(--bad); }
.note { font-size: .85rem; color: var(--muted); }
