:root {
  color-scheme: dark;
  --paper-bg: #f5f2e9;
  --paper-pattern: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, rgba(240,235,223,0.8) 100%);
  --ink-primary: #1c1815;
  --ink-secondary: #575046;
  --ink-muted: #8c8275;
  --accent-gold: #c69c59;
  --accent-gold-dark: #9e7534;
  --accent-bg: rgba(198, 156, 89, 0.12);
  --book-w: min(88vw, 1160px);
  --page-ratio: 0.72;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(circle at 50% 20%, rgba(198, 156, 89, 0.16), transparent 42rem),
    radial-gradient(circle at 80% 80%, rgba(35, 29, 23, 0.6), transparent 30rem),
    linear-gradient(145deg, #1d1915, #0f0d0b 80%);
  color: #f5f1ea;
  overflow-x: hidden;
}

button, input {
  font: inherit;
  color: inherit;
}

/* App Shell Layout */
.app-shell {
  width: min(1600px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px clamp(12px, 2.5vw, 36px) 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

/* Topbar Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 12px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-gold);
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  font-weight: 700;
  font-family: 'Cinzel', serif;
}

h1 {
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.4rem, 2.8vw, 2.2rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #fff;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar button, .nav {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toolbar button:hover, .nav:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(198, 156, 89, 0.5);
}

.toolbar button:active, .nav:active {
  transform: scale(0.96);
}

.btn-icon-text {
  padding: 7px 14px;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
}

.btn-outline {
  padding: 7px 14px;
  font-size: 0.82rem;
  border-radius: 20px;
}

.zoom-group {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 2px 6px;
}

.zoom-group button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  box-shadow: none;
  font-size: 1.1rem;
  border-radius: 50%;
}

#zoomLabel {
  min-width: 44px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

/* Stage & 3D Book Container */
.viewer {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 50px;
  align-items: center;
}

.stage {
  min-height: 580px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: pan-y;
  padding: 10px 0;
}

.book-shadow {
  position: absolute;
  width: min(1100px, 90vw);
  height: 14%;
  bottom: 4%;
  background: rgba(0, 0, 0, 0.8);
  filter: blur(32px);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.book-container {
  position: relative;
  z-index: 5;
  transform: scale(var(--zoom, 1));
  transition: transform 0.25s ease-out;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#book {
  position: relative;
  margin: 0 auto;
}

/* Hide raw page elements before StPageFlip wraps them */
#book > .page {
  display: none;
}

/* StPageFlip Engine Containers */
.stf__parent {
  position: relative;
  display: block;
  margin: 0 auto;
}

.stf__wrapper {
  position: relative;
  overflow: hidden;
  margin: 0 auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.65);
  border-radius: 4px;
}

.stf__block {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.stf__item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--paper-bg);
}

.stf__item .page {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
  background-color: var(--paper-bg);
  background-image: var(--paper-pattern);
}

.page-content {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Hardcover Pages */
.page-cover {
  background-color: #1a1410;
  box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

.cover-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0f0b08;
  position: relative;
}

.cover-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Artwork Page (Right side) */
.art-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  padding: 16px;
  position: relative;
  cursor: zoom-in;
  background-color: var(--paper-bg);
  background-image: var(--paper-pattern);
}

.page-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: contrast(1.03) brightness(0.98);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  border-radius: 2px;
  background: transparent;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.3s ease;
}

.art-page:hover .page-image {
  transform: scale(1.02);
}

.art-zoom-badge {
  position: absolute;
  bottom: 16px;
  right: 18px;
  background: rgba(28, 24, 21, 0.78);
  color: var(--accent-gold);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  backdrop-filter: blur(4px);
  opacity: 0.85;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.art-page:hover .art-zoom-badge {
  opacity: 1;
}

/* Informational Blurb Page (Left side) */
.blurb-page {
  padding: clamp(18px, 3.2vw, 34px) clamp(20px, 3.6vw, 38px);
  color: var(--ink-primary);
  background:
    radial-gradient(circle at 10% 10%, rgba(198, 156, 89, 0.06), transparent 15rem),
    linear-gradient(180deg, rgba(255,255,255,0.6), rgba(243,238,226,0.92));
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}

.blurb-header {
  border-bottom: 2px solid var(--accent-gold);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.blurb-plate-no {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent-gold-dark);
  text-transform: uppercase;
  margin: 0 0 3px;
}

.blurb-title {
  margin: 0 0 3px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.3rem, 2.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink-primary);
}

.blurb-subtitle {
  margin: 0;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-secondary);
  font-family: 'Cormorant Garamond', Georgia, serif;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 10px;
  margin-bottom: 12px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.035);
  border-radius: 6px;
  border-left: 3px solid var(--accent-gold);
}

.meta-item {
  display: flex;
  flex-direction: column;
}

.meta-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  font-weight: 600;
}

.meta-value {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--ink-primary);
}

.blurb-description {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(0.9rem, 1.3vw, 1.05rem);
  line-height: 1.5;
  color: var(--ink-primary);
  margin: 0 0 12px;
}

.blurb-description::first-letter {
  font-size: 2.1em;
  float: left;
  line-height: 0.8;
  padding-right: 5px;
  padding-top: 3px;
  color: var(--accent-gold-dark);
  font-weight: 700;
}

.blurb-highlights {
  margin: 0 0 12px;
}

.highlights-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent-gold-dark);
  margin: 0 0 5px;
}

.blurb-highlights ul {
  margin: 0;
  padding-left: 16px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink-secondary);
}

.blurb-highlights li {
  margin-bottom: 3px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}

.tag-chip {
  background: var(--accent-bg);
  color: var(--accent-gold-dark);
  border: 1px solid rgba(198, 156, 89, 0.3);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.66rem;
  font-weight: 500;
}

.blurb-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed rgba(0, 0, 0, 0.12);
}

.action-btn {
  background: #fff;
  border: 1px solid rgba(198, 156, 89, 0.4);
  color: var(--ink-primary);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.action-btn:hover {
  background: var(--accent-gold);
  color: #fff;
  border-color: var(--accent-gold-dark);
}

.action-btn.speaking {
  background: var(--accent-gold);
  color: #fff;
  animation: pulseAudio 1.5s infinite;
}

@keyframes pulseAudio {
  0% { box-shadow: 0 0 0 0 rgba(198, 156, 89, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(198, 156, 89, 0); }
  100% { box-shadow: 0 0 0 0 rgba(198, 156, 89, 0); }
}

/* Inside Cover & Index Page Layout */
.inside-cover-page {
  padding: clamp(20px, 3.5vw, 38px);
  color: var(--ink-primary);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}

.bookplate {
  border: 2px double var(--accent-gold);
  padding: 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.65);
  margin-bottom: 12px;
  border-radius: 4px;
}

.bookplate h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  margin: 0 0 3px;
  color: var(--accent-gold-dark);
  letter-spacing: 0.1em;
}

.bookplate p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9rem;
  margin: 0;
  color: var(--ink-secondary);
  font-style: italic;
}

.inside-intro {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink-primary);
  margin-bottom: 12px;
}

.mini-toc h3 {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  color: var(--accent-gold-dark);
  margin: 0 0 6px;
  text-transform: uppercase;
}

.mini-toc-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toc-item-btn {
  background: transparent;
  border: none;
  text-align: left;
  padding: 3px 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.88rem;
  color: var(--ink-primary);
  border-bottom: 1px dotted rgba(0,0,0,0.15);
  transition: color 0.2s;
}

.toc-item-btn:hover {
  color: var(--accent-gold-dark);
  font-weight: 600;
}

.provenance-note {
  font-size: 0.66rem;
  color: var(--ink-muted);
  text-align: center;
  margin-top: auto;
  font-style: italic;
}

/* Epilogue Page Layout */
.epilogue-page {
  padding: clamp(22px, 3.5vw, 40px);
  color: var(--ink-primary);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  height: 100%;
}

.epilogue-page h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.15rem;
  color: var(--accent-gold-dark);
  margin: 0 0 6px;
  letter-spacing: 0.15em;
}

.epilogue-page p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.98rem;
  line-height: 1.55;
  max-width: 88%;
  margin: 0 auto 14px;
}

/* Navigation Buttons */
.nav {
  width: 44px;
  height: 72px;
  border-radius: 999px;
  font-size: 2rem;
  line-height: 1;
  z-index: 20;
}

.nav:disabled {
  opacity: 0.25;
  cursor: default;
  border-color: transparent;
}

/* Footer & Scrubber Controls */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ink-muted);
  font-size: 0.82rem;
}

.status-box {
  min-width: 170px;
  color: #f5f1ea;
  font-weight: 500;
  font-size: 0.88rem;
}

.scrubber-container {
  flex: 1;
  max-width: 600px;
}

#pageSlider {
  width: 100%;
  accent-color: var(--accent-gold);
  cursor: pointer;
}

.hint {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.45);
}

/* Dialog Modals */
dialog {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 100vw;
  max-height: 100vh;
}

dialog::backdrop {
  background: rgba(10, 8, 7, 0.82);
  backdrop-filter: blur(8px);
}

.toc-dialog .dialog-content {
  background: #1c1815;
  border: 1px solid rgba(198, 156, 89, 0.4);
  border-radius: 12px;
  width: min(520px, 90vw);
  padding: 24px;
  color: #f5f1ea;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.dialog-header h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.2rem;
  margin: 0;
  color: var(--accent-gold);
}

.close-btn, .lightbox-close {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.close-btn:hover, .lightbox-close:hover {
  background: rgba(198, 156, 89, 0.6);
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toc-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
}

.toc-card:hover {
  background: rgba(198, 156, 89, 0.15);
  border-color: var(--accent-gold);
}

.toc-card-info h4 {
  margin: 0 0 2px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
  color: #fff;
}

.toc-card-info p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--accent-gold);
}

/* Lightbox Modal */
.lightbox-dialog .lightbox-content {
  position: relative;
  width: min(1100px, 94vw);
  max-height: 92vh;
  background: #141210;
  border: 1px solid rgba(198, 156, 89, 0.3);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 50;
}

.lightbox-body {
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  overflow: hidden;
}

.lightbox-img-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #090807;
  overflow: auto;
  max-height: 78vh;
}

.lightbox-img-wrapper img {
  max-width: 100%;
  max-height: 74vh;
  object-fit: contain;
  box-shadow: 0 8px 30px rgba(0,0,0,0.8);
}

.lightbox-info {
  padding: 16px 24px;
  background: #1c1815;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.lightbox-info h3 {
  margin: 0 0 4px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.3rem;
  color: var(--accent-gold);
}

.lightbox-caption {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

/* Responsive Breakpoints */
@media (max-width: 820px) {
  .app-shell {
    padding: 10px 8px;
  }
  .eyebrow {
    font-size: 0.6rem;
  }
  h1 {
    font-size: 1.25rem;
  }
  .toolbar .btn-icon-text span.lbl {
    display: none;
  }
  .viewer {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
  }
  .nav {
    width: 32px;
    height: 56px;
    font-size: 1.5rem;
  }
  .stage {
    min-height: 60vh;
  }
  .hint {
    display: none;
  }
}
