/* โทนกระดาษคำตอบ: หมึกน้ำเงินเข้ม เส้นพิมพ์สีแดงอมชมพูแบบกระดาษ OMR */
:root {
  --paper: #f2f5f8;
  --sheet: #ffffff;
  --ink: #16233f;
  --ink-soft: #4a5672;
  --rule: #d7dee8;
  --omr: #d9435a;
  --omr-tint: #fbe9ec;
  --ok: #1f8a5b;
  --ok-tint: #e3f3eb;
  --mid: #b7791f;
  --mid-tint: #fbf1de;
  --weak: #c2394f;
  --weak-tint: #fbe6ea;
  --mark: #ffe066;
  --radius-lg: 14px;
  --radius-sm: 8px;
  --font-body: "Sarabun", "Leelawadee UI", "Tahoma", sans-serif;
  --font-head: "IBM Plex Sans Thai", "Sarabun", sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 17px; line-height: 1.6; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #4d7cfe; outline-offset: 2px; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
.wrap.wide { max-width: 1180px; }

/* หัวกระดาษ */
.masthead { background: var(--sheet); border-bottom: 3px solid var(--omr); }
.masthead .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; padding-bottom: 12px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--omr); display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; color: var(--omr); }
.brand-mark span { width: 18px; height: 18px; border-radius: 50%; background: var(--ink); }
.brand h1 { font-family: var(--font-head); font-size: 18px; margin: 0; line-height: 1.25; }
.brand small { display: block; color: var(--ink-soft); font-size: 13px; font-family: var(--font-body); font-weight: 400; }
.linkbtn { white-space: nowrap; background: none; border: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 6px 4px; font-size: 15px; }

h2 { font-family: var(--font-head); font-size: 26px; line-height: 1.3; margin: 0 0 6px; }
h3 { font-family: var(--font-head); font-size: 19px; margin: 0 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }

/* แผ่นกระดาษ */
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 22px; margin: 18px 0; }
.sheet.flat { border-radius: var(--radius-sm); padding: 16px; }

/* ฟอร์ม */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field input, .field select { width: 100%; padding: 11px 12px; border: 1.5px solid var(--rule); border-radius: var(--radius-sm); background: #fff; }
.field input:focus, .field select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(22,35,63,.12); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .row3 { grid-template-columns: 1fr 1fr; } .row3 > :first-child { grid-column: 1 / -1; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 20px; border-radius: 999px; border: 2px solid var(--ink); background: var(--ink); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:hover { background: #22345c; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: rgba(22,35,63,.06); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* ตัวเลือกชุดและวิชา */
.pickset { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.pickset button { border: 1.5px solid var(--rule); background: #fff; border-radius: var(--radius-sm); padding: 12px 8px; cursor: pointer; font-family: var(--font-head); font-weight: 600; }
.pickset button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.subjects { display: grid; gap: 10px; }
.subject { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; border: 1.5px solid var(--rule); border-radius: var(--radius-sm); padding: 12px 14px; background: #fff; cursor: pointer; text-align: left; width: 100%; }
.subject:hover { border-color: var(--ink); }
.subject b { font-family: var(--font-head); font-size: 18px; }
.subject .meta { font-size: 14px; color: var(--ink-soft); }
.donechip { font-size: 13px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--ok-tint); color: var(--ok); white-space: nowrap; }

/* วงกลมคำตอบแบบ OMR — จุดเด่นของหน้า */
.qmap { position: sticky; top: 0; z-index: 5; background: rgba(242,245,248,.96); backdrop-filter: blur(4px); border-bottom: 1px solid var(--rule); }
.qmap .wrap { display: flex; align-items: center; gap: 12px; padding-top: 8px; padding-bottom: 8px; }
.dots { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; flex: 1; }
.dots a { aspect-ratio: 1; border-radius: 50%; border: 1.5px solid var(--omr); display: block; }
.dots a.on { background: var(--ink); border-color: var(--ink); }
.timer { font-family: var(--font-head); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 60px; text-align: right; }
.timer.low { color: var(--weak); }

.q { scroll-margin-top: 64px; padding: 18px 0; border-bottom: 1px dashed var(--rule); }
.q:last-of-type { border-bottom: 0; }
.qhead { display: flex; gap: 10px; align-items: baseline; margin-bottom: 10px; }
.qno { font-family: var(--font-head); font-weight: 700; color: var(--omr); min-width: 28px; }
.qtext { font-weight: 600; }
.passage { display: block; font-weight: 400; background: #f7f9fb; border-left: 3px solid var(--omr); padding: 8px 12px; margin: 0 0 8px; white-space: pre-line; border-radius: 0 6px 6px 0; }
.opts { display: grid; gap: 6px; margin-left: 38px; }
@media (max-width: 560px) { .opts { margin-left: 0; } }
.opt { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; border: 1.5px solid transparent; }
.opt:hover { background: #f5f7fa; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.bubble { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--omr); display: grid; place-items: center; color: var(--omr); font-family: var(--font-head); font-weight: 700; font-size: 15px; transition: background .12s, color .12s, border-color .12s; }
.opt input:checked + .bubble { background: var(--ink); border-color: var(--ink); color: #fff; }
.opt input:focus-visible + .bubble { outline: 3px solid #4d7cfe; outline-offset: 2px; }
.opt:has(input:checked) { border-color: var(--rule); background: #f9fbfd; }

/* ผลลัพธ์ */
.score { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.score .big { font-family: var(--font-head); font-size: 64px; font-weight: 700; line-height: 1; }
.score .of { font-size: 22px; color: var(--ink-soft); }
.strip { display: grid; grid-template-columns: repeat(20, 1fr); gap: 4px; margin: 16px 0 4px; }
.strip span { aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; }
.strip .y { background: var(--ok); }
.strip .n { background: var(--weak); }
.strip .b { background: #fff; border: 1.5px dashed var(--weak); color: var(--weak); }

.topic { display: grid; grid-template-columns: minmax(130px, 1.2fr) 2fr 150px; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid #edf1f5; }
.topic:last-child { border-bottom: 0; }
.topic .nm { font-weight: 600; line-height: 1.35; }
.topic .nm small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 13px; }
.bar { height: 12px; border-radius: 999px; background: #edf1f5; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; }
.lv-strong .bar i { background: var(--ok); }
.lv-mid .bar i { background: var(--mid); }
.lv-weak .bar i { background: var(--weak); }
.tag { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; text-align: center; justify-self: start; }
.topic .tag { justify-self: stretch; }
.tag.strong { background: var(--ok-tint); color: var(--ok); }
.tag.mid { background: var(--mid-tint); color: var(--mid); }
.tag.weak { background: var(--weak-tint); color: var(--weak); }
@media (max-width: 560px) { .topic { grid-template-columns: 1fr auto; } .topic .bar { grid-column: 1 / -1; grid-row: 2; } }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .cols { grid-template-columns: 1fr; } }
.panel { border-radius: var(--radius-sm); padding: 14px 16px; }
.panel.good { background: var(--ok-tint); }
.panel.bad { background: var(--weak-tint); }
.panel h3 { font-size: 17px; }
.panel ul { margin: 0; padding-left: 20px; }
.panel li { margin-bottom: 6px; }
.advice { margin: 0; padding: 0; list-style: none; }
.advice li { padding: 12px 0; border-bottom: 1px solid #edf1f5; }
.advice li:last-child { border-bottom: 0; }
.advice b { display: block; }
.hl { background: linear-gradient(transparent 55%, var(--mark) 55%); }

.review .item { padding: 12px 0; border-bottom: 1px solid #edf1f5; }
.review .res { display: inline-block; font-weight: 700; margin-right: 6px; }
.review .res.y { color: var(--ok); }
.review .res.n { color: var(--weak); }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

.notice { background: var(--omr-tint); border: 1px solid #f2c2ca; color: #7d1f2f; border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 20; }

/* ตารางหน้าครู */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius-sm); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 9px 10px; border-bottom: 1px solid #edf1f5; text-align: left; white-space: nowrap; }
th { background: #f6f8fb; font-family: var(--font-head); font-weight: 600; position: sticky; top: 0; }
td.num, th.num { text-align: center; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
.cell { display: inline-block; min-width: 46px; padding: 2px 8px; border-radius: 6px; font-weight: 700; }
.cell.strong { background: var(--ok-tint); color: var(--ok); }
.cell.mid { background: var(--mid-tint); color: var(--mid); }
.cell.weak { background: var(--weak-tint); color: var(--weak); }
.cell.none { color: #9aa4b5; font-weight: 400; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters .field { margin: 0; min-width: 150px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--rule); border-radius: var(--radius-sm); padding: 12px 14px; }
.kpi b { display: block; font-family: var(--font-head); font-size: 26px; }
.drawer-back { position: fixed; inset: 0; background: rgba(22,35,63,.35); z-index: 30; display: flex; justify-content: flex-end; }
.drawer { width: min(640px, 100%); height: 100%; overflow-y: auto; background: var(--paper); padding: 18px 18px 40px; }

@media print {
  body { background: #fff; font-size: 14px; }
  .noprint, .qmap, .masthead button { display: none !important; }
  .sheet { border: 0; padding: 0; margin: 10px 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
