/* =============================================
   Dhammapada Digital Palm-Leaf — ebook-new.css
   Design: Warm editorial, refined manuscript feel
   ============================================= */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;0,700;1,400&family=Cinzel:wght@400;600;700&display=swap');

@font-face {
  font-family: 'THSarabunPali';
  src: url('../fonts/THSarabunPali.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'THSarabunPali';
  src: url('../fonts/THSarabunPali.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Palette — warm parchment / gold / ink */
  --parchment:      #FDFBF7;
  --parchment-deep: #F5F0E8;
  --cream:          #FEFDFB;
  --gold:           #C9A554;
  --gold-light:     #E8D5A0;
  --gold-dark:      #A07D3A;
  --brown:          #5C3D10;
  --brown-dark:     #3C1F10;
  --brown-light:    #8B6914;
  --ink:            #2C1810;
  --ink-light:      #4A3728;
  --pali-color:     #7A2E0E;
  --thai-color:     #1A3A6B;
  --attha-color:    #2D5016;
  --accent:         #B8432F;
  --muted:          #8C7B6B;
  --border:         #DDD0BE;
  --border-light:   #EDE4D4;
  --shadow:         rgba(60, 31, 16, 0.08);
  --shadow-md:      rgba(60, 31, 16, 0.12);
  --shadow-lg:      rgba(60, 31, 16, 0.18);

  /* Typography */
  --font-display: 'Cinzel', 'Cormorant Garamond', serif;
  --font-body:    'Sarabun', sans-serif;
  --font-serif:   'Cormorant Garamond', serif;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Base / Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--parchment);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(201,165,84,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(201,165,84,0.04) 0%, transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* Utility: hide */
.hide { display: none !important; }
[v-cloak] { display: none !important; }

/* ---------- Punctuation Hiding ---------- */
.hide-punctuation .pali-text { }

/* ---------- Loading Spinner ---------- */
.spinner-loading {
  animation: spinner-rotate 1s linear infinite !important;
  display: inline-block;
}
@keyframes spinner-rotate {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ---------- Text Styles ---------- */
.pali-text {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.65rem;
  line-height: 2.3;
  color: var(--pali-color);
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}

.thai-text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--thai-color);
}

.thai-attha-text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--attha-color);
}

/* สำนวนแปลแบบ interlinear — คำแปลอยู่เหนือวลีบาลีต้นทาง */
.idiom-interlinear-text {
  margin: 0 0 0.65rem;
  padding: 0.55rem 0.65rem 0.7rem;
  border: 1px solid rgba(169, 134, 58, 0.24);
  border-left: 3px solid #a9863a;
  border-radius: var(--radius-sm);
  background: rgba(255, 252, 243, 0.72);
}

.idiom-interlinear-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  color: #876820;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.idiom-interlinear-heading > span:last-child {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.idiom-interlinear-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 0.65rem;
  row-gap: 0.8rem;
}

.idiom-interlinear-number {
  align-self: flex-end;
  margin: 0 0 0.32rem;
}

.idiom-interlinear-unit {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  justify-content: flex-end;
  width: max-content;
  max-width: 100%;
}

.idiom-interlinear-unit-matched {
  padding: 0.28rem 0.42rem 0.32rem;
  border-bottom: 2px solid rgba(169, 134, 58, 0.58);
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, rgba(248, 238, 203, 0.72), rgba(252, 247, 231, 0.36));
}

.idiom-interlinear-unit-plain {
  padding: 0.28rem 0 0.32rem;
}

.idiom-interlinear-glosses {
  margin-bottom: 0.12rem;
}

.idiom-interlinear-gloss {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.5;
  color: #51452f;
}

.idiom-interlinear-gloss + .idiom-interlinear-gloss {
  margin-top: 0.18rem;
  padding-top: 0.18rem;
  border-top: 1px dashed rgba(169, 134, 58, 0.25);
}

.idiom-interlinear-pali {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.65rem;
  line-height: 1.6;
  color: var(--pali-color);
  overflow-wrap: anywhere;
}

/* ---------- แปลยกศัพท์ต่อคำ (ปทานุกรมธรรมบท) ---------- */
.yoksap-text {
  margin: 0.35rem 0 0.55rem;
}

.yoksap-heading {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: rgba(122, 96, 42, 0.85);
  margin-bottom: 0.2rem;
}

.yoksap-heading span:last-child {
  font-size: 0.875rem;
  color: rgba(122, 96, 42, 0.55);
}

.yoksap-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.2rem 0.55rem;
}

.yoksap-number {
  align-self: flex-start;
  margin-top: 0.35rem;
}

.yoksap-unit {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  max-width: 100%;
  padding: 0.18rem 0.4rem 0.24rem;
  border-radius: 6px;
  text-decoration: none;
  transition: background 0.15s ease;
}

.yoksap-unit:hover {
  background: rgba(169, 134, 58, 0.14);
}

.yoksap-pali {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.65rem;
  line-height: 1.35;
  color: var(--pali-color);
  overflow-wrap: anywhere;
}

.yoksap-gloss {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.4;
  color: #51452f;
  max-width: 16rem;
  border-top: 1px dashed rgba(169, 134, 58, 0.45);
  margin-top: 0.08rem;
  padding-top: 0.12rem;
}

.yoksap-unit-nogloss .yoksap-gloss {
  border-top-color: transparent;
}

/* ยกศัพท์แบบสลับ (ไทยนำ): คำแปลบน–บาลีล่าง → ย้ายเส้นคั่นไปไว้เหนือบาลี */
.yoksap-unit-rev .yoksap-gloss {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}
.yoksap-unit-rev .yoksap-pali {
  border-top: 1px dashed rgba(169, 134, 58, 0.45);
  margin-top: 0.08rem;
  padding-top: 0.12rem;
}
.yoksap-unit-rev.yoksap-unit-nogloss .yoksap-pali {
  border-top-color: transparent;
}

/* ---------- ไทย-บาลี: อ่านเป็นเฉลยแปลโดยพยัญชนะต่อเนื่อง ---------- */
/* ท่อนติดกันขึ้น เพื่อให้บรรทัดบนอ่านเป็นประโยคเดียว */
.yoksap-text-rev .yoksap-row { gap: 0.15rem 0.35rem; }
.yoksap-text-rev .yoksap-gloss { max-width: 22rem; }
/* เผื่อที่ให้เลขวิภัตติ (เกาะมุมบนของคำบาลี) ไม่ชนบรรทัดคำแปลด้านบน */
.yoksap-unit-rev .yoksap-pali { padding-top: 0.5rem; }

/* คำเสริมในเฉลย (ไม่มีศัพท์บาลีรองรับ) — จาง เอียง ไม่มีเส้นคั่น */
.yoksap-unit-fill .yoksap-gloss { color: #a2937a; font-style: italic; }
.yoksap-unit-fill .yoksap-pali {
  border-top-color: transparent;
  color: rgba(169, 134, 58, 0.35);
  font-size: 1rem;
  text-align: center;
}

/* ตัวโยค (โยคศัพท์) — บาลีที่หนังสือเติมเข้ามาเอง ไม่มีในตัวบาลี: เขียวเข้ม ในวงเล็บ */
.yoksap-yoka {
  color: #1b5e20;
  font-family: 'THSarabunPali', var(--font-body);
}
.yoksap-unit-yoka .yoksap-gloss { color: #4a6b4d; font-style: normal; }
.yoksap-unit-yoka .yoksap-pali {
  border-top: 1px dashed rgba(27, 94, 32, 0.4);
  color: #1b5e20;
  font-size: 1.65rem;
  text-align: left;
}
.yoksap-heading .yoksap-yoka { font-family: var(--font-body); font-weight: 700; }

/* เครื่องหมายคั่นวรรคในเฉลย (, ; ฯ) — ท่อนแคบ ไม่มีช่องบาลี */
.yoksap-unit-punct {
  padding-left: 0;
  padding-right: 0;
  justify-content: flex-start;
}
.yoksap-unit-punct .yoksap-gloss { color: #a2937a; }
.yoksap-unit-punct:hover { background: none; }

/* เลขลำดับคำในประโยคบาลี (จาง ๆ หน้าคำ) — บอกว่าเฉลยอ่านคำไหนก่อนหลัง */
.yoksap-seq {
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: #a8924f;
  vertical-align: 0.75em;
  margin-right: 0.1em;
}

/* คำคร่อม: ท่อนที่ ๑/๒ ของคำเดียวกัน */
.yoksap-partno {
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: #b06a2a;
  vertical-align: 0.75em;
  margin-left: 0.08em;
}
.yoksap-unit-split .yoksap-pali { border-top-style: dotted; border-top-color: rgba(176, 106, 42, 0.7); }

/* บาลีที่คำแปลท่อนเดียวคลุมหลายคำ */
.yoksap-alt { opacity: 0.6; }

/* ยังไม่มีคำแปลยกศัพท์ของคำนี้ (คำสนธิที่ปทานุกรมยังไม่ได้แยก) — โชว์บาลีไว้ + ขีดแทนคำแปล */
.yoksap-gloss-none { color: rgba(190, 60, 60, 0.5); }
.yoksap-unit-nodata { background: rgba(214, 51, 51, 0.05); border-radius: 6px; }

/* หาตำแหน่งในเฉลยไม่ได้ → ต่อท้ายไว้ ไม่ให้คำหาย */
.yoksap-unit-unplaced { background: rgba(214, 51, 51, 0.06); }
.yoksap-unit-unplaced .yoksap-pali { border-top-color: rgba(214, 51, 51, 0.5); }

/* เครื่องหมายคั่น (“ ” ‘ ’ ,) ในมุมมองยกศัพท์ — สีจาง ไม่คลิกลิงก์ */
.yoksap-mark {
  color: var(--muted, #8a7a55);
  font-weight: 400;
}

/* คำ "คร่อม" (อิติ/สเจ/เจ/ยทิ): เขียว=เปิด แดง=ปิด */
.corr-open  { color: #1b7a2e; font-weight: 700; }   /* ถ้าว่า/หากว่า/ผิว่า/ว่า */
.corr-close { color: #c62828; font-weight: 700; }   /* ดังนี้/ไซร้/ด้วยประการฉะนี้ */
.corr-chip {
  background: rgba(27, 122, 46, 0.12);
  border: 1px solid rgba(27, 122, 46, 0.35);
  border-radius: 5px;
  padding: 0 0.35em;
}
.yoksap-unit-corr .yoksap-pali { min-height: 0; }

/* ---------- สีตามหน้าที่ (สัมพันธ์) ---------- */
/* กฎสีจริงถูก inject โดย JS (#roleColorStyle) ตาม config ของ user */
.rword { transition: background 0.1s ease; }

/* แผงตั้งค่าสีในเมนูซ้าย */
.role-settings .role-style-toggle { font-size: 0.875rem; color: #6b5320; }
.role-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.15rem 0;
}
.role-item-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  cursor: pointer;
  margin: 0;
}
.role-swatch {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
}
.role-color {
  width: 1.6rem;
  height: 1.3rem;
  padding: 0;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  flex: 0 0 auto;
}
.role-item-label { flex: 1 1 auto; min-width: 0; }
.role-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* แถวปุ่มเลือกทั้งหมด/เอาออกทั้งหมด + ตัวนับที่เปิดอยู่ */
.role-bulk {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}
.role-bulk .btn { font-size: 0.875rem; padding: 0.2rem 0.45rem; flex: 1 1 0; }
.role-bulk-count {
  font-size: 0.875rem;
  color: var(--muted, #8a7a55);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.role-legend {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  font-size: 0.875rem;
  color: var(--muted, #8a7a55);
  padding-right: 0.1rem;
  margin-bottom: 2px;
}
.role-legend span:first-child { margin-right: auto; }
.role-styles { display: flex; gap: 0.2rem; flex: 0 0 auto; }
.role-hl, .role-ul {
  font-size: 0.875rem;
  line-height: 1;
  padding: 0.18rem 0.3rem;
  border: 1px solid #cbb884;
  border-radius: 4px;
  background: #fff;
  color: #8a6d2f;
  cursor: pointer;
}
.role-hl.active { background: #f5e7bf; border-color: #a9863a; color: #5a4718; font-weight: 700; }
.role-ul.active { background: #f5e7bf; border-color: #a9863a; color: #5a4718; font-weight: 700; text-decoration: underline; }

/* คำบาลีในแถวยกศัพท์ — ให้เลขวิภัตติ (absolute) เกาะได้ */
.yoksap-paliword { position: relative; display: inline-block; }

/* ---------- แยกสนธิ: -คำเดิม- (ส่วน๑ + ส่วน๒) ---------- */
.sandhi-orig {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(160, 82, 45, 0.65);
  opacity: 0.6;
  margin-right: 0.22em;
}

.sandhi-parts {
  white-space: nowrap;
}

.sandhi-part {
  position: relative;          /* ให้เลขวิภัตติเกาะรายส่วน */
  display: inline-block;
  padding-right: 0.12em;
}

.sandhi-plus {
  color: var(--muted, #8a7a55);
  font-size: 0.75em;
  margin: 0 0.14em;
  vertical-align: 0.12em;
}

/* คำบาลีที่คลิกได้ (เปิด popup) */
.pw { cursor: pointer; position: relative; display: inline-block; border-radius: 3px; }
.pw:hover { background: rgba(169, 134, 58, 0.16); }

/* ---------- Word popup (การ์ดเล็กข้างคำ) ---------- */
.word-popup {
  position: fixed;
  z-index: 3000;
  width: min(20rem, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  background: #fffdf8;
  border: 1px solid #d9c79a;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(60, 45, 15, 0.22);
  font-family: var(--font-body);
  animation: wpIn 0.12s ease;
}
@keyframes wpIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.wp-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem 0.4rem;
  border-bottom: 1px solid #efe4c6;
}
.wp-surface {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--pali-color, #6a1b9a);
  line-height: 1.1;
}
.wp-chip {
  font-size: 0.875rem;
  font-weight: 700;
  color: #4338ca;
  background: #eef2ff;
  border-radius: 999px;
  padding: 1px 8px;
}
.wp-close {
  margin-left: auto;
  border: none;
  background: none;
  font-size: 1.3rem;
  line-height: 1;
  color: #b0a074;
  cursor: pointer;
  padding: 0 0.2rem;
}
.wp-close:hover { color: #6b5320; }
.wp-body { padding: 0.5rem 0.75rem 0.7rem; }
.wp-row { font-size: 0.92rem; margin-bottom: 0.3rem; color: #3a3020; }
.wp-k { font-weight: 700; color: #8a6d2f; margin-right: 0.25rem; }
.wp-muted { color: #a99; }
.wp-analysis { margin-top: 0.5rem; padding-top: 0.45rem; border-top: 1px dashed #e5d7ad; }
.wp-sec { font-size: 0.875rem; font-weight: 700; color: #8a6d2f; margin-bottom: 0.3rem; }
.wp-parts { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.15rem; }
.wp-part {
  background: #f3eeff;
  border: 1px solid #dcd0f5;
  border-radius: 7px;
  padding: 0.2rem 0.45rem;
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.15rem;
  line-height: 1.2;
  color: #4a2f7a;
}
.wp-part-role { display: block; font-family: var(--font-body); font-size: 0.875rem; font-weight: 700; color: #7c6aa8; }
.wp-part i { font-family: var(--font-body); font-size: 0.875rem; font-style: normal; color: #6b5320; }
.wp-part-sub { font-family: var(--font-body); font-size: 0.875rem; color: #8a7a55; }
.wp-plus { color: #b0a074; font-weight: 700; }
.wp-base-gana {
  margin-left: 0.3rem;
  font-weight: 600;
  color: #0f6b4f;
  background: #e8f6f0;
  border-radius: 999px;
  padding: 1px 8px;
}
.wp-base-eq { font-family: 'THSarabunPali', var(--font-body); font-size: 1.2rem; line-height: 1.35; color: #3a3020; }
.wp-base-eq b { color: #0f6b4f; }
.wp-base-pac { color: #b45309; font-weight: 700; }
.wp-base-note { font-size: 0.875rem; color: #8a7a55; margin-top: 0.1rem; }
.wp-base-forms { font-family: 'THSarabunPali', var(--font-body); font-size: 1.05rem; color: #4a2f7a; margin-top: 0.2rem; }
.wp-full {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.875rem;
  color: #4338ca;
  text-decoration: none;
}
.wp-full:hover { text-decoration: underline; }
.wp-loading { padding: 0.5rem 0.2rem; color: #8a7a55; font-size: 0.9rem; }

/* ---------- เลขวิภัตติบนคำบาลี ---------- */
.vibhatti-text {
  margin: 0.35rem 0 0.55rem;
}

.vibhatti-heading {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: rgba(122, 96, 42, 0.85);
  margin-bottom: 0.2rem;
}

.vibhatti-heading span:last-child {
  font-size: 0.875rem;
  color: rgba(122, 96, 42, 0.55);
}

.vibhatti-row {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.65rem;
  line-height: 2.1;
  color: var(--pali-color);
  overflow-wrap: anywhere;
}

.vibhatti-number {
  margin-right: 0.35rem;
}

/* แถว "หน้าที่" ล้วน (ติ๊กหน้าที่ ไม่ติ๊กเลขวิภัตติ) — เหลือคำ+สี ซ่อนป้ายเลข/ปัจจัย/วาจก
   ใช้ markup เดียวกับแถวเลขวิภัตติ จึงได้ระยะบรรทัดและการจับคู่สีเหมือนกันทุกอย่าง */
.vibhatti-text.roles-only .vibhatti-num,
.vibhatti-text.roles-only .vword-tag {
  display: none;
}

.vibhatti-text.roles-only .vibhatti-row {
  line-height: 1.9;
}

/* แต่ละคำบาลี — เลขวิภัตติเกาะมุมบน เยื้องเข้ามาจากท้ายคำ (ไม่ล้ำขวาเกินคำ) */
.vibhatti-unit {
  position: relative;
  display: inline-block;
}

.vibhatti-num {
  position: absolute;
  top: -0.62em;            /* ยกให้พ้นสระ/นิคคหิตด้านบนของบาลี */
  right: 0.18em;           /* เยื้องซ้ายเข้ามาจากท้ายคำ ไม่ให้ล้ำขวา */
  font-family: var(--font-body);
  font-size: 1rem;         /* ≈ ตัวหนังสือไทย */
  font-weight: 700;
  color: #d02323;          /* แดงเห็นชัด */
  line-height: 1;
  pointer-events: none;
  /* ห้ามตัดบรรทัด — คำสั้น (โน) แคบกว่าป้าย "6ท." ทำให้ ท. ตกลงมาข้างล่าง
     ป้ายลอยอยู่แล้ว (absolute) ล้นออกซ้ายได้ ไม่ดันข้อความ */
  white-space: nowrap;
}

/* ป้ายวิภัตติแบบยาว ("ติ วตฺตมานา" / "นิบาต") — ขึ้นบรรทัดเหนือคำ
   inline-block จึงยึด baseline ของบรรทัดล่าง (ตัวคำ) → บาลีไม่เยื้อง และป้ายจองที่กว้างไว้เอง */
.vword { display: inline-block; text-align: center; }
.vword-tag {
  display: block;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.05;
  color: #d02323;
  white-space: nowrap;
  pointer-events: none;
}
.vword-w { display: block; }
/* ป้ายปัจจัยกิตก์ (อนฺต · ตฺวา · ต · ตุํ นามกิตก์) — สีม่วงคราม แยกจากเลขวิภัตติที่เป็นสีแดง
   เพื่อให้เห็นทันทีว่าคำนี้เป็นกิริยากิตก์/นามกิตก์ ลงปัจจัยตัวไหน */
.vword-tag.kita-tag { color: #5b21b6; font-size: 0.875rem; margin-bottom: 0.3em; }
/* ป้ายวาจกที่ไม่ใช่กัตตุ (กมฺม · เหตุกตฺตุ · เหตุกมฺม · ภาว)
   วาจกพวกนี้เปลี่ยนรูปประโยคและคำแปล → ทำกรอบสีจัดให้สะดุดตากว่าป้ายอื่นทั้งหมด */
.vword-tag.vac-tag {
  font-size: 0.875rem;
  font-weight: 800;
  color: #fff;
  /* สระใต้พยัญชนะ (ุ ู ฺ) ของบาลียาวลงมามาก — แถบต้องสูงพอ ไม่งั้นสระขาวล้นออกนอกแถบ อ่านไม่ออก
     line-height + padding ล่างเผื่อไว้ให้สระอยู่ในแถบครบ (เหตุกตฺตุ · เหตุกมฺม) */
  line-height: 1.5;
  padding: 0.04em 0.36em 0.2em;
  border-radius: 3px;
  /* เผื่อระยะให้เลขวิภัตติที่เกาะมุมคำ (top:-0.5em) ไม่ชนขอบล่างของแถบ */
  margin-bottom: 0.72em;
  letter-spacing: 0.01em;
}
.vac-tag.vac-kamma { background: #d81b60; }
.vac-tag.vac-hetukattu { background: #e53935; }
.vac-tag.vac-hetukamma { background: #8e24aa; }
.vac-tag.vac-bhava { background: #00897b; }
/* คำที่มีทั้งป้ายปัจจัยและเลขวิภัตติ — เลขเกาะมุมคำ ไม่ให้ชนป้ายด้านบน */
.vword .vword-w.vibhatti-unit { position: relative; display: inline-block; }
.vword .vword-w.vibhatti-unit .vibhatti-num { top: -0.5em; right: -0.1em; }
/* คำที่มีป้ายวาจก (แถบสูง) — ดึงเลขวิภัตติเข้าใกล้คำอีกนิด กันชนขอบแถบ */
.vword:has(> .vac-tag) .vword-w.vibhatti-unit .vibhatti-num { top: -0.34em; }

/* ---------- ศัพท์ที่โยค ในแถวเลขวิภัตติ/หน้าที่ ----------
   ศัพท์ที่หนังสือเติมเข้ามาเพื่อให้ประโยคครบ — ไม่มีในบาลีต้นฉบับ
   จึงต้องแยกให้เห็นทันทีว่าอันไหนของต้นฉบับ อันไหนหนังสือโยคเข้ามา
   เขียว #15803d = สีเดียวกับ .paliyok-text .yok-supplied ผู้อ่านจะโยงสองแถวเข้าหากันได้เอง */
.vibhatti-yok {
  color: #15803d;
  cursor: pointer;
}
.vibhatti-yok .vibhatti-num { color: #15803d; }
/* ชื่อสัมพันธ์เหนือศัพท์ที่โยค — เขียวเข้มกว่าตัวคำ ตัวเล็กกว่าป้ายวิภัตติ ไม่ให้แย่งสายตา */
.vword-tag.yok-role-tag {
  color: #0b5c2f;   /* เข้มกว่าตัวคำเล็กน้อย ให้อ่านป้ายออกแต่ไม่แย่งสายตาจากบาลี */
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 0.28em;
}
/* เลขวิภัตติลอยขึ้นเหนือคำ 0.62em + ความสูงของตัวเลขเอง จะปีนไปทับป้ายชื่อสัมพันธ์
   ต้องเผื่อระยะให้เลขแทรกอยู่ระหว่างป้ายกับคำได้พอดี (วัดด้วย getBoundingClientRect แล้วไม่ทับ) */
.yok-vword .vword-tag.yok-role-tag { margin-bottom: 1.15em; }
/* แถว "หน้าที่" ซ่อนป้ายทุกชนิด — แต่ชื่อสัมพันธ์ของศัพท์ที่โยคคือสาระของแถวนี้ ต้องเห็น
   แถวนี้ไม่โชว์เลข จึงไม่ต้องเผื่อระยะกันชน */
.vibhatti-text.roles-only .vword-tag.yok-role-tag { display: block; margin-bottom: 0.28em; }
.vibhatti-yok-legend { color: #15803d; font-weight: 600; }

/* ---------- Hidden Thai (Quiz Mode) ---------- */
.hidden-thai {
  position: relative;
  background: var(--parchment-deep);
  border-radius: var(--radius-sm);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  padding: 0.5rem;
  border: 1px dashed var(--border);
}

.hidden-thai > * {
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s, opacity 0.25s var(--ease);
}

.hidden-thai.reveal-thai > * {
  visibility: visible;
  opacity: 1;
}

/* =============================================
   USER BAR
   ============================================= */
.en-user-bar {
  background: linear-gradient(135deg, var(--brown-dark), var(--brown), var(--brown-dark));
  padding: 7px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.875rem;
  border-bottom: 2px solid var(--gold-dark);
  position: relative;
}

.en-user-bar::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light), transparent);
}

.en-story-title-bar {
  color: var(--gold-light);
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
  font-weight: 300;
  letter-spacing: 0.02em;
}

.en-story-title-bar i {
  color: var(--gold);
  margin-right: 6px;
}

.en-user-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.en-sync-status {
  color: var(--gold);
  font-size: 0.875rem;
}

.en-user-menu-wrap {
  position: relative;
}

.en-user-menu-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid rgba(201,165,84,0.3);
  border-radius: 20px;
  padding: 3px 14px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  color: var(--gold-light);
  font-family: var(--font-body);
  font-size: 0.875rem;
}

.en-user-menu-btn:hover {
  background: rgba(201,165,84,0.12);
  border-color: rgba(201,165,84,0.5);
}

.en-user-menu-btn img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(201,165,84,0.5);
}

.en-user-menu-btn .chevron {
  font-size: 0.875rem;
  transition: transform 0.2s var(--ease);
}

.en-user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  background: var(--cream);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px var(--shadow-lg);
  min-width: 190px;
  overflow: hidden;
  z-index: 1000;
  border: 1px solid var(--border-light);
}

.en-user-dropdown a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  color: var(--ink-light);
  text-decoration: none;
  transition: background 0.15s;
  font-size: 0.88rem;
}

.en-user-dropdown a:hover {
  background: var(--parchment-deep);
}

.en-user-dropdown a + a {
  border-top: 1px solid var(--border-light);
}

.en-login-link {
  color: var(--gold-light);
  text-decoration: none;
  padding: 5px 18px;
  background: rgba(201,165,84,0.1);
  border-radius: 20px;
  font-size: 0.875rem;
  border: 1px solid rgba(201,165,84,0.25);
  transition: all 0.2s;
}

.en-login-link:hover {
  background: rgba(201,165,84,0.2);
  color: #fff;
}

/* =============================================
   COMPACT NAVIGATION BAR
   ============================================= */
.en-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--cream);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px var(--shadow);
  padding: 8px 14px;
  transition: transform 0.3s var(--ease);
}

.en-nav.hidden {
  transform: translateY(-100%);
}

.en-nav-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

/* Hamburger / Settings */
.en-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
  color: var(--brown);
  cursor: pointer;
  font-size: 1.15rem;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}

.en-nav-btn:hover:not(:disabled) {
  background: var(--parchment-deep);
  border-color: var(--gold-light);
  color: var(--gold-dark);
}

.en-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Center: book + page selects */
.en-nav-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.en-book-select,
.en-page-select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 0.875rem;
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  transition: border-color 0.15s;
}

.en-book-select {
  font-weight: 600;
  color: var(--brown);
  min-width: 78px;
  max-width: 95px;
}

.en-page-select {
  min-width: 72px;
  max-width: 105px;
}

.en-book-select:focus,
.en-page-select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(201,165,84,0.2);
}

/* Right side action buttons */
.en-nav-right {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}

.en-nav-btn-quiz {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gold);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}

.en-nav-btn-quiz:hover { background: var(--gold-dark); }
.en-nav-btn-quiz.active { background: var(--muted); }

.en-nav-btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}

.en-nav-btn-action:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.en-nav-btn-page {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.15s var(--ease);
  flex-shrink: 0;
}

.en-nav-btn-page.prev { background: var(--brown); }
.en-nav-btn-page.prev:hover:not(:disabled) { background: var(--brown-dark); }
.en-nav-btn-page.next { background: var(--gold-dark); }
.en-nav-btn-page.next:hover:not(:disabled) { background: var(--gold); }
.en-nav-btn-page:disabled { background: #C4B8A8; cursor: not-allowed; }

/* Select2 in nav */
.en-nav-center .select2-container {
  min-width: 82px !important;
  max-width: 105px !important;
}
.en-nav-center .select2-container .select2-selection--single {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--cream);
}
.en-nav-center .select2-container .select2-selection--single .select2-selection__rendered {
  line-height: 30px;
  padding-left: 10px;
  font-size: 0.875rem;
  color: var(--ink);
}
.en-nav-center .select2-container .select2-selection--single .select2-selection__arrow {
  height: 30px;
}
.compact-page-dropdown .select2-search--dropdown .select2-search__field {
  font-size: 0.875rem;
  padding: 5px 8px;
}
.compact-page-dropdown .select2-results__option {
  font-size: 0.875rem;
  padding: 5px 8px;
}

/* =============================================
   PANEL TOGGLE (floating gear)
   ============================================= */
.en-panel-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 110;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(201,165,84,0.4);
  transition: all 0.3s var(--ease);
  font-size: 1.1rem;
  align-items: center;
  justify-content: center;
}

.en-panel-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(201,165,84,0.5);
}

/* =============================================
   SETTINGS OFFCANVAS
   ============================================= */
.en-settings-section {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
}

.en-settings-home {
  display: flex;
  width: 100%;
  text-decoration: none;
}
.en-settings-home:hover,
.en-settings-home:focus-visible {
  background: var(--brown);
  border-color: var(--brown);
  color: #fff;
}

.en-settings-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

/* =============================================
   HERO SECTION
   ============================================= */
.en-hero {
  text-align: center;
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
  border-radius: var(--radius-xl);
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg,
    var(--cream) 0%,
    var(--parchment-deep) 30%,
    rgba(201,165,84,0.15) 60%,
    var(--parchment-deep) 80%,
    var(--cream) 100%);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px var(--shadow);
}

.en-hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(circle at 25% 80%, rgba(201,165,84,0.08) 0%, transparent 50%),
    radial-gradient(circle at 75% 20%, rgba(201,165,84,0.06) 0%, transparent 50%),
    linear-gradient(45deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
  pointer-events: none;
  animation: heroShimmer 12s ease-in-out infinite alternate;
}

@keyframes heroShimmer {
  0%   { opacity: 0.5; }
  100% { opacity: 0.9; }
}

.en-hero-title {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--brown-dark);
  margin: 0 0 0.3rem;
  position: relative;
  z-index: 1;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
}

.en-hero-subtitle {
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--brown-light);
  font-weight: 400;
  position: relative;
  z-index: 1;
  margin: 0;
}

/* =============================================
   BOOK SELECTION GRID
   ============================================= */
.en-book-grid {
  padding: 1.5rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  background: linear-gradient(160deg, var(--cream), var(--parchment-deep) 50%, var(--cream));
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px var(--shadow);
}

.en-book-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
  background: var(--cream);
}

.en-book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px var(--shadow-md);
  border-color: var(--gold-light);
}

.en-book-card-inner {
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  position: relative;
}

.en-book-cover {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
}

.en-book-cover img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.en-book-fallback {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.en-book-fallback-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brown);
}

.en-book-fallback-num {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold-dark);
}

.en-book-label {
  text-align: center;
  padding: 0.5rem 0.25rem;
  background: rgba(255,255,255,0.9);
  border-top: 1px solid var(--border-light);
  font-size: 0.875rem;
  color: var(--brown);
}

.en-book-label-title {
  font-weight: 600;
  display: block;
}

.en-book-label-sub {
  font-size: 0.875rem;
  color: var(--muted);
}

/* =============================================
   MAIN CONTENT AREA
   ============================================= */
.en-main {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 2rem 2rem;
}

.en-loading {
  text-align: center;
  padding: 3rem 0;
  color: var(--muted);
  font-style: italic;
}

/* Column / Line View shared */
#columnView, #lineView {
  background: var(--cream);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow:
    0 4px 24px var(--shadow),
    inset 0 1px 0 rgba(255,255,255,0.7);
  padding: 1.5rem;
  position: relative;
  overflow: visible;
}

/* Column View */
.en-col-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.en-col-header h3 {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
  margin: 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

.en-col-header h3:first-child { color: var(--thai-color); }
.en-col-header h3:last-child  { color: var(--pali-color); }

.column-row {
  display: flex;
  margin-bottom: 0.5rem;
  min-height: fit-content;
}

.column-item {
  flex: 1;
  padding: 0.6rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: flex-start;
}

/* Line View — เว้นระหว่างประโยคให้ห่างชัด (เปิดหลายแถวพร้อมกันจะได้ไม่มองปนกัน)
   ประโยคหนึ่งกินพื้นที่สูงมากเมื่อเปิดยกศัพท์ ๒ ทาง + เลขวิภัตติ + บาลี + ไทย
   → ช่องว่างระหว่างประโยคต้องมากกว่าช่องว่างระหว่างแถวในประโยคเดียวกันหลายเท่า */
.sentence-pair {
  margin-bottom: 3.2rem;
  padding: 0.5rem 0 2.6rem;
  border-bottom: 2px solid rgba(169, 134, 58, 0.3);
}
.sentence-pair:last-child { border-bottom: none; }
.sentence-pair .pali-text,
.sentence-pair .thai-text,
.sentence-pair .thai-attha-text,
.sentence-pair .idiom-interlinear-text { margin-bottom: 0.5rem; }

@media (max-width: 768px) {
  /* จอเล็กเลื่อนยาว — ลดลงหน่อยแต่ยังต่างจากช่องว่างในประโยคชัดเจน */
  .sentence-pair { margin-bottom: 1.9rem; padding: 0.3rem 0 1.3rem; }
}

.line-number {
  font-size: 0.875rem;
  color: #999;
  margin-right: 0.5rem;
  -webkit-user-select: none;
  user-select: none;
}

.word-by-word-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-size: 0.875rem;
  margin-left: 0.5rem;
  cursor: pointer;
  vertical-align: middle;
  transition: background var(--transition-speed);
}
.word-by-word-btn:hover {
  background: var(--gold-dark);
}

/* =============================================
   PAGE INFO
   ============================================= */
.en-page-info {
  text-align: center;
  padding: 1.2rem 0;
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
}

/* =============================================
   BOTTOM NAVIGATION
   ============================================= */
.en-bottom-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 1.5rem 0;
}

.en-bottom-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.en-bottom-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.en-bottom-prev {
  background: var(--parchment-deep);
  color: var(--ink-light);
  border: 1px solid var(--border);
}
.en-bottom-prev:hover:not(:disabled) {
  background: var(--border);
  color: var(--ink);
}

.en-bottom-book {
  background: linear-gradient(135deg, var(--brown), var(--brown-dark));
  color: var(--gold-light);
  box-shadow: 0 3px 12px rgba(92,61,16,0.3);
}
.en-bottom-book:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(92,61,16,0.4);
}

.en-bottom-next {
  background: var(--parchment-deep);
  color: var(--ink-light);
  border: 1px solid var(--border);
}
.en-bottom-next:hover:not(:disabled) {
  background: var(--border);
  color: var(--ink);
}

@media (max-width: 576px) {
  .en-bottom-btn {
    padding: 9px 16px;
    font-size: 0.875rem;
  }
  .en-bottom-label { display: none; }
}

/* =============================================
   FOOTER
   ============================================= */
.en-footer {
  text-align: center;
  padding: 2rem 0 1rem;
  color: var(--muted);
  font-size: 0.875rem;
}

.en-footer a {
  display: inline-block;
  margin-bottom: 1rem;
  padding: 8px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--gold-light);
  color: var(--gold-dark);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.en-footer a:hover {
  background: var(--gold-light);
  color: var(--brown-dark);
}

/* =============================================
   WORD CLICK / HOVER
   ============================================= */
.pali-word, .thai-word {
  cursor: pointer;
  padding: 3px 2px;
  border-radius: var(--radius-sm);
  transition: all 0.2s var(--ease);
  display: inline;
  position: relative;
}

.pali-word { white-space: nowrap; }

.pali-word:hover {
  background: linear-gradient(135deg,
    rgba(201,165,84,0.12) 0%,
    rgba(201,165,84,0.2) 50%,
    rgba(201,165,84,0.12) 100%);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(201,165,84,0.25);
}

.thai-word:hover {
  background: linear-gradient(135deg,
    rgba(26,58,107,0.1) 0%,
    rgba(26,58,107,0.16) 50%,
    rgba(26,58,107,0.1) 100%);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(26,58,107,0.2);
}

.word-highlighted {
  background: linear-gradient(135deg,
    rgba(201,165,84,0.5) 0%,
    rgba(201,165,84,0.65) 50%,
    rgba(201,165,84,0.5) 100%) !important;
  font-weight: 600;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(201,165,84,0.35);
}

/* Bracket markers */
.bracket-marker {
  color: var(--accent);
  font-weight: bold;
  font-size: 1.8em;
  display: inline;
  margin: 0 3px;
  cursor: pointer;
  line-height: 0.8;
}

/* =============================================
   NOTE SYSTEM
   ============================================= */
.pali-word[data-has-note="true"],
.thai-word[data-has-note="true"] {
  --note-color: #3b82f6;
}

.pali-word[data-has-note="true"]::before,
.thai-word[data-has-note="true"]::before {
  content: attr(data-note-text);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  color: var(--note-color, #3b82f6);
  font-size: 0.85em;
  font-weight: 500;
  white-space: nowrap;
  margin-bottom: -18px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 5;
}

.has-note {
  color: #7c2d12 !important;
  position: relative;
}

/* Inline Note Editor */
.inline-note-editor {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--cream);
  border: 2px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 6px;
  box-shadow: 0 4px 16px var(--shadow-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 25px;
}

/* พาเนลลอยที่ body — JS คำนวณ top/left เอง (ดู showInlineNoteEditor)
   z-index 1080: สูงกว่าแถบปัก (100) และข้อความทุกชั้น แต่ต่ำกว่า offcanvas (1090)
   ที่ควรบังได้เมื่อเปิดแผงตั้งค่า */
.inline-note-editor.floating {
  position: fixed;
  bottom: auto;
  right: auto;
  transform: none;
  margin: 0;
  z-index: 1080;
}

.inline-note-editor .editor-top {
  display: flex;
  align-items: center;
  gap: 4px;
}

.inline-note-editor .color-swatches {
  display: flex;
  gap: 4px;
  justify-content: center;
  padding-top: 2px;
}

.inline-note-editor .color-swatch {
  width: 22px;
  height: 22px;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.inline-note-editor .color-swatch:hover { transform: scale(1.1); }
.inline-note-editor .color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--gold), 0 2px 5px rgba(0,0,0,0.3);
  transform: scale(1.1);
}

.inline-note-editor .note-input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.875rem;
  width: 200px;
  outline: none;
  font-weight: 500;
  font-family: var(--font-body);
}

.inline-note-editor .note-input:focus { border-color: var(--gold); }

.inline-note-editor button {
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  font-family: var(--font-body);
}

.inline-note-editor .btn-save { background: var(--gold); color: #fff; }
.inline-note-editor .btn-save:hover { background: var(--gold-dark); }
.inline-note-editor .btn-cancel { background: var(--parchment-deep); color: var(--ink-light); }
.inline-note-editor .btn-cancel:hover { background: var(--border); }

/* Floating Note (post-it) */
.floating-note {
  position: fixed;
  z-index: 1050;
  background: #feff9c;
  border: none;
  border-radius: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-width: 300px;
  transform: rotate(-1deg);
  animation: noteIn 0.2s var(--ease);
  padding: 0;
  font-family: var(--font-body);
}

.floating-note::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  border-width: 0 16px 16px 0;
  border-style: solid;
  border-color: #e4e4a1 #fff;
  box-shadow: -2px 2px 2px rgba(0,0,0,0.1);
}

.floating-note-header {
  padding: 8px 12px 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed rgba(0,0,0,0.1);
}

.floating-note-header i { color: #b5b559; font-size: 14px; }

.floating-note-header .close-btn {
  background: none;
  border: none;
  color: #b5b559;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.floating-note-header .close-btn:hover { color: #999933; }

.note-header-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.noted-word {
  font-weight: 500;
  color: #726f3b;
  font-size: 0.95em;
}

.floating-note-content {
  font-family: var(--font-body);
  padding: 12px;
  max-height: 200px;
  overflow-y: auto;
  color: #515151;
  line-height: 1.5;
  font-size: 1em;
}

@keyframes noteIn {
  from { opacity: 0; transform: translateY(-10px) rotate(-1deg); }
  to   { opacity: 1; transform: translateY(0) rotate(-1deg); }
}

/* Post-it Modal */
.post-it-modal {
  background: #feff9c;
  border: none;
  border-radius: 3px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.post-it-modal::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  border-width: 0 20px 20px 0;
  border-style: solid;
  border-color: #e4e4a1 #fff;
  box-shadow: -2px 2px 2px rgba(0,0,0,0.1);
}

.post-it-modal .modal-header {
  border-bottom: 1px dashed rgba(0,0,0,0.1);
  padding: 1rem 1.5rem;
  background: transparent;
}

.post-it-modal .note-header-content i { color: #b5b559; font-size: 1.2rem; }
.post-it-modal .modal-title { color: #726f3b; font-size: 1.1rem; margin: 0; font-weight: 500; }
.post-it-modal .btn-close { opacity: 0.5; font-size: 0.875rem; }

.post-it-modal .modal-body {
  padding: 1.5rem;
  background: linear-gradient(transparent, transparent 28px, #e4e4a1 28px);
  background-size: 100% 29px;
}

.post-it-modal .note-textarea {
  background: transparent;
  border: none;
  line-height: 29px;
  height: auto;
  min-height: 116px;
  resize: vertical;
  color: #515151;
  font-size: 1rem;
  padding: 0;
  font-family: var(--font-body);
}

.post-it-modal .note-textarea:focus { box-shadow: none; outline: none; }
.post-it-modal .note-textarea::placeholder { color: #b5b559; opacity: 0.6; }

.post-it-modal .modal-footer {
  border-top: 1px dashed rgba(0,0,0,0.1);
  padding: 1rem 1.5rem;
  background: transparent;
}

.post-it-modal .save-note-btn { background-color: #b5b559; border-color: #b5b559; }
.post-it-modal .save-note-btn:hover { background-color: #999933; border-color: #999933; }
.post-it-modal .btn-light { background-color: rgba(255,255,255,0.5); border-color: rgba(0,0,0,0.1); }
.post-it-modal .btn-light:hover { background-color: rgba(255,255,255,0.7); }

/* =============================================
   FLOATING MENU (highlight / notes / brackets)
   ============================================= */
.floating-menu {
  position: fixed;
  background: var(--cream);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 28px var(--shadow-lg);
  z-index: 1000;
  padding: 0.5rem;
  border: 1px solid var(--border);
}

.floating-menu-content { padding: 8px; }

.highlight-colors {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 4px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.color-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
}

.color-btn:hover { transform: scale(1.15); border-color: var(--muted); }

.color-btn.clear-highlight {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border: 2px solid var(--border);
}

.color-btn.clear-highlight:hover { color: var(--ink); border-color: var(--muted); }
.color-btn.clear-highlight i { font-size: 12px; }

.note-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--ink-light);
  font-size: 0.875rem;
  font-family: var(--font-body);
}

.note-btn:hover { background: var(--parchment-deep); }

.note-btn .bracket-symbol {
  font-size: 1.8rem;
  font-weight: bold;
  color: var(--accent);
  line-height: 1;
}

/* Text Selection Menu */
.selection-menu {
  position: fixed;
  background: var(--cream);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 28px var(--shadow-lg);
  z-index: 10000;
  padding: 12px;
  border: 1px solid var(--border);
  min-width: 220px;
}

.selection-menu-content { display: flex; flex-direction: column; gap: 12px; }
.menu-section { display: flex; flex-direction: column; gap: 6px; }
.menu-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }

.color-btn-small {
  width: 28px; height: 28px;
  border-radius: 4px;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
}
.color-btn-small:hover { transform: scale(1.15); border-color: var(--muted); }

.underline-btn-small {
  width: 28px; height: 28px;
  border-radius: 4px;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-bottom-style: solid;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
  padding: 0;
}
.underline-btn-small:hover { transform: scale(1.15); border-color: var(--muted); }

.remove-style-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px;
  border: none;
  background: var(--parchment-deep);
  border-radius: 4px;
  cursor: pointer;
  color: var(--ink-light);
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.remove-style-btn:hover { background: var(--border); }

/* Text Highlight & Underline */
.text-highlight { padding: 2px 0; border-radius: 2px; }
.text-underline { border-bottom: 3px solid; padding-bottom: 1px; }

/* Highlight Mode Cursor */
body.highlight-mode .pali-word,
body.highlight-mode .thai-word { cursor: crosshair; }

/* =============================================
   SEARCH HIGHLIGHT
   ============================================= */
.search-highlighted {
  background: linear-gradient(135deg,
    rgba(201,165,84,0.25) 0%,
    rgba(201,165,84,0.18) 50%,
    rgba(201,165,84,0.25) 100%);
  border-radius: var(--radius-md);
  padding: 8px;
  border: 2px solid rgba(201,165,84,0.4);
  box-shadow: 0 4px 12px rgba(201,165,84,0.25);
  animation: searchPulse 0.6s ease-in-out;
  margin: 4px 0;
  transition: all 0.3s var(--ease);
}

@keyframes searchPulse {
  0%   { transform: scale(1);    box-shadow: 0 4px 12px rgba(201,165,84,0.25); }
  50%  { transform: scale(1.02); box-shadow: 0 8px 20px rgba(201,165,84,0.35); }
  100% { transform: scale(1);    box-shadow: 0 4px 12px rgba(201,165,84,0.25); }
}

.search-highlighted mark.bg-warning {
  background: linear-gradient(135deg,
    rgba(201,165,84,0.7) 0%,
    rgba(228,213,160,0.8) 50%,
    rgba(201,165,84,0.7) 100%) !important;
  color: var(--ink) !important;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 3px;
}

.table tbody tr td mark.bg-warning {
  background: linear-gradient(135deg,
    rgba(201,165,84,0.5) 0%,
    rgba(228,213,160,0.6) 50%,
    rgba(201,165,84,0.5) 100%) !important;
  color: var(--ink) !important;
  font-weight: 500;
  padding: 1px 3px;
  border-radius: 3px;
}

/* =============================================
   OFFCANVAS (shared overrides)
   ============================================= */
.offcanvas {
  background: linear-gradient(180deg, var(--cream) 0%, var(--parchment) 100%);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-color: var(--border) !important;
  box-shadow: 0 0 40px var(--shadow-lg);
}

.offcanvas-header {
  background: linear-gradient(135deg, var(--cream), var(--parchment-deep));
  border-bottom: 1px solid var(--border);
}

.offcanvas-body { background: transparent; }

/* =============================================
   TRANSLATION OFFCANVAS
   ============================================= */
.translation-content {
  font-size: 1rem;
  line-height: 1.7;
}

.similar-word {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  transition: all 0.2s var(--ease);
  background: var(--cream);
  margin-bottom: 8px;
}

.similar-word:hover {
  background: var(--parchment-deep);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

.similar-word strong { color: var(--ink); font-weight: 600; }

.similar-word.border-warning { border-left: 4px solid var(--gold); }
.similar-word.border-info    { border-left: 4px solid #3b82f6; }
.similar-word.border-secondary { border-left: 4px solid var(--muted); }
.similar-word.border-success { border-left: 4px solid #10b981; }

/* Translation Details */
.translation-content .btn-outline-secondary.btn-sm,
.similar-word .btn-outline-secondary.btn-sm {
  width: 24px; height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.875rem;
  opacity: 0.7;
}

.translation-content .btn-outline-secondary.btn-sm:hover,
.similar-word .btn-outline-secondary.btn-sm:hover {
  background: var(--muted);
  border-color: var(--muted);
  color: #fff;
  opacity: 1;
}

.details-content { transition: all 0.3s; overflow: hidden; }
.details-content .card-body {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  margin: 0;
}

.clickable-meaning {
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}
.clickable-meaning:hover { background: rgba(201,165,84,0.08); }

.meaning-line {
  padding: 0.75rem;
  border-radius: var(--radius-md);
  transition: all 0.3s var(--ease);
}

/* =============================================
   WORD BY WORD TRANSLATION
   ============================================= */
.word-by-word-translation {
  background: linear-gradient(135deg, var(--cream) 0%, var(--parchment-deep) 100%);
  border-radius: var(--radius-md);
  box-shadow: 0 2px 8px var(--shadow);
  animation: slideInDown 0.3s var(--ease);
}

.word-by-word-translation .grid {
  background: var(--cream);
  border-radius: var(--radius-sm);
  padding: 8px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}

.word-by-word-translation .flex.items-start {
  transition: background 0.2s;
}
.word-by-word-translation .flex.items-start:hover {
  background: var(--parchment-deep);
  border-radius: 4px;
  padding: 2px 4px;
}

@keyframes slideInDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.word-by-word-loading {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  color: var(--muted);
  animation: pulse 1.5s ease-in-out infinite;
}
.word-by-word-loading::after {
  content: '\27F3';
  animation: spin 1s linear infinite;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Confidence colors */
.text-green-600  { color: #059669 !important; font-weight: 600; }
.text-blue-600   { color: #2563eb !important; font-weight: 600; }
.text-orange-600 { color: #ea580c !important; font-weight: 600; }
.text-red-600    { color: #dc2626 !important; font-weight: 600; }

/* =============================================
   EXAM ITEMS
   ============================================= */
.exam-item { transition: background 0.15s; }
.exam-item:hover { background: var(--parchment-deep); }

/* =============================================
   SYNTAX ANNOTATIONS
   ============================================= */
.syntax-lines-svg {
  background: var(--cream);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: visible;
}

.syntax-annotation-block {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  align-items: flex-start !important;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--cream) 0%, var(--parchment-deep) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
}

.syntax-word-item {
  display: inline-flex !important;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  width: auto !important;
  max-width: fit-content;
  padding: 4px 8px;
  background: var(--cream);
  border-radius: var(--radius-sm);
  min-width: 40px;
  box-shadow: 0 1px 3px var(--shadow);
  transition: transform 0.15s;
}

.syntax-word-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px var(--shadow-md);
}

.syntax-word-text { font-size: 1rem; font-weight: 600; color: var(--pali-color); white-space: nowrap; line-height: 1.4; }
.syntax-relation-label { font-size: 0.875rem; font-weight: 500; white-space: nowrap; line-height: 1.3; margin-top: 2px; }
.syntax-link-label { font-size: 0.875rem; color: var(--muted); white-space: nowrap; line-height: 1.2; margin-top: 1px; }

.syntax-implied-item { background: #eff6ff; border: 1px dashed #93c5fd; }
.syntax-implied-item .syntax-word-text { color: #1e40af; font-style: italic; }

.syntax-sandhi-header { background: var(--parchment-deep); border: 1px solid var(--border); }
.syntax-sandhi-header .syntax-word-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--accent); text-decoration-thickness: 2px; }
.syntax-split-label { font-size: 0.875rem; color: var(--muted); font-style: italic; }

.syntax-sandhi-part-item { background: var(--cream); border: 1px solid var(--gold-light); margin-left: -2px; }
.syntax-sandhi-part-item .syntax-word-text { color: var(--pali-color); }

.syntax-inline-implied {
  display: inline;
  color: #1e40af;
  font-style: italic;
  background: #eff6ff;
  border: 1px dashed #93c5fd;
  border-radius: 3px;
  padding: 1px 4px;
  margin: 0 2px;
  font-size: 0.95em;
  vertical-align: baseline;
}

.syntax-inline-sandhi { display: inline; color: var(--pali-color); margin-left: 2px; vertical-align: baseline; }
.syntax-inline-sandhi-part { display: inline; }

/* Syntax Filter Offcanvas */
.syntax-filter-category { border-bottom: 1px solid var(--border-light); }

.syntax-filter-cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  background: var(--parchment);
  transition: background 0.15s;
}
.syntax-filter-cat-header:hover { background: var(--parchment-deep); }

.syntax-filter-items { padding: 4px 12px 8px 28px; }

.syntax-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  font-size: 0.875rem;
}
.syntax-filter-item:hover { color: var(--pali-color); }

.syntax-filter-color {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

.syntax-filter-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Color picker popup */
.syntax-color-picker-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.syntax-color-picker-popup {
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: 0 12px 40px var(--shadow-lg);
  min-width: 260px;
  max-width: 320px;
  border: 1px solid var(--border);
}

/* =============================================
   SELECT2 GLOBAL OVERRIDES
   ============================================= */
.select2-container .select2-selection--single {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--cream);
}

.select2-container .select2-selection--single .select2-selection__rendered {
  line-height: 32px;
  padding-left: 10px;
  font-size: 0.875rem;
  color: var(--ink);
}

.select2-container .select2-selection--single .select2-selection__arrow {
  height: 32px;
}

.select2-dropdown {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px var(--shadow-md);
}

.select2-search--dropdown .select2-search__field {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-family: var(--font-body);
}

/* สารบัญ: ชื่อเรื่องมีทั้งบาลีและไทย จึงต้องใช้ฟอนต์ที่มีสระ/พินทุบาลีครบ */
#tocSelect + .select2-container .select2-selection__rendered,
.select2-container--open .select2-dropdown[dir] .select2-results__option,
.toc-select2 .select2-results__option,
.toc-select2 .select2-selection__rendered {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.05rem;
  line-height: 1.55;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 768px) {
  .en-book-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    padding: 1rem;
  }

  .en-hero-title { font-size: 1.5rem; }
  .en-hero { padding: 1.5rem 1rem; }

  .en-main { padding: 0 0.75rem 2rem; }

  #columnView, #lineView { padding: 1rem; border-radius: var(--radius-md); }

  .word-by-word-translation { margin: 8px 0; padding: 8px; }
  .word-by-word-translation .flex.items-start { flex-direction: column; gap: 4px; }
  .word-by-word-translation .text-xs { font-size: 0.875rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .en-book-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 1025px) {
  .en-book-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* =============================================
   MISC UTILITIES
   ============================================= */
.bg-very-light {
  --bs-bg-opacity: 1;
  background-color: var(--parchment) !important;
}

.table {
  --bs-table-accent-bg: transparent;
}

/* Smooth scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--parchment); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* =============================================
   TAILWIND-EQUIVALENT UTILITY CLASSES
   (used by dynamically generated innerHTML)
   ============================================= */
/* Text colors */
.text-amber-800, .text-amber-900 { color: var(--pali-color); }
.text-blue-600 { color: #2563eb; }
.text-blue-900 { color: var(--thai-attha-color, #1e3a5f); }
.text-red-600 { color: #dc2626; }
.text-gray-400 { color: #9ca3af; }
.text-gray-500 { color: #6b7280; }
.text-gray-600 { color: #6b7280; }
.text-gray-700 { color: #374151; }
.text-black { color: #111; }
.text-white { color: #fff; }
.text-success { color: #16a34a; }

/* Font sizes */
.text-xs { font-size: 0.875rem; }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }

/* Font weight */
.font-semibold { font-weight: 600; }

/* Spacing */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.ml-1 { margin-left: 0.25rem; }
.ml-2 { margin-left: 0.5rem; }
.mr-2 { margin-right: 0.5rem; }
.p-3 { padding: 0.75rem; }
.px-1 { padding-left: 0.25rem; padding-right: 0.25rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.py-0\.5 { padding-top: 0.125rem; padding-bottom: 0.125rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; }

/* Background colors */
.bg-gray-50 { background-color: #f9fafb; }
.bg-gray-500 { background-color: #6b7280; }
.bg-purple-500 { background-color: var(--gold); }
.bg-purple-600 { background-color: var(--gold-dark); }
.bg-orange-500 { background-color: #f97316; }
.bg-orange-600 { background-color: #ea580c; }
.bg-warning { background-color: #fef3c7; }

/* Layout */
.rounded { border-radius: var(--radius-sm); }
.border-l-4 { border-left: 4px solid; }
.border-purple-400 { border-left-color: var(--gold); }
.leading-relaxed { line-height: 1.625; }

/* Word-by-word translation block */
.word-by-word-translation {
  margin: 0.5rem 0;
  padding: 0.75rem;
  background: var(--cream);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--gold);
}

/* Button state colors for word-by-word toggle */
.word-by-word-btn.bg-orange-500 { background: #f97316; }
.word-by-word-btn.bg-orange-500:hover { background: #ea580c; }
.word-by-word-btn.bg-gray-500 { background: #6b7280; }

/* Confidence score badges */
.bg-green-100 { background-color: #dcfce7; }
.text-green-800 { color: #166534; }
.bg-blue-100 { background-color: #dbeafe; }
.text-blue-800 { color: #1e40af; }
.bg-orange-100 { background-color: #ffedd5; }
.text-orange-800 { color: #9a3412; }
.bg-red-100 { background-color: #fee2e2; }
.text-red-800 { color: #991b1b; }

/* Spinner */
.spinner-loading {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════
   SAMPAN (สัมพันธ์) INTEGRATION STYLES
   ═══════════════════════════════════════════════════════════ */

.sampan-toggle-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--cream);
  cursor: pointer; transition: all 0.2s;
  color: var(--muted); vertical-align: middle;
  margin-left: 4px; font-size: 0.875rem; padding: 0;
}
.sampan-toggle-btn:hover { background: #fef3dc; border-color: var(--gold); color: var(--gold); }
.sampan-toggle-btn.active { background: var(--gold); color: #fff; border-color: var(--gold); }

.sampan-panel {
  margin: 10px 0 18px; padding: 14px 16px;
  background: #fdfbf5; border: 1px solid #e2ddd4;
  border-radius: 10px; box-shadow: 0 2px 8px rgba(44,36,22,0.06);
  animation: sampanFadeIn 0.25s ease;
}
.sampan-panel-loading { text-align: center; padding: 24px; color: var(--muted); font-size: 0.9rem; }
.sampan-panel-empty { text-align: center; padding: 16px; color: var(--muted); font-size: 0.875rem; font-style: italic; }
@keyframes sampanFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sampan-section-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: #f8f6f2; border: 1px solid #ece8e0;
  border-radius: 6px; cursor: pointer; font-size: 0.875rem; font-weight: 600;
  color: var(--ink); margin-bottom: 4px; transition: all 0.15s;
}
.sampan-section-toggle:hover { background: #f5f0e8; }
.sampan-section-toggle .sampan-badge { background: #e2ddd4; color: #7a7062; padding: 2px 7px; border-radius: 10px; font-size: 0.875rem; }
.sampan-section-toggle .sampan-arrow { transition: transform 0.2s; font-size: 0.875rem; color: var(--muted); }
.sampan-section-toggle.open .sampan-arrow { transform: rotate(180deg); }
.sampan-section-body { display: none; padding: 10px 0 4px; }
.sampan-section-body.open { display: block; }

/* --- Interlinear --- */
.sampan-interlinear { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.sampan-iu {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 8px; border-radius: 6px; border: 1.5px solid transparent;
  cursor: pointer; transition: all 0.15s; position: relative; min-width: 36px;
}
.sampan-iu:hover { background: #fef9f0; border-color: #e8d5a0; }
.sampan-iu.aligned { border-color: #e2ddd4; background: #fff; }
.sampan-iu.unaligned { opacity: 0.5; border-style: dashed; border-color: #e2ddd4; }
.sampan-iu.highlighted { border-color: var(--gold) !important; background: #fef3dc !important; box-shadow: 0 0 0 2px rgba(201,145,58,0.2); opacity: 1 !important; }
.sampan-iu.implied-unit { opacity: 0.55; border-style: dashed; }
.sampan-iu.implied-unit .iu-pali { font-style: italic; font-weight: 400; }
.sampan-iu .iu-pali { font-family: 'THSarabunPali', var(--font-body); font-size: 1.5rem; color: var(--pali-color); font-weight: 600; line-height: 1.3; text-align: center; }
.sampan-iu .iu-thai { font-size: 1.05rem; color: var(--thai-color); line-height: 1.3; text-align: center; margin-top: 2px; }
.sampan-iu .iu-role { font-size: 0.875rem; font-weight: 600; padding: 2px 6px; border-radius: 2px; color: #fff; margin-top: 3px; white-space: nowrap; }
.sampan-iu .iu-vib { position: absolute; top: -5px; right: -5px; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid #fff; }

/* --- Sambandh Table --- */
.sampan-tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sampan-sambandh-tbl { width: 100%; border-collapse: collapse; font-size: 1rem; }
.sampan-sambandh-tbl th { text-align: left; padding: 8px 12px; font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--pali-color); font-weight: 700; border-bottom: 2px solid #e8d5b0; background: #fdf6e9; white-space: nowrap; }
.sampan-sambandh-tbl td { padding: 8px 12px; border-bottom: 1px solid #ece8e0; vertical-align: middle; }
.sampan-sambandh-tbl tbody tr { cursor: pointer; transition: background 0.1s; }
.sampan-sambandh-tbl tbody tr:hover { background: #fef9f0; }
.sampan-sambandh-tbl .verb-row { background: #f4f7fb; }
.sampan-sambandh-tbl .sabda-row { background: #f6f3fa; }
.sampan-sambandh-tbl .implied-row { opacity: 0.55; }
.sampan-sambandh-tbl .pali-cell { font-family: 'THSarabunPali', var(--font-body); color: var(--pali-color); font-weight: 600; font-size: 1.45rem; }

.sampan-vib-badge { display: inline-block; padding: 3px 10px; border-radius: 3px; font-size: 0.875rem; font-weight: 700; color: #fff; }
.sampan-vib-badge.vib-pathama { background: #1565C0; }
.sampan-vib-badge.vib-dutiya { background: #C62828; }
.sampan-vib-badge.vib-tatiya { background: #2E7D32; }
.sampan-vib-badge.vib-catutthi { background: #6A1B9A; }
.sampan-vib-badge.vib-pancami { background: #E65100; }
.sampan-vib-badge.vib-chatthi { background: #00695C; }
.sampan-vib-badge.vib-sattami { background: #4E342E; }
.sampan-vib-badge.vib-alapana { background: #AD1457; }
.sampan-vib-badge.vib-verb { background: #37474F; }
.sampan-vib-badge.vib-sabda { background: #607D8B; }

/* --- Dependency Arcs --- */
.sampan-dep-container { position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0; padding: 8px 0 0; }
.sampan-dep-words { display: flex; gap: 0; align-items: flex-end; padding-top: 10px; position: relative; }
.sampan-dep-word { display: flex; flex-direction: column; align-items: center; padding: 0 14px; min-width: 46px; cursor: pointer; position: relative; }
.sampan-dep-word-text { font-family: 'THSarabunPali', var(--font-body); font-size: 1.3rem; font-weight: 500; color: var(--ink); padding: 4px 6px; border-radius: 3px; white-space: nowrap; transition: background 0.12s; }
.sampan-dep-word:hover .sampan-dep-word-text { background: #fef3dc; }
.sampan-dep-word-role { font-size: 0.875rem; color: #a39b8e; margin-top: 2px; white-space: nowrap; }
.sampan-dep-word .vib-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 2px; }
.sampan-dep-word.dep-implied .sampan-dep-word-text { color: #bbb; font-style: italic; }
.sampan-dep-word.dep-subject .sampan-dep-word-text { color: #1565C0; font-weight: 700; }
.sampan-dep-word.dep-verb .sampan-dep-word-text { color: #D32F2F; font-weight: 700; }
.sampan-dep-word.dep-highlight .sampan-dep-word-text { background: #fef3dc; box-shadow: 0 0 5px rgba(201,145,58,0.3); }
.sampan-dep-svg { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }
.sampan-dep-svg path { fill: none; stroke-width: 1.5; }
.sampan-dep-svg text { font-size: 13px; text-anchor: middle; font-family: 'Sarabun', sans-serif; }
.sampan-dep-svg .arc-label-bg { fill: #fdfbf5; stroke: none; }

/* --- Responsive --- */
@media (max-width: 768px) {
  .sampan-panel { padding: 10px; margin: 8px 0 14px; }
  .sampan-iu { padding: 4px 6px; min-width: 30px; }
  .sampan-iu .iu-pali { font-size: 1.25rem; }
  .sampan-iu .iu-thai { font-size: 0.9rem; }
  .sampan-iu .iu-role { font-size: 0.875rem; }
  .sampan-sambandh-tbl { font-size: 0.9rem; }
  .sampan-sambandh-tbl .pali-cell { font-size: 1.05rem; }
  .sampan-dep-word { padding: 0 8px; min-width: 36px; }
  .sampan-dep-word-text { font-size: 1.1rem; }
  .sampan-dep-word-role { font-size: 0.875rem; }
}

/* ═══════════════════════════════════════════════════════════
   สัมพันธ์จากหนังสือ (display mode "+ สัมพันธ์")
   ═══════════════════════════════════════════════════════════ */
/* สัมพันธ์: แสดงเป็นบรรทัดปกติ ไม่มีกล่อง/หัวข้อ — ใช้ฟอนต์+ขนาดเดียวกับแถวบาลี
   (ต้องเป็น THSarabunPali เพราะมีคำบาลี ฐ/ญ ตัดเชิงที่ฟอนต์ไทยทั่วไปแสดงเพี้ยน)
   THSarabunPali เส้นบาง/แคบกว่า Sarabun — เพิ่ม text-stroke เล็กน้อยให้น้ำหนักใกล้เคียง */
.sampan-book-text {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.72rem;
  line-height: 1.85;
  color: var(--pali-color);
  -webkit-text-stroke: 0.3px currentColor;
  border: 1px dashed #d8cdb8;
  border-radius: 8px;
  background: transparent;
  padding: 0.5rem 0.85rem;
  margin: 0.35rem 0 0.5rem;
}
.sampan-book-status { margin-top: 4px; }
.sampan-book-badge { font-family: var(--font-body); vertical-align: middle; -webkit-text-stroke: 0; }
.sampan-book-badge.review {
  background: #fff3cd;
  color: #8a6d2f;
  border: 1px solid #e6d9a8;
  font-size: 0.875rem;
  border-radius: 999px;
  padding: 0 8px;
  cursor: help;
}
.sampan-book-line { word-wrap: break-word; overflow-wrap: break-word; }
/* THSarabunPali ลงทะเบียน bold ด้วยไฟล์ regular — จำลองตัวหนาด้วย stroke */
.sampan-book-line strong {
  -webkit-text-stroke: 0.55px currentColor;
  letter-spacing: 0.01em;
}
/* คำบาลีของประโยคโจทย์ — เน้นหนา สีน้ำตาลอ่อนลงเล็กน้อย */
.sampan-src {
  -webkit-text-stroke: 0.5px currentColor;
  letter-spacing: 0.01em;
  color: #6e4526;
}
/* ชื่อสัมพันธ์/ประเภทศัพท์ — สีแยกให้เห็นชัด */
.sampan-role { color: #2e6e5e; }
/* คำเชื่อมสัมพันธ์ — แยกสีตามคำ ให้เห็นทันทีว่าบทนี้เชื่อมด้วยคำไหน
   ใน = น้ำเงินเข้ม · ของ = ส้มเข้ม · เข้ากับ (เข้า/กับ) = ชมพูเข้ม */
.sampan-conn { font-weight: 600; }
.sampan-conn.c-nai { color: #0d47a1; }
.sampan-conn.c-khong { color: #c2560a; }
.sampan-conn.c-kap { color: #c2185b; }
.sampan-book-line.indent { padding-left: 2.2em; }
.sampan-book-line sup { font-size: 0.55em; color: var(--muted); }
.sampan-invisible { border-bottom: 1px dotted #c9a227; cursor: help; }
.sampan-book-loading { color: var(--muted); font-style: italic; font-size: 1rem; }
@media (max-width: 640px) {
  .sampan-book-line.indent { padding-left: 1.4em; }
  .idiom-interlinear-text { padding: 0.5rem 0.45rem 0.6rem; }
  .idiom-interlinear-heading > span:last-child { display: none; }
  .idiom-interlinear-row { column-gap: 0.45rem; row-gap: 0.65rem; }
}
.sampan-book-badge.rejected {
  background: #fde2e2;
  color: #a33;
  border: 1px solid #e8b4b4;
  font-size: 0.875rem;
  border-radius: 999px;
  padding: 0 8px;
  cursor: help;
}

/* ---------- การแสดงผลแบบแถว (ติ๊ก + ลากเรียง + ฝึก) ---------- */
.display-rows { display: flex; flex-direction: column; gap: 4px; }
.drow {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 8px;
}
.drow.drow-off { opacity: .55; }
.drow.drow-unavailable { background: #f4f1eb; }
.drow.drow-unavailable .drow-handle { cursor: not-allowed; }
.drow.sortable-ghost { opacity: .3; background: #fef3dc; }
.drow-handle { color: #b9ab90; cursor: grab; font-size: 1rem; touch-action: none; }
.drow-handle:active { cursor: grabbing; }
.drow-label { display: flex; align-items: center; gap: 7px; flex: 1; margin: 0; cursor: pointer; font-size: .92rem; }
.drow-label input { margin: 0; }
.drow-scope {
  border: 1px solid #d8c79f;
  border-radius: 999px;
  padding: 0 6px;
  color: #876820;
  background: #fbf6e8;
  font-size: 0.875rem;
  line-height: 1.45;
}
.drow-practice {
  border: 1px solid var(--border); background: var(--cream, #faf6ec);
  color: var(--muted); border-radius: 999px; font-size: 0.875rem; padding: 1px 9px;
}
.drow-practice.active { background: #a9863a; border-color: #8a6d2f; color: #fff; font-weight: 600; }

/* ตัวเลือก "ฝึกเขียน..." ในหน้าส่งออก — แยกด้วยสีอ่อน */
.drow.drow-practice-item { background: #fbf7ef; border-style: dashed; }
.drow.drow-practice-item .drow-label span { color: #8a6d2f; }

/* บาลีโยคศัพท์ — บาลี + ศัพท์โยค (วงเล็บ) จากฉบับวัดช้างแดง */
.paliyok-text {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.65rem;
  line-height: 2.3;
  color: var(--pali-color);
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.paliyok-text .yok-supplied {
  color: #15803d;
}
.paliyok-loading {
  color: #9ca3af;
  font-size: 1rem;
}

/* ยกศัพท์ — ภาค ๑–๔ ฉบับบุญสืบ อินสาร · ภาค ๕–๘ ฉบับคัณฐีฯ (มหามกุฏฯ) บาลีสลับคำแปลไทยตามลำดับแปล
   บาลี (.bp) ใช้ฟอนต์/สีเดียวกับแถวบาลี · ศัพท์โยคในวงเล็บ (.by) เขียว #15803d ชุดเดียวกับ .yok-supplied
   คำแปลไทยเป็นฟอนต์เนื้อความ เล็กกว่าบาลีเล็กน้อย ให้สายตาจับคู่ "คำ–คำแปล" ทีละคู่ได้ */
.bsyok-text {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 2.1;
  color: var(--text-color, #2b2118);
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
}
.bsyok-text .bp,
.bsyok-text .by {
  font-family: 'THSarabunPali', var(--font-body);
  font-size: 1.5rem;
  color: var(--pali-color);
  line-height: 1;
}
.bsyok-text .by { color: #15803d; }
.bsyok-loading, .bsyok-none, .bsyok-part { color: #9ca3af; font-size: 0.95rem; }
.bsyok-part span, .bsyok-none span { font-style: italic; }
.reader-compact .bsyok-text { line-height: 1.8; }
/* แถวที่มีโน้ต: เผื่อที่เหนือคำให้ป้ายโน้ต (::before) ไม่ทับบรรทัดก่อนหน้า */
.bsyok-text:has([data-has-note="true"]),
.reader-compact .bsyok-text:has([data-has-note="true"]) { line-height: 2.9; padding-top: .35em; }
.paliyok-text:has([data-has-note="true"]) { padding-top: .35em; }
/* คำบาลีในยกศัพท์ฟอนต์ใหญ่ + line-height 1 — ป้ายโน้ตต้องยกขึ้นพ้นตัวคำ และย่อให้เท่าโน้ตของคำแปล */
.bsyok-text :is(.bp, .by) .pali-word[data-has-note="true"]::before {
  font-family: var(--font-body);
  font-size: .6em;
  margin-bottom: 2px;
}


/* Reader controls and accessible typography. Root scaling also reaches overlays. */
body, #app { font-size: 1rem; }
#app { line-height: 1.6; }
.en-settings-label, .line-number { color: #73604e; }
.en-reader-help, #filterOffcanvas .tagf-help { font-size: 1rem; line-height: 1.7; }
.en-reader-help { margin: 0; color: #6c5946; }
.en-reader-action { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px; height: auto; border: 1px solid var(--border); border-radius: .4rem; padding: .5rem .7rem; background: var(--cream); color: var(--brown-dark); font: inherit; font-size: .875rem; cursor: pointer; white-space: normal; }
.en-reader-action[aria-pressed="true"] { background: var(--brown); border-color: var(--brown); color: white; }
.en-reader-action:hover { box-shadow: inset 0 0 0 1px var(--gold-dark); }
#app :is(button, a, input, select, [role="button"]):focus-visible { outline: 3px solid #176896; outline-offset: 3px; }
.en-reader-tools { display: flex; flex-direction: column; gap: 1rem; }
.en-reader-tools .en-reader-action { justify-content: flex-start; font-size: 1rem; }
.en-nav-inner, .en-nav-right { flex-wrap: wrap; }
.en-nav-right { align-items: center; gap: .4rem; }
.en-nav :is(.en-nav-btn, .en-nav-btn-page, .en-book-select) { min-height: 44px; height: auto; min-width: 44px; }
.en-nav-center { flex: 1 1 auto; }
.en-book-select { max-width: none; }
.en-page-label { font-size: .875rem; }
.en-nav .select2-container { min-width: 5rem; }
.en-nav .select2-selection--single { min-height: 44px; height: auto !important; display: flex; align-items: center; }
.en-nav .select2-selection__rendered { font-size: .875rem !important; line-height: 1.6 !important; padding-right: 1.6rem !important; }
.en-nav .select2-selection__arrow { top: 50% !important; transform: translateY(-50%); }
.offcanvas { max-width: 100vw; }
.offcanvas :is(.btn, .form-select), .drow-practice { min-height: 44px; }
#settingsOffcanvas .btn { font-size: .875rem; }
#settingsOffcanvas .d-flex { flex-wrap: wrap; }
.reader-compact .sentence-pair { padding: .4rem 0 1.25rem; margin-bottom: 1.5rem; border-bottom-width: 1px; }
.reader-compact .pali-text { line-height: 1.75; }
.reader-compact .thai-text, .reader-compact .thai-attha-text { line-height: 1.75; }
/* Keep grammar annotations spaced independently from ordinary reading text. */
.vword-tag, .yoksap-thai, .idiom-interlinear-gloss, .wp-row, .sampan-iu .iu-thai { font-size: 1rem; line-height: 1.6; }
.hidden-thai { display: block; min-height: 44px; }
.hidden-thai > .practice-toggle { visibility: visible; opacity: 1; min-height: 44px; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: .4rem; background: var(--cream); font: inherit; font-size: 1rem; line-height: 1.6; color: var(--brown); cursor: pointer; text-align: left; }
.hidden-thai .practice-hide, .hidden-thai > .practice-answer { display: none; }
.hidden-thai.reveal-thai .practice-prompt { display: none; }
.hidden-thai.reveal-thai .practice-hide, .hidden-thai.reveal-thai > .practice-answer { display: block; }
.hidden-thai.reveal-thai > .practice-answer { margin-top: .5rem; }
@media (max-width: 640px) {
  .en-nav { padding: .5rem; }
  .en-nav-right { flex: 1 1 100%; }
  .en-nav-right .en-reader-action { flex: 1 1 auto; }
  #lineView, #columnView { padding: 1rem; }
  .column-row { flex-direction: column; }
  .en-col-header { display: none; }
  .reader-compact .sentence-pair { padding-bottom: 1rem; margin-bottom: 1rem; }
}

.yoksap-heading > span, .vibhatti-heading > span { font-size: 1rem; line-height: 1.6; }
#translationOffcanvas .small { font-size: 1rem; line-height: 1.6; }
.en-bottom-nav button { min-height: 44px; }

@media (max-width: 640px) {
  .en-nav-inner { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px 44px; gap: 6px; }
  .en-nav-center { grid-column: 2; min-width: 0; }
  .en-nav-btn-page.prev { grid-column: 3; grid-row: 1; width: 44px; }
  .en-nav-btn-page.next { grid-column: 4; grid-row: 1; width: 44px; }
  .en-nav-right { grid-column: 1 / -1; grid-row: 2; }
  .en-nav-right .en-reader-action { padding-inline: .35rem; }
  .en-nav .en-page-label { display: none; }
  .en-nav .select2-container { width: 4rem !important; min-width: 0; flex: 1; }
  .en-nav .en-book-select { min-width: 0; padding-inline: .35rem; max-width: 5rem; }
}

/* Keep forecast context readable alongside the reader's font-size control. */
.en-exam-study { background: #fffaf0; border: 1px solid #c9a554; border-radius: 12px; padding: 18px; margin: 0 auto 22px; color: #3c1f10; max-width: 1100px; line-height: 1.7; overflow-wrap: anywhere; font-family: system-ui, sans-serif; }
.en-exam-study p { font-size: 1em; line-height: 1.7; margin: 6px 0; }
.en-exam-study-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 14px; }
.en-exam-study-actions button, .en-exam-study-actions a { font: inherit; line-height: 1.6; padding: 8px 12px; border: 1px solid #94733b; background: #fff; color: #5c3d10; border-radius: 8px; min-height: 44px; }
.en-exam-study-actions button[aria-pressed="true"] { background: #e7efe2; color: #29451c; border-color: #567747; }
.en-exam-study-actions :focus-visible { outline: 3px solid #5c3d10; outline-offset: 3px; }

/* =============================================
   ที่มาของข้อมูล (โมดัล #sourcesModal + ปุ่มในฟุตเตอร์)
   ============================================= */
.en-footer-sources { margin: 0.75rem 0 0; }

/* ปุ่มเปิดโมดัล — ทำให้เหมือนลิงก์ข้อความ ไม่ใช่ปุ่มก้อนเหมือน "กลับเมนูหลัก" */
.en-sources-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--gold-dark);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.en-sources-link:hover { color: var(--brown-dark); }

.sources-body { padding: 1.25rem 1.5rem 1.5rem; }
.sources-intro {
  margin-bottom: 1.25rem;
  color: var(--muted);
  line-height: 1.75;
}
.sources-item {
  padding: 0.85rem 0 0.85rem 0.9rem;
  border-left: 3px solid var(--gold-light);
  margin-bottom: 0.75rem;
}
.sources-item h6 {
  margin: 0 0 0.35rem;
  color: var(--gold-dark);
  font-weight: 700;
  font-size: 1rem;
}
.sources-item p { margin: 0; line-height: 1.8; }
.sources-note {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}
.sources-item code {
  background: #f4f1eb;
  border-radius: 4px;
  padding: 0 4px;
  color: var(--brown-dark);
}
.sources-foot {
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.75;
}

/* วิธีทำตัว ตามขั้นตอน (lex_verb_steps) */
.wp-vsteps summary { cursor: pointer; list-style: none; }
.wp-vsteps summary::-webkit-details-marker { display: none; }
.wp-vsteps summary::before { content: '▸ '; color: #b0a074; }
.wp-vsteps[open] summary::before { content: '▾ '; }
.wp-vs-formula { font-family: 'THSarabunPali', var(--font-body); font-weight: 400; color: #6b5320; font-size: 1.05rem; }
.wp-vs-scroll { overflow-x: auto; margin: 0.25rem 0; }
.wp-vs-table { border-collapse: collapse; font-family: 'THSarabunPali', var(--font-body); font-size: 1.1rem; line-height: 1.25; }
.wp-vs-table th { font-family: var(--font-body); font-size: 0.75rem; font-weight: 600; color: #8a7a55; text-align: left; padding: 0 0.4rem 0.1rem 0; }
.wp-vs-table td { padding: 0.05rem 0.4rem 0.05rem 0; color: #3a3020; white-space: nowrap; border-top: 1px dotted #eee3c3; }
.wp-vs-table td b { color: #c2410c; }
.wp-vs-table td s { color: #a8a29e; }
.wp-vs-table .wp-vs-rule { font-family: var(--font-body); font-size: 0.8rem; color: #0f6b4f; white-space: normal; min-width: 5.5rem; }
.wp-vs-result { font-family: 'THSarabunPali', var(--font-body); font-size: 1.1rem; color: #3a3020; }
.wp-vs-result b { color: #0f6b4f; }
.wp-vs-explain { font-size: 0.85rem; color: #6b5320; margin-top: 0.15rem; line-height: 1.45; }

/* ───── คลิปสอนยกศัพท์รายประโยค (R2 · media.purivaro.com) ───── */
.yokvid-chips { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .9rem; }
.yokvid-lead { font-size: .95rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; margin-right: .15rem; }
.yokvid-btn {
  display: inline-flex; align-items: center; gap: .45rem; min-height: 40px; padding: .35rem .9rem .35rem .7rem;
  border: 1px solid var(--gold); border-radius: 999px; background: var(--cream); color: var(--brown);
  font: inherit; font-size: .95rem; line-height: 1.3; cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.yokvid-btn .bi { font-size: 1.15rem; color: var(--accent); }
.yokvid-btn:hover { background: #FBF3E2; border-color: var(--gold-dark); box-shadow: 0 2px 8px var(--shadow-md); }
.yokvid-btn:focus-visible { outline: 3px solid rgba(184, 67, 47, .35); outline-offset: 2px; }
.yokvid-dur { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; padding-left: .45rem; border-left: 1px solid var(--border); }

.yokvid-dialog { max-width: 920px; }
.yokvid-content { background: var(--parchment); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.yokvid-header { border-bottom: 1px solid var(--border-light); align-items: flex-start; padding: .9rem 1.2rem; }
.yokvid-kicker { font-size: .85rem; color: var(--gold-dark); letter-spacing: .01em; }
.yokvid-header .modal-title { font-family: var(--font-body); font-size: 1.15rem; font-weight: 600; color: var(--pali-color); line-height: 1.5; margin: .1rem 0 0; }
.yokvid-body { display: flex; gap: 1.25rem; padding: 1.1rem 1.2rem; align-items: flex-start; }
.yokvid-frame { position: relative; flex: 0 0 auto; height: min(72vh, 640px); aspect-ratio: 9 / 16; background: #1d0b0b; border-radius: var(--radius-md); overflow: hidden; box-shadow: 0 6px 24px var(--shadow-lg); }
.yokvid-frame video { width: 100%; height: 100%; display: block; object-fit: contain; background: #1d0b0b; }
.yokvid-error { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .35rem; padding: 1.5rem; text-align: center; color: #f5e9d4; background: rgba(29, 11, 11, .92); }
.yokvid-error[hidden] { display: none; }
.yokvid-error .bi { font-size: 2rem; color: var(--gold-light); }
.yokvid-error p { margin: 0; font-size: 1.05rem; }
.yokvid-side { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 1.1rem; }
.yokvid-label { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.yokvid-rowtags { display: flex; flex-wrap: wrap; gap: .4rem; }
.yokvid-rowtag { font-size: .9rem; padding: .2rem .6rem; border-radius: var(--radius-sm); background: var(--parchment-deep); color: var(--ink-light); border: 1px solid var(--border-light); }
.yokvid-learned ul { margin: 0; padding-left: 1.15rem; }
.yokvid-learned li { color: var(--ink); line-height: 1.7; margin-bottom: .2rem; }
.yokvid-learned li::marker { color: var(--gold); }
.yokvid-footer { justify-content: space-between; border-top: 1px solid var(--border-light); padding: .6rem 1.2rem; }
.yokvid-nav { display: inline-flex; align-items: center; gap: .3rem; min-height: 40px; padding: .35rem .85rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--cream); color: var(--brown); font: inherit; font-size: .95rem; cursor: pointer; }
.yokvid-nav:hover:not(:disabled) { border-color: var(--gold); background: #FBF3E2; }
.yokvid-nav:disabled { opacity: .4; cursor: default; }
.yokvid-count { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
/* คลิปใหญ่เต็มความสูงจอ ไม่มีแถบหัว (หลวงพี่สั่ง ๗ ต.ค. ๒๕๖๙)
   จอคอม: กรอบสูงเกือบเท่าจอ · คลิป 9:16 ยืดเต็มความสูงกรอบ · แผงข้าง (ประโยค/ได้เรียน) อยู่ขวา ปุ่มตอนก่อน/ถัดไปอยู่ใต้แผงข้าง
   มือถือ: เต็มจออยู่แล้ว (modal-fullscreen-sm-down) คลิปบน แผงข้างล่าง */
#yokVideoModal .yokvid-content { position: relative; }
.yokvid-close { position: absolute; top: .6rem; right: .6rem; z-index: 3; width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 50%; background: var(--cream); color: var(--brown); font-size: 1.05rem; cursor: pointer; box-shadow: 0 2px 8px var(--shadow-lg); }
.yokvid-close:hover { border-color: var(--gold); background: #FBF3E2; }
.yokvid-close:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
@media (min-width: 576px) {
  #yokVideoModal .yokvid-dialog { width: fit-content; max-width: calc(100vw - 1.5rem); height: calc(100dvh - 1.5rem); min-height: 0; margin: .75rem auto; }
  #yokVideoModal .yokvid-content { height: 100%; display: grid; grid-template-columns: auto minmax(300px, 460px); grid-template-rows: minmax(0, 1fr) auto; column-gap: 1.4rem; padding: .9rem; }
  #yokVideoModal .yokvid-body { display: contents; }
  #yokVideoModal .yokvid-frame { grid-column: 1; grid-row: 1 / span 2; height: 100%; max-height: 100%; }
  #yokVideoModal .yokvid-side { grid-column: 2; grid-row: 1; overflow-y: auto; padding: .4rem 3.2rem 0 0; }
  #yokVideoModal .yokvid-footer { grid-column: 2; grid-row: 2; padding: .6rem 0 0; }
}
@media (max-width: 575.98px) {
  #yokVideoModal .yokvid-body { padding-top: 3.4rem; }   /* เว้นที่ให้ปุ่มปิด ไม่ทับหัวคลิป */
}

@media (max-width: 575.98px) {
  .yokvid-content { border-radius: 0; }
  .yokvid-body { flex-direction: column; align-items: stretch; padding: .75rem; gap: .9rem; }
  .yokvid-frame { height: auto; width: 100%; max-height: 68vh; margin: 0 auto; }
  .yokvid-header { padding: .75rem .9rem; }
  .yokvid-footer { padding: .5rem .75rem; }
}
/* ชื่อตอนเป็นบาลีล้วน (แปลงเป็น PUA แล้ว) — ต้องใช้ฟอนต์บาลี ไม่งั้น ฐ ญ เป็นกล่องเปล่า */
.yokvid-header .modal-title { font-family: 'THSarabunPali', var(--font-body); font-size: 1.6rem; font-weight: 700; line-height: 1.35; }
/* กดตอนก่อน/ถัดไปในหน้าต่างคลิป → แถวประโยคที่หน้าเว็บเลื่อนไปหา เรืองทองชั่วครู่ */
.yokvid-row-focus { animation: yokvid-row-glow 2.4s ease-out; border-radius: var(--radius-sm); }
@keyframes yokvid-row-glow {
  0%, 35% { box-shadow: 0 0 0 3px var(--gold); background-color: #FBF3E2; }
  100% { box-shadow: 0 0 0 3px transparent; background-color: transparent; }
}
@media (prefers-reduced-motion: reduce) { .yokvid-row-focus { animation-duration: .01s; box-shadow: 0 0 0 3px var(--gold); } }
