:root {
  /* KMUTT house colours: the logo orange is #E64011. Text and UI use deeper shades of it so
     white-on-orange and orange-on-white both clear WCAG AA (5.3:1 and 7.0:1). */
  --brand: #e64011;          /* the logo orange - accents, eyebrows, section titles */
  --brand-deep: #c6390f;     /* top bar, primary buttons, headings   (5.26:1 on white) */
  --brand-dark: #a62e0b;     /* links and hover states               (6.96:1 on white) */
  --ink: #24201e;
  --muted: #6b625e;
  --line: #ecdfd9;
  --bg: #fdf7f4;             /* warm off-white page behind white cards */
  --card: #ffffff;
  --ok: #1e6b3a;
  --ok-bg: #e7f4ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn-bg: #fff4e5;
  --info-bg: #fdeee8;        /* warm tint, used for the selected answer */
  --radius: 12px;
}
* { box-sizing: border-box; }
html { scroll-padding-top: 90px; }
body {
  margin: 0; font-family: "Sarabun", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  font-size: 17px; line-height: 1.55; color: var(--ink); background: var(--bg);
}
a { color: var(--brand-dark); }
h1 { font-size: 1.6rem; margin: .2rem 0 .6rem; color: var(--brand-deep); line-height: 1.3; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; color: var(--brand-deep); }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small, small { font-size: .88rem; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.eyebrow { margin: 0; color: var(--brand); font-weight: 600; font-size: .9rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: #fff; color: var(--brand-deep); flex-wrap: wrap;
  border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* KMUTT mark: the logo is orange on transparent, so the bar shows it on white */
.brand .logo { height: 34px; width: auto; display: block; flex: none; }

/* visitor counter + credit line, on every page */
.sitefoot {
  max-width: 1240px; margin: 8px auto 28px; padding: 14px 16px 0; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  color: var(--muted); font-size: .85rem; text-align: center;
}
.sitefoot .sep { opacity: .5; }
@media (max-width: 560px) { .sitefoot .sep { display: none; } }
@media (max-width: 560px) { .brand-text { display: none; } .exam-bar { gap: 8px 12px; } .card { padding: 16px; } }
.badge { background: var(--brand-deep); color: #fff; font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: .9rem; }
.brand-text { font-size: .95rem; color: var(--muted); }
.topbar nav { display: flex; align-items: center; gap: 10px; }
.who { font-size: .95rem; color: var(--muted); }

.wrap { max-width: 980px; margin: 24px auto; padding: 0 16px; }
.wrap.narrow { max-width: 620px; }
.wrap.wide { max-width: 1240px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--brand-deep);
  padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--brand-dark); }
.btn.primary { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-ghost { color: var(--bad); }
.btn.ghost { background: transparent; }
.topbar .btn.ghost { color: var(--brand-dark); border-color: var(--line); }
.btn.small { padding: 4px 10px; font-size: .88rem; }
.btn.block { display: block; width: 100%; text-align: center; margin-top: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input, select { font: inherit; }
input[type=text], input:not([type]), input[type=password], input[type=number], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff;
}
input:focus, select:focus { outline: 2px solid #f3a68c; border-color: var(--brand-dark); }

.alert { padding: 11px 14px; border-radius: 9px; margin: 12px 0; }
.alert.error { background: var(--bad-bg); color: var(--bad); }
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: #8a4b00; }
.alert.info { background: var(--info-bg); color: var(--brand-deep); }
.hint { font-size: .9rem; color: var(--muted); margin-top: 14px; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.facts.four { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 560px) { .facts, .facts.four { grid-template-columns: repeat(2, 1fr); } }
.facts div { background: var(--bg); border-radius: 9px; padding: 8px 12px; }
.facts dt { font-size: .82rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; font-size: 1.15rem; color: var(--brand-deep); }
.rules li { margin: 6px 0; }
.score-big { text-align: center; font-size: 1.3rem; margin: 16px 0; color: var(--brand-deep); }
.score-big span { font-size: 3rem; font-weight: 700; }

/* ------------------------------------------------------------------ exam page -- */
.exam-layout { max-width: 1180px; margin: 0 auto; padding: 0 16px 40px; display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; }
.exam-bar {
  grid-column: 1 / -1; position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  background: #fff; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 var(--radius) var(--radius);
  padding: 10px 16px; box-shadow: 0 4px 10px rgba(16, 24, 40, .06); flex-wrap: wrap;
}
.timer { font-size: 1.6rem; font-weight: 700; color: var(--brand-deep); font-variant-numeric: tabular-nums; min-width: 96px; }
.timer.low { color: var(--bad); }
.progress { font-weight: 600; }
.save-state { color: var(--ok); font-size: .92rem; flex: 1; }
.save-state.pending { color: var(--muted); }
.save-state.error { color: var(--bad); font-weight: 600; }
.qnav { position: sticky; top: 76px; align-self: start; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-top: 18px; }
.qnav-title { margin: 0 0 8px; font-weight: 600; color: var(--brand-deep); }
.qnav-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.qnav-grid a { display: block; text-align: center; padding: 3px 0; border: 1px solid var(--line); border-radius: 6px; font-size: .85rem; text-decoration: none; color: var(--ink); }
.qnav-grid a.done { background: var(--brand-deep); border-color: var(--brand-deep); color: #fff; }
.legend { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
.dot { display: inline-block; width: 10px; height: 10px; border: 1px solid var(--line); border-radius: 3px; vertical-align: middle; }
.dot.done { background: var(--brand-deep); border-color: var(--brand-deep); }
.questions { min-width: 0; padding-top: 18px; }
.exam-title { margin-top: 0; }
.section-title { color: var(--brand); font-size: 1.05rem; margin: 26px 0 10px; }
fieldset.q { border: 1px solid var(--line); margin: 0 0 14px; min-width: 0; }  /* fieldsets default to min-content width and overflow phones */
fieldset.q legend { float: left; width: 100%; padding: 0; margin-bottom: 10px; font-weight: 600; }
fieldset.q legend + * { clear: both; }
.qn { color: var(--brand-deep); }
.opt { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 6px 0; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.opt:hover { background: #fdf7f4; }
.opt input { margin-top: 6px; accent-color: var(--brand-deep); }
.opt:has(input:checked) { border-color: var(--brand-dark); background: var(--info-bg); }
.opt .letter { font-weight: 700; color: var(--brand-deep); min-width: 1.4em; }
.opt .text { min-width: 0; overflow-wrap: anywhere; }
.clear { background: none; border: 0; color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer; padding: 4px 0; }
.clear:hover { color: var(--bad); }
.end-card { text-align: center; }
@media (max-width: 820px) {
  .exam-layout { grid-template-columns: minmax(0, 1fr); padding: 0 10px 40px; }
  .qnav { position: static; order: 2; }
  .questions { order: 1; }
  .timer { font-size: 1.3rem; min-width: 80px; }
}

/* ------------------------------------------------------------------ admin -- */
.switch-row { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; }
.switch-row input { width: 20px; height: 20px; margin-top: 4px; }
.inline { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.inline input { width: 90px; }
.status-pill { display: inline-block; margin-top: 12px; padding: 4px 12px; border-radius: 999px; font-weight: 700; }
.status-pill.open { background: var(--ok-bg); color: var(--ok); }
.status-pill.closed { background: var(--bad-bg); color: var(--bad); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.table-wrap { overflow-x: auto; }
table.roster { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.roster th, table.roster td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
table.roster th { background: var(--bg); color: var(--brand-deep); font-weight: 600; }
table.roster td.score { font-weight: 700; color: var(--brand-deep); }
table.roster select { width: auto; padding: 3px 6px; }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; gap: 4px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.run { background: var(--warn-bg); color: #8a4b00; }
.pill.idle { background: var(--bg); color: var(--muted); }
.tag { font-size: .75rem; background: var(--info-bg); color: var(--brand-deep); padding: 1px 7px; border-radius: 999px; }
.add-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.item-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; margin-bottom: 12px; }
.item { text-align: center; border: 1px solid var(--line); border-radius: 6px; padding: 2px 0; font-size: .8rem; line-height: 1.2; }
.item span { display: block; color: var(--muted); font-size: .7rem; }
.item.hard { background: var(--bad-bg); color: var(--bad); }
.item.easy { background: var(--ok-bg); color: var(--ok); }

.review { border-left: 4px solid var(--line); padding: 6px 12px; margin: 8px 0; background: var(--bg); border-radius: 0 8px 8px 0; }
.review.ok { border-color: var(--ok); }
.review.bad { border-color: var(--bad); }
.review.blank { border-color: #f0b429; }
.review p { margin: 2px 0; }
.review .src { display: block; color: var(--muted); font-size: .8rem; }

/* audit tables on the instructor page: long lists scroll inside their card */
.table-wrap.scroll-y { max-height: 320px; overflow-y: auto; }
.bad-pw { color: var(--bad); word-break: break-all; }
