/* ระบบแบบทดสอบออนไลน์ — สีและฟอนต์ชุดเดียวกับเว็บหลัก nitiphong.com */
:root {
  --ink: #10233F;        /* น้ำเงินเข้ม: แถบหัว หัวข้อ */
  --ink-2: #22385A;
  --blue: #2350A8;       /* น้ำเงินหลัก: ลิงก์ ปุ่ม */
  --blue-d: #1B3F86;
  --tint: #E7EDF7;       /* น้ำเงินอ่อน: พื้นตัวเลือกที่เลือก */
  --slate: #5B6B80;      /* เทาอมฟ้า: ข้อความรอง */
  --paper: #F3F5F8;      /* พื้นหลังหน้า */
  --card: #ffffff;
  --line: #DCE2EA;       /* เทาอ่อน: เส้นคั่น */
  --ok: #1e7f5c;
  --ok-bg: #e5f4ee;
  --warn: #b4541a;
  --warn-bg: #fbefe6;
  --err: #b42318;
  --err-bg: #fdecea;
  --r-s: 6px;
  --r-m: 10px;
  --font: "IBM Plex Sans Thai Looped", "Sarabun", "TH SarabunPSK", "Thonburi", "Tahoma",
    system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif Thai", "Taviraj", Georgia, serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1, h2 { font-family: var(--serif); font-weight: 600; color: var(--ink); }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
a { color: var(--blue); }
.muted { color: var(--slate); }
.small { font-size: .88rem; }
[hidden] { display: none !important; }

/* ---------- แถบบน ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  padding-top: env(safe-area-inset-top);
}
.topbar-in {
  max-width: 1180px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}
.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 9px #8DB0EC;
}
/* ปุ่มสลับภาษา แบบเดียวกับเว็บหลัก */
.lang {
  display: inline-flex;
  flex: none;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 999px;
  font-size: .88rem;
}
.lang a {
  padding: .15rem .65rem;
  border-radius: 999px;
  color: #fff;
  line-height: 1.5;
  text-decoration: none;
}
.lang a:hover { background: rgba(255, 255, 255, .12); }
.lang a.on { background: #fff; color: var(--ink); font-weight: 600; }

.adminnav {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1rem .4rem;
  display: flex;
  flex-wrap: wrap;
  gap: .25rem 1.1rem;
  align-items: center;
}
.adminnav a {
  color: #c9d6e4;
  text-decoration: none;
  padding: .3rem 0;
  border-bottom: 2px solid transparent;
}
.adminnav a.on { color: #fff; border-bottom-color: #8DB0EC; }
.nav-logout { margin-left: auto; }
.nav-logout .linkbtn { color: #c9d6e4; }

.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 1.25rem 1rem 2rem; }
.wrap.wide { max-width: 1180px; }
.foot a { color: var(--slate); }
.foot {
  text-align: center;
  color: var(--slate);
  font-size: .8rem;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}

/* ---------- ส่วนประกอบทั่วไป ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 1.25rem;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: .5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: var(--r-s);
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: var(--blue-d); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.ghost:hover { background: var(--tint); }
.btn.light { background: #fff; color: var(--ink); border-color: #fff; }
.btn.danger { background: var(--err); border-color: var(--err); }
.btn.small { min-height: 34px; padding: .2rem .7rem; font-size: .9rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; width: 100%; }
.linkbtn {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--blue);
  cursor: pointer;
  text-decoration: underline;
}
:focus-visible { outline: 3px solid #8DB0EC; outline-offset: 2px; }

.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .3rem; }
.field > span { font-weight: 600; font-size: .95rem; }
.field small { color: var(--slate); font-size: .85rem; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local],
input[type=email], input:not([type]), select, textarea {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  padding: .6rem .7rem;
  border: 1px solid #b9c6d4;
  border-radius: var(--r-s);
  background: #fff;
}
textarea { min-height: 6rem; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none;
  box-shadow: 0 0 0 3px rgba(31, 95, 174, .18); }
.code-input { letter-spacing: .25em; text-transform: uppercase; font-weight: 600; }
.check { display: flex; gap: .55rem; align-items: flex-start; }
.check input { width: 20px; height: 20px; margin-top: .2rem; flex: none; }

.flash {
  padding: .7rem .9rem;
  border-radius: var(--r-s);
  margin-bottom: 1rem;
  border-left: 4px solid var(--ok);
  background: var(--ok-bg);
}
.flash.err { border-left-color: var(--err); background: var(--err-bg); }
.flash.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.notice {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem 1rem;
  align-items: center;
  justify-content: space-between;
  background: var(--tint);
  border-radius: var(--r-m);
  padding: .8rem 1rem;
  margin-bottom: 1rem;
}
.notice p { margin: 0; }

/* ---------- หน้าเข้าสอบ ---------- */
.enter-head { margin: .5rem 0 1.25rem; }
.rules { margin-top: 1.5rem; color: var(--ink-2); }
.rules h2 { font-size: 1rem; }
.rules ul { margin: 0; padding-left: 1.2rem; }
.rules li { margin: .25rem 0; }

/* ---------- หน้าทำข้อสอบ ---------- */
.page-exam .wrap { max-width: 1180px; padding-top: 0; }
.protect, .protect * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}
.exam-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 -1rem 1rem;
  padding: .55rem 1rem;
  background: rgba(238, 242, 246, .96);
  border-bottom: 1px solid var(--line);
}
.exam-who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.exam-who .muted {
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.exam-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.35rem;
  padding: .1rem .7rem;
  border-radius: var(--r-s);
  background: var(--card);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.exam-timer.warn { color: var(--warn); border-color: #e8b893; background: var(--warn-bg); }
.exam-timer.crit { color: #fff; background: var(--err); border-color: var(--err); }

.exam-grid { display: grid; gap: 1rem; }
@media (min-width: 900px) {
  .exam-grid { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .sheet { position: sticky; top: 4.5rem; }
}
.qpane {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 1.1rem 1.1rem 1rem;
}
.qhead { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.qnum { font-weight: 700; color: var(--slate); font-size: .95rem; }
.flagbtn {
  font: inherit;
  font-size: .85rem;
  color: var(--slate);
  background: transparent;
  border: 1px dashed #aab8c7;
  border-radius: 999px;
  padding: .2rem .75rem;
  cursor: pointer;
}
.flagbtn.on { color: var(--warn); border: 1px solid var(--warn); background: var(--warn-bg); }
.qtext {
  font-size: 1.15rem;
  line-height: 1.7;
  margin: .8rem 0 1.1rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.choices { display: grid; gap: .55rem; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: .85rem;
  width: 100%;
  min-height: 56px;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: .7rem .85rem;
  cursor: pointer;
  touch-action: manipulation;
}
.choice:hover { border-color: #9fb3c8; }
.choice.on { background: var(--tint); border-color: var(--blue); }
/* วงกลมแบบกระดาษคำตอบ */
.bubble {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .95rem;
  color: var(--ink-2);
  background: #fff;
  transition: background .12s, color .12s, box-shadow .12s;
}
.choice.on .bubble {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  box-shadow: 0 0 0 3px rgba(22, 50, 79, .15);
}
.ctext { padding-top: .2rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.qtools {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 2.2rem;
  margin-top: .6rem;
  font-size: .88rem;
}
.savestate { color: var(--slate); margin-left: auto; }
.savestate.saved { color: var(--ok); }
.savestate.offline { color: var(--err); font-weight: 600; }
.qnav { display: flex; gap: .7rem; margin-top: .6rem; }
.qnav .btn { flex: 1; min-height: 50px; }

.sheet {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  padding: 1rem;
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: .7rem;
  font-size: .95rem;
}
.bubbles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: .45rem;
  margin-bottom: 1rem;
}
.bub {
  position: relative;
  aspect-ratio: 1;
  min-height: 42px;
  border-radius: 50%;
  border: 2px solid #9fb0c2;
  background: #fff;
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}
.bub.done { background: var(--ink); border-color: var(--ink); color: #fff; }
.bub.cur { box-shadow: 0 0 0 3px #7fb0e8; }
.bub.flag::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid #fff;
}
.btn-submit { width: 100%; min-height: 50px; }

.loading { text-align: center; padding: 3rem 1rem; color: var(--slate); }

/* ลายน้ำทับทั้งหน้าจอ */
.watermark {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  background-repeat: repeat;
}

/* หน้าต่างและหน้าจอปิดบัง */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(22, 50, 79, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.dialog {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border-radius: var(--r-m);
  padding: 1.4rem;
}
.dialog-rules { padding-left: 1.2rem; color: var(--ink-2); font-size: .95rem; }
.dialog-actions { display: flex; gap: .7rem; margin-top: 1rem; }
.dialog-actions .btn { flex: 1; }
.facts { margin: .8rem 0 1rem; display: grid; gap: .35rem; }
.facts div { display: flex; gap: .8rem; }
.facts dt { color: var(--slate); min-width: 7.5rem; }
.facts dd { margin: 0; font-weight: 600; }

.cover {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}
.cover-in { max-width: 420px; }
.cover p { color: #d3deea; }
body.is-away .exam-grid, body.is-away .exam-bar { filter: blur(14px); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 85;
  max-width: calc(100% - 2rem);
  background: var(--ink);
  color: #fff;
  padding: .65rem 1rem;
  border-radius: var(--r-s);
  font-size: .95rem;
}

/* ---------- หน้าผลการสอบ ---------- */
.result { text-align: center; margin-top: 1rem; }
.result .facts { text-align: left; max-width: 360px; margin-left: auto; margin-right: auto; }
.result-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto .8rem;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 6px var(--tint);
}
.score { margin: 1rem 0; display: flex; justify-content: center; align-items: baseline;
  gap: .4rem; flex-wrap: wrap; }
.score-n { font-size: 3.2rem; font-weight: 700; line-height: 1; }
/* ทำได้หลายครั้ง */
.attempt-no { margin: -.2rem 0 .4rem; color: var(--blue); font-weight: 600; }
.best-line { margin: .2rem 0 .8rem; font-weight: 600; color: var(--ink); }
.again-box { text-align: left; margin: 1rem auto; max-width: 420px; }
.again-box p { margin: 0 0 .6rem; }
.card.again h2 { margin-top: 0; }
.roundbox { border-left: 4px solid var(--blue); margin-bottom: 1rem; }
.roundbox h2 { margin: 0 0 .3rem; font-size: 1.1rem; }
.roundbox h2 + p { margin-top: 0; }
.roundbox > form.inline + h2, .roundbox .roundform { margin-top: .6rem; }
.roundform .check { margin-bottom: .6rem; }
.show-round { font-weight: 700; color: var(--blue); }
.wait-box { text-align: left; margin: 1rem auto; max-width: 420px; }
.wait-box .dots::after { content: ''; animation: dots 1.6s steps(4, end) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; }
  75% { content: '...'; } }
@media (prefers-reduced-motion: reduce) { .wait-box .dots::after { animation: none; } }
.again-rules { margin: .4rem 0 1rem; padding-left: 1.2rem; color: var(--slate); }
.again-rules li { margin: .2rem 0; }
.score-of { font-size: 1.4rem; color: var(--slate); }
.score-pct { margin-left: .6rem; font-size: 1.1rem; color: var(--blue); font-weight: 600; }

/* ---------- หน้าผู้ดูแล ---------- */
.pagehead {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .7rem;
  margin-bottom: 1rem;
}
.pagehead h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.tablewrap { overflow-x: auto; background: #fff; border: 1px solid var(--line);
  border-radius: var(--r-m); }
table.list { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.list th, table.list td {
  text-align: left;
  padding: .55rem .7rem;
  border-bottom: 1px solid #e6ebf1;
  vertical-align: top;
}
table.list th { background: #f4f7fa; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; }
table.list tr:last-child td { border-bottom: 0; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list .clip { max-width: 34rem; min-width: 16rem; }
table.list td.rowact { white-space: nowrap; }
table.list td.rowact > a, table.list td.rowact > form { margin: 0 .25rem .25rem 0; }
table.list td.nw { white-space: nowrap; }
table.list td.name { min-width: 9rem; }
.pill {
  display: inline-block;
  padding: .05rem .55rem;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
  background: #e9eef4;
  color: var(--slate);
  white-space: nowrap;
}
.pill.open { background: var(--ok-bg); color: var(--ok); }
.pill.scheduled { background: var(--tint); color: var(--blue); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.err { background: var(--err-bg); color: var(--err); }
.pill.best { background: var(--ink); color: #fff; }
.grid2 { display: grid; gap: 1rem; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.stats { display: flex; flex-wrap: wrap; gap: .5rem 1.6rem; margin: 0 0 1rem; }
.stats div { display: flex; flex-direction: column; }
.stats dt { font-size: .82rem; color: var(--slate); }
.stats dd { margin: 0; font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.optlist { margin: .3rem 0 0; padding-left: 0; list-style: none; }
.optlist li { padding: .1rem 0; }
.optlist .correct { color: var(--ok); font-weight: 600; }
.optlist .picked-wrong { color: var(--err); font-weight: 600; }
.show-code {
  font-size: clamp(3rem, 12vw, 7rem);
  font-weight: 700;
  letter-spacing: .12em;
  line-height: 1.1;
  margin: .3rem 0;
}
.qr { display: inline-block; background: #fff; padding: 12px; border-radius: var(--r-m); }
.qr img, .qr svg { display: block; width: 260px; height: 260px; }
.section { margin-top: 1.6rem; }
details.box { background: #fff; border: 1px solid var(--line); border-radius: var(--r-m);
  padding: .8rem 1rem; }

/* ---------- ส่งผลทางอีเมล ---------- */
.h-step { margin: 0; font-size: 1.1rem; }
h2.section.h-step { margin-bottom: .7rem; }
fieldset.radios { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap;
  gap: .4rem 1.4rem; align-items: center; }
fieldset.radios > span { flex-basis: 100%; }
.mailpreview { background: var(--tint); border: 1px solid var(--line);
  border-radius: var(--r-m); padding: 1rem; }
.mailmeta { margin: 0 0 .8rem; display: grid; gap: .25rem; font-size: .95rem; }
.mailmeta div { display: flex; gap: .6rem; }
.mailmeta dt { color: var(--slate); min-width: 5.5rem; }
.mailmeta dd { margin: 0; overflow-wrap: anywhere; }
.mailcard { overflow-x: auto; }
.confirmbox { border-color: var(--blue); }
.mailcount { margin: 0; }
.mailcount strong { font-size: 1.3rem; margin-left: .3rem; }
.mailjob progress { width: 100%; height: 14px; accent-color: var(--blue); }
.mailtext { font-weight: 600; margin: .6rem 0 .2rem; font-variant-numeric: tabular-nums; }
.mailfails { margin: .8rem 0 0; padding-left: 1.2rem; color: var(--err); font-size: .9rem; }
.mailfails:empty { display: none; }
table.list td.mstat { min-width: 13rem; }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .qtext { font-size: 1.08rem; }
  .facts dt { min-width: 6rem; }
  table.list { font-size: .88rem; }
}

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

/* ---------- sec (กลุ่มเรียน) ---------- */
.sec-tabs { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 .9rem; }
.sec-tabs a { display: inline-flex; gap: .45rem; align-items: baseline; padding: .35rem .8rem;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink);
  text-decoration: none; font-weight: 600; }
.sec-tabs a span { color: var(--slate); font-weight: 400; font-size: .85rem; }
.sec-tabs a.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.sec-tabs a.on span { color: #c9d4e5; }
.sec-tabs a:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
input.sec-input { max-width: 10rem; }
.secbar { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; align-items: center;
  justify-content: space-between; padding: .8rem 1rem; margin-bottom: 1rem; }
.secbar p { margin: 0; }
.secbar .actions { margin: 0; }
table.list.sec-overview th { white-space: normal; }
table.list.sec-overview td.rowact { white-space: normal; }
table.list.sec-overview td.rowact .btn { white-space: nowrap; }
.show-secs { list-style: none; padding: 0; margin: .4rem 0 1rem; display: flex; flex-wrap: wrap;
  gap: .5rem; justify-content: center; }
.show-secs li { display: flex; flex-direction: column; align-items: center; gap: .1rem;
  padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 10px; min-width: 7rem;
  color: var(--slate); }
.show-secs li strong { color: var(--ink); font-size: 1.1rem; }
.show-secs li.on { border-color: var(--ink); background: var(--tint); }
.show-secs li.on span { color: var(--ink); font-weight: 600; }
.show-secs small { font-size: .8rem; }
input.sec-input.prefilled { border-color: var(--blue); background: var(--tint); }
