/* e-Book: หน้าอ่านแบบพลิกหน้า — โต๊ะอ่านหนังสือสีเขียวสักหลาด หน้ากระดาษขาว แผงเครื่องมือเป็นการ์ดกระดาษ */
@font-face { font-family: "IBM Plex Sans Thai"; src: url("../../../assets/fonts/ibm-plex-sans-thai/IBMPlexSansThai-Regular.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Thai"; src: url("../../../assets/fonts/ibm-plex-sans-thai/IBMPlexSansThai-SemiBold.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --felt: #1B3530;
  --felt-lit: #24463F;
  --felt-deep: #12251F;
  --bar: rgba(16, 33, 29, .78);
  --ink-on-felt: #E9F0EC;
  --muted-on-felt: #A8BDB4;
  --paper: #F6F1E7;
  --paper-2: #EDE6D7;
  --paper-line: #DDD3C0;
  --ink: #1F2A26;
  --ink-2: #4D5A54;
  --brass: #C8A25B;
  --brass-deep: #7E5F24;
  --brass-wash: #EBD9AE;
  --dock-h: 56px;
  --top-h: 60px;
  --drawer-w: 380px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.ebv {
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 42%, var(--felt-lit) 0%, var(--felt) 55%, var(--felt-deep) 100%);
  color: var(--ink-on-felt);
  font: 400 15px/1.55 "IBM Plex Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
.ebv-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.tnum { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.ebv-i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- โครงหน้า ---------- */
.ebv-app { position: fixed; inset: 0; display: flex; flex-direction: column; }

.ebv-top {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--top-h); padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
}
.ebv-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ebv-logo { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: #8C5A2B; color: #FFF6EA; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
.ebv-logo .ebv-i { width: 21px; height: 21px; stroke-width: 1.6; }
.ebv-titles { min-width: 0; }
.ebv-title { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.35; letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ebv-sub { margin: 0; font-size: 12.5px; color: var(--muted-on-felt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ebv-tools { flex: none; display: flex; gap: 2px; }

.ebv-btn {
  width: 42px; height: 42px; flex: none; display: inline-grid; place-items: center; padding: 0;
  border: 0; border-radius: 12px; background: transparent; color: inherit; cursor: pointer; text-decoration: none;
  transition: background-color .15s ease, color .15s ease;
}
.ebv-btn:hover { background: rgba(255, 255, 255, .09); }
.ebv-btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 1px; }
.ebv-btn.is-on { background: rgba(200, 162, 91, .2); color: #F1D9A6; }
.ebv-btn:disabled { opacity: .32; cursor: default; background: transparent; }

.ebv-preview { flex: none; margin: 0 auto 4px; padding: 5px 14px; border-radius: 99px; background: var(--brass-wash); color: #4A3711; font-size: 13px; text-align: center; max-width: calc(100% - 24px); }

/* ---------- พื้นที่หนังสือ ---------- */
.ebv-stage { position: relative; flex: 1 1 auto; min-height: 0; padding: 14px 72px 18px; }
.ebv-bookwrap { position: relative; width: 100%; height: 100%; }
/* ตัวพลิกหน้าใส่ .stf__parent { position: relative } ไว้ท้าย head จึงต้องระบุให้เจาะจงกว่า */
.ebv-bookwrap > .ebv-book { position: absolute; inset: 0; }
.ebv-book .stf__wrapper { position: relative; width: 100%; height: 100%; }
.ebv-book .stf__block { perspective: 2400px; }
.ebv-book .stf__item { box-shadow: 0 1px 2px rgba(0, 0, 0, .18), 0 14px 34px rgba(4, 14, 11, .38); }
@media (min-width: 1100px) { .ebv-app.has-drawer .ebv-stage { padding-left: calc(var(--drawer-w) + 12px + 72px); } }

.ebv-page { background: #fff; overflow: hidden; }
.ebv-page-box { position: absolute; }
.ebv-page img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; pointer-events: none; opacity: 0; transition: opacity .25s ease; }
.ebv-page.is-loaded img { opacity: 1; }
.ebv-page:not(.is-loaded)::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; border: 3px solid #E7E1D4; border-top-color: var(--brass); animation: ebv-spin .9s linear infinite;
}
.ebv-page.is-error::before { content: "โหลดหน้านี้ไม่สำเร็จ"; width: auto; height: auto; margin: 0; transform: translate(-50%, -50%); border: 0; animation: none; color: #8A8478; font-size: 13px; white-space: nowrap; }
/* แนวสันหนังสือ: เงาจาง ๆ ที่ขอบด้านใน */
.ebv-page::after { content: ""; position: absolute; top: 0; bottom: 0; width: 7%; pointer-events: none; }
.ebv-page.--left::after { right: 0; background: linear-gradient(to left, rgba(40, 30, 10, .16), rgba(40, 30, 10, 0)); }
.ebv-page.--right::after { left: 0; background: linear-gradient(to right, rgba(40, 30, 10, .14), rgba(40, 30, 10, 0)); }
.ebv-app.is-fallback .ebv-page::after { display: none; }

.ebv-links { position: absolute; inset: 0; }
.ebv-link { position: absolute; display: block; border-radius: 3px; }
.ebv-link:hover, .ebv-link:focus-visible { background: rgba(200, 162, 91, .2); box-shadow: 0 0 0 2px rgba(200, 162, 91, .85); outline: none; }

.ebv-arrow {
  position: absolute; top: 50%; z-index: 5; width: 48px; height: 48px; margin-top: -24px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(255, 255, 255, .08); color: var(--ink-on-felt); cursor: pointer;
  transition: background-color .15s ease, opacity .2s ease;
}
.ebv-arrow .ebv-i { width: 26px; height: 26px; }
.ebv-arrow:hover { background: rgba(255, 255, 255, .16); }
.ebv-arrow:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.ebv-arrow:disabled { opacity: 0; pointer-events: none; }
.ebv-arrow.is-prev { left: 14px; }
.ebv-arrow.is-next { right: 14px; }
@media (min-width: 1100px) { .ebv-app.has-drawer .ebv-arrow.is-prev { left: calc(var(--drawer-w) + 12px + 14px); } }

.ebv-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted-on-felt); font-size: 14px; pointer-events: none; }
.ebv-spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .14); border-top-color: var(--brass); animation: ebv-spin .9s linear infinite; }
@keyframes ebv-spin { to { transform: rotate(360deg); } }

/* แสดงแบบเลื่อนลง (หน้าเดียว หรือโหลดตัวพลิกหน้าไม่ได้) */
.ebv-book.ebv-scroll { overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 4px 0 24px; }
.ebv-scroll .ebv-page { position: relative; flex: none; width: min(100%, 900px); box-shadow: 0 14px 34px rgba(4, 14, 11, .38); }
.ebv-app.is-single-page .ebv-scroll { justify-content: center; }
.ebv-app.is-single-page .ebv-scroll .ebv-page { width: auto; height: 100%; max-width: 100%; }
.ebv-app.is-single-page .ebv-bar .ebv-btn:not(#ebvZoomBtn), .ebv-app.is-single-page .ebv-range, .ebv-app.is-single-page .ebv-goto, .ebv-app.is-single-page .ebv-sep { display: none; }

/* ---------- แถบควบคุมด้านล่าง ---------- */
.ebv-bar {
  flex: none; align-self: center; width: min(760px, calc(100% - 24px)); margin: 0 0 max(12px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 4px; min-height: var(--dock-h); padding: 6px 8px;
  border-radius: 18px; background: var(--bar); box-shadow: 0 10px 30px rgba(3, 12, 9, .35), inset 0 0 0 1px rgba(255, 255, 255, .06);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.ebv-range { flex: 1 1 auto; min-width: 60px; margin: 0 8px; accent-color: var(--brass); height: 28px; cursor: pointer; }
.ebv-goto { display: flex; align-items: baseline; gap: 4px; margin: 0 6px; white-space: nowrap; }
.ebv-pageinput {
  width: 4.6em; padding: 5px 6px; border: 0; border-radius: 9px; text-align: center;
  background: rgba(255, 255, 255, .1); color: var(--ink-on-felt); font: inherit; font-weight: 600; font-size: 15px;
}
.ebv-pageinput:focus { outline: 2px solid var(--brass); outline-offset: 1px; background: rgba(255, 255, 255, .16); }
.ebv-pagetotal { color: var(--muted-on-felt); font-size: 14px; }
.ebv-sep { width: 1px; height: 24px; margin: 0 4px; background: rgba(255, 255, 255, .14); flex: none; }

/* ---------- แผงภาพหน้า / สารบัญ / ค้นหา (การ์ดกระดาษ) ---------- */
.ebv-drawer {
  position: fixed; z-index: 30; left: 12px; top: calc(var(--top-h) + env(safe-area-inset-top)); bottom: calc(var(--dock-h) + 30px);
  width: var(--drawer-w); display: flex; flex-direction: column; overflow: hidden;
  border-radius: 16px; background: var(--paper); color: var(--ink); color-scheme: light;
  box-shadow: 0 18px 50px rgba(3, 12, 9, .45);
}
.ebv-drawer-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 8px 0 14px; border-bottom: 1px solid var(--paper-line); }
.ebv-drawer-head .ebv-btn:hover { background: var(--paper-2); }
.ebv-tabs { display: flex; gap: 2px; }
.ebv-tab {
  padding: 10px 12px 11px; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 600; font-size: 14.5px; cursor: pointer;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.ebv-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brass-deep); }
.ebv-tab:focus-visible { outline: 2px solid var(--brass-deep); outline-offset: -2px; border-radius: 6px; }
.ebv-pane { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.ebv-drawer .ebv-btn:focus-visible { outline-color: var(--brass-deep); }

.ebv-thumbs { list-style: none; margin: 0; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 14px 12px; }
.ebv-thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; font: inherit; }
.ebv-thumb-img { position: relative; display: block; width: 100%; aspect-ratio: var(--ratio, .707); background: #fff; border-radius: 3px; box-shadow: 0 1px 3px rgba(31, 42, 38, .2); overflow: hidden; outline: 2px solid transparent; outline-offset: 2px; }
.ebv-thumb-img img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ebv-thumb-no { font-size: 12.5px; }
.ebv-thumb:hover .ebv-thumb-img { outline-color: var(--paper-line); }
.ebv-thumb[aria-current="true"] .ebv-thumb-img { outline-color: var(--brass-deep); }
.ebv-thumb[aria-current="true"] .ebv-thumb-no { color: var(--ink); font-weight: 600; }
.ebv-thumb:focus-visible { outline: none; }
.ebv-thumb:focus-visible .ebv-thumb-img { outline-color: var(--ink); }

.ebv-toc { list-style: none; margin: 0; padding: 8px 0 14px; }
.ebv-toc-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; padding: 9px 16px; border: 0;
  background: transparent; color: var(--ink); font: inherit; font-size: 14.5px; text-align: left; cursor: pointer; line-height: 1.45;
}
.ebv-toc .lvl-1 .ebv-toc-item { padding-left: 32px; font-size: 14px; color: var(--ink-2); }
.ebv-toc .lvl-2 .ebv-toc-item, .ebv-toc .lvl-3 .ebv-toc-item { padding-left: 48px; font-size: 13.5px; color: var(--ink-2); }
.ebv-toc-item:hover { background: var(--paper-2); }
.ebv-toc-item[aria-current="true"] { background: var(--brass-wash); color: var(--ink); box-shadow: inset 3px 0 0 var(--brass-deep); }
.ebv-toc-item:focus-visible { outline: 2px solid var(--brass-deep); outline-offset: -2px; }
.ebv-toc-page { flex: none; color: var(--ink-2); font-size: 13px; }

.ebv-searchform { display: flex; gap: 6px; padding: 14px 14px 6px; }
.ebv-input {
  flex: 1 1 auto; min-width: 0; padding: 9px 12px; border: 1px solid var(--paper-line); border-radius: 10px;
  background: #fff; color: var(--ink); font: inherit; font-size: 15px;
}
.ebv-input:focus { outline: 2px solid var(--brass-deep); outline-offset: 0; border-color: transparent; }
.ebv-searchform .ebv-btn { background: var(--ink); color: var(--paper); }
.ebv-searchform .ebv-btn:hover { background: #33433D; }
.ebv-searchnote { margin: 4px 16px 6px; font-size: 13px; color: var(--ink-2); min-height: 1.2em; }
.ebv-results { list-style: none; margin: 0; padding: 0 0 14px; }
.ebv-result { display: block; width: 100%; padding: 10px 16px; border: 0; border-top: 1px solid var(--paper-2); background: transparent; color: var(--ink); text-align: left; cursor: pointer; font: inherit; font-size: 14px; line-height: 1.55; }
.ebv-result:hover { background: var(--paper-2); }
.ebv-result:focus-visible { outline: 2px solid var(--brass-deep); outline-offset: -2px; }
.ebv-result-page { display: block; font-size: 12.5px; font-weight: 600; color: var(--brass-deep); }
.ebv-result-text { overflow-wrap: anywhere; }
.ebv-result mark { background: var(--brass-wash); color: inherit; padding: 0 1px; border-radius: 2px; }

/* ---------- แชร์ ---------- */
.ebv-modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(6, 16, 13, .55); }
.ebv-modal-box {
  width: min(420px, 100%); max-height: calc(100% - 16px); overflow: auto; padding: 18px 18px 20px;
  border-radius: 18px; background: var(--paper); color: var(--ink); color-scheme: light; box-shadow: 0 24px 60px rgba(3, 12, 9, .5);
}
.ebv-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ebv-modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.ebv-modal-head .ebv-btn:hover { background: var(--paper-2); }
.ebv-modal .ebv-btn:focus-visible { outline-color: var(--brass-deep); }
.ebv-share-link { display: flex; gap: 6px; }
.ebv-share-link .ebv-input { font-size: 14px; }
.ebv-pill {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 0; border-radius: 10px;
  background: var(--ink); color: var(--paper); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.ebv-pill .ebv-i { width: 18px; height: 18px; }
.ebv-pill:hover { background: #33433D; }
.ebv-pill:focus-visible { outline: 2px solid var(--brass-deep); outline-offset: 2px; }
.ebv-pill:disabled { opacity: .5; cursor: default; }
.ebv-check { display: flex; align-items: center; gap: 8px; margin: 10px 2px 0; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.ebv-check input { width: 18px; height: 18px; accent-color: var(--brass-deep); }
.ebv-qr { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 16px 0 4px; }
.ebv-qr canvas { width: 196px; height: 196px; padding: 8px; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 1px var(--paper-line); image-rendering: pixelated; }
.ebv-share-apps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.ebv-app-btn {
  display: flex; align-items: center; justify-content: center; min-height: 42px; padding: 8px 12px; border: 1px solid var(--paper-line); border-radius: 12px;
  background: var(--paper-2); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; cursor: pointer; gap: 8px;
}
.ebv-app-btn .ebv-i { width: 18px; height: 18px; }
.ebv-app-btn.is-line { background: #E6F6EC; border-color: #B4E2C4; }
.ebv-app-btn.is-fb { background: #E8F0FD; border-color: #BCD2F5; }
.ebv-app-btn:hover { filter: brightness(.96); }
.ebv-app-btn:focus-visible { outline: 2px solid var(--brass-deep); outline-offset: 2px; }
.ebv-app-btn.is-line { color: #06A04A; }
.ebv-app-btn.is-fb { color: #1A64D8; }
#ebvNative { grid-column: 1 / -1; }

/* ---------- ขยายหน้า ---------- */
.ebv-zoom { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--felt-deep); }
.ebv-zoom-bar {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 58px;
  padding: env(safe-area-inset-top) 10px 0; background: rgba(10, 22, 19, .9); box-shadow: inset 0 -1px 0 rgba(255, 255, 255, .06);
}
.ebv-zoom-page, .ebv-zoom-level { min-width: 4.5em; text-align: center; font-size: 14px; color: var(--ink-on-felt); }
.ebv-zoom-page { min-width: 7.5em; }
.ebv-zoom-view { flex: 1 1 auto; min-height: 0; overflow: auto; cursor: grab; outline: none; }
.ebv-zoom-view.is-drag { cursor: grabbing; }
.ebv-zoom-page-box { position: relative; margin: 12px auto; background: #fff; box-shadow: 0 14px 40px rgba(0, 0, 0, .45); }
.ebv-zoom-page-box img { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; }

/* ---------- ข้อความแจ้ง ---------- */
.ebv-toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(var(--dock-h) + 30px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); padding: 9px 10px 9px 18px;
  border-radius: 99px; background: var(--paper); color: var(--ink); font-size: 14px; box-shadow: 0 12px 30px rgba(3, 12, 9, .4);
}
.ebv-toast-btn { border: 0; border-radius: 99px; padding: 5px 14px; background: var(--ink); color: var(--paper); font: inherit; font-weight: 600; cursor: pointer; }
.ebv-toast:not(:has(.ebv-toast-btn)) { padding-right: 18px; }

.ebv-noscript { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; color: var(--ink-on-felt); padding: 24px; }
.ebv-noscript a { color: var(--brass); }

/* ---------- ฝังในเว็บไซต์อื่น ---------- */
.is-embed { --top-h: 50px; --dock-h: 50px; }
.is-embed .ebv-logo { display: none; }
.is-embed .ebv-title { font-size: 15px; }
.is-embed .ebv-sub { display: none; }
.is-embed .ebv-stage { padding: 6px 60px 10px; }
.is-embed .ebv-bar { margin-bottom: 8px; }

/* ---------- จอเล็ก ---------- */
@media (max-width: 760px) {
  :root { --top-h: 54px; --dock-h: 52px; }
  .ebv-top { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); gap: 6px; }
  .ebv-logo { display: none; }
  .ebv-title { font-size: 15px; }
  .ebv-btn { width: 38px; height: 38px; border-radius: 10px; }
  .ebv-stage { padding: 8px 8px 12px; }
  .ebv-arrow { display: none; }
  .ebv-bar { width: calc(100% - 16px); margin-bottom: max(8px, env(safe-area-inset-bottom)); padding: 4px 6px; gap: 2px; border-radius: 16px; }
  .is-wide-only, .ebv-sep { display: none; }
  .ebv-range { margin: 0 4px; }
  .ebv-pageinput { width: 4.2em; font-size: 14px; }
  .ebv-drawer { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: min(72vh, 620px); border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .ebv-thumbs { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}
@media (max-width: 420px) {
  #ebvMode { display: none; }
  .ebv-tools .ebv-btn { width: 34px; }
  .ebv-pagetotal { font-size: 13px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  :root { --top-h: 46px; --dock-h: 46px; }
  .ebv-sub { display: none; }
  .ebv-stage { padding-top: 4px; padding-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media print {
  .ebv-top, .ebv-bar, .ebv-arrow { display: none; }
}
