/* ลวดลายพื้นหลังโทนทอง */
.bg-thai {
  background-color: #3d130c;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(221, 174, 47, .18), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(221, 174, 47, .12), transparent 45%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Cpath d='M24 4l6 14 14 6-14 6-6 14-6-14-14-6 14-6z' fill='none' stroke='%23ddae2f' stroke-opacity='.10' stroke-width='1'/%3E%3C/svg%3E");
}

.ornament {
  display: flex; align-items: center; gap: .75rem; color: #c6911c;
}
.ornament::before, .ornament::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, currentColor, transparent);
}

/* กรอบรูปทอง + ขอบในสีขาว + เงา */
.photo-frame {
  background: linear-gradient(135deg, #f9efc9 0%, #c6911c 28%, #f2dd8f 50%, #a87115 72%, #f2dd8f 100%);
  padding: 4px;
  box-shadow: 0 1px 2px rgba(61, 19, 12, .12), 0 8px 20px -6px rgba(61, 19, 12, .28);
}
.photo-frame > img,
.photo-frame > div {
  border: 4px solid #fffdf6;
  box-shadow: inset 0 0 0 1px rgba(168, 113, 21, .25);
}

.quote-mark::before { content: "“"; }
.quote-mark::after { content: "”"; }

.book-grads > .cc { width: 10rem; }
.cc-photo { box-shadow: 0 4px 14px -4px rgba(61, 19, 12, .35); }

.line-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ฉบับพิมพ์ */
/* เลขหน้าส่วนหน้า: ก ข ค ... (ข้าม ฃ ฅ ตามธรรมเนียมหนังสือไทย) */
@counter-style thai-letter {
  system: alphabetic;
  symbols: ก ข ค ง จ ฉ ช ซ ฌ ญ ฎ ฏ ฐ ฑ ฒ ณ ด ต ถ ท ธ น บ ป ผ ฝ พ ฟ ภ ม ย ร ล ว ศ ษ ส ห ฬ อ ฮ;
}

.book-blank { display: none; }

@media print {
  /* ---------- หน้ากระดาษ / เลขหน้า / ชื่อเล่มท้ายหน้า ----------
     หน้าขวา (คี่): เลขหน้าชิดขวา ชื่อเล่มชิดซ้าย  |  หน้าซ้าย (คู่): กลับด้าน */
  @page {
    size: A4;
    margin: 11mm 11mm 15mm;
  }
  /* ปก: ใช้ระยะขอบเท่าหน้าอื่น (Chrome จัดความกว้างทั้งเล่มตามหน้าแรก) แล้วดึงภาพปกออกไปชนขอบกระดาษด้วย margin ติดลบ */

  /* @page front/main (เลขหน้า + ชื่อเล่ม) อยู่ใน book.php เพื่อดึงรุ่น/ชื่อจาก config */

  .book-cover { page: cover; margin: -11mm -11mm -15mm !important; width: 210mm !important; height: 297mm !important; min-height: 0 !important; overflow: hidden; border-radius: 0 !important; }
  .book-front { page: front; padding: 0 5mm; }   /* ระยะห่างจากกรอบ (Chrome ไม่นับ padding ของ @page ตอนจัดหน้า) */
  .book-main  { page: main; padding: 0 5mm; }
  .book-blank { display: block !important; page: blank; break-before: page; height: 1px; }   /* หน้าว่างไม่มีเลขหน้า */

  /* ---------- พื้นขาว + กรอบเส้นคู่สีทอง ทุกหน้า ยกเว้นปก (ไม่ใช้ลายไทยพื้นหลัง) ---------- */
  @page {
    /* กรอบวาดเป็นภาพพื้นหลังขนาดเท่ากระดาษ (Chrome คำนวณความกว้างผิดเมื่อใส่ border ให้ @page) */
    background: url("page-frame.svg") 0 0 / 210mm 297mm no-repeat, #fff;
  }
  @page cover { background: none; border: none; padding: 0; }

  /* ---------- ย่อหน้าแบบหนังสือ ---------- */
  .book-msg-body p, .book-text p {
    text-indent: 10mm; text-align: justify; text-justify: inter-character;
    margin: 0 !important; orphans: 2; widows: 2;
  }
  .book-msg-body > * + *, .book-text > p + p { margin-top: 1.2mm !important; }
  .book-text ul { margin: 2mm 0 2mm 4mm !important; }
  .book-text li { text-align: justify; orphans: 2; widows: 2; }
  .gp-sections section > div p { text-align: justify; text-indent: 0; orphans: 2; widows: 2; }

  html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: transparent !important; }
  body { font-size: 10.5pt; }
  main > div { padding-left: 0 !important; padding-right: 0 !important; max-width: none !important; }
  a { text-decoration: none; color: inherit; }
  .page-break { break-before: page; }
  .avoid-break, figure { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
  .photo-frame { box-shadow: none !important; }

  /* หัวบท: กระชับ ไม่กินหน้า */
  .book-chapter { padding-top: 2mm !important; padding-bottom: 6mm !important; }
  .book-chapter h2 { font-size: 22pt !important; }

  /* สารแสดงความยินดี: หนึ่งฉบับต่อหน้า รูปซ้าย ข้อความขวา */
  .book-msg { padding-top: 0 !important; }
  .book-msg-title { font-size: 18pt !important; margin-bottom: 1mm; }
  .book-msg-head { margin-bottom: 5mm !important; font-size: 11pt; }
  .book-msg > .flex { gap: 6mm !important; }
  .book-msg-body { font-size: 10.5pt; line-height: 1.65 !important; }
  .book-msg-body > * + * { margin-top: 2mm !important; }
  .book-msg-sign { margin-top: 6mm !important; break-inside: avoid; }

  /* รายชื่อบุคลากร */
  .pg > * + * { margin-top: 7mm !important; }
  .pg section { break-inside: auto; }
  .pg h3 { font-size: 13pt !important; }
  .pg h3.pg-head { font-size: 15pt !important; margin-bottom: 4mm !important; }
  .pg .ornament { margin-bottom: 4mm !important; }
  .pg-list { column-gap: 4mm !important; row-gap: 5mm !important; }

  /* ประวัติ */
  .book-text { font-size: 10.5pt; line-height: 1.7 !important; }
  .book-text > * + * { margin-top: 2mm !important; }
  .book-text h3 { font-size: 13pt !important; margin-top: 5mm !important; }

  /* หน้าแรกหลักสูตร + รูปบัณฑิต 5 คนต่อแถว */
  .book-prog { padding: 8mm !important; border-radius: 8px !important; }
  .book-prog h3 { font-size: 22pt !important; }

  /* รูปวงกลมแบบ directory: แถวละ 4 จัดกึ่งกลาง */
  .pg-item.pg-circle { width: calc(25% - 4mm) !important; break-inside: avoid; }
  .book-grads { display: flex !important; flex-wrap: wrap !important; justify-content: center !important; column-gap: 5mm !important; row-gap: 6mm !important; }
  .book-grads > .cc { width: calc(25% - 4mm) !important; }
  .cc-photo { width: 32mm !important; height: 32mm !important; box-shadow: none !important; border: .7mm solid #e9e2d6; }   /* เงาใน Chrome ตอนพิมพ์เป็นสี่เหลี่ยม จึงใช้เส้นขอบแทน */
  .cc-name { margin-top: 2mm !important; font-size: 10pt !important; line-height: 1.3 !important; }
  .cc-sub { font-size: 8.5pt !important; line-height: 1.3 !important; }
  .cc-badge { font-size: 8pt !important; }

  /* โปรไฟล์บัณฑิต: หนึ่งคนต่อหน้า รูปซ้าย เรื่องราวขวา */
  .gp { box-shadow: none !important; border-radius: 8px !important; }
  .gp-grid { break-inside: auto; }
  .gp > div:first-child { padding: 2mm 6mm !important; font-size: 9pt; }
  .gp-grid { display: grid !important; grid-template-columns: 46mm 1fr !important; gap: 6mm !important; padding: 6mm 6mm 5mm !important; }
  .gp-photo { max-width: 46mm !important; }
  .gp-photo.gp-circle { width: 44mm !important; height: 44mm !important; box-shadow: none !important; border: .8mm solid #e9e2d6; }
  .gp-meta { margin-top: 4mm !important; font-size: 8.5pt !important; }
  .gp-meta > * + * { margin-top: 1.5mm !important; }
  .gp-name { font-size: 19pt !important; margin-top: 2mm !important; }
  .gp-motto { margin-top: 4mm !important; padding: 3mm 4mm !important; border-radius: 6px !important; }
  .gp-motto p { font-size: 11pt !important; line-height: 1.45 !important; }
  .gp-sections { margin-top: 4mm !important; }
  .gp-sections > * + * { margin-top: 2.5mm !important; }
  .gp-sections h3 { font-size: 10pt; }
  .gp-sections section > div { font-size: 9.2pt; line-height: 1.5 !important; margin-top: 0.6mm !important; }
  .gp-contact { margin-top: 4mm !important; padding: 3mm 4mm !important; border-radius: 6px !important; }
  .gp-contact h3 { margin-bottom: 1.5mm !important; font-size: 10pt; }
  .gp-contact ul { grid-template-columns: 1fr 1fr !important; gap: 1mm 4mm !important; font-size: 8.5pt !important; }
  .gp-contact li:first-child { grid-column: 1 / -1; }
  .gp-foot { display: none !important; }
}
