:root {
  --bg: #eef1ec;
  --panel: rgba(255,255,255,0.75);
  --panel-strong: rgba(255,255,255,0.92);
  --text: #263238;
  --muted: #66717a;
  --line: rgba(71, 102, 109, 0.18);
  --accent: #5f7f77;
  --accent-2: #7f9e96;
  --cta: #547b73;
  --shadow: 0 18px 45px rgba(38, 50, 56, 0.12);
  --radius: 22px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: radial-gradient(circle at top, #f7faf7 0%, var(--bg) 60%, #e7ece7 100%); }
button, input, a { font: inherit; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: rgba(255,255,255,0.5);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar.compact .thumbnail-list { display: none; }
.sidebar-header h2, .topbar h1 { margin: 4px 0 0; font-size: 1.25rem; }
.brand, .topbar-label, .eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  color: var(--muted);
}
.collapse-btn, .ghost-btn, .secondary-btn {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.66);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
}
.primary-btn {
  background: linear-gradient(180deg, #6e9189, var(--cta));
  color: white;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  box-shadow: 0 10px 26px rgba(84,123,115,0.22);
}
.primary-btn.small { padding: 10px 16px; }
.section-nav {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.section-nav button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.82);
  border-radius: 12px;
  padding: 9px 10px;
  text-align: left;
  font-size: 0.9rem;
}
.thumbnail-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}
.thumb {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.78);
  border-radius: 16px;
  padding: 8px;
}
.thumb img {
  width: 58px;
  aspect-ratio: 11 / 17;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.thumb p { margin: 0; font-size: 0.88rem; line-height: 1.25; }
.thumb span { display: block; color: var(--muted); font-size: 0.76rem; margin-bottom: 4px; }
.thumb.active { border-color: rgba(84,123,115,0.45); box-shadow: inset 0 0 0 1px rgba(84,123,115,0.15); }

.main-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 20px clamp(16px, 3vw, 32px);
  gap: 14px;
}
.topbar, .book-tools, .bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.book-tools {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px 12px;
  backdrop-filter: blur(8px);
}
.page-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
#pageJumpInput {
  width: 70px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  padding: 10px;
}
.book-stage-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 6px 0;
}
.book-stage {
  --gap: 18px;
  position: relative;
  width: min(1120px, 100%);
  max-width: 100%;
  aspect-ratio: 22 / 17;
  max-height: 76vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  align-items: stretch;
}
.page-shell {
  position: relative;
  perspective: 1800px;
  min-width: 0;
  min-height: 0;
  height: 100%;
}
.page-card {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background: #f8faf8;
  box-shadow: var(--shadow);
  border: 1px solid rgba(84,123,115,0.15);
  overflow: hidden;
  transform-origin: center center;
  will-change: transform, opacity;
}
.left-page .page-card { transform-origin: right center; }
.right-page .page-card { transform-origin: left center; }
.page-card img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f4f4f1;
}
.page-card .page-meta {
  position: absolute;
  left: 14px;
  bottom: 14px;
  background: rgba(255,255,255,0.88);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
}
.page-card.enter-right { animation: enterRight 420ms cubic-bezier(.2,.7,.2,1); }
.page-card.enter-left { animation: enterLeft 420ms cubic-bezier(.2,.7,.2,1); }
.page-card.exit-left { animation: exitLeft 420ms cubic-bezier(.2,.7,.2,1); }
.page-card.exit-right { animation: exitRight 420ms cubic-bezier(.2,.7,.2,1); }

@keyframes enterRight { from { opacity: 0; transform: rotateY(-24deg) translateX(28px) scale(0.985); filter: saturate(.95); } to { opacity: 1; transform: rotateY(0) translateX(0) scale(1); filter: saturate(1); } }
@keyframes enterLeft { from { opacity: 0; transform: rotateY(24deg) translateX(-28px) scale(0.985); filter: saturate(.95); } to { opacity: 1; transform: rotateY(0) translateX(0) scale(1); filter: saturate(1); } }
@keyframes exitLeft { from { opacity: 1; transform: rotateY(0) translateX(0) scale(1); } to { opacity: 0; transform: rotateY(-30deg) translateX(-38px) scale(0.985); } }
@keyframes exitRight { from { opacity: 1; transform: rotateY(0) translateX(0) scale(1); } to { opacity: 0; transform: rotateY(30deg) translateX(38px) scale(0.985); } }

.page-hotspot {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8%;
  background: transparent;
  border: none;
}
.hotspot-left { left: 0; }
.hotspot-right { right: 0; }
.legend, .mobile-hint { color: var(--muted); font-size: 0.9rem; }
.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
}



.book-stage.cover-mode {
  width: min(560px, 100%);
  aspect-ratio: 11 / 17;
  grid-template-columns: 1fr;
}
.book-stage.cover-mode .left-page,
.book-stage.cover-mode .hotspot-left {
  display: none;
}
.book-stage.cover-mode .right-page {
  display: block;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--line); max-height: 38vh; }
  .main-panel { order: 1; }
}

@media (max-width: 780px) {
  .topbar, .book-tools, .bottom-bar { flex-direction: column; align-items: stretch; }
  .book-stage {
    grid-template-columns: 1fr;
    width: min(560px, 100%);
    aspect-ratio: 11 / 17;
    max-height: 70vh;
  }
  .left-page { display: none; }
  .right-page { display: block; }
  .page-hotspot { width: 18%; }
  .intro-card { grid-template-columns: 1fr; }
}


.app-shell.no-sidebar {
  display: block;
}

.app-shell.no-sidebar .main-panel {
  max-width: 1280px;
  margin: 0 auto;
}


/* no-thumbnails TOC layout */
.sidebar { justify-content: flex-start; }
.section-nav button { width: 100%; }

.section-nav button.active {
  border-color: rgba(84,123,115,0.5);
  background: rgba(255,255,255,0.98);
  box-shadow: inset 0 0 0 1px rgba(84,123,115,0.12);
}


/* Touch improvements */
.book-stage {
  touch-action: pan-y pinch-zoom;
  overscroll-behavior: contain;
}

@media (max-width: 780px) {
  .page-card.enter-right { animation: mobileSlideInRight 260ms ease-out; }
  .page-card.enter-left { animation: mobileSlideInLeft 260ms ease-out; }
  .page-shell { perspective: none; }
  .page-card { border-radius: 18px; }
  .page-hotspot { width: 12%; }
}

@keyframes mobileSlideInRight {
  from { opacity: .65; transform: translateX(24px) scale(.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes mobileSlideInLeft {
  from { opacity: .65; transform: translateX(-24px) scale(.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
