/**
 * Vaerfel Idle - Living Storybook Styles
 * 
 * A CSS-first approach to creating an immersive "living storybook" experience.
 * Mobile-first, dark mode support, scroll-driven animations.
 * 
 * @version 1.0.0
 */

/* ═══════════════════════════════════════════════════════════════════════════
   THEME VARIABLES - Light Mode (Default)
   "Candlelit Parchment" - warm, inviting, like reading by firelight
   ═══════════════════════════════════════════════════════════════════════════ */

:root,
[data-theme="light"] {
  /* Backgrounds */
  --vfi-bg-primary: #f4e8d0;      /* Parchment */
  --vfi-bg-secondary: #ebe0c8;    /* Darker parchment */
  --vfi-bg-tertiary: #1a1a1a;     /* Dark panels (like game UI) */
  --vfi-bg-elevated: #faf3e3;     /* Elevated surfaces */
  
  /* Text */
  --vfi-text-primary: #2c2416;    /* Book ink */
  --vfi-text-secondary: #3d2e1a;  /* Book ink rich brown */
  --vfi-text-muted: #5c4a32;      /* Muted text - warm brown */
  
  /* Accents */
  --vfi-accent: #d4a574;          /* Book accent / gold */
  --vfi-accent-hover: #c49464;    /* Accent hover state */
  --vfi-binding: #8b4513;         /* Book binding / leather */
  --vfi-binding-dark: #6b3510;    /* Darker binding */
  
  /* Effects */
  --vfi-glow: rgba(212, 165, 116, 0.3);
  --vfi-glow-strong: rgba(212, 165, 116, 0.5);
  --vfi-shadow: rgba(0, 0, 0, 0.2);
  --vfi-shadow-strong: rgba(0, 0, 0, 0.4);
  
  /* Particles */
  --vfi-particle-opacity: 0.4;
}

/* ═══════════════════════════════════════════════════════════════════════════
   THEME VARIABLES - Dark Mode
   "Midnight Tome" - mysterious, magical, gothic undertones
   ═══════════════════════════════════════════════════════════════════════════ */

[data-theme="dark"] {
  /* Backgrounds */
  --vfi-bg-primary: #0e0e0e;      /* Deep black */
  --vfi-bg-secondary: #1a1a1a;    /* Panel dark */
  --vfi-bg-tertiary: #252525;     /* Elevated surfaces */
  --vfi-bg-elevated: #2a2a2a;     /* Cards/modals */
  
  /* Text */
  --vfi-text-primary: #f4e8d0;    /* Inverted parchment */
  --vfi-text-secondary: #c4b8a0;  /* Muted parchment */
  --vfi-text-muted: #8b8070;      /* Very muted */
  
  /* Accents */
  --vfi-accent: #d4a574;          /* Same warm accent */
  --vfi-accent-hover: #e4b584;    /* Lighter on dark */
  --vfi-binding: #a0522d;         /* Lighter binding for visibility */
  --vfi-binding-dark: #8b4513;    /* Standard binding */
  
  /* Effects */
  --vfi-glow: rgba(212, 165, 116, 0.4);
  --vfi-glow-strong: rgba(212, 165, 116, 0.6);
  --vfi-shadow: rgba(0, 0, 0, 0.4);
  --vfi-shadow-strong: rgba(0, 0, 0, 0.6);
  
  /* Particles - more visible on dark */
  --vfi-particle-opacity: 0.5;
}


/* ═══════════════════════════════════════════════════════════════════════════
   BOOK STRUCTURE - Mobile First
   ═══════════════════════════════════════════════════════════════════════════ */

.book-wrapper {
  min-height: 100vh;
  background: var(--vfi-bg-primary);
  color: var(--vfi-text-primary);
  position: relative;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Dark mode background override */
[data-theme="dark"] .book-wrapper {
  background: #0a0a0a;
}

/* The Eternal Scroll Stage */
.scroll-stage {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80vw; /* 80% of viewport width */
  max-width: none;
  height: 98vh;
  background-image: url('../assets/VerticalBackground2x.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
}

/* Book spine - removed */
.book-spine {
  display: none;
}

/* Fixed Title on Scroll Header */
.scroll-title {
  position: fixed;
  top: 6.5vh; /* Position in scroll header area */
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Alagard', serif;
  font-size: clamp(1.8rem, 4vw, 3.5rem);
  color: #2c2416;
  z-index: 1;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,0.1);
  letter-spacing: 1px;
}

/* Spine texture overlay */
.book-spine::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 20px,
    rgba(0,0,0,0.1) 20px,
    rgba(0,0,0,0.1) 21px
  );
}

.book-content {
  padding: 1rem;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
}

/* Particles container */
#vfi-particles {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}


/* ═══════════════════════════════════════════════════════════════════════════
   SCROLL REVEAL ANIMATIONS (The Eternal Scroll)
   ═══════════════════════════════════════════════════════════════════════════ */

.chapter-section {
  min-height: 100vh; /* Full viewport height for each "page" */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0; /* Hidden by default */
  transform: translateY(20px);
  transition: opacity 0.8s ease, transform 0.8s ease;
  position: relative;
  z-index: 1; /* Above the scroll stage */
  padding: 2rem;
}

/* Active state - triggered by JS when in view */
.chapter-section.active {
  opacity: 1;
  transform: translateY(0);
}

/* Legacy support for existing classes if needed, mapping to new behavior */
.chapter-section.animate-reveal {
  /* Handled by base class now */
}

.chapter-section.animate-reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Fade in variant */
.chapter-section[data-reveal="fade-in"] {
  transform: none;
}

/* Slide from left */
.chapter-section[data-reveal="slide-left"] {
  transform: translateX(-30px);
}

.chapter-section[data-reveal="slide-left"].revealed {
  transform: translateX(0);
}

/* Slide from right */
.chapter-section[data-reveal="slide-right"] {
  transform: translateX(30px);
}

.chapter-section[data-reveal="slide-right"].revealed {
  transform: translateX(0);
}


/* ═══════════════════════════════════════════════════════════════════════════
   CHAPTER HEADERS
   ═══════════════════════════════════════════════════════════════════════════ */

.chapter-header {
  text-align: center;
  padding: 2rem 1rem;
  margin: 0 0 2rem;
  position: relative;
}

.chapter-number {
  font-size: 0.7rem;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--vfi-text-secondary);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.chapter-divider {
  width: 60%;
  max-width: 300px;
  height: 2px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    var(--vfi-accent) 20%, 
    var(--vfi-accent) 80%, 
    transparent 100%
  );
  margin: 0.5rem auto;
}

.chapter-title {
  font-family: 'Alagard', serif;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  color: var(--vfi-text-primary);
  margin: 0.5rem 0;
  animation: breathe 4s ease-in-out infinite;
}

.chapter-subtitle {
  font-size: 1rem;
  color: var(--vfi-text-secondary);
  font-style: italic;
  margin-top: 0.5rem;
}

/* Fleuron ornament removed */
.chapter-header::after {
  display: none;
}

/* Breathing animation */
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   ILLUMINATED DROP CAPS
   ═══════════════════════════════════════════════════════════════════════════ */

.chapter-section > p:first-of-type::first-letter,
.illuminated-first::first-letter {
  font-family: 'Alagard', serif;
  font-size: 4.5rem;
  float: left;
  line-height: 0.75;
  margin-right: 0.75rem;
  margin-top: 0.1rem;
  color: var(--vfi-binding);
  text-shadow: 
    2px 2px 0 var(--vfi-accent),
    -1px -1px 0 rgba(0,0,0,0.2);
  animation: dropCapGlow 4s ease-in-out infinite;
}

@keyframes dropCapGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.1); }
}

/* Dark mode drop cap adjustments */
[data-theme="dark"] .chapter-section > p:first-of-type::first-letter,
[data-theme="dark"] .illuminated-first::first-letter {
  color: var(--vfi-accent);
  text-shadow: 
    2px 2px 0 var(--vfi-binding),
    0 0 20px var(--vfi-glow);
}

/* Magical text glow effect */
.magical-text {
  animation: inkGlow 3s ease-in-out infinite;
}

@keyframes inkGlow {
  0%, 100% { text-shadow: 0 0 0 transparent; }
  50% { text-shadow: 0 0 8px var(--vfi-glow); }
}


/* ═══════════════════════════════════════════════════════════════════════════
   PIXEL ORNAMENTS - Pure CSS 8-bit Style
   ═══════════════════════════════════════════════════════════════════════════ */

/* Pixel Sword Divider */
.pixel-divider-sword {
  height: 16px;
  width: 100%;
  max-width: 200px;
  margin: 1.5rem auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pixel-divider-sword::before {
  content: '';
  width: 120px;
  height: 4px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--vfi-accent) 10%,
    #c0c0c0 30%,
    #e0e0e0 50%,
    #c0c0c0 70%,
    var(--vfi-accent) 90%,
    transparent 100%
  );
}

.pixel-divider-sword::after {
  content: '⚔';
  position: absolute;
  font-size: 1rem;
  color: var(--vfi-accent);
}

/* Pixel Scroll Divider */
.pixel-divider-scroll {
  height: 24px;
  width: 100%;
  max-width: 120px;
  margin: 1rem auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.pixel-divider-scroll::before,
.pixel-divider-scroll::after {
  content: '';
  width: 16px;
  height: 20px;
  background: var(--vfi-accent);
  border-radius: 3px;
  box-shadow: inset -3px -3px 0 var(--vfi-binding);
}

.pixel-divider-scroll span {
  display: block;
  width: 60px;
  height: 6px;
  background: var(--vfi-binding);
  border-radius: 2px;
}

/* Pixel Corner Ornaments */
.pixel-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--vfi-accent);
  clip-path: polygon(
    0 0, 100% 0, 100% 25%, 75% 25%, 75% 50%, 50% 50%, 50% 75%, 25% 75%, 25% 100%, 0 100%
  );
}

.pixel-corner.top-left { top: -2px; left: -2px; }
.pixel-corner.top-right { top: -2px; right: -2px; transform: scaleX(-1); }
.pixel-corner.bottom-left { bottom: -2px; left: -2px; transform: scaleY(-1); }
.pixel-corner.bottom-right { bottom: -2px; right: -2px; transform: scale(-1); }

/* Pixel Star / Sparkle */
.pixel-star {
  width: 12px;
  height: 12px;
  background: var(--vfi-accent);
  clip-path: polygon(
    50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%
  );
  display: inline-block;
}

.pixel-star.twinkle {
  animation: pixelTwinkle 2s ease-in-out infinite;
}

@keyframes pixelTwinkle {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

/* Pixel Diamond (rarity indicator style) */
.pixel-diamond {
  width: 10px;
  height: 10px;
  background: var(--vfi-accent);
  transform: rotate(45deg);
  display: inline-block;
  margin: 0 6px;
}

/* Chapter ornament wrapper */
.chapter-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.chapter-ornament::before,
.chapter-ornament::after {
  content: '';
  width: 40px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--vfi-accent), transparent);
}


/* ═══════════════════════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON
   ═══════════════════════════════════════════════════════════════════════════ */

.vfi-theme-toggle {
  background: var(--vfi-bg-tertiary);
  border: 2px solid var(--vfi-accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.vfi-theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 0 12px var(--vfi-glow);
}

.vfi-theme-toggle:focus {
  outline: 2px solid var(--vfi-accent);
  outline-offset: 2px;
}

[data-theme="dark"] .vfi-theme-toggle {
  background: var(--vfi-bg-elevated);
}

/* Theme toggle icons - show moon in light mode, sun in dark mode */
.theme-icon-light,
.theme-icon-dark {
  line-height: 1;
}

.theme-icon-dark {
  display: none;
}

[data-theme="dark"] .theme-icon-light {
  display: none;
}

[data-theme="dark"] .theme-icon-dark {
  display: inline;
}


/* ═══════════════════════════════════════════════════════════════════════════
   STORYBOOK CARDS (Feature cards, etc.)
   ═══════════════════════════════════════════════════════════════════════════ */

.storybook-card {
  background: var(--vfi-bg-elevated);
  border: 3px solid var(--vfi-accent);
  border-radius: 8px;
  padding: 1.25rem;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.storybook-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px var(--vfi-shadow-strong);
}

/* Add pixel corners to cards */
.storybook-card.with-corners {
  overflow: visible;
}

.storybook-card.with-corners::before,
.storybook-card.with-corners::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--vfi-accent);
}

.storybook-card.with-corners::before {
  top: -3px;
  left: -3px;
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.storybook-card.with-corners::after {
  bottom: -3px;
  right: -3px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE - Tablet (768px+)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 768px) {
  .book-spine {
    width: 20px;
  }
  
  .book-content {
    padding: 2rem;
    padding-left: 2.5rem;
  }
  
  .chapter-section {
    padding: 3rem 0;
  }
  
  .chapter-header {
    padding: 3rem 2rem;
  }
  
  .chapter-title {
    font-size: clamp(2rem, 4vw, 3rem);
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE - Desktop (1024px+)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 1024px) {
  .book-wrapper {
    /* Full screen immersion for Eternal Scroll */
    max-width: 100%;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    min-height: 100vh;
  }
  
  .book-spine {
    display: none;
  }
  
  .book-content {
    padding: 3rem;
    /* Centered content max-width if needed, but wrapper stays full */
    max-width: 100%; 
    margin: 0 auto;
  }
  
  /* Remove desktop shadow for depth */
  .book-wrapper::before {
    display: none;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   ACCESSIBILITY - Reduced Motion
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .chapter-section {
    opacity: 1;
    transform: none;
    transition: none;
  }
  
  .chapter-title,
  .chapter-header::after,
  .magical-text,
  .pixel-star.twinkle,
  .chapter-section > p:first-of-type::first-letter,
  .illuminated-first::first-letter {
    animation: none;
  }
  
  .storybook-card:hover {
    transform: none;
  }
  
  /* Disable particles via CSS (JS should also check) */
  #vfi-particles {
    display: none;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════ */

.text-center { text-align: center; }
.text-accent { color: var(--vfi-accent); }
.text-muted { color: var(--vfi-text-muted); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
