/* HEADFACE STUDY - หน้าเรียน: รายละเอียดวิชา (course) / บทเรียน (lesson) / Mock Exam (mock-exam)
   ใช้ร่วมกับ css/style.css (โทนสี .hue-*, .tile, .chip, .bar, .btn, .fchip, .sheet) — ไม่ใช้ Tailwind ในหน้ากลุ่มนี้ */

/* ───────── พื้นฐานของหน้ากลุ่มนี้ (แทน reset ที่เคยได้จาก Tailwind; ใช้ :where เพื่อไม่ทับคลาสคอมโพเนนต์) ───────── */
:where(body.flow) { margin: 0; background: #EEF4F8; color: #0F172A; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; min-height: 100vh; }
:where(body.flow) :is(h1, h2, h3, h4, p, figure, ul, ol, dl, dd) { margin: 0; }
:where(body.flow) :is(ul, ol) { padding: 0; list-style: none; }
:where(body.flow) a { color: inherit; text-decoration: none; }
:where(body.flow) button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:where(body.flow) :is(img, svg) { display: block; }
:where(body.flow) summary { list-style: none; cursor: pointer; }
:where(body.flow) summary::-webkit-details-marker { display: none; }
body.flow .bar > i { background: var(--bar); }

/* ห้ามหน้าล้นแนวนอนแม้ชั่วคราว: หน้า/ข้อใหม่เลื่อนเข้ามาจากด้านข้าง (translateX 40px) ทำให้เนื้อหากว้างกว่าจอ
   เบราว์เซอร์มือถือจึงขยาย viewport ออก (zoom out) แล้วแถบปุ่มล่าง (position: fixed) ถูกดันลงไปครึ่งหนึ่งนอกจอ = กดปุ่มท้ายกิจกรรมไม่ได้
   body { overflow-x: hidden } อย่างเดียวไม่พอสำหรับมือถือ ต้องกันที่ html และตัดที่ตัวหน้า (clip = ตัดโดยไม่สร้างกล่องเลื่อน และไม่ตัดแถบ fixed) */
html { overflow-x: hidden; }
/* html กันล้นแนวนอนแล้ว: body ต้องไม่มี overflow ของตัวเอง (style.css ตั้ง overflow-x: hidden) ไม่งั้น body กลายเป็นกล่องเลื่อนและ position: sticky ของแถบหัวไม่เกาะจอ */
body.flow { overflow-x: visible; }
.fmain { overflow-x: clip; }
.fwrap { width: 100%; max-width: 42rem; margin: 0 auto; padding: 0 20px; }
.fmain { position: relative; z-index: 10; padding-bottom: 120px; }
.fmain.has-nav { padding-bottom: 112px; }
.fmain.has-abar { padding-bottom: 132px; }
.stack { display: grid; gap: 14px; }

/* ข้อความแจ้งว่าเป็นข้อมูลตัวอย่าง */
.demo-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #FFFBEB;
  border: 1.5px dashed #F59E0B;
  color: #78350F;
  font-size: 12px;
  line-height: 18px;
  font-weight: 600;
}
.demo-note span { flex: 1; min-width: 0; }
.demo-note button { flex: none; display: inline-flex; align-items: center; min-height: 44px; margin: -10px -4px -10px 0; padding: 0 8px; font-size: 12px; font-weight: 700; color: #78350F; text-decoration: underline; }
.demo-note { align-items: center; }

.loading, .notfound { margin-top: 24px; padding: 28px 20px; text-align: center; background: #fff; border: 2px dashed #CBD5E1; border-radius: 20px; }
.notfound h2 { font-size: 18px; line-height: 26px; font-weight: 700; }
.notfound p { margin: 4px 0 14px; color: #475569; }

/* ───────── ส่วนหัวสีเขียวของหน้ารายละเอียดวิชา ───────── */
.ctop { position: relative; }
.flow-shell {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: -64px; /* ยืดเลยลงมาจากหัว 64px (ปรับตามความสูงหัวเอง แม้ชื่อวิชายาวหลายบรรทัด) */
  z-index: 0;
  background: linear-gradient(180deg, #047857 0, #047857 calc(100% - 66px), #059669 100%);
  border-radius: 0 0 50% 50% / 0 0 24px 24px;
  pointer-events: none;
}
.chd { position: relative; z-index: 30; width: 100%; max-width: 42rem; margin: 0 auto; padding: 8px 20px 0 12px; color: #fff; }
.back {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(2, 44, 34, .35);
  color: #fff;
}
.chd :focus-visible { outline-color: #fff; }
.chd-t { padding: 6px 0 0 8px; }
.eyebrow { font-size: 12px; line-height: 18px; font-weight: 700; letter-spacing: .02em; color: #ECFDF5; }
.chd-title { font-size: 26px; line-height: 34px; font-weight: 700; color: #fff; }
.chd-meta { font-size: 14px; line-height: 22px; font-weight: 500; color: #fff; }

/* ───────── สรุปความคืบหน้าวิชา + ปุ่มเรียนต่อ ───────── */
.sum { background: #fff; border: 2px solid var(--bd); border-radius: 22px; box-shadow: 0 4px 0 var(--edge); padding: 16px; }
.sum-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.sum-pct { display: flex; align-items: baseline; gap: 6px; }
.sum-pct .num { font-size: 34px; line-height: 40px; color: var(--strong); }
.sum .bar { height: 10px; }
.btn-lg { min-height: 52px; margin-top: 14px; border-radius: 16px; font-size: 15px; }
.sum-cap { margin-top: 8px; text-align: center; }

/* เกี่ยวกับวิชา (ยุบ/ขยาย) */
.about { background: #fff; border: 2px solid #E2E8F0; border-radius: 18px; box-shadow: 0 3px 0 #CBD5E1; }
.about summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; font-size: 14px; font-weight: 700; }
.about summary .chev { margin-left: auto; }
.about[open] summary .chev { transform: rotate(180deg); }
.about-body { display: grid; gap: 10px; padding: 0 14px 14px; }
.about-row dt { font-size: 12px; line-height: 18px; font-weight: 700; color: #475569; }
.about-row dd { font-size: 14px; line-height: 22px; color: #475569; font-weight: 500; }

.fsec { margin-top: 24px; }
.fsec-h { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.fsec-h h2 { font-size: 18px; line-height: 26px; font-weight: 700; }

/* ───────── หน่วยและบทเรียน (Course Outline) ───────── */
.units { display: grid; gap: 12px; margin-top: 6px; }
.unit-card { background: #fff; border: 2px solid var(--bd); border-radius: 18px; box-shadow: 0 3px 0 var(--edge); overflow: hidden; }
.unit-h { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px; background: var(--bg); text-align: left; color: #0F172A; }
.unit-badge { width: 36px; height: 36px; flex: none; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; background: #fff; border: 1.5px solid var(--bd); font-size: 14px; font-weight: 800; color: var(--strong); }
.unit-badge.done { background: #059669; border-color: #059669; color: #fff; }
.unit-t { min-width: 0; flex: 1; }
.unit-n { display: block; font-size: 14px; line-height: 22px; font-weight: 700; }
.unit-s { display: block; font-size: 12px; line-height: 18px; font-weight: 500; color: #475569; }
.unit-c { font-size: 12px; line-height: 18px; font-weight: 700; color: var(--strong); font-variant-numeric: tabular-nums; }
.chev { flex: none; color: #475569; transition: transform .15s; }
.chev.up { transform: rotate(180deg); }
.lessons { background: #fff; border-top: 2px solid var(--bd); }
.ls { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border-top: 1px solid #EEF2F6; min-height: 64px; }
.ls:first-child { border-top: 0; }
a.ls:hover { background: #F8FAFC; }
.ls-i { width: 24px; height: 24px; flex: none; margin-top: 1px; display: inline-flex; }
.ls-b { min-width: 0; flex: 1; }
.ls-n { font-size: 14px; line-height: 22px; font-weight: 700; color: #0F172A; }
.ph { font-weight: 500; color: #475569; }
.ls-st { font-size: 12px; line-height: 18px; font-weight: 700; }
.st-done, .st-now { color: #047857; }
.st-todo { color: #475569; }
.minis { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mini { display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 8px; border-radius: 8px; font-size: 12px; line-height: 18px; font-weight: 600; border: 1.5px solid #CBD5E1; background: #fff; color: #475569; }
.mini.ok { background: #ECFDF5; border-color: #A7F3D0; color: #065F46; }

/* Mock Exam ประจำวิชา */
.mock { display: flex; flex-direction: column; gap: 12px; margin-top: 26px; padding: 16px; background: #FFF7ED; border: 2px solid #FDBA74; border-radius: 22px; box-shadow: 0 4px 0 #FED7AA; }
.mock-top { display: flex; align-items: center; gap: 12px; }
.mock-tile { width: 44px; height: 44px; flex: none; border-radius: 14px; background: #fff; border: 1.5px solid #FDBA74; display: flex; align-items: center; justify-content: center; color: #9A3412; }
.mock h3 { font-size: 16px; line-height: 24px; font-weight: 700; }
.mock-btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border-radius: 16px; background: #C2410C; color: #fff; font-size: 15px; font-weight: 700; box-shadow: 0 4px 0 #7C2D12; transition: transform .1s; }
.mock-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #7C2D12; }

/* ───────── แถบหัวลอย (บทเรียน / Quiz / ข้อสอบ / AI Tutor) ─────────
   เป็น "เม็ดยา" ลอยเหนือเนื้อหา ไม่ติดขอบจอ: เนื้อหาเลื่อนลอดใต้แถบ (เบลอแบบกระจกฝ้า) ขอบล่างหนาแบบปุ่มเกม
   ปุ่มย้อนกลับเป็นปุ่มสีไล่เฉดกดแล้วยุบ; ฉากจางด้านหลังกันตัวอักษรของเนื้อหาชนกับแถบ */
.fbar { position: sticky; top: 0; z-index: 40; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 0; pointer-events: none; }
.fbar::before { content: ""; position: absolute; left: 0; right: 0; top: 0; bottom: -16px; z-index: -1; background: linear-gradient(180deg, #EEF4F8 55%, rgba(238, 244, 248, 0)); pointer-events: none; }
.fbar-in { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 40rem; min-height: 60px; margin: 0 auto; padding: 6px 10px 6px 6px; border-radius: 26px; background: rgba(255, 255, 255, .84); -webkit-backdrop-filter: blur(18px) saturate(1.5); backdrop-filter: blur(18px) saturate(1.5); border: 2px solid rgba(255, 255, 255, .95); box-shadow: 0 4px 0 var(--edge, #CBD5E1), 0 12px 28px rgba(15, 23, 42, .10); }
.fback { width: 46px; height: 46px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 18px; background: linear-gradient(180deg, var(--bar, #10B981), var(--strong, #047857)); color: #fff; box-shadow: 0 3px 0 rgba(2, 44, 34, .32); transition: transform .1s, box-shadow .1s; }
.fback:active { transform: translateY(3px); box-shadow: 0 0 0 rgba(2, 44, 34, .32); }
.fbar-t { min-width: 0; flex: 1; }
.fbar-e { font-size: 12px; line-height: 16px; font-weight: 800; letter-spacing: .02em; color: var(--strong, #047857); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fbar-e:not(:empty)::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; vertical-align: 1px; border-radius: 50%; background: var(--bar, #10B981); box-shadow: 0 0 0 3px var(--chip, #D1FAE5); }
.fbar-h { font-size: 16px; line-height: 22px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#barRight { flex: none; display: flex; align-items: center; gap: 6px; }
#barRight:empty { display: none; }
@media (max-width: 360px) { .fbar { padding-left: 8px; padding-right: 8px; } .fbar-in { gap: 8px; } }

/* แท็บ เนื้อหา / Quiz / Practice (แสดงสถานะของแต่ละกิจกรรมแยกกัน) */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; margin-top: 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 18px; box-shadow: 0 3px 0 #CBD5E1; }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 52px; border-radius: 14px; font-size: 14px; line-height: 20px; font-weight: 700; color: #334155; }
.tab small { font-size: 12px; line-height: 16px; font-weight: 600; color: #475569; }
.tab[aria-selected="true"] { background: var(--strong); color: #fff; }
.tab[aria-selected="true"] small { color: #fff; }

.panel { margin-top: 16px; }
.panel:focus { outline: none; }

/* ───────── เนื้อหาบทเรียน (Content) ───────── */
.read { display: grid; gap: 16px; }
.rblock { background: #fff; border: 2px solid #E2E8F0; border-radius: 20px; box-shadow: 0 3px 0 #CBD5E1; padding: 16px; }
.rmeta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.rh { font-size: 20px; line-height: 30px; font-weight: 700; }
.rp { margin-top: 8px; font-size: 16px; line-height: 30px; color: #1E293B; }
.rfig { display: flex; align-items: center; justify-content: center; margin-top: 12px; min-height: 160px; border-radius: 16px; background: var(--bg); border: 2px dashed var(--bd); }
.rcap { margin-top: 8px; text-align: center; }
.callout { padding: 14px; border-radius: 16px; background: var(--bg); border: 2px solid var(--bd); }
.callout h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; line-height: 22px; font-weight: 700; color: var(--strong); }
.callout p { margin-top: 6px; font-size: 16px; line-height: 28px; color: #1E293B; }
.steps { display: grid; gap: 10px; margin-top: 10px; counter-reset: st; }
.steps li { position: relative; padding-left: 40px; font-size: 16px; line-height: 28px; color: #1E293B; counter-increment: st; }
.steps li::before { content: counter(st); position: absolute; left: 0; top: 2px; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--chip); color: var(--strong); font-size: 14px; font-weight: 800; }
.checks { display: grid; gap: 8px; margin-top: 10px; }
.checks li { display: flex; align-items: flex-start; gap: 10px; font-size: 16px; line-height: 28px; color: #1E293B; }
.checks svg { flex: none; margin-top: 4px; color: #059669; }
.rdone { display: flex; flex-direction: column; gap: 10px; }
.btn-line { background: #fff; color: var(--strong); border: 2px solid var(--bd); box-shadow: 0 4px 0 var(--edge); }
.btn-line:active { box-shadow: 0 1px 0 var(--edge); }
.btn-done { background: #ECFDF5; color: #065F46; border: 2px solid #A7F3D0; box-shadow: 0 4px 0 #A7F3D0; }
.lnav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.lnav-a { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 68px; padding: 10px 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; box-shadow: 0 3px 0 #CBD5E1; }
.lnav-a.next { text-align: right; align-items: flex-end; }
.lnav-a b { font-size: 14px; line-height: 20px; font-weight: 700; color: #0F172A; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lnav-a[aria-disabled="true"] { opacity: .55; pointer-events: none; box-shadow: none; }

/* ───────── Quiz / Practice / ข้อสอบ: องค์ประกอบร่วม ───────── */
.intro { text-align: center; padding: 22px 18px; }
.intro .tile { width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 10px; font-size: 26px; }
.intro h2 { font-size: 20px; line-height: 30px; font-weight: 700; }
.intro p { margin-top: 4px; font-size: 14px; line-height: 22px; color: #475569; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0 4px; }

.qhead { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.qbar { flex: 1; height: 10px; border-radius: 999px; background: #E2E8F0; overflow: hidden; }
.qbar > i { display: block; height: 100%; border-radius: 999px; background: var(--bar); transition: width .55s cubic-bezier(.2, .8, .2, 1); }
.qcount { font-size: 14px; font-weight: 800; color: var(--strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.qcard { margin-top: 14px; padding: 16px; background: #fff; border: 2px solid #E2E8F0; border-radius: 20px; box-shadow: 0 3px 0 #CBD5E1; }
.qtopic { font-size: 12px; line-height: 18px; font-weight: 700; color: var(--strong); }
.qtext { margin-top: 4px; font-size: 18px; line-height: 30px; font-weight: 700; color: #0F172A; }
.choices { display: grid; gap: 10px; margin-top: 14px; }
.choice { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 14px; text-align: left; background: #fff; border: 2px solid #CBD5E1; border-radius: 16px; box-shadow: 0 3px 0 #CBD5E1; font-size: 16px; line-height: 24px; font-weight: 500; color: #0F172A; transition: transform .12s, background-color .2s, border-color .2s, box-shadow .2s, opacity .3s; }
.choice:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #CBD5E1; }
.choice-l { width: 32px; height: 32px; flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #F1F5F9; border: 1.5px solid #CBD5E1; font-size: 14px; font-weight: 800; color: #334155; }
.choice-t { flex: 1; min-width: 0; }
.choice-m { flex: none; width: 24px; height: 24px; display: none; }
.choice.is-sel { background: var(--bg); border-color: var(--strong); box-shadow: 0 3px 0 var(--edge); }
.choice.is-sel .choice-l { background: var(--strong); border-color: var(--strong); color: #fff; }
.choice.is-ok { background: #ECFDF5; border-color: #10B981; box-shadow: 0 3px 0 #A7F3D0; }
.choice.is-ok .choice-l { background: #047857; border-color: #047857; color: #fff; }
.choice.is-bad { background: #FFF1F2; border-color: #F43F5E; box-shadow: 0 3px 0 #FECDD3; }
.choice.is-bad .choice-l { background: #BE123C; border-color: #BE123C; color: #fff; }
.choice.is-ok .choice-m, .choice.is-bad .choice-m { display: block; }
.choice.is-ok .choice-m { color: #047857; }
.choice.is-bad .choice-m { color: #BE123C; }
.choice:disabled { cursor: default; }

.fb { display: flex; align-items: flex-start; gap: 12px; margin-top: 14px; padding: 14px; border-radius: 18px; border: 2px solid; animation: fbSlide .42s cubic-bezier(.34, 1.56, .64, 1) both; }
.fb.ok { background: #ECFDF5; border-color: #10B981; color: #064E3B; }
.fb.bad { background: #FFF1F2; border-color: #F43F5E; color: #881337; }
.fb-i { flex: none; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; }
.fb.ok .fb-i { background: #16A34A; }
.fb.bad .fb-i { background: #E11D48; }
.fb-b { min-width: 0; flex: 1; }
.fb h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 17px; line-height: 24px; font-weight: 800; }
.fb p { margin-top: 2px; font-size: 14px; line-height: 22px; font-weight: 500; }
.fb a, .fb .linkbtn { display: inline-flex; align-items: center; min-height: 44px; margin-top: 2px; font-size: 14px; font-weight: 700; text-decoration: underline; color: inherit; }
.fb .streak { display: inline-flex; align-items: center; gap: 3px; padding: 0 8px; min-height: 24px; border-radius: 999px; background: #FFEDD5; color: #9A3412; font-style: normal; font-size: 12px; font-weight: 800; white-space: nowrap; animation: pillIn .5s .2s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes fbIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fbSlide { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }

/* แถบปุ่มค้างด้านล่าง */
.abar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: rgba(255, 255, 255, .97); border-top: 1.5px solid #E2E8F0; box-shadow: 0 -6px 24px rgba(15, 23, 42, .06); padding: 12px 0 calc(12px + env(safe-area-inset-bottom, 0px)); transition: background-color .3s, border-color .3s; animation: abarIn .42s cubic-bezier(.2, .8, .2, 1) both; }
.abar-in { display: flex; gap: 10px; max-width: 42rem; margin: 0 auto; padding: 0 20px; }
.abar .btn { flex: 1; margin-top: 0; }
.btn[disabled] { background: #CBD5E1; color: #334155; box-shadow: 0 4px 0 #94A3B8; cursor: not-allowed; }

/* ผลลัพธ์ (Quiz / Mock Exam) */
.result { text-align: center; padding: 22px 18px; }
.ring { position: relative; width: 132px; height: 132px; margin: 0 auto; }
.ring svg { width: 132px; height: 132px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .trk { stroke: #E2E8F0; }
.ring .val { stroke: var(--bar); stroke-linecap: round; transition: stroke-dashoffset .9s cubic-bezier(.3, .7, .2, 1); }
.ring-t { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-t b { font-size: 30px; line-height: 34px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--strong); }
.ring-t span { font-size: 12px; line-height: 18px; font-weight: 700; color: #475569; }
.result h2 { margin-top: 12px; font-size: 20px; line-height: 30px; font-weight: 700; }
.result p { margin-top: 2px; color: #475569; font-size: 14px; line-height: 22px; }
.rows { display: grid; gap: 0; margin-top: 14px; background: #fff; border: 1px solid #E2E8F0; border-radius: 18px; overflow: hidden; text-align: left; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px; border-top: 1px solid #EEF2F6; font-size: 14px; }
.row:first-child { border-top: 0; }
.row .k { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; color: #475569; font-weight: 600; }
.row .v { font-weight: 800; font-variant-numeric: tabular-nums; color: #0F172A; }
.delta { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.delta.up { background: #ECFDF5; color: #065F46; }
.delta.down { background: #FFF1F2; color: #9F1239; }
.delta.same { background: #F1F5F9; color: #334155; }
.topic-row { display: grid; gap: 6px; padding: 10px 14px; border-top: 1px solid #EEF2F6; }
.topic-row:first-child { border-top: 0; }
.topic-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-weight: 600; color: #334155; }
.review { display: grid; gap: 10px; margin-top: 8px; text-align: left; }
.review-i { padding: 12px 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; }
.review-i.ok { border-color: #A7F3D0; }
.review-i.bad { border-color: #FECDD3; }
.review-i h3 { display: flex; align-items: center; gap: 8px; font-size: 14px; line-height: 22px; font-weight: 700; }
.review-i p { margin-top: 2px; font-size: 14px; line-height: 22px; color: #475569; }
.res-actions { display: grid; gap: 10px; margin-top: 16px; }

/* ───────── Practice ───────── */
.pfilter { display: flex; gap: 10px; overflow-x: auto; margin: 0 -20px; padding: 4px 20px 10px; scrollbar-width: none; }
.pfilter::-webkit-scrollbar { display: none; }
.psum { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 18px; box-shadow: 0 3px 0 #CBD5E1; }
.psum .bar { flex: 1; }
.psum b { font-size: 14px; font-weight: 800; color: var(--strong); font-variant-numeric: tabular-nums; white-space: nowrap; }
.plist { display: grid; gap: 12px; margin-top: 12px; }
.pcard { background: #fff; border: 2px solid #E2E8F0; border-radius: 18px; box-shadow: 0 3px 0 #CBD5E1; overflow: hidden; }
.pcard.ok { border-color: #A7F3D0; }
.pcard.bad { border-color: #FECDD3; }
.pcard-h { display: flex; align-items: center; gap: 10px; padding: 12px 14px 0; }
.lvl { display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.lvl-ง่าย { background: #ECFDF5; color: #065F46; border: 1.5px solid #A7F3D0; }
.lvl-กลาง { background: #FEF3C7; color: #78350F; border: 1.5px solid #FCD34D; }
.lvl-ยาก { background: #FFE4E6; color: #9F1239; border: 1.5px solid #FECDD3; }
.pcard-q { padding: 8px 14px 12px; font-size: 16px; line-height: 28px; font-weight: 600; }
.pcard-sol { margin: 0 14px 12px; padding: 12px; background: var(--bg); border: 2px solid var(--bd); border-radius: 14px; font-size: 14px; line-height: 22px; color: #1E293B; }
.pcard-sol b { display: block; color: var(--strong); }
.pcard-act { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.pbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 12px; background: #fff; border: 2px solid #CBD5E1; box-shadow: 0 3px 0 #CBD5E1; font-size: 14px; font-weight: 700; color: #334155; }
.pbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 #CBD5E1; }
.pbtn.ok.on { background: #ECFDF5; border-color: #10B981; color: #065F46; box-shadow: 0 3px 0 #A7F3D0; }
.pbtn.bad.on { background: #FFF1F2; border-color: #F43F5E; color: #9F1239; box-shadow: 0 3px 0 #FECDD3; }
.empty-p { padding: 22px 16px; text-align: center; background: #fff; border: 2px dashed #CBD5E1; border-radius: 18px; color: #475569; }

/* ───────── Mock Exam ───────── */
.pick-list { display: grid; gap: 12px; margin-top: 6px; }
.pick { display: flex; align-items: center; gap: 12px; min-height: 76px; padding: 10px 14px; background: var(--bg); border: 2px solid var(--bd); border-radius: 18px; box-shadow: 0 3px 0 var(--edge); }
.pick:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--edge); }
.pick .sc-tile { flex: none; }
.pick-t { min-width: 0; flex: 1; }
.pick-t h3 { font-size: 16px; line-height: 24px; font-weight: 700; }
.pick-t p { font-size: 12px; line-height: 18px; font-weight: 500; color: #475569; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.info { display: flex; align-items: center; gap: 10px; padding: 12px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; box-shadow: 0 3px 0 #CBD5E1; }
.info .tile { width: 40px; height: 40px; }
.info b { display: block; font-size: 16px; line-height: 22px; font-weight: 800; }
.info span.l { display: block; font-size: 12px; line-height: 18px; font-weight: 600; color: #475569; }
.rules { display: grid; gap: 10px; padding: 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 18px; }
.rules li { display: flex; gap: 10px; font-size: 14px; line-height: 22px; color: #334155; }
.rules svg { flex: none; margin-top: 2px; color: #C2410C; }
.hist { background: #fff; border: 1px solid #E2E8F0; border-radius: 18px; box-shadow: 0 3px 0 #CBD5E1; overflow: hidden; }
.hist-i { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 14px; border-top: 1px solid #EEF2F6; }
.hist-i:first-child { border-top: 0; }
.hist-i .n { width: 28px; flex: none; font-size: 14px; font-weight: 800; color: #475569; text-align: center; }
.hist-i .d { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.hist-i .d small { display: block; font-size: 12px; line-height: 18px; font-weight: 500; color: #475569; }
.hist-i .s { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; color: #9A3412; }
.btn-orange { background: #C2410C; box-shadow: 0 4px 0 #7C2D12; }
.btn-orange:active { box-shadow: 0 1px 0 #7C2D12; }

/* ข้อสอบ: ตัวจับเวลา + ตัวนำทางข้อ */
.timer { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px; background: #F1F5F9; color: #0F172A; font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.warn { background: #FEF3C7; color: #78350F; }
.timer.crit { background: #FFE4E6; color: #9F1239; }
.xnav-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 12px; border-radius: 12px; background: #F1F5F9; color: #334155; font-size: 14px; font-weight: 700; }
.flagbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border-radius: 12px; border: 2px solid #CBD5E1; background: #fff; font-size: 14px; font-weight: 700; color: #334155; }
.flagbtn[aria-pressed="true"] { background: #FEF3C7; border-color: #F59E0B; color: #78350F; }
.xhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.grid5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.qn { position: relative; display: flex; align-items: center; justify-content: center; min-height: 48px; border-radius: 14px; background: #fff; border: 2px solid #CBD5E1; font-size: 16px; font-weight: 800; color: #334155; font-variant-numeric: tabular-nums; }
.qn.ans { background: var(--chip); border-color: var(--bd); color: var(--strong); }
.qn.cur { border-color: var(--strong); box-shadow: 0 0 0 3px var(--edge); }
.qn .fl { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: #F59E0B; color: #fff; display: flex; align-items: center; justify-content: center; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; font-weight: 600; color: #475569; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -1px; border: 2px solid #CBD5E1; background: #fff; }
.legend i.a { background: var(--chip); border-color: var(--bd); }
.legend i.f { background: #F59E0B; border-color: #F59E0B; }

/* ชั้นซ้อนหน้าจอ (Bottom Sheet) */
.ov { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; background: rgba(15, 23, 42, .55); animation: ovIn .18s ease-out; }
.ov .sheet { animation: sheetIn .26s cubic-bezier(.2, .8, .2, 1); }
@keyframes ovIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: none; } }
.sheet-b { display: grid; gap: 10px; margin-top: 12px; }
.sheet-p { font-size: 14px; line-height: 22px; color: #334155; margin-top: 8px; }
.sheet-p b { color: #0F172A; }

.fade-in { animation: fbIn .22s ease-out; }

@media (min-width: 640px) {
  .fmain { padding-bottom: 96px; }
  .chd { padding-left: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .fb, .ov, .ov .sheet, .fade-in { animation: none; }
  .qbar > i, .ring .val, .choice, .chev, .mock-btn { transition: none; }
}

/* ───── ข้อมูลจริง (js/study-live.js) ───── */
.notfound-act { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.notfound-act .btn { margin-top: 0; }
.rp { white-space: normal; }
.rfig.has-media { min-height: 0; padding: 0; overflow: hidden; border-style: solid; background: #fff; }
.rfig img, .rfig video { display: block; width: 100%; height: auto; max-height: 420px; object-fit: contain; }
.rfig .btn { margin: 14px; }
.about-list { display: grid; gap: 4px; padding-left: 18px; list-style: disc; }
.mock-btn[aria-disabled="true"] { background: #64748B; box-shadow: 0 4px 0 #475569; color: #fff; cursor: not-allowed; pointer-events: none; }
.note { margin-top: 12px; padding: 10px 14px; border-radius: 14px; background: var(--bg); border: 2px solid var(--bd); font-size: 14px; line-height: 22px; color: #1E293B; text-align: left; }
.note.ok { background: #ECFDF5; border-color: #6EE7B7; color: #064E3B; }
.note.warn { background: #FFFBEB; border-color: #FCD34D; color: #78350F; }
.note svg { vertical-align: -3px; margin-right: 4px; }
.errbox { margin-top: 12px; padding: 10px 14px; border-radius: 14px; background: #FFF1F2; border: 2px solid #FDA4AF; color: #881337; font-size: 14px; line-height: 22px; font-weight: 600; text-align: left; }
.rdone .errbox { margin-top: 0; }

/* ───── ผลการเรียนรายวิชา (js/study-live-report.js) ───── */
.tgroup { margin-top: 14px; font-size: 15px; line-height: 22px; font-weight: 800; }
.tgroup small { font-weight: 600; font-size: 12px; color: #475569; }
.tgroup.weak { color: #9F1239; }
.tgroup.ok { color: #334155; }
.tgroup.strong { color: #065F46; }
.tlist { display: grid; gap: 10px; margin-top: 8px; }
.tcard { padding: 12px 14px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; box-shadow: 0 3px 0 #CBD5E1; }
.tcard.weak { border-color: #FECDD3; box-shadow: 0 3px 0 #FECDD3; }
.tcard.strong { border-color: #A7F3D0; box-shadow: 0 3px 0 #A7F3D0; }
.tcard .top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 14px; line-height: 20px; }
.tcard .top b { font-weight: 700; }
.tcard .top span { font-weight: 700; color: #334155; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tcard.weak .bar > i { background: #F43F5E; }
.inl { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 4px; font-weight: 700; color: var(--strong); text-decoration: underline; }
.trend { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding: 12px 12px 8px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; }
.trend-b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.trend-b span { font-size: 12px; line-height: 16px; font-weight: 700; color: #334155; margin-bottom: 4px; }
.trend-b i { display: block; width: 100%; max-width: 36px; border-radius: 8px 8px 0 0; background: var(--bar); }
.lres { display: grid; gap: 8px; }
.lr { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 56px; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; box-shadow: 0 3px 0 #CBD5E1; text-decoration: none; color: inherit; }
.lr-n { flex: none; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; background: #F1F5F9; color: #334155; }
.lr-n.st-done { background: #059669; color: #fff; }
.lr-n.st-now { background: var(--chip); color: var(--strong); }
.lr-b { min-width: 0; }
.lr-t { font-size: 14px; line-height: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ───── ชุดเนื้อหาหลายหน้า (js/study-live-content.js) ───── */
.cn { margin-top: 14px; }
.cn-dots { flex: 1; display: flex; gap: 5px; }
.cn-dots i { flex: 1; height: 8px; border-radius: 999px; background: #E2E8F0; transition: background-color .35s, flex-grow .35s; }
.cn-dots i.on { background: var(--bar); }
.cn-dots i.cur { background: var(--bar); animation: cnCur 1.5s ease-in-out infinite; }
@keyframes cnCur { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
.cn-page { min-height: 36vh; }
.cn-done { margin-top: 20px; }
.cn-medal { font-size: 64px; line-height: 1; margin-bottom: 4px; animation: cnMedal 2s ease-in-out infinite; }
@keyframes cnMedal { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-8px) rotate(6deg); } }

/* ───── ภาพ / วิดีโอ ในเนื้อหา โจทย์ และตัวเลือก (js/study-media.js) ───── */
.rfig.has-media { display: block; }
.rfig.has-media .rcap { margin: 0; padding: 8px 12px 10px; text-align: center; }
.rfig img[data-zoom] { cursor: zoom-in; }
.rvid { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #0F172A; }
.rvid iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.rfig.is-video video { background: #0F172A; }
.qmedia { display: grid; gap: 10px; margin-top: 12px; }
.qmedia .rfig { margin-top: 0; }
.choice-t { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.choice-img { display: block; max-width: 100%; max-height: 150px; border-radius: 10px; object-fit: contain; background: #fff; }
.zoomv { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .86); cursor: zoom-out; animation: ovIn .18s ease-out; }
.zoomv img { max-width: 100%; max-height: 100%; border-radius: 12px; background: #fff; object-fit: contain; }
.zoomv-x { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .92); color: #0F172A; font-size: 18px; font-weight: 800; }

/* ───── สีสันและการเคลื่อนไหวของหน้าเรียน ───── */
.read > .rblock { animation: fbIn .4s both; }
.read > :nth-child(2) { animation-delay: .06s; }
.read > :nth-child(3) { animation-delay: .12s; }
.read > :nth-child(4) { animation-delay: .18s; }
.read > :nth-child(5) { animation-delay: .24s; }
.intro .tile, .intro-tile { animation: tileBob 2.8s ease-in-out infinite; }
@keyframes tileBob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }
.choice:hover:not(:disabled) { border-color: var(--strong); transform: translateY(-1px); }
.fb.ok { background: linear-gradient(135deg, #ECFDF5, #D1FAE5); }
.fb.bad { background: linear-gradient(135deg, #FFF1F2, #FFE4E6); }
.result .ring { animation: ringIn .6s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes ringIn { from { opacity: 0; transform: scale(.6) rotate(-30deg); } to { opacity: 1; transform: none; } }
body.flow .qbar > i, body.flow .bar > i { background: linear-gradient(90deg, var(--bar), var(--strong)); }

@media (prefers-reduced-motion: reduce) {
  .read > .rblock, .intro .tile, .intro-tile, .qcard, .cn-dots i.cur, .cn-medal, .result .ring, .zoomv { animation: none; }
}

/* ═════════ v3: ข้อความน้อย ไม่กะพริบ สีปุ่มชัด และการเคลื่อนไหวที่มีความหมาย ═════════
   หน้าแก้เฉพาะจุดที่เปลี่ยน (js/study-dom.js): แอนิเมชันเข้าฉากเล่นเฉพาะองค์ประกอบที่ "เพิ่งเกิด" (ข้อใหม่ เฉลย หน้าเนื้อหาใหม่)
   องค์ประกอบเดิมเปลี่ยนด้วย transition (สี ความกว้าง) เท่านั้น ทั้งหมดปิดได้ด้วย prefers-reduced-motion */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
#content { animation: pageFade .4s ease both; }
@keyframes pageFade { from { opacity: 0; } to { opacity: 1; } }

/* โครงเปล่าระหว่างรอข้อมูล */
.sk { display: block; border-radius: 14px; background: linear-gradient(100deg, #E2E8F0 30%, #F1F5F9 50%, #E2E8F0 70%); background-size: 300% 100%; animation: skShimmer 1.4s linear infinite; }
.sk-wrap { display: grid; gap: 14px; margin-top: 16px; }
.sk-line { height: 14px; width: 55%; }
.sk-line.s { width: 35%; }
.sk-card { height: 170px; border-radius: 20px; }
.sk-card.s { height: 96px; }
.sk-inline { display: grid; gap: 8px; margin-top: 8px; }
@keyframes skShimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ปุ่ม: สีไล่เฉดตามสีประจำบท + เงา 3 มิติ; เขียว = ถูก/ไปต่อ, แดง = ผิด, ส้ม = ข้อสอบ, ขาว = ปุ่มรอง */
body.flow .btn:not([disabled]) { background: linear-gradient(180deg, var(--bar, #059669), var(--strong, #047857)); box-shadow: 0 5px 0 rgba(2, 44, 34, .32); }
body.flow .btn:not([disabled]):active { box-shadow: 0 1px 0 rgba(2, 44, 34, .32); }
body.flow .btn.btn-line:not([disabled]) { background: #fff; color: var(--strong, #047857); border: 2px solid var(--bd, #A7F3D0); box-shadow: 0 4px 0 var(--edge, #A7F3D0); }
body.flow .btn.btn-line:not([disabled]):active { box-shadow: 0 1px 0 var(--edge, #A7F3D0); }
body.flow .btn.btn-orange:not([disabled]) { background: linear-gradient(180deg, #EA580C, #C2410C); box-shadow: 0 5px 0 #7C2D12; }
body.flow .btn.btn-orange:not([disabled]):active { box-shadow: 0 1px 0 #7C2D12; }
body.flow .btn.btn-ok:not([disabled]) { background: linear-gradient(180deg, #22C55E, #15803D); box-shadow: 0 5px 0 #14532D; }
body.flow .btn.btn-ok:not([disabled]):active { box-shadow: 0 1px 0 #14532D; }
body.flow .btn.btn-bad:not([disabled]) { background: linear-gradient(180deg, #FB7185, #E11D48); box-shadow: 0 5px 0 #9F1239; }
body.flow .btn.btn-bad:not([disabled]):active { box-shadow: 0 1px 0 #9F1239; }
body.flow .btn.btn-ok.on, body.flow .btn.btn-bad.on { outline: 3px solid rgba(255, 255, 255, .85); outline-offset: -6px; }
.btn { position: relative; overflow: hidden; }
.btn-block.btn-lg:not(.btn-line):not([disabled])::after { content: ""; position: absolute; top: 0; bottom: 0; left: -60%; width: 34%; background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .38), transparent); transform: skewX(-20deg); animation: btnShine 4.2s 1s ease-in-out infinite; pointer-events: none; }
@keyframes btnShine { 0% { left: -60%; } 36%, 100% { left: 130%; } }
.btn-ico { flex: none; width: 54px; height: 54px; display: inline-flex; align-items: center; justify-content: center; border-radius: 16px; background: #fff; border: 2px solid var(--bd, #CBD5E1); color: var(--strong, #334155); box-shadow: 0 4px 0 var(--edge, #CBD5E1); cursor: pointer; transition: transform .1s, box-shadow .1s, opacity .2s; }
.btn-ico:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge, #CBD5E1); }
.btn-ico:disabled { opacity: .4; box-shadow: none; cursor: default; }
.linkbtn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 6px; font-size: 14px; font-weight: 800; color: var(--strong, #047857); text-decoration: underline; background: none; border: 0; cursor: pointer; }
.res-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; }

/* แถบปุ่มล่างย้อมสีตามผลของข้อ */
.abar.is-ok { background: rgba(236, 253, 245, .98); border-top-color: #86EFAC; }
.abar.is-bad { background: rgba(255, 241, 242, .98); border-top-color: #FDA4AF; }
@keyframes abarIn { from { transform: translateY(100%); } to { transform: none; } }

/* ป้ายสถานะ (แทนประโยคอธิบายยาว ๆ) */
.pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.pill { display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 0 12px; border-radius: 999px; background: #F1F5F9; color: #334155; border: 1.5px solid #CBD5E1; font-size: 13px; line-height: 20px; font-weight: 800; animation: pillIn .5s cubic-bezier(.34, 1.56, .64, 1) both; }
.pills .pill:nth-child(2) { animation-delay: .1s; }
.pills .pill:nth-child(3) { animation-delay: .2s; }
.pill.ok { background: #ECFDF5; color: #065F46; border-color: #6EE7B7; }
.pill.warn { background: #FFFBEB; color: #78350F; border-color: #FCD34D; }
.pill.gold { background: linear-gradient(135deg, #FEF3C7, #FDE68A); color: #78350F; border-color: #FBBF24; }
@keyframes pillIn { from { opacity: 0; transform: scale(.55); } to { opacity: 1; transform: none; } }

/* ส่วนที่พับเก็บไว้ (ข้อความยาวไม่แสดงต่อหน้า): กดเปิดเมื่อต้องการ */
.fold { margin-top: 14px; text-align: left; background: #fff; border: 2px solid #E2E8F0; border-radius: 16px; }
.fold > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; padding: 0 14px; font-size: 14px; font-weight: 800; color: #334155; cursor: pointer; list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary i { display: inline-flex; transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
.fold[open] > summary i { transform: rotate(180deg); }
.fold > :not(summary) { padding: 0 14px 14px; }
.fold .review { margin-top: 0; }

/* เปลี่ยนหน้า/ข้อ: องค์ประกอบใหม่เลื่อนเข้ามาจากทิศที่ไป (data-dir) เดิมอยู่ที่เดิม */
.cn-view, .qview, .pk-view { animation: viewIn .36s cubic-bezier(.2, .8, .2, 1) both; --from: 0px; --fromY: 12px; }
.cn-view[data-dir="1"], .qview[data-dir="1"], .pk-view[data-dir="1"] { --from: 40px; --fromY: 0px; }
.cn-view[data-dir="-1"], .qview[data-dir="-1"], .pk-view[data-dir="-1"] { --from: -40px; --fromY: 0px; }
@keyframes viewIn { from { opacity: 0; transform: translate(var(--from), var(--fromY)); } to { opacity: 1; transform: none; } }

/* ชุดเนื้อหา */
.cn-top { display: flex; align-items: center; gap: 12px; }
.cn-dots i.cur { flex-grow: 2.2; }
.cn-count { flex: none; font-size: 13px; font-weight: 800; color: var(--strong); font-variant-numeric: tabular-nums; }
.cn-kicker { margin: 14px 0 0; font-size: 13px; line-height: 20px; font-weight: 800; letter-spacing: .02em; color: var(--strong); }
.cn-page { margin-top: 12px; }
.cn-done-t { margin-top: 2px; font-size: 15px; font-weight: 700; color: #475569; }

/* หน้าเริ่ม Quiz */
.intro { margin-top: 16px; padding: 28px 18px 20px; }
.intro .intro-tile { display: flex; align-items: center; justify-content: center; width: 88px; height: 88px; margin: 0 auto 8px; border-radius: 30px; background: linear-gradient(145deg, var(--chip), #fff); border: 2px solid var(--bd); box-shadow: 0 6px 0 var(--edge); font-size: 46px; }
.intro .facts .chip { animation: pillIn .5s cubic-bezier(.34, 1.56, .64, 1) both; }
.intro .facts .chip:nth-child(2) { animation-delay: .08s; }
.intro .facts .chip:nth-child(3) { animation-delay: .16s; }
.intro .facts .chip:nth-child(4) { animation-delay: .24s; }
.intro .btn-block { margin-top: 18px; }
.choice.is-dim { opacity: .5; }
.choice.is-sel .choice-l { transform: scale(1.08); }
.choice-l { transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), background-color .2s, border-color .2s, color .2s; }

/* Practice ทีละข้อ */
.pk-top { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.pk-dots { flex: 1; display: flex; gap: 5px; }
.pk-dots i { flex: 1; height: 8px; border-radius: 999px; background: #E2E8F0; transition: background-color .3s, flex-grow .3s; }
.pk-dots i.ok { background: #22C55E; }
.pk-dots i.bad { background: #F43F5E; }
.pk-dots i.cur { flex-grow: 2.2; }
.pk-dots i.cur:not(.ok):not(.bad) { background: var(--bar); }
.pk-view { margin-top: 12px; }
.pcard-h { gap: 8px; }
.pcard-topic { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard-r { flex: none; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; animation: pillIn .45s cubic-bezier(.34, 1.56, .64, 1) both; }
.pcard-r.ok { background: #16A34A; }
.pcard-r.bad { background: #E11D48; }
.pcard-nav { flex: none; display: inline-flex; gap: 6px; }
.pcard-nav button { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: #F1F5F9; color: #334155; transition: transform .1s, opacity .2s; }
.pcard-nav button:active:not(:disabled) { transform: scale(.9); }
.pcard-nav button:disabled { opacity: .35; cursor: default; }
.pcard-q { padding-bottom: 14px; font-size: 18px; line-height: 30px; }
.pcard-sol { animation: fbSlide .4s cubic-bezier(.34, 1.56, .64, 1) both; }
.pk-done { margin-top: 18px; }
.pfilter { margin-top: 10px; padding-bottom: 4px; }

@media (prefers-reduced-motion: reduce) {
  #content, .sk, .btn-block.btn-lg::after, .abar, .pill, .pills .pill, .intro .facts .chip, .cn-view, .qview, .pk-view, .fb, .fb .streak, .pcard-r, .pcard-sol { animation: none; }
  .qbar > i, .choice, .choice-l, .cn-dots i, .pk-dots i, .fold > summary i, .abar { transition: none; }
}

/* ผลสอบ: กล่องดาว */
.stars-big { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 2px 8px; margin-top: 14px; padding: 10px 14px; border-radius: 16px; background: linear-gradient(135deg, #FEF3C7, #FDE68A); border: 2px solid #FBBF24; color: #78350F; font-size: 18px; line-height: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stars-big small { flex-basis: 100%; text-align: center; font-size: 12px; line-height: 18px; font-weight: 600; }
.stars-big > svg { animation: tileBob 2.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .stars-big > svg { animation: none; } }

/* ═════════ v4: หน้าสรุปผลทีละหน้า, เฉลยทันทีใต้ข้อ, EXP ที่ได้ระหว่างทาง ═════════ */
.fmain.has-abar { padding-bottom: calc(var(--abar-h, 108px) + 28px); }
.rs-view { animation: viewIn .4s cubic-bezier(.2, .8, .2, 1) both; --from: 40px; --fromY: 0px; }

.rs-dots { display: flex; gap: 6px; margin-top: 14px; }
.rs-dots i { flex: 1; height: 8px; border-radius: 999px; background: #E2E8F0; transition: background-color .35s, flex-grow .35s; }
.rs-dots i.on { background: var(--bar); }
.rs-dots i.cur { background: var(--bar); flex-grow: 2.2; }

.rs-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 58vh; margin-top: 14px; padding: 26px 18px; text-align: center; background: #fff; border: 2px solid #E2E8F0; border-radius: 26px; box-shadow: 0 4px 0 #CBD5E1; }
.rs-emoji { font-size: 76px; line-height: 1; animation: tileBob 2.6s ease-in-out infinite; }
.rs-k { margin: 0; font-size: 15px; line-height: 22px; font-weight: 700; color: #64748B; }
.rs-k em { font-style: normal; color: var(--strong); font-variant-numeric: tabular-nums; }
.rs-big { margin: 0; font-size: 68px; line-height: 1.05; font-weight: 800; color: var(--strong); font-variant-numeric: tabular-nums; animation: bigIn .6s cubic-bezier(.34, 1.56, .64, 1) both; }
.rs-big small { margin-left: 6px; font-size: 18px; font-weight: 700; color: #64748B; }
.rs-big.gold { color: #B45309; }
.rs-card h2 { margin: 6px 0 0; font-size: 22px; line-height: 30px; font-weight: 800; }
.rs-cap { margin: 0; font-size: 13px; line-height: 20px; font-weight: 600; color: #64748B; }
.rs-pills { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; min-height: 32px; }
.rs-badge { animation-delay: 1.1s; }

/* คะแนน: ลูกบอลโผล่ทีละลูก (ถูกเขียว ผิดแดง) แทนกราฟ */
.rs-marks { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 320px; margin-top: 8px; }
.rs-marks i { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; animation: markIn .5s cubic-bezier(.34, 1.56, .64, 1) both; animation-delay: calc(var(--i) * 110ms + 350ms); }
.rs-marks i.ok { background: #22C55E; box-shadow: 0 3px 0 #15803D; }
.rs-marks i.bad { background: #FB7185; box-shadow: 0 3px 0 #BE123C; }
@keyframes markIn { from { opacity: 0; transform: scale(.2) translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes bigIn { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }

/* ทบทวนทีละข้อ */
.rs-review { align-items: stretch; justify-content: flex-start; text-align: left; gap: 10px; min-height: 0; }
.rs-review .rs-k { text-align: center; }
.rs-q { margin: 2px 0 0; font-size: 18px; line-height: 28px; font-weight: 800; }
.rs-yours { margin: 0; font-size: 14px; line-height: 22px; font-weight: 600; color: #BE123C; }
.rs-yours s { text-decoration-thickness: 2px; }
.rs-right { display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 10px 12px; border-radius: 14px; background: #ECFDF5; border: 2px solid #86EFAC; color: #065F46; font-size: 16px; line-height: 24px; font-weight: 600; }
.rs-right svg { flex: none; margin-top: 2px; }
.rs-why { margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--bg); border: 2px solid var(--bd); font-size: 15px; line-height: 26px; color: #1E293B; animation: fbSlide .45s .15s cubic-bezier(.34, 1.56, .64, 1) both; }

/* EXP / ดาว / เลเวล */
.rs-bolt { display: flex; align-items: center; justify-content: center; width: 88px; height: 88px; border-radius: 50%; background: linear-gradient(145deg, #FEF3C7, #FBBF24); color: #B45309; box-shadow: 0 6px 0 #D97706, 0 0 0 8px rgba(251, 191, 36, .22); animation: boltPulse 1.8s ease-in-out infinite; }
@keyframes boltPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.rs-star { animation: starSpin 1.1s cubic-bezier(.34, 1.56, .64, 1) both; }
@keyframes starSpin { from { transform: scale(.2) rotate(-200deg); opacity: 0; } to { transform: none; opacity: 1; } }
.rs-parts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.rs-parts span { padding: 2px 12px; border-radius: 999px; background: #FEF3C7; color: #78350F; font-size: 13px; line-height: 22px; font-weight: 800; animation: pillIn .5s .9s cubic-bezier(.34, 1.56, .64, 1) both; }
.rs-lvl { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 300px; margin-top: 12px; }
.rs-lvl b { flex: none; font-size: 15px; color: var(--strong); }
.rs-lbar { flex: 1; height: 14px; border-radius: 999px; background: #E2E8F0; overflow: hidden; }
.rs-lbar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #FBBF24, #F59E0B); transition: width 1.3s cubic-bezier(.2, .8, .2, 1); }

/* เฉลยทันทีใต้ข้อ: แผงในแถบปุ่มล่าง (เห็นเฉลยโดยไม่ต้องเลื่อนหา) */
.abar-fb.fb { display: flex; align-items: flex-start; gap: 12px; max-width: 42rem; max-height: 36vh; margin: 0 auto; padding: 4px 20px 10px; overflow-y: auto; border: 0; border-radius: 0; background: transparent; animation: panelUp .38s cubic-bezier(.34, 1.4, .64, 1) both; }
.abar .abar-fb.fb.ok, .abar .abar-fb.fb.bad { background: transparent; }
.abar-fb .fb-i { width: 38px; height: 38px; }
.abar-fb h3 { flex-wrap: wrap; justify-content: flex-start; }
.fb-ans { margin: 2px 0 0; font-size: 15px; line-height: 24px; font-weight: 600; }
.fb-ans b { font-weight: 800; }
.xp-gain, .passed-now { display: inline-flex; align-items: center; padding: 0 9px; min-height: 24px; border-radius: 999px; font-style: normal; font-size: 12px; font-weight: 800; white-space: nowrap; animation: pillIn .5s .15s cubic-bezier(.34, 1.56, .64, 1) both; }
.xp-gain { background: #FBBF24; color: #78350F; }
.passed-now { background: #16A34A; color: #fff; }
@keyframes panelUp { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }

/* EXP ที่สะสมระหว่างทำ + EXP ก่อนเริ่ม */
.xp-pill { flex: none; display: inline-flex; align-items: center; gap: 3px; min-height: 26px; padding: 0 10px; border-radius: 999px; background: #FEF3C7; color: #78350F; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.xp-pill.bump { animation: xpBump .5s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes xpBump { 40% { transform: scale(1.25); } }
.cn-xp { flex: none; }

@media (prefers-reduced-motion: reduce) {
  .rs-view, .rs-emoji, .rs-big, .rs-marks i, .rs-bolt, .rs-star, .rs-parts span, .rs-why, .abar-fb.fb, .xp-gain, .passed-now, .xp-pill.bump { animation: none; }
  .rs-lbar i, .rs-dots i { transition: none; }
}
