/* ══════════════════════════════════════════════════════════════════
   MinedFruitOS — Living Book Chapter System
   7-modality full-screen page-turn navigator
   ══════════════════════════════════════════════════════════════════ */

/* ── OUTER SECTION ── */
.book-chapters-section {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 560px;
  max-height: 900px;
  overflow: hidden;
  background: #080606;
  scroll-margin-top: 54px; /* match body padding-top */
}

@media (max-width: 500px) {
  .book-chapters-section { scroll-margin-top: 66px; }
}

/* ── CHAPTER BOOK TRACK ── */
.chapter-book {
  display: flex;
  width: 700%; /* 7 pages × 100% */
  height: 100%;
  transition: transform 0.88s cubic-bezier(0.77, 0, 0.18, 1);
  will-change: transform;
  touch-action: pan-y; /* allow vertical scroll, capture horizontal */
}

/* During page turn transition — adds perspective curl */
.chapter-book.turning {
  transition: transform 0.88s cubic-bezier(0.77, 0, 0.18, 1);
}

/* ── INDIVIDUAL CHAPTER PAGE ── */
.chapter-page {
  position: relative;
  width: calc(100% / 7);
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
}

/* ── BACKDROP SYSTEM ── */
.chapter-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.chapter-backdrop-color {
  position: absolute;
  inset: 0;
  transition: opacity 1.2s ease;
}

.chapter-backdrop-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transition: opacity 1.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  mix-blend-mode: luminosity;
  filter: brightness(0.35) contrast(1.1);
}
.chapter-backdrop-img.loaded {
  opacity: 1;
}

.chapter-backdrop-vignette {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(8,6,6,0.35) 0%, rgba(8,6,6,0) 20%, rgba(8,6,6,0) 45%, rgba(8,6,6,0.75) 75%, rgba(8,6,6,0.97) 100%),
    linear-gradient(to right, rgba(8,6,6,0.6) 0%, rgba(8,6,6,0) 40%, rgba(8,6,6,0) 60%, rgba(8,6,6,0.6) 100%);
}

/* ── GRAIN LAYER ── */
.chapter-grain {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='0.028'/%3E%3C/svg%3E");
  opacity: 0.6;
}

/* ── CHAPTER CONTENT ── */
.chapter-content {
  position: relative;
  z-index: 3;
  padding: 40px 48px 56px;
  max-width: 720px;
  width: 100%;
}

@media (max-width: 768px) {
  .chapter-content {
    padding: 32px 24px 48px;
    max-width: 100%;
  }
}

/* ── ROMAN NUMERAL ── */
.chapter-roman {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(3.5rem, 8vw, 7rem);
  font-weight: 300;
  font-style: italic;
  color: rgba(196, 30, 58, 0.18);
  line-height: 0.9;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
  display: block;
  transition: color 0.4s;
}

.chapter-page:hover .chapter-roman {
  color: rgba(196, 30, 58, 0.28);
}

/* ── CHAPTER LABEL (modality name) ── */
.chapter-label {
  font-size: 0.62rem;
  letter-spacing: 0.38em;
  text-transform: uppercase;
  color: var(--crimson, #c41e3a);
  font-weight: 500;
  margin-bottom: 24px;
  display: block;
}

/* ── CHAPTER HOOK (headline) ── */
.chapter-hook {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: clamp(1.9rem, 4.5vw, 3.6rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--text, #f0ece4);
  margin-bottom: 20px;
  text-shadow: 0 2px 30px rgba(0,0,0,0.6);
}

@media (max-width: 480px) {
  .chapter-hook { font-size: clamp(1.6rem, 6vw, 2.2rem); }
}

/* ── CHAPTER SUBTEXT ── */
.chapter-sub {
  font-size: clamp(0.84rem, 1.8vw, 1rem);
  color: rgba(240, 236, 228, 0.65);
  max-width: 480px;
  line-height: 1.75;
  font-weight: 300;
  margin-bottom: 36px;
}

@media (max-width: 480px) {
  .chapter-sub { display: none; } /* hide on very small screens to keep CTA visible */
}

/* ── CHAPTER CTA ── */
.chapter-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(196, 30, 58, 0.12);
  border: 1px solid rgba(196, 30, 58, 0.45);
  color: var(--text, #f0ece4);
  text-decoration: none;
  padding: 14px 32px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  transition: background 0.25s, border-color 0.25s, transform 0.2s;
  cursor: pointer;
}

.chapter-cta:hover {
  background: rgba(196, 30, 58, 0.22);
  border-color: rgba(196, 30, 58, 0.75);
  transform: translateX(3px);
}

/* ── DURATION TAG ── */
.chapter-duration {
  margin-top: 14px;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(240, 236, 228, 0.3);
  font-weight: 300;
}

/* ── PAGE NUMBER (top-right corner) ── */
.chapter-page-number {
  position: absolute;
  top: 24px;
  right: 28px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: rgba(240, 236, 228, 0.2);
  z-index: 4;
  writing-mode: horizontal-tb;
}

@media (max-width: 768px) {
  .chapter-page-number { top: 16px; right: 16px; font-size: 0.62rem; }
}

/* ── PAGE TURN EFFECT (corner peel) ── */
.chapter-page::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 0; height: 0;
  border-style: solid;
  border-width: 0;
  border-color: transparent transparent rgba(255,255,255,0.05) transparent;
  transition: border-width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  pointer-events: none;
  z-index: 10;
}

.chapter-page.active::after {
  border-width: 0 0 60px 60px;
}

/* ── SPINE FLASH during transition ── */
.chapter-book.page-turning::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 2px;
  background: linear-gradient(to bottom, transparent 0%, rgba(201, 168, 76, 0.4) 30%, rgba(201, 168, 76, 0.6) 50%, rgba(201, 168, 76, 0.4) 70%, transparent 100%);
  transform: translateX(-50%);
  z-index: 100;
  animation: spineFlash 0.5s ease forwards;
  pointer-events: none;
}

@keyframes spineFlash {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  80%  { opacity: 0.6; }
  100% { opacity: 0; }
}

/* ── SHADOW on current page edge ── */
.chapter-page.active {
  box-shadow:
    inset -40px 0 60px rgba(0,0,0,0.4),
    inset 40px 0 60px rgba(0,0,0,0.2);
}

/* ── NAV ARROWS ── */
.chapter-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(8, 6, 6, 0.72);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(196, 30, 58, 0.25);
  color: rgba(240, 236, 228, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, opacity 0.3s, transform 0.15s;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.chapter-nav-btn:hover {
  background: rgba(20, 10, 12, 0.88);
  border-color: rgba(196, 30, 58, 0.55);
  color: rgba(240, 236, 228, 0.9);
  transform: translateY(-50%) scale(1.05);
}

.chapter-nav-btn:active {
  transform: translateY(-50%) scale(0.95);
}

.chapter-nav-btn:disabled {
  opacity: 0.2;
  pointer-events: none;
}

.chapter-nav-prev { left: 20px; }
.chapter-nav-next { right: 20px; }

@media (max-width: 640px) {
  .chapter-nav-prev { left: 12px; width: 40px; height: 40px; }
  .chapter-nav-next { right: 12px; width: 40px; height: 40px; }
}

/* ── CHAPTER DOTS ── */
.chapter-dots {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 20;
  padding: 8px 16px;
  background: rgba(8,6,6,0.5);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.05);
}

.chapter-dot {
  width: 24px; height: 2px;
  background: rgba(240, 236, 228, 0.2);
  border: none;
  cursor: pointer;
  transition: background 0.3s, transform 0.3s, width 0.3s;
  padding: 0;
  position: relative;
}

.chapter-dot::after {
  content: '';
  position: absolute;
  inset: -6px;
}

.chapter-dot.active {
  background: rgba(196, 30, 58, 0.85);
  width: 40px;
}

.chapter-dot:hover:not(.active) {
  background: rgba(240, 236, 228, 0.4);
}

/* ── SWIPE HINT (mobile, fades out) ── */
.chapter-swipe-hint {
  position: absolute;
  bottom: 58px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(240, 236, 228, 0.3);
  z-index: 20;
  pointer-events: none;
  transition: opacity 0.6s ease;
  animation: swipeHintPulse 3s ease-in-out infinite;
}

@keyframes swipeHintPulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 0.85; }
}

.chapter-swipe-hint.hidden {
  opacity: 0 !important;
  animation: none;
}

/* Desktop: hide swipe hint */
@media (min-width: 641px) {
  .chapter-swipe-hint { display: none; }
}

/* ── CHAPTER ENTRY ANIMATION ── */
.chapter-page .chapter-content .chapter-roman,
.chapter-page .chapter-content .chapter-label,
.chapter-page .chapter-content .chapter-hook,
.chapter-page .chapter-content .chapter-sub,
.chapter-page .chapter-content .chapter-cta,
.chapter-page .chapter-content .chapter-duration {
  opacity: 0;
  transform: translateY(16px);
  filter: blur(4px);
  transition:
    opacity 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    transform 0.75s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    filter 0.75s ease;
}

.chapter-page.active .chapter-content .chapter-roman { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.05s; }
.chapter-page.active .chapter-content .chapter-label  { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.12s; }
.chapter-page.active .chapter-content .chapter-hook   { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.22s; }
.chapter-page.active .chapter-content .chapter-sub    { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.36s; }
.chapter-page.active .chapter-content .chapter-cta    { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.5s; }
.chapter-page.active .chapter-content .chapter-duration { opacity: 1; transform: translateY(0); filter: blur(0); transition-delay: 0.62s; }

/* ── BOOK OPENING HEADER ── */
.book-opening-header {
  padding: 0;
  background: #080606;
}

.book-opening-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 28px 48px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 640px) {
  .book-opening-inner { padding: 22px 24px; }
}

.book-opening-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(196, 30, 58, 0.2) 40%, rgba(201, 168, 76, 0.15) 60%, transparent);
}

.book-opening-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 0.68rem;
  font-style: italic;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(240, 236, 228, 0.25);
  white-space: nowrap;
  font-weight: 300;
}

/* ── ACCESSIBILITY: reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .chapter-book { transition: transform 0.15s linear; }
  .chapter-page .chapter-content > * { opacity: 1 !important; transform: none !important; filter: none !important; transition: none !important; }
  .chapter-backdrop-img { transition: opacity 0.3s ease; }
  .chapter-swipe-hint { animation: none; }
  .chapter-dot { transition: background 0.15s, width 0.15s; }
  @keyframes spineFlash { 0%, 100% { opacity: 0; } 50% { opacity: 0.8; } }
}
