/* =============================================
   คู่มือแปลมคธเป็นไทย — reader
   Shares the palette of dhammabot/css/ebook.css so the two readers feel
   like one family; layout is simpler because this book is prose + examples.
   ============================================= */

@font-face {
  font-family: 'THSarabunPali';
  src: url('/page/dhammabot/fonts/THSarabunPali.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'THSarabunPali';
  src: url('/page/dhammabot/fonts/THSarabunPali.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

:root {
  --parchment:      #FDFBF7;
  --parchment-deep: #F5F0E8;
  --cream:          #FEFDFB;
  --gold:           #C9A554;
  --gold-light:     #E8D5A0;
  --gold-dark:      #A07D3A;
  --brown:          #5C3D10;
  --ink:            #2C1810;
  --ink-light:      #4A3728;
  --pali-color:     #7A2E0E;
  --thai-color:     #1A3A6B;
  --muted:          #8C7B6B;
  --border:         #DDD0BE;
  --border-light:   #EDE4D4;
  --shadow:         rgba(60, 31, 16, .08);
  --shadow-md:      rgba(60, 31, 16, .12);

  --bar-h: 52px;
  --reader-fs: 1.06rem;     /* driven by the A- / A+ buttons */
}

* { box-sizing: border-box; }

body.hb {
  margin: 0;
  background: var(--parchment-deep);
  color: var(--ink);
  font-family: 'Sarabun', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ---------- top bar ---------- */
.hb-bar {
  position: sticky; top: 0; z-index: 30;
  height: var(--bar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: linear-gradient(180deg, #fffdf8, #f7f1e5);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px var(--shadow);
}
.hb-bar .hb-title {
  font-weight: 600; color: var(--brown);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1 1 auto; min-width: 0; font-size: .98rem;
}
.hb-bar .hb-title small { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; }

.hb-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  min-width: 36px; height: 36px; padding: 0 9px;
  border: 1px solid var(--border); border-radius: 9px;
  background: #fff; color: var(--brown); cursor: pointer;
  font-size: .9rem; line-height: 1; transition: .13s;
}
.hb-btn:hover { border-color: var(--gold); background: #fffdf6; }
.hb-btn:disabled { opacity: .4; cursor: default; }
.hb-btn.on { background: var(--gold); border-color: var(--gold); color: #fff; }
.hb-btn i { font-size: 1.05rem; }

/* ---------- table of contents ---------- */
.hb-toc {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); z-index: 50;
  background: var(--cream); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .22s ease;
  box-shadow: 4px 0 24px rgba(60, 31, 16, .16);
}
.hb-toc.open { transform: none; }
.hb-toc-head { padding: 12px 12px 9px; border-bottom: 1px solid var(--border-light); }
.hb-toc-head .row1 { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.hb-toc-head strong { flex: 1; color: var(--brown); font-size: .95rem; }
.hb-search {
  width: 100%; padding: 8px 11px; font: inherit; font-size: .9rem;
  border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--ink);
}
.hb-search:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201, 165, 84, .17); }
.hb-hits { font-size: .78rem; color: var(--muted); padding: 6px 2px 0; min-height: 1.1em; }

.hb-toc-list { flex: 1; overflow-y: auto; padding: 6px 0 22px; }
.hb-part {
  padding: 13px 14px 5px; font-size: .74rem; font-weight: 700; letter-spacing: .4px;
  color: var(--gold-dark); text-transform: none;
  position: sticky; top: 0; background: var(--cream);
}
.hb-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 7px 14px 7px 16px; cursor: pointer;
  color: var(--ink-light); font: inherit; font-size: .9rem; line-height: 1.45;
  border-left: 3px solid transparent;
}
.hb-item:hover { background: #faf6ec; }
.hb-item.lv3 { padding-left: 30px; font-size: .855rem; color: var(--muted); }
.hb-item.lv4 { padding-left: 44px; font-size: .83rem; color: var(--muted); }
.hb-item.cur { background: #f6edd8; border-left-color: var(--gold); color: var(--brown); font-weight: 600; }
.hb-item .pg { float: right; font-size: .74rem; color: var(--muted); font-weight: 400; margin-left: 8px; }
.hb-item mark { background: var(--gold-light); color: var(--ink); padding: 0 1px; border-radius: 2px; }

.hb-scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(44, 24, 16, .38);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.hb-scrim.on { opacity: 1; pointer-events: auto; }

/* ---------- reading surface ---------- */
.hb-wrap { max-width: 780px; margin: 0 auto; padding: 18px 14px 90px; }
.hb-sheet {
  background: var(--parchment); border: 1px solid var(--border-light);
  border-radius: 14px; box-shadow: 0 3px 16px var(--shadow);
  padding: 26px 26px 30px;
}

.hb-crumb { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.hb-h {
  margin: 0 0 4px; color: var(--brown); line-height: 1.35;
  font-size: 1.45rem; font-weight: 700;
}
.hb-h.lv3 { font-size: 1.22rem; }
.hb-h.lv4 { font-size: 1.1rem; }
.hb-meta { font-size: .8rem; color: var(--muted); margin-bottom: 16px; }
.hb-meta .dot { opacity: .5; margin: 0 6px; }

.hb-body { font-size: var(--reader-fs); line-height: 1.95; }
.hb-body p { margin: 0 0 .85em; text-align: left; }
.hb-body ul { margin: 0 0 .9em; padding-left: 1.3em; }
.hb-body li { margin-bottom: .25em; }
.hb-body strong { color: var(--brown); font-weight: 700; }

/* Pali examples and their word-by-word Thai rendering */
.hb-pali {
  /* THSarabunPali is the only local face that draws พินทุ / นิคคหิต correctly,
     and it runs narrow — hence the size bump rather than a matching one. */
  font-family: 'THSarabunPali', 'Sarabun', serif;
  font-size: calc(var(--reader-fs) * 1.42);
  line-height: 1.6; color: var(--pali-color);
  margin: .5em 0 .1em; padding-left: .7em;
  border-left: 3px solid var(--gold-light);
}
.hb-gloss {
  font-size: calc(var(--reader-fs) * .99);
  line-height: 1.85; color: var(--thai-color);
  margin: 0 0 .85em; padding-left: .8em;
  border-left: 3px solid #cfd9ea;
}
.hb-pali strong, .hb-gloss strong { color: inherit; font-weight: 700; }

.hb-figure {
  font-size: .86rem; color: var(--muted); font-style: italic;
  background: #f8f4ea; border: 1px dashed var(--border);
  border-radius: 8px; padding: 7px 11px; margin: .7em 0;
}

.hb-pagemark {
  display: flex; align-items: center; gap: 10px;
  margin: 1.5em 0 1em; font-size: .74rem; color: var(--muted); letter-spacing: .5px;
}
.hb-pagemark::before, .hb-pagemark::after {
  content: ""; flex: 1; height: 1px; background: var(--border-light);
}
body.hb-nopage .hb-pagemark { display: none; }

.hb-tablewrap { overflow-x: auto; margin: 0 0 1em; }
.hb-body table { border-collapse: collapse; min-width: 100%; font-size: .95em; }
.hb-body th, .hb-body td {
  border: 1px solid var(--border-light); padding: 6px 11px; text-align: left; vertical-align: top;
  white-space: nowrap;
}
.hb-body th { background: var(--parchment-deep); color: var(--brown); font-weight: 600; }

/* continuous mode puts a rule between sections */
.hb-sec + .hb-sec { margin-top: 30px; padding-top: 26px; border-top: 1px solid var(--border-light); }

/* ---------- footer nav ---------- */
.hb-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; gap: 10px; justify-content: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, #fffdf8, rgba(255, 253, 248, .93));
  border-top: 1px solid var(--border);
}
.hb-foot .pos { font-size: .82rem; color: var(--muted); min-width: 92px; text-align: center; }

.hb-empty { text-align: center; color: var(--muted); padding: 40px 10px; }

@media (max-width: 560px) {
  .hb-wrap { padding: 12px 9px 84px; }
  .hb-sheet { padding: 18px 15px 22px; border-radius: 11px; }
  .hb-h { font-size: 1.3rem; }
  .hb-bar .hb-title small { display: none; }
}

@media print {
  .hb-bar, .hb-foot, .hb-toc, .hb-scrim { display: none !important; }
  .hb-wrap { max-width: none; padding: 0; }
  .hb-sheet { border: 0; box-shadow: none; padding: 0; }
}

/* container headings: list of children, or a pointer to the heading they introduce */
.hb-lead { color: var(--muted); font-size: .92rem; margin: 0 0 .6em; }
.hb-children { list-style: none; padding: 0; margin: 0; }
.hb-children li { margin: 0 0 6px; }
.hb-children a,
.hb-lead a {
  color: var(--brown); text-decoration: none;
  border-bottom: 1px solid var(--gold-light);
}
.hb-children a { display: inline-block; padding: 3px 0; font-weight: 600; }
.hb-children a:hover, .hb-lead a:hover { border-bottom-color: var(--gold); }
