/* ระบบสอบรับบุญ ชั้น 9 */
:root {
  --ink: #1D1F24; --ink2: #3A3D44; --muted: #5A5E66; --line: #E2DED3; --line2: #ECE8DE; --chip: #C9C4B6;
  --bg: #F6F4EE; --card: #FFFFFF;
  --p: #5B3FA0; --p-dark: #2E2152; --p-soft: #EFEBF8;
  --ok: #2F6B45; --ok-soft: #E4F2E8;
  --warn: #B7791F; --warn-ink: #4A2F05; --warn-soft: #FDF1D8;
  --bad: #B42318; --bad-ink: #4A0D08; --bad-soft: #FBE4E2;
  --info: #3B5B86; --info-soft: #E6EEF7;
  --wA: #8FCBF2; --wA-ink: #0B2A3F; --wB: #2F8F57; --wB-ink: #FFFFFF; --wC: #EF8A2E; --wC-ink: #2A1300; --wD: #1F3A6E; --wD-ink: #FFFFFF;
  --fs: 20px;
}
body.fs-s { --fs: 18px; } body.fs-l { --fs: 24px; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Sarabun', sans-serif; font-size: 18px; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--p); }
h1 { margin: 0; font-size: 30px; line-height: 1.25; }
h2 { margin: 0; font-size: 24px; line-height: 1.3; }
h3 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); }
.small { font-size: 16px; }
.hidden { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.pad { padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; }
.stripe { height: 6px; flex-shrink: 0; }
.card { background: var(--card); border-radius: 16px; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.grow { flex: 1 1 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.btn { min-height: 56px; padding: 0 20px; border-radius: 14px; border: 2px solid var(--p); background: var(--p); color: #fff; font-size: 20px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.sec { background: #fff; color: var(--p); font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--p); text-decoration: underline; font-weight: 600; }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.sm { min-height: 44px; font-size: 17px; padding: 0 14px; border-radius: 10px; }
.btn:disabled { background: #CFCAC0; border-color: #CFCAC0; color: var(--ink2); }
.btn.sec:disabled { background: #fff; color: #9A968C; border-color: #D5D0C4; }
.input { height: 58px; padding: 0 16px; border: 2px solid var(--chip); border-radius: 12px; background: #fff; font-size: 22px; width: 100%; }
.input:focus, textarea:focus { outline: 3px solid var(--p-soft); border-color: var(--p); }
textarea { width: 100%; font-size: var(--fs); line-height: 1.6; padding: 12px; border: 2px solid var(--chip); border-radius: 12px; resize: vertical; background: #fff; }
label.lbl { font-size: 20px; font-weight: 600; }

.wingbtn { height: 64px; border-radius: 14px; font-size: 28px; font-weight: 700; border: 4px solid transparent; }
.wingbtn.sel { border-color: var(--p); }
.roombtn { height: 58px; border-radius: 12px; font-size: 22px; font-weight: 600; background: #fff; border: 3px solid var(--chip); }
.w-A { background: var(--wA); color: var(--wA-ink); } .w-B { background: var(--wB); color: var(--wB-ink); }
.w-C { background: var(--wC); color: var(--wC-ink); } .w-D { background: var(--wD); color: var(--wD-ink); }
.bw-A { border-color: var(--wA) !important; } .bw-B { border-color: var(--wB) !important; } .bw-C { border-color: var(--wC) !important; } .bw-D { border-color: var(--wD) !important; }
.s-A { background: var(--wA); } .s-B { background: var(--wB); } .s-C { background: var(--wC); } .s-D { background: var(--wD); }
.wtag { display: inline-flex; min-width: 32px; height: 28px; padding: 0 6px; align-items: center; justify-content: center; border-radius: 6px; font-weight: 700; font-size: 16px; }

.alert { padding: 12px 16px; border-radius: 12px; font-size: 18px; line-height: 1.5; border: 2px solid; }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn-ink); }
.alert.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad-ink); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); color: #1E4D30; }
.alert.info { background: var(--info-soft); border-color: var(--info); color: #1B2C44; }
.pill { display: inline-flex; padding: 4px 10px; border-radius: 999px; font-size: 15px; background: var(--line2); }
.pill.ok { background: var(--ok-soft); } .pill.warn { background: var(--warn-soft); } .pill.info { background: var(--info-soft); } .pill.bad { background: var(--bad-soft); }

/* sheets & dialogs */
.overlay { position: fixed; inset: 0; background: rgba(29, 31, 36, .5); z-index: 90; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.overlay.center { justify-content: center; padding: 20px; }
.sheet { width: 100%; max-width: 560px; background: #fff; border-radius: 22px 22px 0 0; padding: 12px 22px 28px; display: flex; flex-direction: column; gap: 14px; max-height: 88vh; overflow-y: auto; }
.sheet .grab { align-self: center; width: 48px; height: 5px; border-radius: 3px; background: #D5D0C4; }
.dialog { width: 100%; max-width: 440px; background: #fff; border-radius: 20px; padding: 24px 22px 20px; display: flex; flex-direction: column; gap: 14px; }

/* exam */
.exam { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.ehead { flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.timer { display: flex; flex-direction: column; line-height: 1.1; min-width: 104px; }
.timer b { font-size: 28px; }
.timer.warn b { color: #8A5A12; } .timer.bad b { color: var(--bad); }
.prog { flex: 1; display: flex; flex-direction: column; gap: 5px; background: none; border: 0; text-align: left; padding: 6px 4px; }
.bar { height: 10px; background: var(--line2); border-radius: 5px; overflow: hidden; width: 100%; }
.bar > i { display: block; height: 100%; background: var(--p); border-radius: 5px; }
.iconbtn { width: 52px; height: 52px; flex-shrink: 0; border-radius: 12px; border: 2px solid var(--p); background: #fff; color: var(--p); font-size: 26px; }
.ebody { flex: 1; overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.efoot { flex-shrink: 0; display: flex; gap: 10px; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); }
.efoot .btn { flex: 1 1 0; min-height: 60px; }
.secbtn { align-self: stretch; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; min-height: 52px; border-radius: 14px; border: 2px solid var(--p); background: #fff; font-size: 19px; font-weight: 700; text-align: left; line-height: 1.3; }
.secbtn .pos { flex-shrink: 0; font-size: 16px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.qtext { font-size: var(--fs); line-height: 1.6; white-space: pre-line; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 14px; min-height: 58px; border-radius: 12px; text-align: left; font-size: calc(var(--fs) - 1px); line-height: 1.5; background: #fff; border: 2px solid var(--chip); width: 100%; }
.choice .dot { flex-shrink: 0; width: 32px; height: 32px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-weight: 700; background: var(--line2); }
.choice.sel { background: var(--p-soft); border-color: var(--p); }
.choice.sel .dot { background: var(--p); color: #fff; }
.choice:disabled { opacity: .75; }
.qgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.qgrid button { height: 46px; border-radius: 8px; border: 2px solid var(--p); background: #fff; font-size: 18px; }
.qgrid button.done { background: var(--p); color: #fff; }
.qgrid button.cur { outline: 3px solid var(--ink); outline-offset: 1px; }
.lockbox { padding: 10px 14px; background: var(--line2); border-radius: 10px; font-size: 17px; }
.objective { padding: 12px 14px; background: var(--p-soft); border-radius: 12px; font-size: 18px; line-height: 1.5; }
.savestate { font-size: 16px; }

/* lists */
.list { background: #fff; border-radius: 14px; overflow: hidden; }
.list > .it { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line2); font-size: 18px; min-height: 52px; background: #fff; width: 100%; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.list > .it:last-child { border-bottom: 0; }
.list > .it.bad { background: var(--bad-soft); }
.stat { background: #fff; border-radius: 12px; padding: 14px; }
.stat b { font-size: 30px; display: block; line-height: 1.1; }
.hbar { display: flex; flex-direction: column; gap: 4px; }
.hbar .top { display: flex; justify-content: space-between; font-size: 17px; }

/* score buttons */
.scores { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.scores button { height: 52px; border-radius: 12px; font-size: 22px; font-weight: 700; background: #fff; border: 2px solid var(--p); color: var(--ink); }
.scores button.sel { background: var(--p); color: #fff; }
.answerbox { padding: 14px 16px; border: 2px solid var(--p); border-radius: 14px; background: #fff; font-size: 19px; line-height: 1.65; white-space: pre-wrap; }
.guide { padding: 12px 16px; background: var(--line2); border-radius: 14px; font-size: 17px; line-height: 1.55; white-space: pre-wrap; }

.tabs { display: flex; gap: 6px; background: #fff; border-radius: 14px; padding: 6px; }
.tabs button { flex: 1; min-height: 48px; border: 0; border-radius: 10px; background: transparent; font-size: 18px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--p); color: #fff; }
.seg { display: inline-flex; border: 2px solid var(--p); border-radius: 12px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 14px; border: 0; background: #fff; color: var(--p); font-weight: 600; font-size: 17px; }
.seg button.on { background: var(--p); color: #fff; }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 17px; z-index: 100; max-width: 90vw; }
.offline { position: fixed; top: 0; left: 0; right: 0; z-index: 70; background: var(--warn-soft); color: var(--warn-ink); border-bottom: 2px solid var(--warn); padding: 8px 14px; text-align: center; font-size: 16px; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--p-soft); border-top-color: var(--p); animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* report */
.itemcard { background: #fff; border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; font-size: 18px; line-height: 1.55; }
.itemcard.wrong { background: var(--bad-soft); }
.itemcard .head { font-size: 16px; color: var(--muted); font-weight: 600; }
.passcard { padding: 20px; border-radius: 16px; border: 3px solid; display: flex; flex-direction: column; gap: 10px; }
.passcard.pass { background: var(--ok-soft); border-color: var(--ok); }
.passcard.fail { background: var(--info-soft); border-color: var(--info); }
@media print {
  .noprint { display: none !important; }
  body { background: #fff; }
  .itemcard, .card { break-inside: avoid; }
}
/* หน้าเบรกระหว่างส่วน */
.brk { display: flex; flex-direction: column; gap: 18px; padding: 12px 4px; max-width: 560px; width: 100%; margin: 0 auto; }
.brk-done { display: flex; gap: 14px; align-items: center; background: #fff; border-radius: 16px; padding: 16px; font-size: 19px; line-height: 1.5; }
.brk-ic { flex-shrink: 0; width: 48px; height: 48px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.brk-line { border: 0; border-top: 2px dashed var(--line); margin: 4px 0; width: 100%; }
.brk-next { text-align: center; display: flex; flex-direction: column; gap: 6px; padding: 18px 12px; background: var(--p-soft); border: 2px solid var(--p); border-radius: 18px; font-size: 19px; }
.brk-name { font-size: 28px; font-weight: 700; color: var(--p-dark); line-height: 1.35; }
.brk-ic.warn { background: var(--warn-soft); color: #8A5A12; }
.list .it .pill { white-space: nowrap; flex-shrink: 0; }
