/* =====================================================================
   E-Library ภายในองค์กร — สไตล์หลัก
   โทนสี: กระดาษอุ่น + เขียวหมึกลึก + ทองอำพัน
   ===================================================================== */
:root {
  --paper: #f6f2ea;
  --paper-2: #efe9dd;
  --surface: #fffdf9;
  --ink: #1b2430;
  --ink-2: #3c4654;
  --muted: #7a7468;
  --line: #e6dfd1;
  --line-2: #d9d0bf;
  --brand: #0f5257;
  --brand-2: #0b3f43;
  --brand-soft: #e3efed;
  --accent: #e0a43a;
  --accent-soft: #fbf0db;
  --danger: #b4412f;
  --danger-soft: #f9e6e1;
  --ok: #2f7a4f;
  --ok-soft: #e4f2e8;
  --warn: #a96d0c;
  --warn-soft: #fbf0d6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(40, 30, 10, .06), 0 1px 1px rgba(40, 30, 10, .04);
  --shadow: 0 1px 2px rgba(40, 30, 10, .05), 0 8px 24px -12px rgba(40, 30, 10, .18);
  --shadow-lg: 0 30px 60px -30px rgba(25, 20, 10, .45);
  --font: "IBM Plex Sans Thai", "Sarabun", "Leelawadee UI", "Noto Sans Thai", Tahoma, system-ui, sans-serif;
  --display: "Anuphan", "IBM Plex Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font); font-size: 15.5px; line-height: 1.6; color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(rgba(120, 100, 60, .06) 1px, transparent 1px);
  background-size: 22px 22px;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; }
h1, h2, h3 { font-family: var(--display); line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.005em; }
h1 { font-size: clamp(1.6rem, 2.2vw + 1rem, 2.3rem); font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
h2 .ic { color: var(--brand); }
p { margin: 0 0 .8em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
code { background: var(--paper-2); padding: .1em .4em; border-radius: 6px; font-size: .9em; }
.ic { flex-shrink: 0; vertical-align: -0.2em; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.nowrap { white-space: nowrap; }
.d-block { display: block; }
[hidden] { display: none !important; }

.container { width: min(1240px, 100% - 40px); margin-inline: auto; }
.container.narrow, .narrow { max-width: 820px; }
.page { padding: 34px 0 60px; }
.section { margin-top: 22px; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 253, 249, .86);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 18px; height: 68px; }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none !important; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-family: var(--display); font-size: 1.08rem; }
.brand small { color: var(--muted); font-size: .76rem; }
.nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav > a {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: 999px;
  color: var(--ink-2); font-weight: 500; font-size: .93rem; text-decoration: none;
}
.nav > a:hover { background: var(--paper-2); }
.nav > a.on { background: var(--brand); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 6px; margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--line); }
.nav-user form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 4px 10px 4px 4px; border-radius: 999px; color: var(--ink); text-decoration: none !important; }
.user-chip:hover, .user-chip.on { background: var(--paper-2); }
.who { display: flex; flex-direction: column; line-height: 1.15; }
.who b { font-size: .86rem; font-weight: 600; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { font-size: .72rem; color: var(--muted); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0;
  background: linear-gradient(140deg, var(--brand), #2a7f73); color: #fff; font-family: var(--display); font-weight: 600;
}
.avatar-lg { width: 64px; height: 64px; font-size: 1.6rem; }
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 0;
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn.copied { color: var(--ok); }
.nav-toggle { display: none; margin-left: auto; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  background: var(--brand); color: #fff; font: 600 .95rem var(--font); cursor: pointer;
  text-decoration: none !important; transition: background .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .15) inset, 0 6px 16px -8px rgba(15, 82, 87, .7);
}
.btn:hover { background: var(--brand-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-lg { padding: 13px 24px; font-size: 1rem; border-radius: 14px; }
.btn-sm { padding: 6px 12px; font-size: .84rem; border-radius: 9px; box-shadow: none; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-2); box-shadow: none; }
.btn-ghost:hover { background: var(--surface); border-color: var(--ink-2); }
.btn-danger { background: var(--danger); box-shadow: none; }
.btn-danger:hover { background: #932f20; }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: #e8c3ba; box-shadow: none; }
.btn-ghost-danger:hover { background: var(--danger-soft); }

/* ------------------------------------------------------------------ forms */
.form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .92rem; color: var(--ink-2); }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), select, textarea {
  width: 100%; padding: 11px 14px; border-radius: 11px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font: 400 .97rem var(--font);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(15, 82, 87, .13); }
input[disabled] { background: var(--paper-2); color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 500; cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 17px; height: 17px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.req { color: var(--danger); }
.row-actions { display: flex; gap: 10px; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input { max-width: 320px; }

/* ------------------------------------------------------------ card/alert */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 24px 26px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 15px; border-radius: 12px; font-size: .92rem; flex-direction: column; }
.alert-error { background: var(--danger-soft); color: #7d2a1d; }
.alert-ok { background: var(--ok-soft); color: #1f5536; }
.alert-warn { background: var(--warn-soft); color: #74490a; }
.alert > .ic { display: none; }

.toasts { position: fixed; top: 84px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: 13px; max-width: 380px;
  background: var(--ink); color: #fff; font-size: .93rem; box-shadow: var(--shadow-lg);
  animation: toastIn .35s cubic-bezier(.2, .9, .3, 1.2);
}
.toast-error { background: var(--danger); }
.toast-warn { background: #8a5a0c; }
.toast.out { opacity: 0; transform: translateX(20px); transition: .35s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.96); } }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; background: var(--paper-2); color: var(--ink-2); white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-muted { background: var(--paper-2); color: var(--muted); }
.badge-draft { background: var(--accent); color: #3d2a05; }
.badge-lock { background: rgba(20, 28, 38, .78); color: #fff; backdrop-filter: blur(4px); }
.badge-role-admin { background: #1b2430; color: #fff; }
.badge-role-editor { background: var(--brand-soft); color: var(--brand); }
.badge-role-viewer { background: var(--paper-2); color: var(--ink-2); }

/* ------------------------------------------------------------------- hero */
.hero { padding: 46px 0 34px; position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; right: -120px; top: -160px; width: 520px; height: 520px; border-radius: 50%;
  background: radial-gradient(circle, rgba(224, 164, 58, .22), transparent 65%); pointer-events: none;
}
.hero-inner { display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: end; position: relative; }
.eyebrow { color: var(--brand); font-weight: 600; font-size: .92rem; margin-bottom: .35rem; }
.hero h1 { font-size: clamp(1.9rem, 3vw + 1rem, 3rem); margin-bottom: 22px; max-width: 760px; }
.hero h1 .org-line { display: block; font-size: .52em; font-weight: 600; color: var(--brand); margin-top: .35em; letter-spacing: 0; }
.search {
  display: flex; align-items: center; gap: 10px; max-width: 640px; padding: 7px 7px 7px 18px;
  background: #fff; border: 1px solid var(--line-2); border-radius: 16px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(15, 82, 87, .12), var(--shadow); }
.search .ic { color: var(--muted); }
.search input { border: 0 !important; box-shadow: none !important; padding: 8px 0 !important; font-size: 1rem !important; background: transparent !important; }
.hero-stats { display: flex; gap: 10px; }
.hero-stats > div {
  min-width: 120px; padding: 16px 18px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.hero-stats b { font-family: var(--display); font-size: 1.7rem; line-height: 1.1; color: var(--brand); }
.hero-stats span { font-size: .8rem; color: var(--muted); line-height: 1.35; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 6px 0 22px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 15px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-2); font-size: .9rem; font-weight: 500; text-decoration: none !important; transition: .15s;
}
.chip small { color: var(--muted); margin-left: 3px; }
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip.on small { color: rgba(255, 255, 255, .6); }
.sort select { width: auto; padding: 8px 34px 8px 14px; border-radius: 999px; font-size: .9rem; }
.result-line { color: var(--ink-2); margin: -14px 0 22px; }

/* ------------------------------------------------------------ book shelf */
.shelf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 38px 28px; padding-bottom: 50px; }
.book-card { animation: rise .5s both; animation-delay: calc(var(--i) * 35ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.cover-link { display: block; text-decoration: none !important; perspective: 900px; }
.cover {
  position: relative; aspect-ratio: 1 / 1.414; border-radius: 4px 10px 10px 4px; overflow: hidden; background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .08), 0 14px 26px -14px rgba(30, 20, 5, .55), 0 3px 8px -4px rgba(30, 20, 5, .25);
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), box-shadow .35s;
  transform-origin: left center;
}
.cover::before { /* สันปก */
  content: ""; position: absolute; inset: 0 auto 0 0; width: 12px; z-index: 2; pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, .22), rgba(255, 255, 255, .18) 45%, rgba(0, 0, 0, .06) 70%, transparent);
}
.cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(125deg, rgba(255, 255, 255, .22), transparent 40%); pointer-events: none; z-index: 2; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-link:hover .cover { transform: rotateY(-12deg) translateX(4px); box-shadow: 14px 22px 34px -16px rgba(30, 20, 5, .55); }
.cover-badges { position: absolute; top: 9px; right: 9px; left: 18px; display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; z-index: 3; }
.read-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translate(-50%, 8px); opacity: 0; z-index: 3;
  display: inline-flex; gap: 6px; align-items: center; padding: 7px 14px; border-radius: 999px;
  background: rgba(20, 28, 38, .86); color: #fff; font-size: .82rem; font-weight: 600; white-space: nowrap; transition: .25s;
}
.cover-link:hover .read-hint { opacity: 1; transform: translate(-50%, 0); }
.cover-fallback {
  position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 18px 16px 22px 22px;
  background:
    radial-gradient(circle at 80% 15%, hsla(calc(var(--h) * 1deg), 60%, 70%, .55), transparent 45%),
    linear-gradient(160deg, hsl(calc(var(--h) * 1deg), 38%, 30%), hsl(calc(var(--h) * 1deg + 30deg), 45%, 18%));
}
.cover-fallback::before { content: ""; position: absolute; left: 22px; right: 16px; top: 22px; height: 3px; background: var(--accent); width: 34px; }
.cover-fallback span { color: #fff; font-family: var(--display); font-weight: 600; font-size: 1.02rem; line-height: 1.3; }
.book-meta { padding: 14px 2px 0; }
.book-meta .cat { font-size: .74rem; font-weight: 600; color: var(--brand); text-transform: uppercase; letter-spacing: .02em; }
.book-meta h3 { font-size: 1rem; font-weight: 600; margin: 3px 0 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta h3 a { color: var(--ink); }
.book-meta .sub { color: var(--muted); font-size: .82rem; margin: 0; }
.manage-link { display: inline-flex; gap: 4px; align-items: center; margin-top: 6px; font-size: .8rem; color: var(--ink-2); padding: 3px 9px; border-radius: 8px; background: var(--paper-2); }

.empty-state { text-align: center; padding: 70px 20px; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.empty-state .ic { color: var(--brand); margin-bottom: 8px; }
.empty-state h1, .empty-state h2 { margin-top: 10px; }
.empty-state p { color: var(--muted); }
.empty-books { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-bottom: 10px; }
.empty-books span { width: 26px; border-radius: 3px 5px 5px 3px; background: var(--brand); height: 80px; box-shadow: inset 4px 0 0 rgba(0, 0, 0, .15); }
.empty-books span:nth-child(2) { height: 64px; background: var(--accent); }
.empty-books span:nth-child(3) { height: 74px; background: #c9bfae; transform: rotate(10deg); transform-origin: bottom left; margin-left: 4px; }

.pager { display: flex; justify-content: center; gap: 6px; margin: 10px 0 40px; flex-wrap: wrap; }
.pager a { min-width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); text-decoration: none; }
.pager a.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.foot { padding: 24px 0 30px; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); margin-top: 20px; }

/* ------------------------------------------------------------------ auth */
.auth-body { background: var(--paper); }
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art {
  position: relative; overflow: hidden; color: #f3ece0; display: flex; align-items: center; padding: 60px;
  background:
    radial-gradient(circle at 85% 10%, rgba(224, 164, 58, .35), transparent 40%),
    radial-gradient(circle at 10% 95%, rgba(42, 127, 115, .55), transparent 45%),
    linear-gradient(160deg, #0f5257, #0a2f33 70%);
}
.auth-art::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px); background-size: 20px 20px; pointer-events: none; }
.auth-art-inner { position: relative; z-index: 1; max-width: 480px; }
.auth-art h2 { font-size: clamp(1.8rem, 2.4vw + 1rem, 2.6rem); font-weight: 700; display: block; color: #fff; margin: 34px 0 14px; }
.auth-art p { color: rgba(243, 236, 224, .8); font-size: 1.02rem; }
.auth-points { list-style: none; padding: 0; margin: 26px 0 0; display: grid; gap: 10px; }
.auth-points li { display: flex; gap: 10px; align-items: center; font-size: .95rem; }
.auth-points .ic { color: var(--accent); }
.shelf { display: flex; align-items: flex-end; gap: 7px; height: 150px; padding-bottom: 10px; border-bottom: 3px solid rgba(255, 255, 255, .25); width: max-content; }
.spine { width: 30px; border-radius: 3px 3px 2px 2px; box-shadow: inset 5px 0 0 rgba(0, 0, 0, .14), inset -2px 0 0 rgba(255, 255, 255, .1); position: relative; }
.spine::after { content: ""; position: absolute; left: 7px; right: 7px; top: 18px; height: 2px; background: rgba(255, 255, 255, .45); box-shadow: 0 6px 0 rgba(255, 255, 255, .3); }
.s1 { height: 128px; background: #e0a43a; }
.s2 { height: 112px; background: #f3ece0; width: 24px; }
.s3 { height: 140px; background: #2a7f73; width: 36px; }
.s4 { height: 100px; background: #c96f4a; }
.s5 { height: 122px; background: #f3ece0; width: 26px; }
.s6 { height: 118px; background: #e0a43a; width: 28px; }
.spine.lean { transform: rotate(14deg); transform-origin: bottom left; margin-left: 10px; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: min(410px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 18px 0 0; font-size: 1.9rem; }
.auth-card > .muted { margin: -8px 0 6px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand div { display: flex; flex-direction: column; line-height: 1.2; }
.auth-brand b { font-family: var(--display); font-size: 1.1rem; }
.auth-brand small { color: var(--muted); }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 46px !important; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; }
.privacy-note { display: flex; gap: 8px; font-size: .78rem; color: var(--muted); margin-top: 8px; line-height: 1.5; }
.privacy-note .ic { margin-top: 2px; color: var(--brand); }
.share-gate { min-height: 100vh; display: grid; place-items: center; padding: 30px 20px; }
.share-gate .auth-card { background: var(--surface); padding: 34px; border-radius: 22px; border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
.share-gate h1 { font-size: 1.4rem; }

.install { width: min(760px, 100% - 32px); margin: 40px auto 80px; display: flex; flex-direction: column; gap: 18px; }
.install-head { display: flex; gap: 16px; align-items: center; }
.install-head h1 { font-size: 1.6rem; margin: 0; }
.install-head p { margin: 0; color: var(--muted); }
.install h2 { margin-top: 6px; }
.checklist { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.checklist .ok { color: var(--ok); }
.checklist .bad { color: var(--danger); font-weight: 600; }
.steps li { margin-bottom: 6px; }

/* ------------------------------------------------------------- page head */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 24px; }
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin: 0; }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: .88rem; color: var(--muted); margin-bottom: 8px; }

/* ---------------------------------------------------------------- editor */
.editor { display: grid; grid-template-columns: 340px 1fr; gap: 22px; align-items: start; }
.drop-col { position: sticky; top: 90px; display: flex; flex-direction: column; gap: 14px; }
.dropzone {
  position: relative; display: block; aspect-ratio: 1 / 1.3; border-radius: 14px; cursor: pointer; overflow: hidden;
  border: 2px dashed var(--line-2); background: repeating-linear-gradient(-45deg, #fbf8f2, #fbf8f2 10px, #f7f2e9 10px, #f7f2e9 20px);
  transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 3; }
.dz-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 20px; color: var(--ink-2); }
.dz-empty span { font-size: .84rem; color: var(--muted); }
.dz-icon { width: 66px; height: 66px; border-radius: 20px; display: grid; place-items: center; background: #fff; color: var(--brand); box-shadow: var(--shadow); margin-bottom: 8px; }
.dropzone.has-file .dz-empty { display: none; }
.dropzone.has-file { border-style: solid; border-color: var(--line); background: #ece6da; }
.dz-preview { position: absolute; inset: 0; display: grid; place-items: center; padding: 22px; }
.dz-preview img, .dz-preview canvas, .dz-preview .cover-fallback {
  max-width: 100%; max-height: 100%; border-radius: 3px 8px 8px 3px; box-shadow: 0 20px 34px -18px rgba(0, 0, 0, .6);
}
.dz-preview .cover-fallback { position: relative; width: 78%; aspect-ratio: 1 / 1.414; }
.dropzone.has-file::after {
  content: "เปลี่ยนไฟล์"; position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 2;
  padding: 6px 14px; border-radius: 999px; background: rgba(20, 28, 38, .82); color: #fff; font-size: .8rem; opacity: 0; transition: .2s;
}
.dropzone.has-file:hover::after { opacity: 1; }
.dropzone.busy::before { content: ""; position: absolute; inset: 0; z-index: 2; background: rgba(255, 255, 255, .5); }
.file-info { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; }
.file-info:empty { display: none; }
.file-info .ic { color: var(--ok); margin-top: 3px; }
.file-info span { display: flex; flex-direction: column; min-width: 0; }
.file-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-info small { color: var(--muted); }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--brand); animation: spin .8s linear infinite; flex-shrink: 0; margin-top: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.vis-group { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.vis-group legend { font-weight: 500; font-size: .92rem; color: var(--ink-2); margin-bottom: 8px; padding: 0; }
.vis-option { position: relative; display: block; }
.vis-option input { position: absolute; opacity: 0; }
.vis-card {
  display: flex; flex-direction: column; gap: 3px; height: 100%; padding: 14px; border-radius: 13px; cursor: pointer;
  border: 1.5px solid var(--line-2); background: #fff; transition: .15s;
}
.vis-card .ic { color: var(--muted); margin-bottom: 4px; }
.vis-card b { font-size: .93rem; color: var(--ink); }
.vis-card small { color: var(--muted); font-weight: 400; font-size: .78rem; line-height: 1.4; }
.vis-option input:checked + .vis-card { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(15, 82, 87, .1); }
.vis-option input:checked + .vis-card .ic { color: var(--brand); }
.vis-option input:focus-visible + .vis-card { outline: 2px solid var(--brand); outline-offset: 2px; }
.vis-option input:disabled + .vis-card { opacity: .5; cursor: not-allowed; }

.switches { display: grid; gap: 4px; border-top: 1px solid var(--line); padding-top: 14px; }
.switch { flex-direction: row; align-items: flex-start; gap: 14px; padding: 9px 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch > span:last-child { display: flex; flex-direction: column; }
.switch b { color: var(--ink); font-weight: 600; font-size: .93rem; }
.switch small { color: var(--muted); font-weight: 400; }
.track { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line-2); flex-shrink: 0; transition: .2s; margin-top: 1px; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: .2s cubic-bezier(.3, 1.4, .5, 1); }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }

.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 16px; border-top: 1px solid var(--line); padding-top: 18px; }
.upload-progress { flex: 1; position: relative; height: 38px; border-radius: 11px; background: var(--paper-2); overflow: hidden; }
.upload-progress i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--brand), #2a8f80); transition: width .2s; }
.upload-progress span { position: relative; z-index: 1; display: grid; place-items: center; height: 100%; font-size: .86rem; font-weight: 600; color: var(--ink); mix-blend-mode: hard-light; }

.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin-bottom: 2px; }
.section-head p { margin: 0; }
.share-form { display: grid; grid-template-columns: 1.4fr .8fr .8fr 1fr auto auto; gap: 12px; align-items: end; padding: 16px; border-radius: 14px; background: var(--paper); border: 1px solid var(--line); margin-bottom: 18px; }
.share-form .check { padding-bottom: 12px; white-space: nowrap; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; font-size: .78rem; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fcfaf5; }
.table form { margin: 0; }
.row-new td { background: var(--accent-soft) !important; }
.row-dim td { opacity: .55; }
.copy-field { display: flex; align-items: center; gap: 4px; min-width: 260px; }
.copy-field input { font-family: ui-monospace, Menlo, monospace; font-size: .78rem !important; padding: 7px 10px !important; background: var(--paper) !important; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.timeline li { position: relative; padding: 8px 0 8px 22px; font-size: .9rem; border-bottom: 1px dashed var(--line); }
.timeline li:last-child { border-bottom: 0; }
.t-dot { position: absolute; left: 2px; top: 15px; width: 9px; height: 9px; border-radius: 50%; background: var(--line-2); }
.t-view, .t-share_view { background: var(--brand); }
.t-download, .t-share_download { background: var(--accent); }
.t-delete, .t-login_failed, .t-share_revoke { background: var(--danger); }
.t-upload, .t-share_create, .t-login { background: var(--ok); }
.danger { border-color: #ecd0c9; }
.danger h2 .ic { color: var(--danger); }
.profile-card { display: flex; gap: 20px; align-items: center; }
.profile-card h2 { margin: 0; }
.profile-card p { margin: 2px 0 0; }

/* ----------------------------------------------------------------- admin */
.tabs { display: flex; gap: 4px; margin-bottom: 22px; padding: 5px; background: var(--paper-2); border-radius: 14px; width: max-content; max-width: 100%; overflow-x: auto; }
.tabs a { display: inline-flex; gap: 7px; align-items: center; padding: 9px 16px; border-radius: 10px; color: var(--ink-2); font-weight: 500; font-size: .92rem; white-space: nowrap; text-decoration: none; }
.tabs a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat { padding: 20px 22px; display: flex; flex-direction: column; }
.stat-ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); margin-bottom: 12px; }
.stat b { font-family: var(--display); font-size: 2rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.grid-2col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 22px; }
.health { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.health li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 11px; font-size: .9rem; }
.health .ic { margin-top: 3px; }
.health .ok { background: var(--ok-soft); color: #1f5536; }
.health .warn { background: var(--warn-soft); color: #74490a; }
.health .bad { background: var(--danger-soft); color: #7d2a1d; font-weight: 600; }
.mini-list { display: grid; gap: 4px; margin-top: 10px; font-size: .86rem; }
.mini-list small { color: var(--muted); }
.rank { margin: 0; padding: 0 0 0 1.4em; display: grid; gap: 4px; }
.rank li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.rank li > * { vertical-align: middle; }
.rank a { color: var(--ink); }
.rank b { float: right; color: var(--brand); font-family: var(--display); }
.grid-side { display: grid; grid-template-columns: 360px 1fr; gap: 22px; align-items: start; }
.grid-side > .form { position: sticky; top: 90px; }
.user-cell { display: flex; gap: 10px; align-items: center; }
.user-cell span:last-child { display: flex; flex-direction: column; line-height: 1.3; }
.user-cell small { color: var(--muted); }
.mini-search input { padding: 7px 12px !important; width: 200px !important; border-radius: 999px !important; }
.temp-pw .copy-field { min-width: 0; margin-top: 6px; width: 100%; }
.temp-pw .copy-field input { font-size: 1.05rem !important; letter-spacing: .06em; background: #fff !important; }
.cat-row { display: flex; gap: 8px; align-items: center; }
.cat-row .w-num { width: 74px !important; flex-shrink: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.filters label { min-width: 160px; }
.act { font-size: .8rem; font-weight: 600; padding: 3px 9px; border-radius: 7px; background: var(--paper-2); white-space: nowrap; }
.act-view, .act-share_view { background: var(--brand-soft); color: var(--brand); }
.act-download, .act-share_download { background: var(--accent-soft); color: var(--warn); }
.act-login_failed, .act-delete, .act-share_revoke { background: var(--danger-soft); color: var(--danger); }
.narrow-form { max-width: 860px; }

/* ================================================================ VIEWER */
.viewer-body { background: #11151b; overflow: hidden; }
.viewer {
  position: fixed; inset: 0; display: grid; grid-template-rows: auto 1fr auto; color: #e9e4da;
  background:
    radial-gradient(ellipse at 50% 40%, #2a313b 0%, #161b22 55%, #0d1015 100%);
}
.viewer::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5; background-image: radial-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px); background-size: 18px 18px; }
.v-bar { position: relative; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
.v-left-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.v-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.v-title b { font-family: var(--display); font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.v-title small { color: rgba(233, 228, 218, .55); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-tools { display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 14px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .07); flex-shrink: 0; }
.v-btn {
  height: 38px; min-width: 38px; padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; border-radius: 10px; background: transparent; color: #e9e4da; cursor: pointer; text-decoration: none !important; font: 500 .88rem var(--font);
}
.v-btn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.v-btn-text { background: var(--accent); color: #2b1d03; font-weight: 600; margin-left: 4px; }
.v-btn-text:hover { background: #ecb552; color: #2b1d03; }
.v-zoom { min-width: 58px; height: 38px; border: 0; background: transparent; color: #e9e4da; font: 600 .84rem var(--font); cursor: pointer; border-radius: 10px; }
.v-zoom:hover { background: rgba(255, 255, 255, .1); }
.v-sep { width: 1px; height: 20px; background: rgba(255, 255, 255, .12); margin: 0 4px; }

.v-stage { position: relative; overflow: hidden; display: flex; outline: none; touch-action: pan-y pinch-zoom; user-select: none; -webkit-user-select: none; }
.is-zoomed .v-stage { overflow: auto; cursor: grab; touch-action: auto; }
.v-stage.grabbing { cursor: grabbing; }
.v-book { position: relative; margin: auto; flex-shrink: 0; perspective: 2600px; transition: transform .6s cubic-bezier(.45, .05, .25, 1); cursor: pointer; }
.is-zoomed .v-book { cursor: inherit; }
.v-book::before { /* เงาใต้เล่ม */
  content: ""; position: absolute; left: 4%; right: 4%; bottom: -26px; height: 40px; border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .55), transparent 70%); filter: blur(6px); z-index: -1;
}
.v-page { position: absolute; top: 0; width: var(--pw); height: 100%; background: #fff; overflow: hidden; }
.v-page canvas, .face canvas { width: 100%; height: 100%; display: block; }
.v-left { left: 0; border-radius: 4px 0 0 4px; box-shadow: -2px 0 0 #f1ede4, -4px 1px 0 #e4ded1, -6px 2px 0 #d6cfc0, 0 20px 50px -20px rgba(0, 0, 0, .8); }
.v-right { left: var(--pw); border-radius: 0 4px 4px 0; box-shadow: 2px 0 0 #f1ede4, 4px 1px 0 #e4ded1, 6px 2px 0 #d6cfc0, 0 20px 50px -20px rgba(0, 0, 0, .8); }
.v-left::after, .v-right::after { content: ""; position: absolute; top: 0; bottom: 0; width: 46px; pointer-events: none; }
.v-left::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .06) 55%, rgba(0, 0, 0, .2)); }
.v-right::after { left: 0; background: linear-gradient(270deg, transparent, rgba(0, 0, 0, .06) 55%, rgba(0, 0, 0, .22)); }
.v-page.blank { visibility: hidden; }
.v-book.single .v-left { border-radius: 4px; box-shadow: 2px 0 0 #f1ede4, 4px 1px 0 #e4ded1, 0 20px 50px -20px rgba(0, 0, 0, .8); }
.v-book.single .v-left::after { display: none; }
.v-page.loading::before, .face.loading::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(100deg, #fff 30%, #f2eee6 50%, #fff 70%); background-size: 300% 100%; animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.v-leaf { position: absolute; top: 0; width: var(--pw); height: 100%; z-index: 5; transform-style: preserve-3d; transition: transform .75s cubic-bezier(.645, .045, .355, 1); }
.v-leaf.from-right { left: var(--pw); transform-origin: left center; }
.v-leaf.from-left { left: 0; transform-origin: right center; }
.v-leaf.from-right.turn { transform: rotateY(-180deg); }
.v-leaf.from-left.turn { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; background: #fff; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face.back { transform: rotateY(180deg); }
.face.blank canvas { visibility: hidden; }
.shade { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.from-right .front .shade { background: linear-gradient(90deg, rgba(0, 0, 0, .25), rgba(0, 0, 0, .05) 30%, rgba(255, 255, 255, .15) 85%, rgba(0, 0, 0, .1)); }
.from-right .back .shade { background: linear-gradient(270deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, .06) 35%, transparent); }
.from-left .front .shade { background: linear-gradient(270deg, rgba(0, 0, 0, .25), rgba(0, 0, 0, .05) 30%, rgba(255, 255, 255, .15) 85%, rgba(0, 0, 0, .1)); }
.from-left .back .shade { background: linear-gradient(90deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, .06) 35%, transparent); }
.v-leaf.turn .front .shade { animation: shadeFront .75s ease-in forwards; }
.v-leaf.turn .back .shade { animation: shadeBack .75s ease-out forwards; }
@keyframes shadeFront { from { opacity: 0; } to { opacity: 1; } }
@keyframes shadeBack { from { opacity: 1; } to { opacity: 0; } }
.from-right .front, .from-right .back { border-radius: 0 4px 4px 0; }
.from-right .back { border-radius: 4px 0 0 4px; }
.from-left .front { border-radius: 4px 0 0 4px; }
.from-left .back { border-radius: 0 4px 4px 0; }
.v-leaf.single { left: 0; transform-origin: left center; transition: transform .6s cubic-bezier(.5, 0, .3, 1), opacity .6s ease; }
.v-leaf.single .face { border-radius: 4px; }
.v-leaf.single.out.turn { transform: rotateY(-95deg); opacity: 0; }
.v-leaf.single.in { transform: rotateY(-95deg); opacity: 0; }
.v-leaf.single.in.turn { transform: none; opacity: 1; }

.v-wm { position: absolute; inset: 0; z-index: 8; pointer-events: none; background-repeat: repeat; }

.v-nav {
  position: absolute; top: 50%; z-index: 9; width: 52px; height: 52px; margin-top: -10px; display: grid; place-items: center;
  border: 0; border-radius: 50%; color: #fff; cursor: pointer; background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .1); backdrop-filter: blur(6px); transition: .2s; opacity: .75;
}
.v-nav:hover { background: rgba(255, 255, 255, .18); opacity: 1; transform: scale(1.05); }
.v-prev { left: 16px; }
.v-next { right: 16px; }
.show-thumbs .v-next { right: 336px; }
.at-start .v-prev, .at-end .v-next { opacity: 0; pointer-events: none; }

.v-foot { position: relative; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 10px 24px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.v-foot input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 999px; background: linear-gradient(90deg, var(--accent) var(--pct, 0%), rgba(255, 255, 255, .14) var(--pct, 0%)); outline: none; cursor: pointer; }
.v-foot input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 17px; height: 17px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.v-foot input[type=range]::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.v-pageinfo { display: flex; align-items: center; gap: 7px; font-size: .88rem; color: rgba(233, 228, 218, .7); white-space: nowrap; }
.v-pageinfo input { width: 74px !important; padding: 5px 8px !important; text-align: center; border-radius: 8px !important; background: rgba(255, 255, 255, .08) !important; border: 1px solid rgba(255, 255, 255, .12) !important; color: #fff !important; font-size: .88rem !important; }

.v-loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; z-index: 12; transition: opacity .5s; }
.v-loading.done { opacity: 0; pointer-events: none; }
.v-loading p { color: rgba(233, 228, 218, .75); margin: 0; font-size: .92rem; }
.v-loading.error p { color: #ffb4a3; max-width: 380px; text-align: center; }
.v-loading.error .v-loader, .v-loading.error .v-progress { display: none; }
.v-loader { display: flex; gap: 5px; align-items: flex-end; height: 44px; }
.v-loader span { width: 13px; height: 44px; border-radius: 2px 3px 3px 2px; background: var(--accent); transform-origin: bottom; animation: bookBob 1.1s ease-in-out infinite; }
.v-loader span:nth-child(2) { background: #f3ece0; height: 36px; animation-delay: .12s; }
.v-loader span:nth-child(3) { background: #2a8f80; animation-delay: .24s; }
@keyframes bookBob { 0%, 100% { transform: scaleY(.65); } 50% { transform: scaleY(1); } }
.v-progress { width: 200px; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.v-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.viewer .v-book { opacity: 0; transition: opacity .5s, transform .6s cubic-bezier(.45, .05, .25, 1); }
.viewer.ready .v-book { opacity: 1; }

.v-thumbs {
  position: absolute; top: 0; right: 0; bottom: 0; width: 320px; z-index: 20; display: flex; flex-direction: column;
  background: rgba(17, 21, 27, .94); backdrop-filter: blur(16px); border-left: 1px solid rgba(255, 255, 255, .08);
  transform: translateX(100%); transition: transform .3s cubic-bezier(.3, .8, .3, 1);
}
.show-thumbs .v-thumbs { transform: none; }
.v-thumbs-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.v-thumbs-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; padding: 16px; align-content: start; }
.v-thumb { border: 0; background: none; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; color: rgba(233, 228, 218, .6); }
.v-thumb-img { display: block; width: 100%; aspect-ratio: var(--r); background: rgba(255, 255, 255, .06); border-radius: 3px; overflow: hidden; outline: 2px solid transparent; outline-offset: 3px; transition: outline-color .15s; }
.v-thumb-img canvas { width: 100%; height: 100%; display: block; opacity: 0; transition: opacity .3s; }
.v-thumb.ready canvas { opacity: 1; }
.v-thumb:hover .v-thumb-img { outline-color: rgba(255, 255, 255, .35); }
.v-thumb.on .v-thumb-img { outline-color: var(--accent); }
.v-thumb.on small { color: var(--accent); font-weight: 600; }
.show-thumbs .v-stage { margin-right: 320px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1060px) {
  .editor { grid-template-columns: 280px 1fr; }
  .share-form { grid-template-columns: 1fr 1fr 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .grid-2col, .grid-side { grid-template-columns: 1fr; }
  .grid-side > .form { position: static; }
  .hero-inner { grid-template-columns: 1fr; gap: 26px; }
}
@media (max-width: 860px) {
  .nav-toggle { display: inline-grid; }
  .nav {
    display: none; position: absolute; top: 68px; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 2px;
    padding: 12px 16px 18px; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
  }
  .nav.open { display: flex; }
  .nav > a { border-radius: 10px; }
  .nav-user { margin: 8px 0 0; padding: 10px 0 0; border-left: 0; border-top: 1px solid var(--line); justify-content: space-between; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 34px 24px; }
  .auth-art .shelf { height: 90px; transform: scale(.7); transform-origin: bottom left; }
  .auth-art h2 { margin-top: 10px; font-size: 1.6rem; }
  .auth-art p, .auth-points { display: none; }
  .editor { grid-template-columns: 1fr; }
  .drop-col { position: static; }
  .dropzone { aspect-ratio: auto; height: 300px; }
  .vis-group { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .chip { white-space: nowrap; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .container { width: calc(100% - 28px); }
  .pad { padding: 18px; }
  .grid2, .share-form, .checklist { grid-template-columns: 1fr; }
  .hero { padding: 26px 0 22px; }
  .hero-stats > div { min-width: 0; flex: 1; padding: 12px; }
  .hero-stats b { font-size: 1.3rem; }
  .shelf-grid { grid-template-columns: repeat(2, 1fr); gap: 26px 16px; }
  .brand small, .who { display: none; }
  .stat-grid { gap: 10px; }
  .stat b { font-size: 1.5rem; }
  .v-bar { padding: 8px 10px; }
  .v-title small, .v-sep, [data-act="zoom-out"], [data-act="zoom-in"], .v-zoom, .v-btn-text span { display: none; }
  .v-nav { display: none; }
  .v-thumbs { width: 100%; }
  .show-thumbs .v-stage { margin-right: 0; }
  .v-foot { padding: 8px 14px 12px; gap: 12px; }
}

@media print { body * { display: none !important; } body::after { content: "เอกสารภายใน — ไม่อนุญาตให้พิมพ์จากระบบนี้"; display: block; padding: 40px; font-size: 18px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------------------------------------------------- public / guest */
.badge-public { background: var(--accent); color: #3d2a05; }
.nav-guest { display: flex !important; position: static !important; flex-direction: row !important; padding: 0 !important; background: none !important; border: 0 !important; box-shadow: none !important; gap: 14px; }
.guest-note { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .88rem; }
.public-warn { line-height: 1.55; }
.copy-field.inline { display: inline-flex; vertical-align: middle; min-width: 0; width: min(460px, 100%); margin-left: 4px; }
@media (max-width: 1060px) { .vis-group { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .guest-note { display: none; } }
.nav-guest > a.btn { color: #fff; background: var(--brand); border-radius: 12px; }
.nav-guest > a.btn:hover { background: var(--brand-2); }

/* ---- ความเข้ากันได้กับ Safari/iOS รุ่นเก่า (ไม่รู้จัก inset / aspect-ratio) ---- */
.viewer, .v-loading, .v-wm, .face, .shade, .viewer::before,
.v-page.loading::before, .face.loading::before { top: 0; right: 0; bottom: 0; left: 0; }
.v-errdetail { max-width: 340px; color: rgba(233, 228, 218, .45); font-size: .7rem; text-align: center; word-break: break-all; padding: 0 16px; }
.v-loading.error p b { color: #fff; }
/* ชื่อเรื่องยาวต้องไม่ดันพื้นที่อ่านให้กว้างเกินจอมือถือ */
.viewer { grid-template-columns: minmax(0, 1fr); width: 100%; }
.v-bar, .v-stage, .v-foot { min-width: 0; }
.v-left-group { flex: 1 1 auto; }
@media (max-width: 640px) {
  .v-title b { font-size: .92rem; }
  .v-pageinfo input { width: 64px !important; }
}

/* ======================================================================
   ตกแต่ง E-book: วัตถุบนหน้า (ใช้ทั้งตัวอ่านและสตูดิโอ)
   ====================================================================== */
.pg-layer { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 2; overflow: hidden; }
.v-page canvas, .face canvas, .v-spage canvas { position: relative; z-index: 1; }
.el { position: absolute; box-sizing: border-box; }
.el-text { white-space: pre-wrap; word-break: break-word; overflow: hidden; }
.el-image img { width: 100%; height: 100%; display: block; pointer-events: none; user-select: none; }
.el-image.shadow img { box-shadow: 0 10px 28px -10px rgba(0, 0, 0, .55); }
.el-image.shadow { overflow: visible; }
.el-hotspot { border-radius: calc(var(--pgw) * .01); }
.el-hotspot .hs-ic { display: none; }
.el-hotspot.hint { background: rgba(224, 164, 58, .14); box-shadow: inset 0 0 0 2px rgba(224, 164, 58, .85); animation: hsPulse 2.2s ease-in-out infinite; }
@keyframes hsPulse { 0%, 100% { box-shadow: inset 0 0 0 2px rgba(224, 164, 58, .85); } 50% { box-shadow: inset 0 0 0 2px rgba(224, 164, 58, .25), 0 0 0 4px rgba(224, 164, 58, .25); } }
.el-act { cursor: pointer; }
.el-act:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.el-hotspot.el-act:hover { background: rgba(224, 164, 58, .22); }
.el-video { background: #111 center / cover no-repeat; border-radius: calc(var(--pgw) * .008); display: grid; place-items: center; overflow: hidden; box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .6); }
.el-video::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 50%, rgba(0, 0, 0, .35)); }
.el-video .play { position: relative; z-index: 1; width: max(26px, calc(var(--pgw) * .1)); height: max(26px, calc(var(--pgw) * .1)); border-radius: 50%; background: rgba(255, 255, 255, .92); box-shadow: 0 4px 16px rgba(0, 0, 0, .4); transition: transform .2s; }
.el-video .play::after { content: ""; position: absolute; left: 40%; top: 30%; border-style: solid; border-width: calc(var(--pgw) * .02) 0 calc(var(--pgw) * .02) calc(var(--pgw) * .033); border-color: transparent transparent transparent #c0392b; }
.el-video.el-act:hover .play { transform: scale(1.1); }
.el-note { overflow: visible; z-index: 3; }
.note-ic { display: grid; place-items: center; width: 100%; height: 100%; border-radius: 50% 50% 50% 12%; color: #fff; font: 700 calc(var(--pgw) * .03) Georgia, serif; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
.el-note.el-act .note-ic { animation: notePop 2.6s ease-in-out infinite; }
@keyframes notePop { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }
.note-pop {
  display: none; position: absolute; left: 115%; top: 0; width: calc(var(--pgw) * .42); max-width: 320px; min-width: 160px; z-index: 6;
  background: #fffbea; color: #3b2f12; padding: 10px 12px; border-radius: 10px; box-shadow: 0 12px 28px -8px rgba(0, 0, 0, .45);
  font: 400 max(13px, calc(var(--pgw) * .024)) / 1.55 var(--font); white-space: pre-wrap; text-align: left;
}
.el-note.open .note-pop { display: block; }

/* ----- ธีมหน้าอ่าน ----- */
.viewer { background: var(--v-bg, radial-gradient(ellipse at 50% 40%, #2a313b 0%, #161b22 55%, #0d1015 100%)); }
#bgLayer { display: none; }
#bgLayer.v-bgimg { display: block; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: center / cover no-repeat; z-index: 0; }
#bgLayer.v-bgimg::after { content: ""; position: absolute; inset: 0; background: rgba(10, 14, 20, .35); }
#bgLayer.blur { filter: blur(30px) saturate(1.2); transform: scale(1.15); }
#bgLayer.blur::after { background: rgba(10, 14, 20, .45); }
.viewer > * { position: relative; }
.viewer > .v-nav, .viewer > .v-thumbs, .viewer > .v-lightbox { position: absolute; }
.v-brandlogo { display: flex; align-items: center; height: 36px; }
.v-brandlogo img { max-height: 36px; max-width: 140px; object-fit: contain; display: block; }
.viewer.tone-light { color: #1b2430; }
.tone-light .v-title b { color: #1b2430; }
.tone-light .v-title small, .tone-light .v-pageinfo { color: rgba(27, 36, 48, .6); }
.tone-light .v-btn, .tone-light .v-zoom { color: #1b2430; }
.tone-light .v-btn:hover, .tone-light .v-zoom:hover { background: rgba(0, 0, 0, .06); color: #000; }
.tone-light .v-btn-text { color: #2b1d03; }
.tone-light .v-tools { background: rgba(255, 255, 255, .6); border-color: rgba(0, 0, 0, .08); }
.tone-light .v-sep { background: rgba(0, 0, 0, .12); }
.tone-light .v-nav { color: #1b2430; background: rgba(255, 255, 255, .7); border-color: rgba(0, 0, 0, .08); }
.tone-light .v-foot input[type=range] { background: linear-gradient(90deg, var(--accent) var(--pct, 0%), rgba(0, 0, 0, .12) var(--pct, 0%)); }
.tone-light .v-pageinfo input { background: rgba(255, 255, 255, .8) !important; color: #1b2430 !important; border-color: rgba(0, 0, 0, .12) !important; }
.tone-light .v-loading p { color: rgba(27, 36, 48, .7); }
.tone-light .v-book::before { background: radial-gradient(ellipse at center, rgba(60, 40, 10, .35), transparent 70%); }
.tone-light::before { opacity: .25; }
.v-btn-text { background: var(--accent); }

/* ----- รูปแบบการพลิก: เลื่อนข้าง / จางหาย ----- */
.v-book.tr .v-page { transition: transform .2s ease, opacity .2s ease; }
.v-book.tr-out-l .v-page { transform: translateX(-36px); opacity: 0; }
.v-book.tr-out-r .v-page { transform: translateX(36px); opacity: 0; }
.v-book.tr-in-r .v-page { transform: translateX(36px); opacity: 0; transition: none; }
.v-book.tr-in-l .v-page { transform: translateX(-36px); opacity: 0; transition: none; }
.v-book.tr-fade .v-page { opacity: 0; }
.v-book.tr .v-page.v-right { transition-delay: .03s; }

/* ----- โหมดเลื่อนแนวตั้ง ----- */
.mode-scroll .v-stage { overflow-y: auto; overflow-x: auto; touch-action: auto; display: block; -webkit-overflow-scrolling: touch; }
.v-scroll { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 22px 0 60px; min-width: max-content; margin: 0 auto; }
.v-spage { position: relative; width: var(--spw); height: var(--sph); background: #fff; border-radius: 4px; overflow: hidden; flex-shrink: 0; box-shadow: 0 18px 40px -18px rgba(0, 0, 0, .7); }
.v-spage canvas { width: 100%; height: 100%; display: block; }
.v-spage .v-wm { z-index: 4; }
.mode-scroll .v-nav { display: none; }

/* ----- สารบัญในตัวอ่าน ----- */
.v-tabs { display: flex; gap: 4px; padding: 3px; border-radius: 10px; background: rgba(255, 255, 255, .07); }
.v-tabs button { border: 0; background: none; color: rgba(233, 228, 218, .7); padding: 6px 14px; border-radius: 8px; font: 600 .86rem var(--font); cursor: pointer; }
.v-tabs button.on { background: rgba(255, 255, 255, .14); color: #fff; }
.v-tabs:not([hidden]) + .v-tabs-solo { display: none; }
.v-toc { flex: 1; overflow-y: auto; padding: 10px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.v-toc button { display: flex; justify-content: space-between; gap: 12px; text-align: left; border: 0; background: none; color: #e9e4da; padding: 11px 12px; border-radius: 10px; font: 500 .92rem/1.4 var(--font); cursor: pointer; }
.v-toc button small { color: rgba(233, 228, 218, .5); flex-shrink: 0; }
.v-toc button:hover { background: rgba(255, 255, 255, .07); }
.v-toc button.on { background: rgba(224, 164, 58, .16); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.v-thumb-img { position: relative; }

/* ----- หน้าต่างวิดีโอ ----- */
.v-lightbox { top: 0; right: 0; bottom: 0; left: 0; z-index: 40; display: grid; place-items: center; background: rgba(5, 8, 12, .86); backdrop-filter: blur(6px); padding: 20px; }
.v-lb-body { width: min(1000px, 100%); aspect-ratio: 16 / 9; background: #000; border-radius: 12px; overflow: hidden; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.v-lb-body iframe, .v-lb-body video { width: 100%; height: 100%; border: 0; display: block; }
.v-lb-close { position: absolute; top: 14px; right: 14px; color: #fff !important; background: rgba(255, 255, 255, .12) !important; }

/* ======================================================================
   หน้าสร้าง: เลือกโหมด PDF / ออกแบบเอง
   ====================================================================== */
.btn-accent { background: var(--accent); color: #2b1d03; box-shadow: 0 6px 16px -8px rgba(224, 164, 58, .9); }
.btn-accent:hover { background: #ecb552; }
.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; max-width: 760px; }
.mode-tabs button { display: flex; gap: 14px; align-items: flex-start; text-align: left; padding: 16px 18px; border-radius: 14px; border: 1.5px solid var(--line-2); background: var(--surface); cursor: pointer; font: inherit; color: var(--ink); transition: .15s; }
.mode-tabs button .ic { color: var(--muted); margin-top: 2px; }
.mode-tabs button span { display: flex; flex-direction: column; }
.mode-tabs button small { color: var(--muted); font-size: .82rem; }
.mode-tabs button.on { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(15, 82, 87, .1); }
.mode-tabs button.on .ic { color: var(--brand); }
.size-pick { display: none; grid-template-columns: 1fr 1fr; gap: 10px; }
.size-title { grid-column: 1 / -1; margin: 0; font-weight: 600; font-size: .92rem; color: var(--ink-2); }
.mode-design .size-pick { display: grid; }
.mode-design .dropzone, .mode-design .file-info, .mode-design .dl-switch { display: none !important; }
.size-opt { position: relative; }
.size-opt input { position: absolute; opacity: 0; }
.size-card { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 14px 8px 12px; border-radius: 12px; border: 1.5px solid var(--line-2); background: #fff; cursor: pointer; text-align: center; height: 100%; }
.size-card i { display: block; height: 54px; max-width: 90px; background: var(--paper-2); border: 2px solid var(--line-2); border-radius: 3px; margin-bottom: 8px; }
.size-card b { font-size: .86rem; color: var(--ink); }
.size-card small { font-size: .74rem; color: var(--muted); font-weight: 400; }
.size-opt input:checked + .size-card { border-color: var(--brand); background: var(--brand-soft); }
.size-opt input:checked + .size-card i { border-color: var(--brand); background: #fff; }
.design-cover { display: grid; place-items: center; padding: 18px; border-radius: 14px; background: #ece6da; }
.design-cover img, .design-cover .cover-fallback { width: 78%; aspect-ratio: 1 / 1.414; position: relative; object-fit: cover; border-radius: 3px 8px 8px 3px; box-shadow: 0 20px 34px -18px rgba(0, 0, 0, .6); }

/* ======================================================================
   สตูดิโอ
   ====================================================================== */
.studio-body { background: #e9e5dd; overflow: hidden; }
.studio { position: fixed; top: 0; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: 72px 300px minmax(0, 1fr) 300px; grid-template-rows: 58px minmax(0, 1fr); }
.st-bar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 16px 0 10px; background: #fffdf9; border-bottom: 1px solid var(--line); z-index: 5; }
.st-back { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; color: var(--ink); }
.st-back:hover { background: var(--paper-2); }
.st-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.st-title b { font-family: var(--display); font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.st-title small { font-size: .76rem; color: var(--muted); }
.st-title small.dirty { color: var(--warn); }
.st-title small.ok { color: var(--ok); }
.st-title small.err { color: var(--danger); }
.st-actions { display: flex; align-items: center; gap: 8px; }
.st-icon { min-width: 34px; height: 34px; padding: 0 8px; display: inline-grid; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2); cursor: pointer; font-size: 1rem; }
.st-icon:hover:not(:disabled) { background: var(--paper-2); color: var(--ink); }
.st-icon:disabled { opacity: .35; cursor: default; }
.st-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }
.st-rail { background: #1b2430; display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; }
.st-rail button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px; border: 0; border-radius: 12px; background: none; color: rgba(255, 255, 255, .62); cursor: pointer; font: 500 .72rem var(--font); }
.st-rail button:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.st-rail button.on { background: rgba(224, 164, 58, .16); color: var(--accent); }
.st-panel, .st-inspector { background: #fffdf9; overflow-y: auto; padding: 16px 16px 40px; }
.st-panel { border-right: 1px solid var(--line); }
.st-inspector { border-left: 1px solid var(--line); }
.st-ph h3 { font-family: var(--display); font-size: 1.1rem; margin: 0 0 12px; }
.st-ph small { color: var(--muted); font-weight: 500; font-size: .85rem; margin-left: 4px; }
.st-sub, .st-group h4 { font-size: .78rem; font-weight: 600; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .03em; }
.st-group { border-top: 1px solid var(--line); margin-top: 16px; }
.st-hint { font-size: .8rem; color: var(--muted); line-height: 1.5; margin: 10px 0; }
.st-hint.bad { color: var(--danger); }
.st-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.st-field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: .84rem; font-weight: 500; color: var(--ink-2); }
.st-field > span { display: flex; justify-content: space-between; }
.st-field em { font-style: normal; color: var(--muted); font-weight: 400; }
.st-field input:not([type=range]):not([type=color]), .st-field textarea, .st-toc input { padding: 8px 10px !important; font-size: .88rem !important; border-radius: 9px !important; }
.st-field input[type=range] { width: 100%; accent-color: var(--brand); }
.st-check { flex-direction: row !important; align-items: center; gap: 8px; font-size: .86rem; margin: 10px 0; cursor: pointer; }
.st-seg { display: flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 10px; background: var(--paper-2); }
.st-seg button { flex: 1; min-width: 0; padding: 6px 8px; border: 0; border-radius: 8px; background: none; color: var(--ink-2); font: 500 .8rem var(--font); cursor: pointer; white-space: nowrap; }
.st-seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm); }
.st-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.sw { width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); position: relative; padding: 0; display: inline-block; }
.sw.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--brand); }
.sw.none { background: repeating-linear-gradient(45deg, #fff 0 4px, #e9e2d4 4px 8px); }
.sw.custom { background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.st-stage { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #f3efe7, #ddd6c9); }
.st-loading { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.st-page { position: relative; background: #fff; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .55), 0 0 0 1px rgba(0, 0, 0, .05); flex-shrink: 0; }
.st-page > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.st-page .pg-layer { overflow: visible; z-index: 2; }
.st-el { cursor: move; user-select: none; }
.st-el:hover:not(.sel) { outline: 1.5px dashed rgba(15, 82, 87, .55); outline-offset: 1px; }
.st-el.sel { outline: 2px solid #3b82f6; outline-offset: 1px; z-index: 50; }
.st-el.editing { cursor: text; user-select: text; outline: 2px solid var(--accent); }
.st-el.el-text:empty::before { content: "พิมพ์ข้อความ…"; opacity: .35; }
.studio .el-hotspot { outline: 2px dashed rgba(224, 164, 58, .9); background: rgba(224, 164, 58, .12); animation: none; box-shadow: none; }
.studio .el-hotspot .hs-ic { display: grid; place-items: center; position: absolute; right: 4px; top: 4px; width: 20px; height: 20px; border-radius: 6px; background: var(--accent); color: #2b1d03; font-size: 12px; font-weight: 700; }
.studio .note-pop { display: none !important; }
.st-h { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid #3b82f6; border-radius: 3px; z-index: 2; }
.st-h-nw { left: -7px; top: -7px; cursor: nwse-resize; }
.st-h-ne { right: -7px; top: -7px; cursor: nesw-resize; }
.st-h-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
.st-h-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
.st-guide { position: absolute; z-index: 60; pointer-events: none; background: #ec4899; }
.st-guide-v { left: 50%; top: 0; bottom: 0; width: 1px; }
.st-guide-h { top: 50%; left: 0; right: 0; height: 1px; }
.st-pagenav { display: flex; align-items: center; gap: 10px; padding: 4px 6px; background: #fffdf9; border-radius: 12px; box-shadow: var(--shadow); font-size: .88rem; color: var(--ink-2); }

.st-pagetools { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.st-add { position: relative; margin-right: auto; }
.st-add summary { list-style: none; cursor: pointer; }
.st-add summary::-webkit-details-marker { display: none; }
.st-tpls { position: absolute; top: 40px; left: 0; z-index: 20; width: 260px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--line); }
.st-tpls button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font: 500 .76rem var(--font); color: var(--ink-2); }
.st-tpls button:hover { border-color: var(--brand); background: var(--brand-soft); }
.tpl { display: block; width: 46px; height: 62px; border-radius: 3px; border: 1px solid var(--line-2); background: #fff; position: relative; overflow: hidden; }
.tpl-cover { background: linear-gradient(transparent 55%, #e0a43a 55% 57%, transparent 57%), #0f5257; }
.tpl-article { background: linear-gradient(#0f5257, #0f5257) 6px 8px / 60% 5px no-repeat, repeating-linear-gradient(#fff 0 5px, #d9d0bf 5px 7px) 6px 20px / 80% 36px no-repeat, #fff; }
.tpl-feature { background: linear-gradient(#c9bfae, #c9bfae) 0 0 / 100% 55% no-repeat, linear-gradient(#1b2430, #1b2430) 6px 40px / 60% 4px no-repeat, #f6f2ea; }
.tpl-twocol { background: linear-gradient(#0f5257, #0f5257) 6px 7px / 60% 5px no-repeat, repeating-linear-gradient(#fff 0 4px, #d9d0bf 4px 6px) 6px 20px / 40% 36px no-repeat, repeating-linear-gradient(#fff 0 4px, #d9d0bf 4px 6px) 26px 20px / 40% 36px no-repeat, #fff; }
.tpl-quote { background: radial-gradient(circle at 30% 35%, #e0a43a 0 3px, transparent 4px), linear-gradient(#fff, #fff) 8px 28px / 70% 4px no-repeat, #1b2430; }
.st-thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; margin-top: 14px; }
.st-thumb { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 0; background: none; cursor: pointer; padding: 0; color: var(--muted); font: 500 .76rem var(--font); }
.st-thumb-img { position: relative; display: block; width: 100%; background: #fff; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px var(--line-2); transition: box-shadow .15s; }
.st-thumb-img canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.st-thumb:hover .st-thumb-img { box-shadow: 0 0 0 2px var(--line-2), var(--shadow); }
.st-thumb.on .st-thumb-img { box-shadow: 0 0 0 3px var(--brand); }
.st-thumb.on small { color: var(--brand); font-weight: 700; }
.st-thumb em { position: absolute; top: 6px; right: 6px; z-index: 3; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #2b1d03; font-style: normal; font-weight: 700; font-size: .72rem; display: grid; place-items: center; }
.st-ins-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.st-ins { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; font: inherit; color: var(--ink); text-align: center; transition: .15s; }
.st-ins:hover { border-color: var(--brand); background: var(--brand-soft); transform: translateY(-1px); }
.ins-ic { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--paper-2); font-size: 1.05rem; color: var(--brand); margin-bottom: 4px; }
.st-ins b { font-size: .8rem; font-weight: 600; }
.st-ins small { font-size: .68rem; color: var(--muted); line-height: 1.3; }
.st-themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 8px; }
.st-theme { display: flex; flex-direction: column; align-items: center; gap: 5px; border: 0; background: none; padding: 0; cursor: pointer; font: 500 .74rem var(--font); color: var(--ink-2); position: relative; }
.st-theme i { position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1; border-radius: 12px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .1); overflow: hidden; }
.st-theme i span { width: 36%; height: 50%; background: #fff; border-radius: 2px; box-shadow: 0 4px 8px rgba(0, 0, 0, .3); }
.st-theme i input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.st-theme.on i { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--brand); }
.st-theme.on { color: var(--brand); font-weight: 700; }
.st-logo { padding: 10px; border-radius: 10px; background: #1b2430; display: grid; place-items: center; }
.st-logo img { max-height: 44px; max-width: 100%; }
.st-preview { position: relative; height: 120px; border-radius: 14px; margin-top: 18px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.st-preview .pv-page { width: 56px; height: 78px; background: #fff; box-shadow: 0 10px 20px -8px rgba(0, 0, 0, .6); }
.st-preview .pv-page:first-child { border-radius: 3px 0 0 3px; background: linear-gradient(90deg, #fff 80%, #eee); }
.st-preview i { position: absolute; left: 20%; right: 20%; bottom: 14px; height: 4px; border-radius: 2px; }
.st-flips { display: grid; gap: 8px; }
.st-flip { position: relative; display: grid !important; grid-template-columns: 58px 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; cursor: pointer; }
.st-flip input { position: absolute; opacity: 0; }
.st-flip .fx { grid-row: 1 / 3; position: relative; width: 58px; height: 42px; border-radius: 8px; background: #1b2430; perspective: 120px; overflow: hidden; }
.st-flip b { font-size: .88rem; color: var(--ink); }
.st-flip small { font-size: .74rem; color: var(--muted); font-weight: 400; }
.st-flip.on { border-color: var(--brand); background: var(--brand-soft); }
.fx i { position: absolute; top: 8px; width: 20px; height: 26px; background: #fff; }
.fx i:first-child { left: 9px; }
.fx i:last-child { left: 29px; background: #e0a43a; transform-origin: left center; }
.fx-book i:last-child { animation: fxBook 1.8s ease-in-out infinite; }
.fx-slide i { left: 19px !important; animation: fxSlide 1.8s ease-in-out infinite; }
.fx-slide i:first-child { animation-delay: -.9s; }
.fx-fade i { left: 19px !important; animation: fxFade 1.8s ease-in-out infinite; }
.fx-fade i:first-child { animation-delay: -.9s; }
.fx-scroll i { left: 19px !important; animation: fxScroll 1.8s linear infinite; }
.fx-scroll i:first-child { animation-delay: -.9s; }
.fx-none i:first-child { display: none; }
.fx-none i:last-child { left: 19px; }
@keyframes fxBook { 0%, 30% { transform: rotateY(0); } 70%, 100% { transform: rotateY(-180deg); } }
@keyframes fxSlide { 0% { transform: translateX(60px); } 30%, 50% { transform: translateX(0); } 80%, 100% { transform: translateX(-60px); } }
@keyframes fxFade { 0%, 100% { opacity: 0; } 30%, 60% { opacity: 1; } }
@keyframes fxScroll { 0% { transform: translateY(46px); } 100% { transform: translateY(-46px); } }
.st-toc { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.st-toc-row { display: grid; grid-template-columns: 1fr 58px 30px 30px; gap: 4px; align-items: center; }
.st-cover { display: grid; place-items: center; padding: 18px; background: #ece6da; border-radius: 14px; margin-bottom: 8px; }
.st-cover img, .st-cover .cover-fallback { width: 70%; aspect-ratio: 1 / 1.414; position: relative; object-fit: cover; border-radius: 3px 8px 8px 3px; box-shadow: 0 18px 30px -16px rgba(0, 0, 0, .6); }
.st-panel .btn-block + .btn-block { margin-top: 8px; }
.st-insp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.st-insp-head b { font-family: var(--display); font-size: 1rem; }
.st-imgprev { border-radius: 10px; overflow: hidden; background: var(--paper-2); margin: 12px 0 8px; display: grid; place-items: center; max-height: 160px; }
.st-imgprev img { max-width: 100%; max-height: 160px; display: block; }
.st-empty { text-align: center; padding: 30px 8px; color: var(--ink-2); }
.st-empty-ic { font-size: 1.8rem; color: var(--accent); }
.st-empty p { font-size: .86rem; color: var(--muted); }
.st-keys { list-style: none; padding: 14px 0 0; margin: 18px 0 0; border-top: 1px solid var(--line); text-align: left; display: grid; gap: 7px; font-size: .8rem; color: var(--muted); }
kbd { font: 600 .72rem ui-monospace, Menlo, monospace; padding: 2px 6px; border-radius: 5px; background: #fff; box-shadow: 0 1px 0 var(--line-2), 0 0 0 1px var(--line); color: var(--ink); }
.st-mobile-note { display: none; }
@media (max-width: 1180px) { .studio { grid-template-columns: 64px 260px minmax(0, 1fr) 260px; } .st-themes { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .studio { display: none; }
  .st-mobile-note { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 100vh; padding: 30px; text-align: center; }
}
@media (max-width: 640px) { .mode-tabs { grid-template-columns: 1fr; } }
/* วัตถุตกแต่งที่คลิกไม่ได้ ต้องไม่บังลิงก์/วิดีโอที่อยู่ข้างใต้ */
.viewer .el:not(.el-act) { pointer-events: none; }

.cover.contain { background: #2b3440; }
.cover-blur { position: absolute; inset: -10%; background: center / cover no-repeat; filter: blur(14px) brightness(.55); }
.cover.contain img { position: relative; z-index: 1; object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .45)); padding: 0 8%; }
.st-seg button { padding: 6px 6px; }

/* ======================================================================
   รูปแบบการพลิกเพิ่มเติม
   ====================================================================== */
/* เล่นอัตโนมัติ */
.viewer > .v-autobar { position: absolute; top: 0; left: 0; right: 0; height: 3px; z-index: 30; pointer-events: none; }
.v-autobar i { display: block; height: 100%; width: 0; background: var(--accent); }
.v-autobar.run i { animation: autobar var(--dur, 8s) linear forwards; }
@keyframes autobar { to { width: 100%; } }
.v-auto .i-pause, .autoplaying .v-auto .i-play { display: none; }
.autoplaying .v-auto .i-pause { display: block; }
.autoplaying .v-auto { color: var(--accent) !important; }

/* กระดาษอ่อน (โค้งตอนพลิก) / ปกแข็ง */
.v-leaf.soft.turn.from-right .face > canvas, .v-leaf.soft.turn.from-right .face > .pg-layer { transform-origin: left center; animation: bendR .75s ease-in-out; }
.v-leaf.soft.turn.from-left .face > canvas, .v-leaf.soft.turn.from-left .face > .pg-layer { transform-origin: right center; animation: bendL .75s ease-in-out; }
@keyframes bendR { 50% { transform: skewY(-2.2deg) scaleX(.965); } }
@keyframes bendL { 50% { transform: skewY(2.2deg) scaleX(.965); } }
.v-leaf.hard { transition-duration: .65s; transition-timing-function: cubic-bezier(.55, 0, .25, 1); }
.v-leaf.hard .face { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25), 0 0 0 1px #b9ae98; }
.v-leaf.hard .shade { background: rgba(0, 0, 0, .28) !important; }

/* ลากมุมกระดาษ */
.style-curl .v-stage { touch-action: none; }
.style-curl .v-book { cursor: grab; }
.style-curl .v-book:active { cursor: grabbing; }
.v-leaf.manual .front .shade { animation: none !important; opacity: calc(var(--p, 0) * 1.25); transition: opacity .45s; }
.v-leaf.manual .back .shade { animation: none !important; opacity: calc(1 - var(--p, 0)); transition: opacity .45s; }
.style-curl .v-book:not(.single) .v-right:not(.blank)::before,
.style-curl .v-book.single .v-left:not(.blank)::before {
  content: ""; position: absolute; right: 0; bottom: 0; z-index: 4; width: 0; height: 0;
  background: linear-gradient(315deg, transparent 49%, rgba(0, 0, 0, .2) 50%, #ebe5d8 56%, #fff 80%);
  box-shadow: -4px -4px 10px rgba(0, 0, 0, .12); border-top-left-radius: 6px; transition: width .25s, height .25s;
}
.style-curl .v-book:not(.single) .v-left:not(.blank)::before {
  content: ""; position: absolute; left: 0; bottom: 0; z-index: 4; width: 0; height: 0;
  background: linear-gradient(45deg, transparent 49%, rgba(0, 0, 0, .2) 50%, #ebe5d8 56%, #fff 80%);
  box-shadow: 4px -4px 10px rgba(0, 0, 0, .12); border-top-right-radius: 6px; transition: width .25s, height .25s;
}
@media (hover: none) { .style-curl.ready .v-book:not(.single) .v-right::before, .style-curl.ready .v-book.single .v-left::before { animation: peekCorner 1.4s ease-in-out .8s 2; } }
@keyframes peekCorner { 50% { width: calc(var(--pw) * .12); height: calc(var(--pw) * .12); } }

/* ทรานซิชันทั้งเล่ม: เลื่อนข้าง จางหาย ซูม ซ้อนการ์ด ลูกบาศก์ */
.viewer .v-book.tr { transition: opacity .25s ease, translate .25s ease, scale .25s ease, rotate .3s ease, transform .6s cubic-bezier(.45, .05, .25, 1) !important; }
.viewer .v-book.tr.tr-in { transition: none !important; }
.viewer.ready .v-book.fx-slide.tr-out.next { translate: -48px 0; opacity: 0; }
.viewer.ready .v-book.fx-slide.tr-in.next { translate: 48px 0; opacity: 0; }
.viewer.ready .v-book.fx-slide.tr-out.prev { translate: 48px 0; opacity: 0; }
.viewer.ready .v-book.fx-slide.tr-in.prev { translate: -48px 0; opacity: 0; }
.viewer.ready .v-book.fx-fade.tr-out, .viewer.ready .v-book.fx-fade.tr-in { opacity: 0; }
.viewer.ready .v-book.fx-zoom.tr-out { scale: 1.14; opacity: 0; }
.viewer.ready .v-book.fx-zoom.tr-in { scale: .86; opacity: 0; }
.viewer.ready .v-book.fx-cards.tr-out.next { translate: -75% 3%; rotate: -9deg; opacity: 0; }
.viewer.ready .v-book.fx-cards.tr-in.next { scale: .9; translate: 0 22px; opacity: .25; }
.viewer.ready .v-book.fx-cards.tr-out.prev { scale: .9; translate: 0 22px; opacity: 0; }
.viewer.ready .v-book.fx-cards.tr-in.prev { translate: -75% 3%; rotate: -9deg; opacity: 0; }
.viewer.ready .v-book.fx-cube.tr-out.next { rotate: y -78deg; translate: -22% 0; opacity: .35; }
.viewer.ready .v-book.fx-cube.tr-in.next { rotate: y 78deg; translate: 22% 0; opacity: .35; }
.viewer.ready .v-book.fx-cube.tr-out.prev { rotate: y 78deg; translate: 22% 0; opacity: .35; }
.viewer.ready .v-book.fx-cube.tr-in.prev { rotate: y -78deg; translate: -22% 0; opacity: .35; }
.style-cube .v-stage { perspective: 1500px; }
.style-cards .v-page { border-radius: 8px !important; box-shadow: 7px 7px 0 -2px #ece6da, 14px 14px 0 -4px #d6cfc0, 0 24px 50px -20px rgba(0, 0, 0, .8) !important; }
.style-cards .v-left::after, .style-cards .v-right::after { display: none; }
.style-cards .v-book:not(.single) .v-left { left: -6px; }
.style-cards .v-book:not(.single) .v-right { left: calc(var(--pw) + 6px); }

/* เลื่อนแนวนอน (Carousel) */
.mode-carousel .v-stage { display: block; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; touch-action: pan-x pinch-zoom; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.mode-carousel .v-stage::-webkit-scrollbar { display: none; }
.v-scroll.horiz { flex-direction: row; height: 100%; padding: 0 calc(50% - var(--spw) / 2); gap: 28px; align-items: center; margin: 0; }
.v-scroll.horiz .v-spage { scroll-snap-align: center; transition: transform .35s ease, opacity .35s ease; cursor: pointer; }
.v-scroll.horiz .v-spage.off { transform: scale(.88); opacity: .45; }
.tone-light .v-spage { box-shadow: 0 18px 40px -18px rgba(60, 40, 10, .45); }

/* ตัวอย่างเคลื่อนไหวในสตูดิโอ */
.fx-curl i:last-child { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); animation: fxCurl 2s ease-in-out infinite; }
@keyframes fxCurl { 0%, 25% { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); } 60% { clip-path: polygon(0 0, 100% 0, 100% 35%, 35% 100%, 0 100%); } 100% { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); } }
.fx-zoom i { left: 19px !important; animation: fxZoom 1.8s ease-in-out infinite; }
.fx-zoom i:first-child { animation-delay: -.9s; }
@keyframes fxZoom { 0% { transform: scale(.6); opacity: 0; } 30%, 55% { transform: scale(1); opacity: 1; } 85%, 100% { transform: scale(1.5); opacity: 0; } }
.fx-cards i { left: 19px !important; }
.fx-cards i:first-child { transform: translate(3px, 3px); background: #cfc6b4; }
.fx-cards i:last-child { animation: fxCards 1.8s ease-in-out infinite; }
@keyframes fxCards { 0%, 35% { transform: none; opacity: 1; } 75% { transform: translateX(-40px) rotate(-14deg); opacity: 0; } 100% { opacity: 0; } }
.fx-cube { perspective: 80px; }
.fx-cube i { left: 19px !important; animation: fxCube 1.8s ease-in-out infinite; backface-visibility: hidden; }
.fx-cube i:first-child { animation-delay: -.9s; background: #fff; }
@keyframes fxCube { 0% { transform: rotateY(90deg) translateX(10px); } 30%, 55% { transform: none; } 85%, 100% { transform: rotateY(-90deg) translateX(-10px); } }
.fx-carousel i { width: 16px; height: 22px; top: 10px; animation: fxCar 2s ease-in-out infinite; }
.fx-carousel i:first-child { left: 2px; opacity: .5; }
.fx-carousel i:last-child { left: 21px; }
@keyframes fxCar { 0%, 30% { transform: translateX(0); } 60%, 100% { transform: translateX(-19px); } }
.st-flips { grid-template-columns: 1fr; }
.st-flip-tag { position: absolute; top: 8px; right: 10px; font-size: .64rem; font-weight: 700; color: #2b1d03; background: var(--accent); padding: 1px 7px; border-radius: 6px; }
.st-trybtn { margin-top: 18px; }
.st-flips + .st-sub { margin-top: 16px; }

/* ----- พับมุมกระดาษสมจริง ----- */
.cv-root { position: absolute; z-index: 6; pointer-events: none; transform-origin: 50% 50%; }
.cv-ushade, .cv-front, .cv-bhold { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.cv-ushade { z-index: 1; }
.cv-front { z-index: 2; will-change: clip-path; }
.cv-bhold { z-index: 3; }
.cv-back { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform-origin: 0 0; will-change: transform, clip-path; }
.cv-face { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #fff; overflow: hidden; }
.cv-face.paper { background: linear-gradient(90deg, #f1ece2, #fffdf8 35%, #faf7f1); }
.cv-flapshade { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
.cv-face.spine-l::after, .cv-face.spine-r::after { content: ""; position: absolute; top: 0; bottom: 0; width: 46px; z-index: 3; pointer-events: none; }
.cv-face.spine-l::after { left: 0; background: linear-gradient(270deg, transparent, rgba(0, 0, 0, .06) 55%, rgba(0, 0, 0, .22)); }
.cv-face.spine-r::after { right: 0; background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .06) 55%, rgba(0, 0, 0, .2)); }
.style-curl .v-book { cursor: default; }
.style-curl .v-page { cursor: pointer; }
.v-book.curling .v-page::before { display: none !important; }
