/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: auto; }
body { font-family: 'Inter', system-ui, sans-serif; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
img { display: block; max-width: 100%; }

/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --primary:     #0F4D4C;
  --primary-fg:  #ffffff;
  --accent:      #E9BC32;
  --accent-fg:   #1a1a00;
  --bg:          #e8f0ef;
  --card:        #ffffff;
  --border:      #cdd8d4;
  --fg:          #111c1c;
  --muted-fg:    #5c7a78;
  --sidebar-bg:  #0d3d3c;
  --sidebar-fg:  #d6eceb;
  --top-bar-h:   60px;
  --back-bar-h:  34px;
  --controls-h:  72px;
  --progress-h:  3px;
  --sidebar-w:   280px;
}
html.dark {
  --bg:          #111c1c;
  --card:        #1a2828;
  --border:      #2a3e3e;
  --fg:          #e8f0ef;
  --muted-fg:    #7aadab;
}

/* ─── App shell ─────────────────────────────────────────────── */
.flipbook-app {
  position: fixed; inset: 0;
  background: var(--bg);
  color: var(--fg);
  transition: background 0.3s, color 0.3s;
  overflow: auto;
}

/* ─── Top bar ───────────────────────────────────────────────── */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--top-bar-h);
  background: var(--primary);
  color: var(--primary-fg);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.top-bar-left  { display: flex; align-items: center; gap: 10px; }
.top-bar-right { display: flex; align-items: center; gap: 4px; }
.top-bar-title {
  font-family: 'Playfair Display', serif;
  font-size: 0.9rem; font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--primary-fg);
}
.menu-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary-fg);
  transition: background 0.15s;
}
.menu-btn:hover { background: rgba(255,255,255,0.15); }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.85);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* ─── Back bar ──────────────────────────────────────────────── */
.back-bar {
  position: fixed;
  top: var(--top-bar-h); left: 0; right: 0;
  height: var(--back-bar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 12px;
  z-index: 98;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.back-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
}
.back-btn:hover { background: var(--bg); color: var(--primary); }
.back-bar-right {
  margin-left: auto;
  display: flex; align-items: center; gap: 2px;
}
.back-bar-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px;
  color: var(--primary);
  background: none; border: none; cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
}
.back-bar-icon-btn:hover { background: var(--bg); }
.zoom-level-label {
  font-size: 0.72rem; font-weight: 700; color: var(--fg-muted, var(--primary));
  min-width: 34px; text-align: center; user-select: none;
}
.back-bar-fs-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.78rem; font-weight: 600;
  color: var(--primary);
  background: none; border: none; cursor: pointer;
  padding: 4px 10px;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.back-bar-fs-btn:hover { background: var(--bg); }
@media (max-width: 480px) { #fs-label { display: none; } }

/* ─── Audio panel minimized ─────────────────────────────────── */
.audio-panel.minimized .audio-list { display: none; }
.audio-panel.minimized { max-height: none; }
#audio-panel-minimize svg { transition: transform 0.2s; }
.audio-panel.minimized #audio-panel-minimize svg { transform: rotate(180deg); }

/* ─── Progress bar ──────────────────────────────────────────── */
.progress-track {
  position: fixed; top: calc(var(--top-bar-h) + var(--back-bar-h)); left: 0; right: 0;
  height: var(--progress-h);
  background: rgba(15,77,76,0.18);
  z-index: 99;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s ease;
}

/* ─── Sidebar ───────────────────────────────────────────────── */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 149;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.sidebar-overlay.active { opacity: 1; pointer-events: all; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  z-index: 150;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.32s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 4px 0 24px rgba(0,0,0,0.35);
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem; font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}
.sidebar-search {
  width: 100%; padding: 7px 11px;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-fg); font-size: 0.82rem;
  outline: none; font-family: inherit;
}
.sidebar-search::placeholder { color: rgba(255,255,255,0.35); }
.sidebar-search:focus { border-color: var(--accent); }

.toc-list { overflow-y: auto; flex: 1; padding: 8px 0; }
.toc-list::-webkit-scrollbar { width: 4px; }
.toc-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.toc-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
  font-size: 0.8rem;
}
.toc-item:hover { background: rgba(255,255,255,0.07); }
.toc-item.active {
  background: rgba(233,188,50,0.12);
  border-left-color: var(--accent);
  color: var(--accent);
}
.toc-item-name { font-weight: 500; }
.toc-item-pages { font-size: 0.74rem; opacity: 0.55; }

/* ─── Main area ─────────────────────────────────────────────── */
.main-area {
  position: fixed;
  top: calc(var(--top-bar-h) + var(--back-bar-h) + var(--progress-h));
  bottom: var(--controls-h);
  left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: center;
  overflow: auto;
  padding-top: 40px;
}

.flipbook-wrapper {
  /* Natural size for 100% zoom — JS overrides min-h/min-w when zoomed */
  width: 100%;
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  padding-top: 0; /* top padding comes from main-area */
}

/* ─── Book outer — zoom scale target ────────────────────────── */
#book-outer {
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transform-style: preserve-3d;
  /* Scale is applied here by JS (applyZoom). transform-origin set inline. */
  /* flex-shrink:0 prevents the flex parent from squashing it before JS runs */
  flex-shrink: 0;
  margin-top: 40px; /* visual breathing room at 100% zoom */
}

.book-container {
  position: relative;
  z-index: 1;
  border-radius: 8px;
  overflow: visible;
  perspective: 2800px;
  /* No transform here — zoom lives on #book-outer to keep clientWidth/Height accurate */
  box-shadow:
    0 20px 60px rgba(0,0,0,0.32),
    0 6px 16px rgba(0,0,0,0.22),
    inset 0 0 0 0.5px rgba(255,255,255,0.08);
}
/* ─── Book thickness edges ──────────────────────────────────── */
/* Left spine — dark binding/cover wrap */
.book-container::before {
  content: '';
  position: absolute;
  top: 3px;
  left: -11px;
  width: 11px;
  height: calc(100% - 6px);
  background: linear-gradient(to right, #1a0e06 0%, #3d2512 35%, #5c3820 65%, #4a2c18 100%);
  border-radius: 4px 0 0 4px;
  box-shadow: -3px 2px 10px rgba(0,0,0,0.35);
  z-index: 0;
  pointer-events: none;
}

/* Right edge — stacked unread pages */
#book-outer::after {
  content: '';
  position: absolute;
  top: 3px;
  right: -14px;
  width: 14px;
  height: calc(100% - 6px);
  background: repeating-linear-gradient(
    0deg,
    #f5f0e8 0px, #f5f0e8 2px,
    #c8c3b8 2px, #c8c3b8 3px
  );
  border-radius: 0 4px 4px 0;
  box-shadow: 3px 2px 10px rgba(0,0,0,0.18), inset -2px 0 5px rgba(0,0,0,0.10);
  z-index: 0;
  pointer-events: none;
}

/* Bottom edge — page block bottom */
#book-outer::before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: -8px;
  right: -12px;
  height: 11px;
  background: linear-gradient(to bottom, #c8bfa8 0%, #a8a090 55%, #908878 100%);
  border-radius: 0 0 5px 4px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.22);
  z-index: 0;
  pointer-events: none;
}



/* ─── Corner curl hint ──────────────────────────────────────── */
.page-right::after {
  content: '';
  position: absolute;
  bottom: 0; right: 0;
  width: 30px; height: 30px;
  background: linear-gradient(225deg, #cdc8bc 0%, #eae4d8 45%, transparent 51%);
  pointer-events: none;
  transition: width 0.2s ease, height 0.2s ease;
}
.page-right:hover::after { width: 46px; height: 46px; }
.floor-shadow {
  position: absolute;
  bottom: -10px;
  left: 50%; transform: translateX(-50%);
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.28) 0%, transparent 72%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Static spread (desktop) ───────────────────────────────── */
.static-spread {
  position: absolute; inset: 0;
  display: flex; align-items: stretch;
  border-radius: 8px; overflow: hidden;
}
.page-left, .page-right {
  flex: 1; position: relative;
  overflow: hidden;
  background: #f5f0e8;
}
.page-left {
  box-shadow: inset -10px 0 20px rgba(0,0,0,0.08);
  border-radius: 8px 0 0 8px;
}
.page-right {
  box-shadow: inset 10px 0 20px rgba(0,0,0,0.05);
  border-radius: 0 8px 8px 0;
}
.book-spine {
  width: 7px; flex-shrink: 0;
  background: linear-gradient(to right, #b0b0b0 0%, #f0f0f0 45%, #b8b8b8 100%);
  box-shadow: 0 0 10px rgba(0,0,0,0.16);
}

/* ─── Static single page (mobile) ──────────────────────────── */
.static-single {
  position: absolute; inset: 0;
  border-radius: 10px; overflow: hidden;
  background: #f5f0e8;
}

/* ─── Page image & label ────────────────────────────────────── */
.page-img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.page-num {
  position: absolute; bottom: 6px;
  left: 50%; transform: translateX(-50%);
  font-size: 0.68rem; color: rgba(0,0,0,0.4);
  pointer-events: none; user-select: none;
  font-family: 'Inter', sans-serif;
}

/* ─── Page navigation arrows ────────────────────────────────── */
.page-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.88);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  transition: background 0.15s, transform 0.15s, opacity 0.2s;
  z-index: 20;
  opacity: 0;
}
.page-arrow:hover { background: #fff; transform: translateY(-50%) scale(1.08); }
#book-outer:hover .page-arrow { opacity: 1; }
.page-arrow.disabled { opacity: 0 !important; pointer-events: none; }
.page-arrow-left  { left: -52px; }
.page-arrow-right { right: -52px; }

/* ─── Controls bar ──────────────────────────────────────────── */
.controls-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--controls-h);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 0 12px;
  z-index: 100;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.08);
}
.controls-divider { width: 1px; height: 28px; background: var(--border); margin: 0 4px; }

.control-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.85rem; font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.ghost-btn {
  color: var(--muted-fg);
  background: transparent;
}
.ghost-btn:hover { background: var(--bg); color: var(--fg); }

.primary-btn {
  background: var(--primary); color: var(--primary-fg);
}
.primary-btn:hover { opacity: 0.88; }
.primary-btn:disabled { opacity: 0.35; pointer-events: none; }

.accent-btn { background: var(--accent); color: var(--accent-fg); }
.accent-btn:hover { opacity: 0.88; }
.accent-btn.playing { background: #c0392b; color: #fff; }

.page-counter {
  display: flex; align-items: center;
}
.page-form { display: flex; align-items: center; gap: 5px; }
.page-input {
  width: 48px; text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 4px;
  font-size: 0.85rem; font-weight: 600;
  color: var(--fg); background: var(--card);
  outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.page-input:focus { border-color: var(--primary); }
.page-total { font-size: 0.8rem; color: var(--muted-fg); }

/* ─── Autoplay badge ────────────────────────────────────────── */
.autoplay-badge {
  position: fixed; top: calc(var(--top-bar-h) + var(--back-bar-h) + 10px); right: 10px;
  background: var(--accent); color: var(--accent-fg);
  padding: 4px 10px; border-radius: 20px;
  font-size: 0.73rem; font-weight: 700;
  z-index: 110;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}

/* ─── Settings panel ────────────────────────────────────────── */
.settings-panel {
  position: fixed; top: calc(var(--top-bar-h) + var(--back-bar-h) + var(--progress-h) + 8px); right: 10px;
  width: 300px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px 16px;
  z-index: 110;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  animation: panel-in 0.2s ease;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.settings-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 700; font-size: 0.9rem; color: var(--fg);
}
.settings-close-btn {
  width: 26px; height: 26px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted-fg);
  transition: background 0.15s;
}
.settings-close-btn:hover { background: var(--bg); color: var(--fg); }
.settings-section-label {
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted-fg); margin-bottom: 8px;
}
.settings-divider { height: 1px; background: var(--border); margin: 12px 0 8px; }

.effect-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.effect-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.effect-card:hover { background: var(--bg); }
.effect-card.active { border-color: var(--primary); background: rgba(15,77,76,0.06); }
html.dark .effect-card.active { background: rgba(15,77,76,0.2); }
.effect-card-icon { font-size: 1.2rem; margin-bottom: 3px; }
.effect-card-name {
  font-size: 0.78rem; font-weight: 700;
  color: var(--fg);
}
.effect-card.active .effect-card-name { color: var(--primary); }
.effect-card-dur { font-size: 0.68rem; color: var(--muted-fg); }

.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0;
}
.settings-row-label {
  font-size: 0.8rem; font-weight: 500;
  color: var(--fg);
  display: flex; align-items: center;
}
.toggle-btn {
  position: relative;
  width: 38px; height: 22px;
  border-radius: 11px;
  background: var(--border);
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-btn::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.toggle-btn.on { background: var(--primary); }
.toggle-btn.on::after { transform: translateX(16px); }

.current-effect-info {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
}
.current-effect-name { font-size: 0.82rem; font-weight: 600; color: var(--fg); }
.current-effect-desc { font-size: 0.75rem; color: var(--muted-fg); }

/* ─── Zoom overlay ──────────────────────────────────────────── */
.zoom-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 200;
  display: flex !important; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.zoom-overlay[style*="display:none"] { display: none !important; }
.zoom-overlay img {
  max-width: 90vw; max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.zoom-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.zoom-close:hover { background: rgba(255,255,255,0.28); }

/* ─── Flip animations ───────────────────────────────────────── */
.flip-leaf {
  position: absolute;
  top: 0; bottom: 0;
  z-index: 10;
  pointer-events: none;
}
.flip-leaf.is-3d {
  transform-style: preserve-3d;
}

/* 3D face */
.flip-face {
  position: absolute; inset: 0;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-face-back {
  transform: rotateY(180deg);
}

/* Keyframes for 3D flip */
@keyframes flip-next-3d {
  0%   { transform: rotateY(0deg); }
  35%  { transform: rotateY(-90deg); animation-timing-function: cubic-bezier(0.0,0.0,0.2,1); }
  100% { transform: rotateY(-180deg); }
}
@keyframes flip-prev-3d {
  0%   { transform: rotateY(0deg); }
  35%  { transform: rotateY(90deg); animation-timing-function: cubic-bezier(0.0,0.0,0.2,1); }
  100% { transform: rotateY(180deg); }
}
/* Slide keyframes */
@keyframes slide-out-left {
  from { transform: translateX(0); }
  to   { transform: translateX(-100%); }
}
@keyframes slide-out-right {
  from { transform: translateX(0); }
  to   { transform: translateX(100%); }
}

/* Fade keyframe */
@keyframes fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* Curl shadow on flip-front */
@keyframes curl-shadow-next {
  0%   { opacity: 0; }
  40%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Receiving shadow */
@keyframes recv-shadow {
  0%   { opacity: 0; }
  30%  { opacity: 1; }
  100% { opacity: 0; }
}
.recv-shadow {
  position: absolute; top: 0; bottom: 0;
  pointer-events: none; z-index: 9;
  animation: recv-shadow var(--flip-dur, 700ms) ease-in-out forwards;
}

/* Paper back texture */
.paper-back {
  background: linear-gradient(120deg, #f0ece4 0%, #faf8f4 50%, #ede9e0 100%);
}
.paper-lines {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    transparent, transparent 28px,
    rgba(0,0,0,0.025) 28px, rgba(0,0,0,0.025) 29px
  );
}
.gloss-back { background: linear-gradient(135deg, #ffffff 0%, #f2f6fa 100%); }
/* ─── Audio panel ───────────────────────────────────────────── */
.audio-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-height: 52%;
  background: var(--card);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 28px rgba(0,0,0,0.18);
  display: flex; flex-direction: column;
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
.audio-panel.open { transform: translateY(0); }

.audio-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.audio-panel-title {
  font-size: 0.88rem; font-weight: 700;
  color: var(--fg);
  display: flex; align-items: center;
}

.audio-list {
  overflow-y: auto; flex: 1;
  padding: 6px 0 8px;
}
.audio-list::-webkit-scrollbar { width: 4px; }
.audio-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.audio-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.14s;
}
.audio-item:last-child { border-bottom: none; }
.audio-item:hover { background: var(--bg); }
.audio-item.playing { background: rgba(15,77,76,0.07); }
.audio-item-icon {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.audio-item.playing .audio-item-icon { background: var(--accent); color: var(--accent-fg); }
.audio-item-name {
  font-size: 0.84rem; font-weight: 500;
  color: var(--fg);
}

.audio-page-label {
  padding: 7px 16px 5px;
  font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--primary);
  background: rgba(15,77,76,0.05);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
html.dark .audio-page-label { background: rgba(15,77,76,0.15); }

.audio-empty {
  padding: 20px 16px;
  font-size: 0.82rem; color: var(--muted-fg);
  text-align: center;
}
/* ─── Tablet (single page) ──────────────────────────────────── */
@media (min-width: 641px) and (max-width: 1024px) {
  :root {
    --top-bar-h:   60px;
    --back-bar-h:  34px;
    --controls-h:  72px;
  }
  .page-arrow-left  { left: -48px; }
  .page-arrow-right { right: -48px; }
  .btn-label { display: inline; }
  .settings-panel { right: 10px; width: 300px; }
}

/* ─── Mobile (single page) ──────────────────────────────────── */
@media (max-width: 640px) {
  :root {
    --top-bar-h:   56px;
    --back-bar-h:  30px;
    --controls-h:  68px;
  }
  .top-bar-title { font-size: 0.95rem; }
  .page-arrow-left  { left: -44px; }
  .page-arrow-right { right: -44px; }
  .btn-label { display: none; }
  .control-btn { padding: 8px 10px; }
  .settings-panel { right: 6px; left: 6px; width: auto; }
  /* Compact edges on mobile */
  .book-container::before { width: 7px; left: -7px; }
  #book-outer::after { width: 9px; right: -9px; }
  #book-outer::before { display: none; }
}

/* ─── Desktop (two page spread) ────────────────────────────── */
@media (min-width: 1025px) {
  /* Default desktop styles remain in place */
}

/* ─── Scrollbar (webkit) ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }