/* =============================================
   คู่มือแปลมคธเป็นไทย — หน้าอ่าน (/handbook/)
   ธีมเดียวกับทั้งเว็บ: คราม-ทอง · โหมดสว่าง/มืดตาม <html data-ui> (ชุดเดียวกับ /principle/)
   สีมีความหมาย: ม่วง = บาลี · ดำ = คำแปล · อำพัน = ส่วนที่เล่มเน้น (คำสอนของหัวข้อนั้น)
   ============================================= */

@font-face {
	font-family: 'THSarabunPali';
	src: url('/assets/fonts/thsarabun/THSarabunPaliCut.ttf?v=20260823.1') format('truetype');   /* ฐ ญ บาลีไม่มีเชิง */
	font-display: swap;
}

:root {
	--hb-paper:      #f5f7fc;
	--hb-paper-rgb:  245, 247, 252;
	--hb-paper2:     #eef1f8;
	--hb-card:       #ffffff;
	--hb-ink:        #141a33;
	--hb-ink-soft:   #3b4560;
	--hb-ink-faint:  #5d6683;
	--hb-line:       rgba(20, 26, 51, .12);
	--hb-line-soft:  rgba(20, 26, 51, .07);
	--hb-brand:      #4338ca;
	--hb-brand-deep: #312e81;
	--hb-brand-soft: #eef2ff;
	--hb-brand-line: rgba(79, 70, 229, .28);
	--hb-pali:       #5b21b6;
	--hb-key:        #9c430a;   /* ส่วนที่เล่มเน้น */
	--hb-key-soft:   rgba(245, 191, 69, .28);
	--hb-gold:       #d4a017;
	--hb-ok:         #0f766e;
	--hb-ok-soft:    #e7f8f4;
	--hb-on-brand:   #ffffff;
	--hb-radius:     14px;
	--hb-shadow:     0 1px 2px rgba(20, 26, 51, .05), 0 10px 26px -16px rgba(20, 26, 51, .3);
	--hb-bar-h:      58px;
	--hb-scale:      1;
	color-scheme: light;
}
html[data-ui="dark"] {
	--hb-paper:      #0a0f1e;
	--hb-paper-rgb:  10, 15, 30;
	--hb-paper2:     #0f1730;
	--hb-card:       #131c38;
	--hb-ink:        #f3f6ff;
	--hb-ink-soft:   #c9d1e8;
	--hb-ink-faint:  #8b95b3;
	--hb-line:       rgba(255, 255, 255, .11);
	--hb-line-soft:  rgba(255, 255, 255, .06);
	--hb-brand:      #a5b4fc;
	--hb-brand-deep: #c7d2fe;
	--hb-brand-soft: rgba(129, 140, 248, .14);
	--hb-brand-line: rgba(165, 180, 252, .3);
	--hb-pali:       #d4bbff;
	--hb-key:        #fcd34d;
	--hb-key-soft:   rgba(245, 191, 69, .16);
	--hb-gold:       #f5bf45;
	--hb-ok:         #5eead4;
	--hb-ok-soft:    rgba(20, 184, 166, .12);
	--hb-on-brand:   #0a0f1e;
	--hb-shadow:     0 1px 2px rgba(0, 0, 0, .3), 0 14px 30px -18px rgba(0, 0, 0, .9);
	color-scheme: dark;
}

/* ---------- พื้นฐาน (กันสไตล์ของแม่แบบเดิมที่โหลดมากับ doctype_public) ---------- */
html, body.hb { background: var(--hb-paper); }
body.hb {
	margin: 0; color: var(--hb-ink);
	font-family: 'Sarabun', 'Noto Sans Thai', system-ui, sans-serif;
	font-size: max(var(--hb-prose-min, 16px), calc(16px * var(--hb-scale))); line-height: 1.6;
	-webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
.hb *, .hb *::before, .hb *::after { box-sizing: border-box; }
.hb ::selection { background: rgba(245, 191, 69, .38); color: var(--hb-ink); }
.hb :focus-visible { outline: 3px solid #f5bf45; outline-offset: 2px; }
.hb a { color: var(--hb-brand); }
.hb h1, .hb h2, .hb h3 { color: var(--hb-ink); font-family: inherit; }
.hb button { font-family: inherit; }
.pt-topnav-scope { position: relative; z-index: 60; }

/* ---------- แถบเครื่องมือ (ติดบนเมื่อเลื่อน) ---------- */
.hb-bar {
	position: sticky; top: 0; z-index: 40;
	height: var(--hb-bar-h);
	display: flex; align-items: center; gap: 12px;
	padding: 0 16px;
	background: rgba(var(--hb-paper-rgb), .92);
	backdrop-filter: saturate(180%) blur(10px);
	-webkit-backdrop-filter: saturate(180%) blur(10px);
	border-bottom: 1px solid var(--hb-line);
}
.hb-bar-title {
	display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto;
	color: inherit !important; text-decoration: none; line-height: 1.3;
}
.hb-bar-book { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-bar-sub { color: var(--hb-ink-faint); font-weight: 400; }
.hb-bar-chapter {
	font-size: max(14px, .84em); color: var(--hb-ink-faint);
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hb-bar-title:hover .hb-bar-book { color: var(--hb-brand); }
.hb-bar-tools { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.hb-icon {
	display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
	width: 38px; height: 38px; padding: 0;
	border: 1px solid var(--hb-line); border-radius: 10px;
	background: var(--hb-card); color: var(--hb-ink-soft);
	cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.hb-icon i { font-size: max(14px, calc(1.2rem * var(--hb-scale))); }
.hb-icon:hover { background: var(--hb-brand-soft); color: var(--hb-brand); border-color: var(--hb-brand-line); }
.hb-icon:disabled { opacity: .35; cursor: default; pointer-events: none; }
.hb-icon.is-on { background: var(--hb-brand); border-color: var(--hb-brand); color: var(--hb-on-brand); }

.hb-search-btn {
	display: inline-flex; align-items: center; gap: 8px;
	height: 38px; min-width: 210px; padding: 0 10px 0 12px;
	border: 1px solid var(--hb-line); border-radius: 10px;
	background: var(--hb-card); color: var(--hb-ink-faint);
	font-size: max(14px, calc(0.92rem * var(--hb-scale))); cursor: pointer;
}
.hb-search-btn span { flex: 1; text-align: left; }
.hb-search-btn kbd {
	font: 600 .72rem/1 'Sarabun', sans-serif; color: var(--hb-ink-faint);
	border: 1px solid var(--hb-line); border-radius: 5px; padding: 3px 6px; background: var(--hb-paper2);
}
.hb-search-btn:hover { border-color: var(--hb-brand-line); color: var(--hb-brand); }

/* ---------- แผงตั้งค่า ---------- */
.hb-settings-wrap { position: relative; }
.hb-settings {
	position: absolute; top: calc(100% + 10px); right: 0; z-index: 61;
	width: min(330px, calc(100vw - 24px));
	padding: 6px 16px; border: 1px solid var(--hb-line); border-radius: 16px;
	background: var(--hb-card); box-shadow: 0 18px 40px -16px rgba(10, 15, 30, .45);
}
.hb-set-row {
	display: flex; align-items: center; justify-content: space-between; gap: 14px;
	padding: 12px 0; margin: 0; cursor: pointer;
}
.hb-set-row + .hb-set-row { border-top: 1px solid var(--hb-line-soft); }
.hb-set-copy strong { display: block; font-size: max(14px, calc(0.95rem * var(--hb-scale))); color: var(--hb-ink); }
.hb-set-copy p { margin: 2px 0 0; font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); color: var(--hb-ink-faint); line-height: 1.6; }
.hb-stepper { display: inline-flex; align-items: center; border-radius: 10px; background: var(--hb-paper2); padding: 3px; }
.hb-stepper button {
	width: 38px; height: 32px; border: 0; border-radius: 8px; background: transparent;
	color: var(--hb-ink-soft); font-weight: 700; cursor: pointer;
}
.hb-stepper button:hover { background: var(--hb-card); color: var(--hb-brand); }
.hb-stepper output { min-width: 48px; text-align: center; font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 600; color: var(--hb-ink); }
.hb-switch {
	appearance: none; -webkit-appearance: none; flex: 0 0 auto;
	width: 44px; height: 26px; border-radius: 99px; margin: 0;
	background: var(--hb-line); position: relative; cursor: pointer; transition: background .15s;
}
.hb-switch::after {
	content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
	background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .15s;
}
.hb-switch:checked { background: var(--hb-brand); }
.hb-switch:checked::after { transform: translateX(18px); }

/* ---------- โครงหน้า: สารบัญข้าง + เนื้อหา ---------- */
.hb-shell { display: block; }
.hb-main { min-width: 0; }
.hb-page { max-width: 800px; margin: 0 auto; padding: 30px 22px 60px; }

.hb-toc {
	position: fixed; top: 0; bottom: 0; left: 0; z-index: 71;
	width: min(88vw, 350px);
	display: flex; flex-direction: column;
	background: var(--hb-card); border-right: 1px solid var(--hb-line);
	transform: translateX(-104%); transition: transform .22s ease;
	box-shadow: 8px 0 30px rgba(10, 15, 30, .2);
}
.hb-toc.is-open { transform: none; }
.hb-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(10, 15, 30, .45); }

@media (min-width: 1180px) {
	/* จอกว้าง: สารบัญติดข้างซ้ายตลอดเมื่ออ่านบท (หน้าปกมีสารบัญเต็มในหน้าแล้ว สารบัญข้างจึงเป็นลิ้นชักตามเดิม) */
	body:not(.hb-at-home) .hb-shell { display: grid; grid-template-columns: 360px minmax(0, 1fr); }
	body:not(.hb-at-home) .hb-toc {
		position: sticky; top: var(--hb-bar-h); z-index: 5; height: calc(100vh - var(--hb-bar-h));
		width: auto; transform: none; box-shadow: none; background: transparent;
	}
	body:not(.hb-at-home) .hb-toc-part { background: var(--hb-paper); }
	body:not(.hb-at-home) .hb-toc-close,
	body:not(.hb-at-home) #hbMenu,
	body:not(.hb-at-home) .hb-scrim { display: none; }
}

.hb-toc-head {
	display: flex; align-items: center; gap: 8px;
	padding: 12px 12px 10px; border-bottom: 1px solid var(--hb-line-soft);
}
.hb-toc-tabs { display: flex; gap: 4px; flex: 1; padding: 3px; border-radius: 11px; background: var(--hb-paper2); }
.hb-toc-tabs button {
	flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
	min-height: 44px; padding: 8px; border: 0; border-radius: 8px; background: transparent;
	color: var(--hb-ink-faint); font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); line-height: 1.6; font-weight: 600; cursor: pointer;
}
.hb-toc-tabs button.is-on { background: var(--hb-card); color: var(--hb-brand); box-shadow: 0 1px 3px rgba(20, 26, 51, .12); }
.hb-count:not(:empty) {
	min-width: 20px; padding: 0 6px; border-radius: 99px; line-height: 18px; font-size: max(14px, calc(0.875rem * var(--hb-scale)));
	background: var(--hb-brand-soft); color: var(--hb-brand);
}
.hb-toc-list { flex: 1; overflow-y: auto; padding: 4px 0 18px; overscroll-behavior: contain; scrollbar-width: thin; }
.hb-toc-part {
	position: sticky; top: 0; z-index: 1;
	display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
	padding: 18px 20px 10px; background: var(--hb-card);
	font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); line-height: 1.6; font-weight: 700; color: var(--hb-key);
}
.hb-toc-part small { font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 500; color: var(--hb-ink-faint); }
.hb-toc-item {
	display: flex; align-items: flex-start; gap: 10px; width: calc(100% - 16px); min-height: 48px; margin: 3px 8px;
	padding: 10px 12px; border: 0; background: none; text-align: left;
	color: var(--hb-ink-soft); font-size: max(var(--hb-prose-min, 16px), calc(1.0625rem * var(--hb-scale))); line-height: 1.6; text-decoration: none !important;
	border-radius: 8px; cursor: pointer; overflow-wrap: anywhere;
}
.hb-toc-item:hover { background: var(--hb-brand-soft); color: var(--hb-brand); }
.hb-toc-item .no { flex: 0 0 auto; padding-top: 1px; }
.hb-toc-item .t { flex: 1; min-width: 0; }
.hb-toc-item .done { flex: 0 0 auto; color: var(--hb-ok); font-size: max(14px, calc(0.95rem * var(--hb-scale))); padding-top: 2px; }
.hb-toc-item.is-cur { background: var(--hb-brand-soft); color: var(--hb-brand-deep); font-weight: 700; }
.hb-toc-item.is-cur .no { color: var(--hb-brand); }
.hb-toc-sub { display: none; padding: 2px 8px 12px; }
.hb-toc-item.is-cur + .hb-toc-sub { display: block; }
.hb-toc-sub a {
	display: flex; align-items: center; min-height: 44px; margin: 3px 0; padding: 9px 12px 9px 24px;
	font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); line-height: 1.6; border-radius: 8px; overflow-wrap: anywhere;
	color: var(--hb-ink-faint); text-decoration: none;
}
.hb-toc-sub a.lv4 { padding-left: 38px; }
.hb-toc-sub a:hover, .hb-toc-sub a.is-here { background: var(--hb-brand-soft); color: var(--hb-brand-deep); }
.hb-toc a:focus-visible, .hb-toc button:focus-visible { outline: 2px solid var(--hb-brand); outline-offset: -2px; }
.hb-toc-sub a.is-here { font-weight: 700; }
/* กลับหน้าหลักการแปล — บนสุดของเมนูสารบัญ (หลวงพี่สั่ง ๑๒ ต.ค. ให้ไอคอนเมนูอยู่ซ้ายสุดของแถบ) */
.hb-toc-exit {
	display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 12px 20px;
	border-bottom: 1px solid var(--hb-line-soft); color: var(--hb-ink-soft) !important;
	font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); line-height: 1.6; font-weight: 600; text-decoration: none;
}
.hb-toc-exit:hover { color: var(--hb-brand) !important; }
.hb-toc-empty { padding: 26px 20px; text-align: center; color: var(--hb-ink-faint); font-size: max(14px, calc(0.9rem * var(--hb-scale))); line-height: 1.7; }
.hb-toc-empty i { display: block; font-size: max(14px, calc(1.8rem * var(--hb-scale))); margin-bottom: 6px; color: var(--hb-brand-line); }

/* ---------- เนื้อหนังสือ ---------- */
.hb-chapter { font-size: max(var(--hb-prose-min, 16px), calc(17px * var(--hb-scale))); line-height: 1.9; }
.hb-sec { scroll-margin-top: calc(var(--hb-bar-h) + 14px); }
.hb-sec + .hb-sec { margin-top: 2.1em; }
.hb-head { display: flex; align-items: flex-start; gap: 10px; }
.hb-head .hb-h { flex: 1; min-width: 0; }
.hb-h { margin: 0 0 .5em; line-height: 1.35; font-weight: 800; color: var(--hb-ink); }
h1.hb-h { font-size: 1.85em; letter-spacing: -.005em; }
h2.hb-h { font-size: 1.32em; }
.hb-sec.lv4 h2.hb-h { font-size: 1.15em; }
.hb-sec.lv3, .hb-sec.lv4 { padding-top: 1.4em; border-top: 1px solid var(--hb-line-soft); }
/* หัวข้อนำ (ไม่มีเนื้อความ — เล่มใช้ขึ้นต้นหัวข้อถัดไป) ชิดกับหัวข้อที่มันนำ */
.hb-sec.is-lead .hb-h { margin-bottom: 0; }
.hb-sec.is-lead + .hb-sec { margin-top: .5em; padding-top: 0; border-top: 0; }
.hb-sec-tools { display: flex; gap: 4px; padding-top: .25em; }
.hb-sec-tools .hb-icon { width: 34px; height: 34px; border-color: transparent; background: transparent; color: var(--hb-ink-faint); }
.hb-sec-tools .hb-icon:hover { background: var(--hb-brand-soft); color: var(--hb-brand); }
.hb-sec-tools .hb-icon.is-marked { color: var(--hb-gold); }
.hb-sec-tools .hb-icon.is-marked i::before { content: "\fa88"; }   /* ti-bookmark-filled */

.hb-inthis {
	margin: .4em 0 1.6em; padding: 12px 14px; border-radius: 12px;
	background: var(--hb-paper2); font-size: 1em; line-height: 1.6;
}
.hb-inthis strong { display: block; margin-bottom: 4px; font-size: .88em; color: var(--hb-ink-faint); font-weight: 700; }
.hb-inthis ol { margin: 0; padding-left: 0; columns: 2 15em; column-gap: 2em; list-style: none; }
.hb-inthis li { break-inside: avoid; }
.hb-inthis a { color: var(--hb-brand); text-decoration: none; }
.hb-inthis a:hover { text-decoration: underline; }

.hb-body { color: var(--hb-ink); }
.hb-body p { margin: 0 0 .85em; }
.hb-body ul { margin: 0 0 1em; padding-left: 1.3em; }
.hb-body li { margin-bottom: .3em; }
.hb-body strong { font-weight: 700; color: var(--hb-key); }
.hb-body u { text-decoration-color: var(--hb-gold); text-decoration-thickness: 2px; text-underline-offset: 4px; }

/* ตัวอย่าง: บาลี + คำแปลอยู่ในการ์ดเดียวกัน (ไม่ใช้แถบสีขอบซ้าย) */
.hb-ex {
	margin: .9em 0 1.1em; padding: .55em 1em .6em;
	border: 1px solid var(--hb-line); border-radius: 12px; background: var(--hb-card);
	box-shadow: 0 1px 2px rgba(20, 26, 51, .04);
}
.hb-pali {
	font-family: 'THSarabunPali', 'Sarabun', serif;
	font-size: 1.6em; line-height: 1.6; color: var(--hb-pali);
}
.hb-pali + .hb-pali { margin-top: .15em; }
.hb-gloss { color: var(--hb-ink); line-height: 1.8; }
.hb-pali + .hb-gloss { margin-top: .35em; padding-top: .45em; border-top: 1px dashed var(--hb-line); }
.hb-gloss + .hb-gloss { margin-top: .2em; }
.hb-pali strong, .hb-gloss strong {
	color: inherit; font-weight: 700;
	background: var(--hb-key-soft); border-radius: 4px; padding: 0 .12em;
	box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.hb-gloss strong { color: var(--hb-ink); }

/* ศัพท์คำเดียว: คู่บาลี–ไทยขนาดตามเนื้อหา เรียงต่อกันและตัดแถวได้ */
.hb-terms { display: flex; flex-wrap: wrap; align-items: stretch; gap: .65em; margin: .9em 0 1.1em; }
.hb-terms .hb-ex { flex: 0 1 auto; min-width: min(100%, 8rem); max-width: 100%; margin: 0; padding: .35em .8em .45em; overflow-wrap: anywhere; }
.hb-terms .hb-pali + .hb-gloss { margin-top: 0; padding-top: 0; border-top: 0; }
.hb-terms .hb-gloss { line-height: 1.6; }

/* ที่มาในธรรมบท → เปิดธรรมบท ๒ ภาษา */
.hb-cite {
	display: inline-flex; align-items: center; gap: 2px; vertical-align: .1em;
	margin-left: .25em; padding: 0 .45em; border-radius: 99px;
	font-family: 'Sarabun', sans-serif; font-size: max(14px, .58em); font-weight: 600; line-height: 1.75;
	background: var(--hb-brand-soft); color: var(--hb-brand) !important; text-decoration: none !important;
	white-space: nowrap;
}
.hb-gloss .hb-cite { font-size: max(14px, .8em); }
.hb-cite::after { content: "\ea99"; font-family: 'tabler-icons'; font-size: .95em; opacity: .75; }   /* ti-external-link */
.hb-cite:hover { background: var(--hb-brand); color: var(--hb-on-brand) !important; }

/* ปิดคำแปล ทดสอบตัวเอง */
.hb-quiz .hb-pali ~ .hb-gloss { position: relative; cursor: pointer; }
.hb-quiz .hb-pali ~ .hb-gloss:not(.is-shown) > * , .hb-quiz .hb-pali ~ .hb-gloss:not(.is-shown) {
	color: transparent !important; background-color: transparent;
	text-shadow: 0 0 10px var(--hb-ink-faint);
	user-select: none; -webkit-user-select: none;
}
.hb-quiz .hb-pali ~ .hb-gloss:not(.is-shown) strong { background: transparent; text-shadow: 0 0 10px var(--hb-ink-faint); }
.hb-quiz .hb-pali ~ .hb-gloss:not(.is-shown) .hb-cite { visibility: hidden; }
.hb-quiz .hb-pali ~ .hb-gloss:not(.is-shown)::after {
	content: "แตะเพื่อดูคำแปล"; position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%);
	padding: 2px 12px; border-radius: 99px; font-size: max(14px, .78em); font-weight: 700; line-height: 1.7; white-space: nowrap;
	color: var(--hb-brand); background: var(--hb-card); border: 1px solid var(--hb-brand-line); text-shadow: none;
}

.hb-figure {
	margin: .9em 0; padding: .6em .95em; border-radius: 10px;
	border: 1px dashed var(--hb-line); background: var(--hb-paper2);
	font-size: max(14px, .86em); color: var(--hb-ink-faint);
}
.hb-figure::before { content: "\eb0a  "; font-family: 'tabler-icons'; }   /* ti-photo */


.hb-tablewrap { overflow-x: auto; margin: 0 0 1.1em; border: 1px solid var(--hb-line); border-radius: 12px; background: var(--hb-card); }
.hb-body table { border-collapse: collapse; min-width: 100%; font-size: 1em; margin: 0; color: var(--hb-ink); }
.hb-body th, .hb-body td {
	border-bottom: 1px solid var(--hb-line-soft); padding: 7px 12px; text-align: left; vertical-align: top; white-space: nowrap;
}
.hb-body td + td, .hb-body th + th { border-left: 1px solid var(--hb-line-soft); }
.hb-body tr:last-child td { border-bottom: 0; }
.hb-body th { background: var(--hb-paper2); font-weight: 700; }
.hb-body tbody tr:nth-child(even) td { background: rgba(var(--hb-paper-rgb), .55); }

/* คำค้นที่พามาจากหน้าผลการค้น */
mark.hb-hit { background: rgba(245, 191, 69, .55); color: inherit; border-radius: 3px; padding: 0 1px; }
mark.hb-hit.is-first { box-shadow: 0 0 0 2px var(--hb-gold); }

/* ---------- ท้ายบท: ก่อน/ถัดไป ---------- */
.hb-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 3em 0 0; font-size: 16px; }
.hb-pager a {
	display: flex; flex-direction: column; gap: 2px; min-width: 0;
	padding: 14px 16px; border: 1px solid var(--hb-line); border-radius: var(--hb-radius);
	background: var(--hb-card); color: var(--hb-ink) !important; text-decoration: none !important;
	transition: border-color .15s, box-shadow .15s;
}
.hb-pager a:hover { border-color: var(--hb-brand-line); box-shadow: var(--hb-shadow); }
.hb-pager small { font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); }
.hb-pager strong { font-size: max(14px, calc(0.98rem * var(--hb-scale))); line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hb-pager .is-next { text-align: right; grid-column: 2; }
.hb-pager .is-next:only-child { grid-column: 2; }
.hb-pager .is-next strong { color: var(--hb-brand); }
.hb-endnote { margin-top: 1.4em; font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); text-align: center; }
.hb-endnote i { color: var(--hb-ok); }

/* ---------- หน้าปก ---------- */
.hb-home .hb-page { max-width: 1120px; padding-top: 26px; }
.hb-hero {
	position: relative; overflow: hidden; border-radius: 22px;
	min-height: 460px; display: flex; align-items: center;
	background: #0d1330 url('/handbook/img/hero.webp') right center / auto 100% no-repeat;
	box-shadow: var(--hb-shadow);
}
.hb-hero::before {
	content: ""; position: absolute; inset: 0;
	background: linear-gradient(90deg, #0d1330 0%, #0d1330 34%, rgba(13, 19, 48, .55) 46%, rgba(13, 19, 48, 0) 58%);
}
.hb-hero-card { position: relative; z-index: 1; max-width: 540px; padding: 40px 44px; color: #f3f6ff; }
.hb-hero-kicker { display: inline-flex; align-items: center; gap: 6px; font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 600; color: #f5d27a; }
.hb-hero h1 { margin: 8px 0 6px; font-size: clamp(calc(2rem * var(--hb-scale)), calc(4.4vw * var(--hb-scale)), calc(2.9rem * var(--hb-scale))); line-height: 1.2; font-weight: 800; color: #fff !important; }
.hb-hero h1 span { display: block; font-size: max(14px, .56em); font-weight: 600; color: #c7d2fe; margin-top: 4px; }
.hb-hero p { margin: 0 0 4px; color: #d7defa; line-height: 1.7; }
.hb-hero .hb-by { font-size: max(14px, calc(0.9rem * var(--hb-scale))); color: #aeb8de; }
.hb-cta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.hb-btn {
	display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 8px 18px;
	border-radius: 12px; border: 1px solid transparent; font-weight: 700; font-size: max(14px, calc(0.98rem * var(--hb-scale)));
	text-decoration: none !important; cursor: pointer; transition: transform .12s, box-shadow .15s, background .15s;
}
.hb-btn:hover { transform: translateY(-1px); }
.hb-btn-gold { background: #f5bf45; color: #1b1505 !important; box-shadow: 0 8px 20px -10px rgba(245, 191, 69, .9); }
.hb-btn-gold:hover { background: #ffcc55; }
.hb-btn-ghost { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .28); color: #fff !important; }
.hb-btn-ghost:hover { background: rgba(255, 255, 255, .16); }
.hb-btn .stack { display: flex; flex-direction: column; line-height: 1.25; text-align: left; }
.hb-btn .stack small { font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 600; opacity: .75; }
.hb-btn .stack span { max-width: 23ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.hb-stats span {
	padding: 3px 12px; border-radius: 99px; font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 600;
	background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2); color: #e4e9ff;
}

.hb-home-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; margin-top: 26px; align-items: start; }
.hb-panel {
	border: 1px solid var(--hb-line); border-radius: 18px; background: var(--hb-card);
	box-shadow: var(--hb-shadow); overflow: hidden;
}
.hb-panel + .hb-panel { margin-top: 18px; }
.hb-panel-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--hb-line-soft); }
.hb-panel-head .ic {
	flex: 0 0 auto; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
	background: var(--hb-brand-soft); color: var(--hb-brand); border: 1px solid var(--hb-brand-line); font-size: max(14px, calc(1.3rem * var(--hb-scale)));
}
.hb-panel-head .ic.is-gold { background: var(--hb-key-soft); color: var(--hb-key); border-color: rgba(217, 119, 6, .3); }
.hb-panel-head h2 { margin: 0; font-size: max(14px, calc(1.12rem * var(--hb-scale))); font-weight: 800; }
.hb-panel-head p { margin: 1px 0 0; font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); }
.hb-panel-head .hb-prog { margin-left: auto; text-align: right; font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); white-space: nowrap; }
.hb-bar-track { width: 110px; height: 6px; border-radius: 99px; background: var(--hb-paper2); overflow: hidden; margin-top: 4px; }
.hb-bar-fill { height: 100%; border-radius: inherit; background: var(--hb-ok); }
.hb-chlist { list-style: none; margin: 0; padding: 6px 0 10px; columns: 2 300px; column-gap: 0; }
.hb-chlist li { break-inside: avoid; }
.hb-chlist a {
	display: flex; align-items: flex-start; gap: 10px; padding: 7px 20px;
	color: var(--hb-ink-soft) !important; text-decoration: none !important; font-size: max(14px, calc(0.95rem * var(--hb-scale))); line-height: 1.45;
}
.hb-chlist a:hover { background: var(--hb-brand-soft); color: var(--hb-brand) !important; }
.hb-chlist .no {
	flex: 0 0 18px; height: 18px; margin-top: 3px; border-radius: 50%; display: grid; place-items: center;
	font-size: max(14px, calc(0.875rem * var(--hb-scale))); font-weight: 800; border: 2px solid var(--hb-line); background: var(--hb-card);
}
.hb-chlist .t { flex: 1; min-width: 0; }
.hb-chlist .meta { font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); white-space: nowrap; padding-top: 2px; }
.hb-chlist a.is-done .no { background: var(--hb-ok); border-color: var(--hb-ok); color: var(--hb-on-brand); }
.hb-chlist a.is-done .no::after { content: "✓"; }

.hb-side .hb-panel { padding: 18px 20px; }
.hb-side h3 { margin: 0 0 10px; font-size: max(14px, calc(1rem * var(--hb-scale))); font-weight: 800; display: flex; align-items: center; gap: 8px; }
.hb-side h3 i { color: var(--hb-brand); }
.hb-side ul { margin: 0; padding: 0; list-style: none; }
.hb-side li { display: flex; gap: 10px; padding: 6px 0; font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); line-height: 1.6; color: var(--hb-ink-soft); }
.hb-side li i { flex: 0 0 auto; color: var(--hb-brand); font-size: max(14px, calc(1.1rem * var(--hb-scale))); padding-top: 2px; }
.hb-side li kbd {
	font: 600 .74rem/1 'Sarabun', sans-serif; border: 1px solid var(--hb-line); border-bottom-width: 2px;
	border-radius: 5px; padding: 2px 6px; background: var(--hb-paper2); color: var(--hb-ink);
}
.hb-side .hb-note { font-size: max(var(--hb-prose-min, 16px), calc(1rem * var(--hb-scale))); color: var(--hb-ink-faint); line-height: 1.65; margin: 0; }
.hb-side .hb-note a { font-weight: 600; }
.hb-front { display: flex; flex-direction: column; gap: 6px; }
.hb-front a {
	display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
	background: var(--hb-paper2); color: var(--hb-ink) !important; text-decoration: none !important; font-weight: 600; font-size: max(14px, calc(0.92rem * var(--hb-scale)));
}
.hb-front a:hover { background: var(--hb-brand-soft); color: var(--hb-brand) !important; }
.hb-front a i { color: var(--hb-brand); }
.hb-marklist a { display: block; padding: 6px 0; font-size: max(14px, calc(0.9rem * var(--hb-scale))); text-decoration: none; }
.hb-marklist small { display: block; color: var(--hb-ink-faint); font-size: max(14px, calc(0.875rem * var(--hb-scale))); }

/* ---------- ค้นทั้งเล่ม ---------- */
.hb-search-panel {
	position: fixed; inset: 0; z-index: 80; background: rgba(10, 15, 30, .5);
	display: flex; justify-content: center; align-items: flex-start; padding: 8vh 14px 14px;
}
.hb-search-panel[hidden] { display: none; }
.hb-search-box {
	width: min(720px, 100%); max-height: 84vh; display: flex; flex-direction: column;
	border-radius: 18px; background: var(--hb-card); border: 1px solid var(--hb-line);
	box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .55); overflow: hidden;
}
.hb-search-field { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--hb-line-soft); }
.hb-search-field > i { font-size: max(14px, calc(1.3rem * var(--hb-scale))); color: var(--hb-brand); }
.hb-search-field input {
	flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
	font: inherit; font-size: max(14px, calc(1.1rem * var(--hb-scale))); color: var(--hb-ink); padding: 6px 0;
}
.hb-search-field input::-webkit-search-cancel-button { display: none; }
.hb-search-hint { margin: 0; padding: 8px 18px; font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); background: var(--hb-paper2); }
.hb-results { overflow-y: auto; padding: 6px 0 10px; overscroll-behavior: contain; }
.hb-result {
	display: block; padding: 10px 18px; color: var(--hb-ink) !important; text-decoration: none !important;
	border-top: 1px solid var(--hb-line-soft);
}
.hb-result:first-child { border-top: 0; }
.hb-result:hover, .hb-result.is-active { background: var(--hb-brand-soft); }
.hb-result .where { font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); }
.hb-result .title { font-weight: 700; color: var(--hb-brand-deep); }
.hb-result .snip { margin-top: 2px; font-size: max(14px, calc(0.88rem * var(--hb-scale))); color: var(--hb-ink-soft); line-height: 1.6; }
.hb-result mark { background: rgba(245, 191, 69, .5); color: inherit; border-radius: 3px; padding: 0 1px; }
.hb-result .n { float: right; margin-left: 8px; font-size: max(14px, calc(0.875rem * var(--hb-scale))); color: var(--hb-ink-faint); }
.hb-results-empty { padding: 28px 18px; text-align: center; color: var(--hb-ink-faint); }

/* ---------- ทั่วไป ---------- */
.hb-loading, .hb-empty { padding: 80px 10px; text-align: center; color: var(--hb-ink-faint); }
.hb-loading i, .hb-empty i { display: block; font-size: max(14px, calc(2rem * var(--hb-scale))); margin-bottom: 8px; color: var(--hb-brand-line); }
.hb-empty strong { display: block; color: var(--hb-ink); font-size: max(14px, calc(1.1rem * var(--hb-scale))); }
.hb-toast {
	position: fixed; left: 50%; bottom: 22px; z-index: 90; transform: translateX(-50%);
	padding: 9px 18px; border-radius: 99px; background: var(--hb-ink); color: var(--hb-paper);
	font-size: max(14px, calc(0.9rem * var(--hb-scale))); font-weight: 600; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .5);
}

/* ---------- จอเล็ก ---------- */
@media (max-width: 900px) {
	.hb-home-grid { grid-template-columns: 1fr; }
	.hb-search-btn { min-width: 0; width: 38px; padding: 0; justify-content: center; }
	.hb-search-btn span, .hb-search-btn kbd { display: none; }
	.hb-search-btn i { font-size: max(14px, calc(1.2rem * var(--hb-scale))); }
}
@media (max-width: 640px) {
	.hb-bar { gap: 8px; padding: 0 10px; }
	.hb-bar-sub { display: none; }
	.hb-bar-tools { gap: 6px; }
	.hb-nav-btn { display: none; }
	.hb-page { padding: 20px 16px 48px; }
	h1.hb-h { font-size: 1.6em; }
	.hb-ex { padding: .5em .8em .55em; margin-left: -4px; margin-right: -4px; }
	.hb-terms .hb-ex { margin: 0; padding: .35em .8em .45em; }
	.hb-hero { min-height: 0; align-items: flex-end; background-position: 70% top; background-size: auto 330px; background-color: #0e1430; padding-top: 250px; border-radius: 18px; }
	.hb-hero::before { background: linear-gradient(180deg, rgba(10, 15, 40, 0) 0px, rgba(10, 15, 40, .2) 170px, rgba(14, 20, 48, 1) 300px); }
	.hb-hero-card { padding: 0 20px 24px; }
	.hb-home .hb-page { padding: 14px 12px 40px; }
	.hb-chlist a { padding: 7px 16px; }
	.hb-panel-head { padding: 14px 16px 10px; flex-wrap: wrap; }
	.hb-panel-head .hb-prog { width: 100%; margin-left: 54px; text-align: left; }
	.hb-pager { grid-template-columns: 1fr; }
	.hb-pager .is-next { grid-column: 1; }
	.hb-search-panel { padding: 10px; }
}

@media print {
	.hb-bar, .hb-toc, .hb-scrim, .hb-pager, .hb-sec-tools, .pt-topnav-scope, .hb-search-panel, .hb-toast { display: none !important; }
	.hb-shell { display: block !important; }
	.hb-page { max-width: none; padding: 0; }
	.hb-ex { box-shadow: none; break-inside: avoid; }
}

/* แผนภาพจากต้นฉบับ: รักษาขนาดอักษร จอแคบเลื่อนในภาพได้ */
.hb-diagram { margin: 1.2em 0; }
.hb-diagram-scroll { overflow-x: auto; background: #fff; padding: 1em; border: 1px solid var(--hb-line); border-radius: 12px; box-shadow: 0 1px 2px rgba(20, 26, 51, .04); }
.hb-diagram img { display: block; margin-inline: auto; width: calc(var(--hb-diagram-width, 710px) * var(--hb-scale)); max-width: none; height: auto; }

.hb-topic { margin: 1.6em 0 .55em; font-family: inherit; font-size: 1.45em; font-weight: 800; line-height: 1.6; color: var(--hb-ink); scroll-margin-top: calc(var(--hb-bar-h) + 24px); }
.hb-sec.hb-hide-title { border-top: 0; padding-top: 0; margin-top: 1em; }

h3.hb-topic { font-size: 1.18em; margin-top: 1.2em; }

/* สารบัญเว็บ: แยกภาค ชื่อบทกดอ่านได้ หัวข้อย่อยเปิดดูเมื่อจำเป็น */
.hb-book-toc { list-style: none; columns: 2 20rem; column-gap: 2.4em; padding: 0; margin: 0; }
.hb-book-toc > li { break-inside: avoid; margin: 0 0 1em; padding: 0 0 .75em; border-bottom: 1px solid var(--hb-line-soft); }
.hb-book-toc > li > a { font-weight: 700; text-decoration: none; }
.hb-book-toc details { margin-top: .35em; }
.hb-book-toc summary { cursor: pointer; font-size: max(14px, .875em); color: var(--hb-ink-soft); }
.hb-book-toc details ul { margin: .5em 0 0; padding-left: 1.25em; }
.hb-book-toc details li { margin-bottom: .4em; }
.hb-body .hb-table-pali { font-family: 'THSarabunPali', 'Sarabun', serif; font-size: 1.6em; line-height: 1.6; color: var(--hb-pali); }
.hb-body td a { text-underline-offset: .2em; }

:root.hb-large-text { --hb-prose-min: 19px; }

.hb-steps { list-style: none; padding: 0; margin: 1em 0; }
.hb-steps li { display: flex; gap: .8em; align-items: baseline; margin-bottom: .7em; }
.hb-step-number { flex: 0 0 1.6em; font-weight: 800; color: var(--hb-key); }
.hb-steps a { color: var(--hb-ink); text-underline-offset: .25em; }

/* ลำดับการแปล: คำอธิบายตามขั้นตอนอยู่นอกการ์ด */
.hb-procedure { margin: 1em 0 1.4em; padding-left: 1.8em; list-style: thai; }
.hb-procedure li { padding-left: .35em; margin-bottom: .85em; line-height: 1.8; }
.hb-procedure li::marker { color: var(--hb-key); font-weight: 800; }
