/* Livebook Scroll Reader — Warm Parchment Aesthetic */
@import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@700;900&family=EB+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=Inter:wght@400;500;600;700&family=Literata:ital,opsz,wght@0,7..72,400;0,7..72,600;1,7..72,400&family=Lora:ital,wght@0,400;0,500;0,600;1,400;1,500&family=MedievalSharp&family=Pirata+One&family=UnifrakturCook:wght@700&family=UnifrakturMaguntia&display=swap');

/* Bookerly Typeface */
@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly'),
       url('../fonts/Bookerly-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Italic'),
       url('../fonts/Bookerly-RegularItalic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Bold'),
       url('../fonts/Bookerly-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Bookerly';
  src: local('Bookerly Bold Italic'),
       url('../fonts/Bookerly-BoldItalic.ttf') format('truetype');
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg-primary: #F7F1E7;
  --bg-surface: rgba(247, 241, 231, 0.95);
  --border-color: rgba(0, 0, 0, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --accent-cyan: #0284c7;
  --accent-blue: #2563eb;
  --accent-glow: rgba(2, 132, 199, 0.15);
  --btn-bg: #f0eae1;
  --btn-hover: #e8dfd3;
  --btn-disabled: rgba(240, 234, 225, 0.6);
  --header-height: 56px;
  --crossfade-duration: 1.2s;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== HEADER ===== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
}

/* ===== BOOK SELECTOR DROPDOWN ===== */
.book-selector {
  position: relative;
}

.book-selector-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.book-selector-btn:hover {
  background: none;
}

.book-selector-chevron {
  color: #0f172a;
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

.book-selector.open .book-selector-chevron {
  transform: rotate(180deg);
}

.book-selector-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 320px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);
  list-style: none;
  padding: 6px;
  z-index: 200;
  opacity: 0;
  transform: translateX(-50%) translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.book-selector.open .book-selector-dropdown {
  display: block;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.book-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: default;
  transition: background 0.15s ease;
}

.book-option.active {
  background: rgba(0, 0, 0, 0.06);
}

.book-option.active .book-option-title {
  color: #0f172a;
  font-weight: 400;
}

.book-option.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.book-option-title {
  font-family: 'Pirata One', 'UnifrakturMaguntia', Georgia, serif;
  font-size: 16px;
  font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap;
}

.book-option-author {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  margin-left: auto;
}

.book-option-badge {
  font-family: 'Inter', sans-serif;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(135deg, #94a3b8, #64748b);
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== SCROLL READER ===== */
.scroll-reader {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin-top: var(--header-height);
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(120, 111, 101, 0.3) transparent;
}

.scroll-reader::-webkit-scrollbar {
  width: 6px;
}

.scroll-reader::-webkit-scrollbar-track {
  background: transparent;
}

.scroll-reader::-webkit-scrollbar-thumb {
  background: rgba(120, 111, 101, 0.25);
  border-radius: 10px;
}

.scroll-reader::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 111, 101, 0.45);
}

/* ===== READER LAYOUT: sticky left + scrolling right ===== */
.reader-layout {
  display: flex;
  flex-direction: row;
  justify-content: center;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 clamp(24px, 4vw, 64px);
  gap: clamp(32px, 5vw, 72px);
}

/* ===== STICKY CANVAS COLUMN ===== */
.sticky-canvas-col {
  flex-shrink: 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: calc(100vh - var(--header-height));
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Container for the crossfade — two canvases stacked absolutely */
.crossfade-container {
  position: relative;
  /* Constrain by height only; let aspect-ratio compute the width */
  height: clamp(400px, 65vh, 780px);
  aspect-ratio: 9 / 16;
  max-width: min(42vw, 440px);
}

.crossfade-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  border: none;
  outline: none;
  border-radius: 2px;
  /* Cinematic crossfade transition */
  transition: opacity var(--crossfade-duration) cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity;
}

/* Layer A is the "back" canvas, Layer B on top */
.crossfade-container .canvas-layer-a {
  z-index: 1;
  opacity: 1;
}

.crossfade-container .canvas-layer-b {
  z-index: 2;
  opacity: 0;
}

/* Active state: whichever layer is active gets opacity 1 */
.crossfade-container .canvas-layer-a.active {
  opacity: 1;
}

.crossfade-container .canvas-layer-a:not(.active) {
  opacity: 0;
}

.crossfade-container .canvas-layer-b.active {
  opacity: 1;
}

.crossfade-container .canvas-layer-b:not(.active) {
  opacity: 0;
}

/* ===== TEXT COLUMN (scrolls naturally) ===== */
.text-scroll-col {
  flex: 1;
  min-width: 280px;
  max-width: 620px;
  padding: 48px 0 120px;
}

/* ===== SCENE TEXT BLOCK ===== */
.scene-text-block {
  padding-bottom: 24px;
  position: relative;
}

/* ===== BOOKMARK ICON (single, sticky, outside text column) ===== */
.text-scroll-col {
  position: relative;
}

.bookmark-indicator {
  position: sticky;
  top: calc(var(--header-height) + 16px);
  float: right;
  margin-right: -40px;
  width: 24px;
  height: 24px;
  color: #1e293b;
  cursor: pointer;
  z-index: 10;
  transition: transform 0.15s ease;
}

.bookmark-indicator:hover {
  transform: scale(1.15);
}

/* Amber-gold pulse on scene crossing */
@keyframes bookmark-pulse {
  0%   { color: #1e293b; }
  30%  { color: #f59e0b; }
  60%  { color: #d97706; }
  100% { color: #1e293b; }
}

.bookmark-indicator.pulse {
  animation: bookmark-pulse 1.2s ease-in-out;
}


.scene-text-body {
  font-family: 'Bookerly', 'Literata', 'EB Garamond', Georgia, serif;
  font-size: clamp(15.5px, 1.2vw, 17.5px);
  line-height: 1.78;
  color: #2c2522;
}

.scene-text-body p {
  margin-bottom: 18px;
  text-align: justify;
  text-justify: inter-word;
}

.scene-text-body p:last-child {
  margin-bottom: 0;
}


/* ===== SCENE SENTINEL (placeholder before materialization) ===== */
.scene-sentinel {
  min-height: 600px;
  width: 100%;
}

/* Legacy scene-block (kept for compatibility during transition) */
.scene-block {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(32px, 5vw, 72px);
  max-width: 1400px;
  margin: 0 auto;
  padding: 48px clamp(24px, 4vw, 64px);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .reader-layout {
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 0;
  }

  .sticky-canvas-col {
    position: sticky;
    top: 0;
    height: auto;
    width: 100%;
    z-index: 10;
    background: var(--bg-primary);
    padding: 12px 0;
  }

  .crossfade-container {
    height: 40vh;
    max-width: 70vw;
    margin: 0 auto;
  }

  .text-scroll-col {
    max-width: 100%;
    min-width: auto;
    padding: 16px 20px 80px;
  }

  .scene-text-block {
    min-height: 40vh;
    padding: 16px 0;
  }
}

/* ===== HEADER BUTTONS ===== */
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.nav-btn:hover:not(:disabled) {
  background: var(--btn-hover);
  border-color: rgba(0, 0, 0, 0.16);
  transform: translateY(-1px);
}

.nav-btn:active:not(:disabled) {
  transform: translateY(0);
}

.nav-btn.active {
  background: rgba(2, 132, 199, 0.1);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ===== LOADING / HIDDEN STATES ===== */
.loading-overlay,
.spinner,
.loading-text {
  display: none !important;
}
