/* เกมสมาส "พับคำ · คลี่เรื่อง" — หน้าทบทวนทุกด่าน (/samasa/<ด่าน>/study) + ส่วนกลางของหน้าเกม
   โลกของวิชา: โรงพับใบลาน — กลางวัน = กระดาษใบลานอุ่น · กลางคืน = ลงรักยามค่ำ · ปุ่มหลักเป็น "ตราหมึก"
   สีมีความหมายเท่านั้น: ๖ สีประจำสมาส ๖ ชื่อ (--t-<key>) ใช้ซ้ำทุกที่ (ใบลาน · ชิป · คำสำคัญ · ตัวเลือก) · ทองใช้กับดาวอย่างเดียว */

@font-face { font-family: "Thunder Pali"; font-weight: 400 500; font-display: swap; src: url("/assets/fonts/thunder-pali/ThunderPali-400.woff2") format("woff2"); unicode-range: U+0E00-0E7F, U+25CC; }
@font-face { font-family: "Thunder Pali"; font-weight: 600 700; font-display: swap; src: url("/assets/fonts/thunder-pali/ThunderPali-700.woff2") format("woff2"); unicode-range: U+0E00-0E7F, U+25CC; }
@font-face { font-family: "Thunder Pali"; font-weight: 800 900; font-display: swap; src: url("/assets/fonts/thunder-pali/ThunderPali-800.woff2") format("woff2"); unicode-range: U+0E00-0E7F, U+25CC; }
@font-face { font-family: "Sriracha Local"; src: url("/assets/fonts/sriracha/Sriracha-Regular.ttf?v=20260806.1") format("truetype"); font-weight: 400; font-display: swap; }

:root {
	color-scheme: light;
	--bg: #f5eedf; --bg2: #ede3cd; --panel: #fffcf4; --panel2: #faf3e3; --sunk: #efe5cf;
	--ink: #2b2118; --ink2: #4b3d30; --muted: #76665a; --dim: #9a8b7c; --strong: #1a120c;
	--line: rgba(70, 45, 20, .14); --line2: rgba(70, 45, 20, .24);
	--stamp: #8f2a1c; --on-stamp: #fff8ec; --stamp-soft: rgba(143, 42, 28, .1);
	--gold: #b8861b; --ok: #1f7a4a; --bad: #be123c;
	--shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 10px 26px -14px rgba(70, 40, 10, .38);
	--t-kam: #5a43c2; --t-digu: #1a6aa8; --t-tap: #1b7647; --t-dvan: #b94d14; --t-aby: #8a6100; --t-bahu: #ad2667;
	--f-body: "Sarabun", system-ui, sans-serif; --f-hand: "Sriracha Local", "Sarabun", cursive;
}
@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		color-scheme: dark;
		--bg: #16110e; --bg2: #1d1713; --panel: #241d18; --panel2: #2b231d; --sunk: #1a1411;
		--ink: #f2e8d8; --ink2: #dacdb9; --muted: #ab9b89; --dim: #85776a; --strong: #fff8ec;
		--line: rgba(255, 235, 205, .11); --line2: rgba(255, 235, 205, .2);
		--stamp: #e07a5f; --on-stamp: #1b110c; --stamp-soft: rgba(224, 122, 95, .14);
		--gold: #f2c25e; --ok: #5fd39a; --bad: #fb7185;
		--shadow: 0 12px 30px -16px rgba(0, 0, 0, .7);
		--t-kam: #a998ff; --t-digu: #72b8f2; --t-tap: #62d49b; --t-dvan: #ff9d66; --t-aby: #e9c552; --t-bahu: #f585bb;
	}
}
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #16110e; --bg2: #1d1713; --panel: #241d18; --panel2: #2b231d; --sunk: #1a1411;
	--ink: #f2e8d8; --ink2: #dacdb9; --muted: #ab9b89; --dim: #85776a; --strong: #fff8ec;
	--line: rgba(255, 235, 205, .11); --line2: rgba(255, 235, 205, .2);
	--stamp: #e07a5f; --on-stamp: #1b110c; --stamp-soft: rgba(224, 122, 95, .14);
	--gold: #f2c25e; --ok: #5fd39a; --bad: #fb7185;
	--shadow: 0 12px 30px -16px rgba(0, 0, 0, .7);
	--t-kam: #a998ff; --t-digu: #72b8f2; --t-tap: #62d49b; --t-dvan: #ff9d66; --t-aby: #e9c552; --t-bahu: #f585bb;
}
[data-main="kam"] { --c: var(--t-kam); } [data-main="digu"] { --c: var(--t-digu); } [data-main="tap"] { --c: var(--t-tap); }
[data-main="dvan"] { --c: var(--t-dvan); } [data-main="aby"] { --c: var(--t-aby); } [data-main="bahu"] { --c: var(--t-bahu); }
.kw { font-weight: 800; white-space: nowrap; }
.kw-kam { color: var(--t-kam); } .kw-digu { color: var(--t-digu); } .kw-tap { color: var(--t-tap); } .kw-dvan { color: var(--t-dvan); } .kw-aby { color: var(--t-aby); } .kw-bahu { color: var(--t-bahu); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body.smk-page {
	margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.6;
	background-image: radial-gradient(ellipse 120% 60% at 50% -10%, color-mix(in srgb, var(--gold) 9%, transparent), transparent 70%),
		repeating-linear-gradient(0deg, transparent 0 27px, color-mix(in srgb, var(--ink) 2.2%, transparent) 27px 28px);
	padding-bottom: 84px;
}
body.sm-play { padding-bottom: 32px; }
.pali, .leaf, .fold-word { font-family: "Thunder Pali", var(--f-body); }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 8px; }
.hide-s { }
@media (max-width: 480px) { .hide-s { display: none; } }

/* ── แถบบน ── */
.smk-bar { position: sticky; top: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.smk-bar-in { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; }
.smk-back, .smk-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px; border-radius: 12px; text-decoration: none; font-weight: 700; color: var(--ink2); }
.smk-back:hover, .smk-link:hover { background: var(--stamp-soft); color: var(--strong); }
.smk-bar-title { font-weight: 800; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.smk-bar-title i { color: var(--stamp); margin-right: 4px; }
.smk-bar-actions { display: flex; align-items: center; gap: 4px; }
.smk-theme { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 44px; justify-content: center; padding: 0 12px; border: 1px solid var(--line2); border-radius: 12px; background: var(--panel); color: var(--ink2); font: 700 14px var(--f-body); cursor: pointer; }
.smk-theme svg { width: 18px; height: 18px; }
.smk-theme .i-sun { display: none; }
.smk-theme[aria-pressed="true"] .i-sun { display: block; } .smk-theme[aria-pressed="true"] .i-moon { display: none; }
@media (max-width: 640px) { .smk-bar-title { display: none; } #theme-label, .smk-link span { display: none; } .smk-back span { display: inline; } }

/* ── ฉากหัว: ข้อความซ้าย · ภาพบทเรียนในกรอบใบลานขวา ── */
.smk-hero { padding: 26px 0 10px; }
.smk-hero-in { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 32px; align-items: center; }
.smk-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.smk-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 2px 12px; border-radius: 99px; border: 1px solid var(--line2); background: var(--panel); color: var(--ink2); font-size: 13px; font-weight: 700; white-space: nowrap; }
.smk-pill-ink { background: var(--stamp); border-color: var(--stamp); color: var(--on-stamp); }
.smk-hero h1 { margin: 0; font-size: clamp(30px, 4.4vw, 46px); line-height: 1.18; font-weight: 800; color: var(--strong); letter-spacing: -.01em; text-wrap: balance; }
.smk-hero h1 em { font-style: normal; color: var(--stamp); }
.smk-quote { margin: 14px 0 0; font-family: var(--f-hand); font-size: clamp(17px, 2vw, 20px); line-height: 1.55; color: var(--stamp); }
.smk-lead { margin: 12px 0 0; max-width: 60ch; color: var(--ink2); font-size: 16px; line-height: 1.75; }
.smk-lead b { color: var(--strong); }
.smk-hero-art { margin: 0; position: relative; border-radius: 22px; padding: 8px; background: var(--panel); border: 1px solid var(--line2); box-shadow: var(--shadow); transform: rotate(.6deg); }
.smk-hero-art img { display: block; width: 100%; height: auto; aspect-ratio: 1717 / 916; object-fit: cover; border-radius: 16px; }
:root[data-theme="dark"] .smk-hero-art img { filter: saturate(.92) brightness(.9); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .smk-hero-art img { filter: saturate(.92) brightness(.9); } }
.smk-hero.is-compact { padding: 16px 0 4px; }
.smk-hero.is-compact .smk-hero-in { grid-template-columns: 1fr; }
.smk-hero.is-compact h1 { font-size: clamp(24px, 3.2vw, 32px); }
.smk-hero.is-compact .smk-lead { margin-top: 6px; }
@media (max-width: 860px) {
	.smk-hero-in { grid-template-columns: 1fr; gap: 18px; }
	.smk-hero-art { order: -1; transform: none; padding: 6px; border-radius: 18px; }
	.smk-hero-art img { border-radius: 13px; aspect-ratio: 16 / 8; }
}

/* ── เส้นทางด่าน ── */
.smk-path { display: flex; gap: 8px; margin: 22px 0 6px; padding: 4px 2px 10px; overflow-x: auto; scrollbar-width: thin; }
.stop { flex: 1 0 104px; min-width: 104px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 6px 9px; border-radius: 14px; border: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 70%, transparent); text-decoration: none; text-align: center; color: var(--ink2); }
a.stop:hover { border-color: var(--line2); background: var(--panel); }
.stop-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 14px; background: var(--sunk); color: var(--muted); border: 1px solid var(--line2); }
.stop.done .stop-dot { background: var(--stamp-soft); color: var(--stamp); border-color: color-mix(in srgb, var(--stamp) 40%, transparent); }
.stop.now { background: var(--panel); border-color: var(--stamp); box-shadow: 0 0 0 3px var(--stamp-soft); color: var(--strong); }
.stop.now .stop-dot { background: var(--stamp); color: var(--on-stamp); border-color: var(--stamp); }
.stop-name { font-size: 13px; font-weight: 800; line-height: 1.3; }
.stop-zone { font-size: 11px; color: var(--dim); white-space: nowrap; }
.stop-stars { font-size: 12px; letter-spacing: 1px; color: var(--line2); } .stop-stars .on { color: var(--gold); }

/* ── ช่วงเนื้อหา ── */
.sec { margin-top: 44px; }
.sec-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.sec-kick { font-size: 13px; font-weight: 800; letter-spacing: .06em; color: var(--stamp); }
.sec h2 { margin: 2px 0 0; font-size: clamp(22px, 2.8vw, 28px); line-height: 1.3; font-weight: 800; color: var(--strong); text-wrap: balance; }
.sec h2 em { font-style: normal; color: var(--stamp); }
.sec-sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; max-width: 70ch; }
.sec-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.smk-note { max-width: 1120px; margin: 40px auto 0; padding: 0 20px; color: var(--dim); font-size: 13px; text-align: center; }
.smk-error { margin-top: 30px; padding: 14px 18px; border-radius: 14px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); font-weight: 700; }

/* ── ปุ่ม ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; font: 800 16px var(--f-body); text-decoration: none; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn-main { background: var(--stamp); color: var(--on-stamp); box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--stamp) 80%, transparent); }
.btn-main:hover { filter: brightness(1.06); }
.btn-ghost { background: var(--panel); color: var(--ink); border-color: var(--line2); }
.btn-ghost:hover { border-color: var(--stamp); }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px 0 8px; border-radius: 99px; border: 1px solid var(--line2); background: var(--panel); color: var(--ink2); font: 700 14px var(--f-body); cursor: pointer; }
.switch-knob { width: 38px; height: 22px; border-radius: 99px; background: var(--sunk); border: 1px solid var(--line2); position: relative; flex: none; transition: background .2s; }
.switch-knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.switch[aria-pressed="true"] { color: var(--strong); border-color: var(--stamp); }
.switch[aria-pressed="true"] .switch-knob { background: var(--stamp-soft); }
.switch[aria-pressed="true"] .switch-knob::after { transform: translateX(16px); background: var(--stamp); }

/* ── แถบล่าง ── */
.smk-dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 35; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); }
.smk-dock .wrap { display: flex; gap: 10px; justify-content: flex-end; }
.smk-dock .btn-main { min-width: 240px; }
@media (max-width: 560px) { .smk-dock .wrap { gap: 8px; } .smk-dock .btn { flex: 1; padding: 0 12px; font-size: 15px; } .smk-dock .btn-main { min-width: 0; flex: 1.6; } }

/* ══════════ รูปวิเคราะห์เป็นแผ่นใบลาน ══════════ */
.vik { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 6px; }
.leaf { display: inline-flex; align-items: center; min-height: 38px; padding: 3px 11px; border-radius: 9px; background: var(--panel2); border: 1px solid var(--line2); font-size: 18px; font-weight: 700; color: var(--strong); white-space: nowrap; line-height: 1.35; box-shadow: 0 1px 0 var(--line); }
.leaf.r-sig, .leaf.r-lead { background: color-mix(in srgb, var(--c) 16%, var(--panel)); border-color: color-mix(in srgb, var(--c) 60%, transparent); color: var(--c); font-weight: 800; }
.leaf.r-sig.trap { border-style: dashed; }
.leaf.r-front { border-bottom: 3px solid var(--c); }
.leaf.r-add { color: var(--muted); font-weight: 500; background: transparent; border-style: dashed; }
.vik.is-neutral .leaf.r-sig, .vik.is-neutral .leaf.r-lead { --c: var(--stamp); }
.vik.is-neutral .leaf.r-front { --c: var(--stamp); }
.vik-eq { font-weight: 800; color: var(--dim); padding: 0 2px; }
.leaf-word { background: var(--strong); color: var(--bg); border-color: var(--strong); }

/* ══════════ การ์ดพับคำ (ปฏิสัมพันธ์ประจำวิชา) ══════════ */
.fold { --c: var(--stamp); position: relative; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.fold::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.fold-face { all: unset; box-sizing: border-box; display: grid; grid-template-columns: 1fr auto; grid-template-areas: "w hint" "t ex"; align-items: center; gap: 2px 10px; width: 100%; min-height: 72px; padding: 12px 14px 12px 20px; cursor: pointer; position: relative; }
.fold-face:hover .fold-hint { color: var(--c); border-color: color-mix(in srgb, var(--c) 50%, transparent); }
.fold-face:focus-visible { outline: 3px solid var(--gold); outline-offset: -3px; border-radius: 16px; }
.fold-pleat { position: absolute; inset: 0 0 0 5px; pointer-events: none; background: repeating-linear-gradient(90deg, transparent 0 46px, color-mix(in srgb, var(--ink) 4%, transparent) 46px 47px); opacity: 1; transition: opacity .3s; }
.fold.is-open .fold-pleat { opacity: 0; }
.fold-word { grid-area: w; font-size: 22px; font-weight: 800; color: var(--strong); white-space: nowrap; line-height: 1.35; position: relative; }
.fold-trans { grid-area: t; font-size: 14px; color: var(--muted); line-height: 1.45; position: relative; }
.fold-hint { grid-area: hint; justify-self: end; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--line2); font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; position: relative; background: var(--panel); }
.fold-exam { grid-area: ex; justify-self: end; font-size: 12px; font-weight: 700; color: var(--gold); white-space: nowrap; position: relative; }
.fold-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .35s ease; }
.fold-in { min-height: 0; overflow: hidden; padding: 0 14px 0 20px; }
.fold.is-open .fold-body { grid-template-rows: 1fr; }
.fold.is-open .fold-in { padding-bottom: 14px; }
.fold:not(.is-open) .fold-in { visibility: hidden; }
.fold-body .vik { padding-top: 2px; }
.fold-body .leaf { font-size: 17px; min-height: 34px; padding: 2px 9px; }
.fold.is-open .fold-body .leaf { animation: leaf-open .42s cubic-bezier(.2, .8, .3, 1.1) both; animation-delay: calc(var(--i) * 70ms); transform-origin: left center; }
@keyframes leaf-open { from { opacity: 0; transform: perspective(300px) rotateY(-80deg) translateX(-8px); } to { opacity: 1; transform: none; } }
.fold-name { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; margin-top: 10px; }
.fold-sub { font-size: 15px; font-weight: 800; color: var(--c); white-space: nowrap; }
.fold-main { font-size: 15px; font-weight: 800; color: var(--strong); white-space: nowrap; }
.fold-note { margin: 8px 0 0; font-size: 13.5px; line-height: 1.6; color: var(--ink2); }
.fold-note i { color: var(--c); }
.fold.is-compact .fold-face { min-height: 60px; padding: 10px 12px 10px 18px; }
.fold.is-compact .fold-word { font-size: 20px; }
@media (max-width: 420px) { .fold-word { font-size: 20px; } .fold-hint span { display: none; } .fold-hint { padding: 0 9px; } }

/* ── ปีที่ออกสอบ ── */
.years { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.years-l { font-size: 12px; font-weight: 800; color: var(--gold); margin-right: 2px; white-space: nowrap; }
.year { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 99px; background: color-mix(in srgb, var(--gold) 14%, transparent); color: var(--ink2); white-space: nowrap; }
.years-none { font-size: 12px; color: var(--dim); }

/* ── ลูกโซ่ประจำชนิด (ชิปชื่อสมาส) ── */
.tchip { --c: var(--stamp); display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 2px 11px; border-radius: 99px; border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 10%, var(--panel)); color: var(--c); font-size: 14px; font-weight: 800; white-space: nowrap; }
.tchip i.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }

/* ── เลนส์/สปอตไลต์ชนิด ── */
.legend { display: flex; flex-wrap: wrap; gap: 8px; }
.leg { --c: var(--stamp); display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel); color: var(--ink2); font: 700 14px var(--f-body); cursor: pointer; white-space: nowrap; }
.leg i { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.leg b { color: var(--muted); font-weight: 700; }
.leg[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--panel)); color: var(--strong); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent); }

/* ══════════ ด่าน ๑ โครงสมาส ══════════ */
.demo { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; padding: 22px; }
.demo-strip { display: flex; align-items: stretch; gap: 0; }
.demo-step { --c: var(--t-tap); flex: 1; min-width: 0; position: relative; padding: 14px 14px 12px; border: 1px solid var(--line2); background: var(--panel2); }
.demo-step:first-child { border-radius: 14px 0 0 14px; }
.demo-step:last-child { border-radius: 0 14px 14px 0; background: color-mix(in srgb, var(--c) 10%, var(--panel)); border-color: color-mix(in srgb, var(--c) 50%, transparent); }
.demo-step + .demo-step { border-left: 0; }
.demo-step .n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--stamp); color: var(--on-stamp); font-size: 12px; font-weight: 800; }
.demo-step .nm { font-size: 13px; font-weight: 800; color: var(--muted); margin-left: 6px; }
.demo-step .tx { display: block; margin-top: 8px; font-size: 22px; font-weight: 800; color: var(--strong); white-space: nowrap; }
.demo-step .nt { display: block; margin-top: 4px; font-size: 13.5px; color: var(--ink2); line-height: 1.5; }
.demo-step:not(:last-child)::after { content: ""; position: absolute; right: -11px; top: 50%; width: 20px; height: 20px; margin-top: -10px; background: var(--panel); border: 1px solid var(--line2); border-left: 0; border-bottom: 0; transform: rotate(45deg); z-index: 2; }
.demo-play { display: flex; gap: 10px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.demo-story { margin: 14px 0 0; font-size: 15px; line-height: 1.75; color: var(--ink2); }
.demo-side { display: flex; flex-direction: column; gap: 12px; }
.demo-side .fold { flex: none; }
.summary-line { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--stamp-soft); color: var(--strong); font-size: 14.5px; line-height: 1.65; }
.summary-line b { color: var(--stamp); }
@media (max-width: 900px) { .demo { grid-template-columns: 1fr; padding: 16px; } }
@media (max-width: 620px) {
	.demo-strip { flex-direction: column; }
	.demo-step:first-child { border-radius: 14px 14px 0 0; } .demo-step:last-child { border-radius: 0 0 14px 14px; }
	.demo-step + .demo-step { border-left: 1px solid var(--line2); border-top: 0; }
	.demo-step:not(:last-child)::after { right: auto; left: 50%; top: auto; bottom: -11px; margin: 0 0 0 -10px; transform: rotate(135deg); }
	.demo-step .tx { font-size: 20px; }
}

.tree { padding: 22px; }
.tree-root { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 1px dashed var(--line2); }
.tree-root .seal { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 12px; background: var(--stamp); color: var(--on-stamp); font-size: 18px; font-weight: 800; white-space: nowrap; }
.tree-root p { margin: 0; flex: 1 1 320px; color: var(--ink2); font-size: 15px; line-height: 1.7; }
.tree-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2.1fr); gap: 22px; padding-top: 18px; }
.tree-col h3 { margin: 0 0 10px; font-size: 16px; font-weight: 800; color: var(--strong); display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tree-col h3 .big { font-size: 30px; color: var(--stamp); line-height: 1; }
.tree-col h3 small { font-size: 13px; color: var(--muted); font-weight: 600; }
.kija { display: grid; gap: 10px; }
.kija-i { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); }
.kija-i b { display: block; font-size: 16px; color: var(--strong); }
.kija-i b .pali { font-weight: 700; color: var(--muted); font-size: 15px; }
.kija-i p { margin: 4px 0 0; font-size: 14px; color: var(--ink2); line-height: 1.6; }
.kija-i .ex { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.kija-i .ex .leaf { font-size: 16px; min-height: 32px; }
.names { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.name-c { --c: var(--stamp); position: relative; display: grid; grid-template-columns: auto 1fr; grid-template-areas: "syl nm" "syl pl" "ct ct"; gap: 0 10px; align-items: center; padding: 12px 12px 12px 14px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--c) 35%, var(--line)); background: color-mix(in srgb, var(--c) 7%, var(--panel)); }
.name-c .syl { grid-area: syl; width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--c); color: var(--panel); font-size: 17px; font-weight: 800; white-space: nowrap; }
.name-c .nm { grid-area: nm; font-size: 16px; font-weight: 800; color: var(--strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name-c .pl { grid-area: pl; font-size: 14px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.name-c .ct { grid-area: ct; margin-top: 8px; font-size: 13px; color: var(--ink2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.name-c .ct b { color: var(--c); font-size: 15px; }
.memo-line { margin: 14px 0 0; text-align: center; font-size: 15px; color: var(--muted); }
.memo-line b { color: var(--stamp); font-size: 18px; letter-spacing: .04em; }
@media (max-width: 900px) { .tree-cols { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .names { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tree { padding: 16px; } }
@media (max-width: 560px) { .names { grid-template-columns: 1fr; } .name-c { grid-template-areas: "syl nm ct" "syl pl ct"; grid-template-columns: auto 1fr auto; } .name-c .ct { margin-top: 0; flex-direction: column; align-items: flex-end; gap: 0; text-align: right; } }

.stories { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.story { --c: var(--stamp); display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-top: 4px solid var(--c); }
.story-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.story-n { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: var(--panel); font-size: 14px; font-weight: 800; flex: none; }
.story-kind { font-size: 13px; font-weight: 800; color: var(--c); white-space: nowrap; }
.story h3 { margin: 0; font-size: 18px; font-weight: 800; color: var(--strong); }
.story-ask { margin: 0; font-size: 15.5px; line-height: 1.6; color: var(--ink); font-weight: 600; }
.story .fold { box-shadow: none; border-color: var(--line2); }
.story-tip { margin-top: 16px; }
@media (max-width: 900px) { .stories { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .stories { grid-template-columns: 1fr; } }

/* ══════════ ด่าน ๒ ตัวชี้ ══════════ */
.board { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.sigs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sig { --c: var(--stamp); all: unset; box-sizing: border-box; display: flex; flex-direction: column; gap: 6px; padding: 14px; min-height: 104px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); cursor: pointer; position: relative; }
.sig::before { content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 3px; border-radius: 0 0 3px 3px; background: var(--c); }
.sig:hover { border-color: color-mix(in srgb, var(--c) 50%, transparent); }
.sig[aria-pressed="true"] { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent), var(--shadow); }
.sig:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sig-cue { font-size: 16px; font-weight: 800; color: var(--c); line-height: 1.45; }
.sig-to { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; color: var(--strong); margin-top: auto; }
.sig-to i { color: var(--dim); font-size: 12px; }
.sig-n { font-size: 12px; color: var(--muted); font-weight: 700; }
.detail { position: sticky; top: 72px; padding: 18px; }
.detail h3 { margin: 0; font-size: 18px; color: var(--strong); }
.detail .d-cue { display: inline-block; margin-top: 6px; font-size: 20px; font-weight: 800; color: var(--c); }
.detail p { margin: 8px 0 0; font-size: 14.5px; color: var(--ink2); line-height: 1.7; }
.detail .d-list { display: grid; gap: 10px; margin-top: 14px; max-height: 520px; overflow: auto; padding-right: 2px; }
.detail .d-empty { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--sunk); color: var(--muted); font-size: 14px; }
.pron { margin-top: 16px; padding: 14px 16px; border-radius: 14px; background: color-mix(in srgb, var(--t-bahu) 8%, var(--panel)); border: 1px solid color-mix(in srgb, var(--t-bahu) 30%, var(--line)); font-size: 15px; line-height: 1.75; color: var(--ink2); }
.pron b { color: var(--t-bahu); }
@media (max-width: 960px) { .board { grid-template-columns: 1fr; } .detail { position: static; } .detail .d-list { max-height: none; } }
@media (max-width: 640px) { .sigs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 360px) { .sigs { grid-template-columns: 1fr; } }

/* ══════════ ด่าน ๓ ลำดับดูตัวชี้ + คู่สับสน ══════════ */
.flow { display: grid; gap: 0; padding: 8px 0; }
.fstep { --c: var(--stamp); display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 18px; position: relative; }
.fstep + .fstep { border-top: 1px dashed var(--line2); }
.fnum { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: var(--panel); font-weight: 800; font-size: 17px; }
.fq { min-width: 0; }
.fq b { font-size: 17px; color: var(--strong); }
.fq .pali { display: block; font-size: 15px; color: var(--c); font-weight: 700; margin-top: 2px; }
.fq small { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.fout { display: inline-flex; align-items: center; gap: 8px; }
.fout i { color: var(--dim); }
@media (max-width: 560px) { .fstep { grid-template-columns: 40px minmax(0, 1fr); padding: 12px 14px; } .fout { grid-column: 2; } }
.flow-tip { margin: 12px 0 0; font-size: 14.5px; color: var(--muted); }
.traps { display: grid; gap: 18px; }
.trap { padding: 20px; }
.trap h3 { margin: 0; font-size: 19px; font-weight: 800; color: var(--strong); }
.trap > p { margin: 6px 0 0; font-size: 15px; color: var(--ink2); line-height: 1.7; max-width: 80ch; }
.vs { display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); gap: 10px; margin-top: 16px; align-items: stretch; }
.vs-mid { display: grid; place-items: center; font-weight: 800; color: var(--dim); font-size: 14px; }
.side { --c: var(--stamp); display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 14px; background: color-mix(in srgb, var(--c) 7%, var(--panel)); border: 1px solid color-mix(in srgb, var(--c) 35%, var(--line)); }
.side-label { font-size: 16px; font-weight: 800; color: var(--c); }
.side-rule { display: inline-flex; align-self: flex-start; padding: 4px 12px; border-radius: 10px; background: var(--c); color: var(--panel); font-weight: 800; font-size: 14.5px; }
.side-why { margin: 0; font-size: 14px; color: var(--ink2); line-height: 1.6; }
.side .fold { box-shadow: none; }
@media (max-width: 760px) { .vs { grid-template-columns: 1fr; } .vs-mid { padding: 2px 0; } .trap { padding: 16px; } }

/* ══════════ ด่าน ๔ ตู้คำสมาส ══════════ */
.gal-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.gal { display: grid; gap: 26px; }
.gal-g { --c: var(--stamp); }
.gal-g[hidden] { display: none; }
.gal-h { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 2px solid color-mix(in srgb, var(--c) 40%, transparent); }
.gal-h h3 { margin: 0; font-size: 21px; font-weight: 800; color: var(--c); }
.gal-h span { font-size: 14px; color: var(--muted); }
.gal-def { margin: 0 0 12px; font-size: 14.5px; color: var(--ink2); line-height: 1.7; max-width: 90ch; }
.gal-sub { margin-top: 12px; }
.gal-sub-h { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.gal-sub-h b { font-size: 15.5px; color: var(--strong); }
.gal-sub-h span { font-size: 13.5px; color: var(--muted); }
.gal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-items: start; }
@media (max-width: 960px) { .gal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .gal-grid { grid-template-columns: 1fr; } }

/* ══════════ ด่าน ๕ ตารางข้อสอบจริง ══════════ */
.xt { display: grid; gap: 10px; }
.xr { --c: var(--stamp); display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; align-items: center; padding: 14px 16px; border-left: 5px solid var(--c); }
.xr .vik .leaf { font-size: 17px; }
.xr-a { min-width: 0; }
.xr-name { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.xr-name .s { font-size: 16px; font-weight: 800; color: var(--c); white-space: nowrap; }
.xr-name .m { font-size: 16px; font-weight: 800; color: var(--strong); white-space: nowrap; }
.xr .years { margin-top: 6px; }
.xr-a.hide .xr-name { filter: blur(7px); user-select: none; }
.xr-a .peek-btn { display: none; }
.xr-a.hide .peek-btn { display: inline-flex; margin-top: 6px; }
.xt-tools { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 720px) { .xr { grid-template-columns: 1fr; gap: 8px; } }
.namerule { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.nr { padding: 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.nr b { display: block; font-size: 13px; color: var(--muted); font-weight: 700; }
.nr span { display: block; margin-top: 2px; font-size: 18px; font-weight: 800; color: var(--strong); }
.nr.eq span { color: var(--stamp); }
@media (max-width: 640px) { .namerule { grid-template-columns: 1fr; } }

/* ══════════ ด่าน ๖ คำตอบสนามหลวง ══════════ */
.qa-list { display: grid; gap: 12px; }
.qa { padding: 16px 18px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.qa.is-known { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.qa-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.qa-topic { font-size: 13px; font-weight: 800; color: var(--stamp); }
.qa-q { margin: 8px 0 0; font-size: 17px; font-weight: 800; color: var(--strong); line-height: 1.6; }
.qa-a { margin: 8px 0 0; font-size: 16px; color: var(--ink); line-height: 1.85; padding: 10px 12px; border-radius: 12px; background: var(--panel2); cursor: default; }
.qa-list.recite .qa-a { filter: blur(6px); cursor: pointer; user-select: none; }
.qa-list.recite .qa-a.peek { filter: none; }
.qa-known { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--ink2); cursor: pointer; }
.qa-known input { width: 20px; height: 20px; accent-color: var(--ok); }
.toc { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.toc a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line2); background: var(--panel); text-decoration: none; font-size: 14px; font-weight: 700; color: var(--ink2); white-space: nowrap; }
.toc a:hover { border-color: var(--stamp); color: var(--strong); }
.meter { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.meter b { font-size: 14px; color: var(--ink2); white-space: nowrap; }
.meter-bar { flex: 1 1 200px; height: 10px; border-radius: 99px; background: var(--sunk); overflow: hidden; border: 1px solid var(--line); }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 99px; transition: width .3s; }

/* ══════════ ด่าน ๗ ตั้งวิเคราะห์ ══════════ */
.method { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding: 0; overflow: hidden; }
.mstep { padding: 18px 16px; position: relative; }
.mstep + .mstep { border-left: 1px dashed var(--line2); }
.mstep .n { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--stamp); color: var(--on-stamp); font-weight: 800; }
.mstep b { display: block; margin-top: 8px; font-size: 17px; color: var(--strong); }
.mstep p { margin: 4px 0 0; font-size: 14px; color: var(--ink2); line-height: 1.6; }
@media (max-width: 860px) { .method { grid-template-columns: repeat(2, minmax(0, 1fr)); } .mstep:nth-child(3) { border-left: 0; } .mstep:nth-child(n+3) { border-top: 1px dashed var(--line2); } }
@media (max-width: 480px) { .method { grid-template-columns: 1fr; } .mstep + .mstep { border-left: 0; border-top: 1px dashed var(--line2); } }
.detect { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; padding: 20px; }
.detect-steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; counter-reset: d; }
.detect-steps li { counter-increment: d; display: grid; grid-template-columns: 32px 1fr; gap: 10px; align-items: start; }
.detect-steps li::before { content: counter(d, thai); width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--t-tap); color: var(--panel); font-weight: 800; font-size: 14px; }
.detect-steps b { display: block; font-size: 15.5px; color: var(--strong); }
.detect-steps span { font-size: 15px; color: var(--ink2); }
@media (max-width: 760px) { .detect { grid-template-columns: 1fr; padding: 16px; } }
.guess-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 960px) { .guess-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px) { .guess-grid { grid-template-columns: 1fr; } }
.guess-grid.is-guess .fold:not(.is-open) .fold-trans { visibility: visible; }

/* ══════════ ด่าน ๙ คลังการ์ด ══════════ */
.deck { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1000px) { .deck { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .deck { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 400px) { .deck { grid-template-columns: 1fr; } }
.dcard { --c: var(--stamp); position: relative; min-height: 210px; perspective: 900px; }
.dcard-in { all: unset; box-sizing: border-box; display: block; position: relative; width: 100%; height: 100%; min-height: 210px; cursor: pointer; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .7, .3, 1); border-radius: 16px; }
.dcard.flip .dcard-in { transform: rotateY(180deg); }
.dcard-in:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.dface { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 6px; padding: 16px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.dface::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--c); }
.dfront { justify-content: center; align-items: center; text-align: center; }
.dfront .w { font-size: 24px; font-weight: 800; color: var(--strong); white-space: nowrap; }
.dfront .t { font-size: 14px; color: var(--muted); line-height: 1.5; }
.dfront .k { position: absolute; top: 14px; left: 14px; font-size: 12px; font-weight: 800; color: var(--c); }
.dfront .e { position: absolute; top: 14px; right: 14px; font-size: 12px; font-weight: 800; color: var(--gold); }
.dfront .h { position: absolute; bottom: 12px; left: 0; right: 0; font-size: 12px; color: var(--dim); }
.dback { transform: rotateY(180deg); background: color-mix(in srgb, var(--c) 6%, var(--panel)); }
.dback .vik { gap: 4px; }
.dback .vik .leaf { font-size: 15px; min-height: 30px; padding: 1px 7px; }
.dback .nm { margin-top: 6px; font-size: 14.5px; font-weight: 800; color: var(--c); line-height: 1.4; }
.dback .t { font-size: 13.5px; color: var(--ink2); line-height: 1.5; }
.dback .years { margin-top: auto; }
.dknown { display: flex; align-items: center; gap: 8px; min-height: 40px; margin-top: 6px; font-size: 14px; font-weight: 700; color: var(--ink2); cursor: pointer; }
.dknown input { width: 20px; height: 20px; accent-color: var(--ok); }
.dcard.is-known .dfront { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.deck-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; }

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation: none !important; transition: none !important; }
}
.d-empty { padding: 14px; border-radius: 12px; background: var(--sunk); color: var(--muted); font-size: 14px; text-align: center; }

/* สีประจำชนิดต้องชนะค่า --c ตั้งต้นของทุกส่วนประกอบ (ประกาศซ้ำท้ายไฟล์ + เพิ่มน้ำหนัก) */
[data-main="kam"][data-main] { --c: var(--t-kam); } [data-main="digu"][data-main] { --c: var(--t-digu); } [data-main="tap"][data-main] { --c: var(--t-tap); }
[data-main="dvan"][data-main] { --c: var(--t-dvan); } [data-main="aby"][data-main] { --c: var(--t-aby); } [data-main="bahu"][data-main] { --c: var(--t-bahu); }
/* ตู้คำ: ชนิดย่อยเรียงแบบก่ออิฐ (ไม่มีช่องว่างเมื่อชนิดย่อยมีคำเดียว) */
.gal-subs { columns: 3 280px; column-gap: 12px; }
.gal-sub { break-inside: avoid; margin: 0 0 12px; padding: 12px; border-radius: 14px; background: color-mix(in srgb, var(--c) 5%, var(--panel2)); border: 1px solid color-mix(in srgb, var(--c) 22%, var(--line)); }
.gal-sub .gal-grid { grid-template-columns: 1fr; gap: 8px; }
.gal-sub .fold { box-shadow: none; }
.smk-lead b { white-space: nowrap; }
.name-c .ct-n { white-space: nowrap; }
.dcard, .dcard-in { min-height: 236px; }
.dback { overflow-y: auto; }
/* อัญญบทหลังพหุพพิหิสมาส (เช่น อาคตสมโณ (อาราโม)) — เล็กกว่าและเบากว่าคำสมาส แต่ยังเป็นตัวบาลี
   แต่ละชิ้นห้ามตัดกลางคำ แต่ขึ้นบรรทัดใหม่ระหว่างคำสมาสกับอัญญบทได้ (จอแคบ) */
.has-anya { white-space: normal !important; }
.has-anya .aw, .anya { white-space: nowrap; }
.anya { font-size: .74em; font-weight: 700; color: var(--muted); }
.anya .pali { color: inherit; font-weight: 800; }
.leaf-word .anya { color: inherit; opacity: .75; }
