/* ==========================================================================
   Magic of the Mind - Minimalist Book & Reader Stylesheet
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Color Palette - Light Mode */
  --bg-primary-light: #fbfbfa;
  --bg-surface-light: #ffffff;
  --bg-subtle-light: #f4f4f0;
  --text-primary-light: #1c1c1e;
  --text-secondary-light: #59595f;
  --text-muted-light: #8e8e93;
  --border-subtle-light: #e6e6e2;
  --accent-light: #8a5836;
  --accent-hover-light: #6e4326;
  --accent-subtle-light: #f6ede6;
  --card-shadow-light: 0 4px 20px rgba(0, 0, 0, 0.05);

  /* Color Palette - Dark Mode */
  --bg-primary-dark: #121316;
  --bg-surface-dark: #1a1b1f;
  --bg-subtle-dark: #23242a;
  --text-primary-dark: #e8e8ea;
  --text-secondary-dark: #a0a0a8;
  --text-muted-dark: #6e6e76;
  --border-subtle-dark: #2c2d35;
  --accent-dark: #e2a77a;
  --accent-hover-dark: #f0be95;
  --accent-subtle-dark: #2c221a;
  --card-shadow-dark: 0 4px 24px rgba(0, 0, 0, 0.35);

  /* Active Theme Defaults (Fallbacks) */
  --bg-primary: var(--bg-primary-light);
  --bg-surface: var(--bg-surface-light);
  --bg-subtle: var(--bg-subtle-light);
  --text-primary: var(--text-primary-light);
  --text-secondary: var(--text-secondary-light);
  --text-muted: var(--text-muted-light);
  --border-subtle: var(--border-subtle-light);
  --accent: var(--accent-light);
  --accent-hover: var(--accent-hover-light);
  --accent-subtle: var(--accent-subtle-light);
  --card-shadow: var(--card-shadow-light);

  /* Typography */
  --font-serif: "Charter", "Iowan Old Style", "Palatino Linotype", Palatino, "Merriweather", "Georgia", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, Consolas, "Liberation Mono", monospace;

  /* Layout */
  --reading-max-width: 68ch;
  --container-max-width: 860px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: var(--bg-primary-dark);
    --bg-surface: var(--bg-surface-dark);
    --bg-subtle: var(--bg-subtle-dark);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --text-muted: var(--text-muted-dark);
    --border-subtle: var(--border-subtle-dark);
    --accent: var(--accent-dark);
    --accent-hover: var(--accent-hover-dark);
    --accent-subtle: var(--accent-subtle-dark);
    --card-shadow: var(--card-shadow-dark);
  }
}

:root[data-theme="dark"] {
  --bg-primary: var(--bg-primary-dark);
  --bg-surface: var(--bg-surface-dark);
  --bg-subtle: var(--bg-subtle-dark);
  --text-primary: var(--text-primary-dark);
  --text-secondary: var(--text-secondary-dark);
  --text-muted: var(--text-muted-dark);
  --border-subtle: var(--border-subtle-dark);
  --accent: var(--accent-dark);
  --accent-hover: var(--accent-hover-dark);
  --accent-subtle: var(--accent-subtle-dark);
  --card-shadow: var(--card-shadow-dark);
}

:root[data-theme="light"] {
  --bg-primary: var(--bg-primary-light);
  --bg-surface: var(--bg-surface-light);
  --bg-subtle: var(--bg-subtle-light);
  --text-primary: var(--text-primary-light);
  --text-secondary: var(--text-secondary-light);
  --text-muted: var(--text-muted-light);
  --border-subtle: var(--border-subtle-light);
  --accent: var(--accent-light);
  --accent-hover: var(--accent-hover-light);
  --accent-subtle: var(--accent-subtle-light);
  --card-shadow: var(--card-shadow-light);
}

/* Base Resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.25s ease, color 0.25s ease;
}

body {
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Reading Progress Bar */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background-color: var(--accent);
  z-index: 1000;
  transition: width 0.1s linear;
}

/* Navigation Header */
.site-header {
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 500;
  transition: border-color 0.25s ease;
}

.header-container {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: opacity 0.2s;
}

.brand-link:hover {
  opacity: 0.8;
}

.brand-badge {
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Theme Switcher Button */
.theme-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.sun-icon {
  display: none;
}

.moon-icon {
  display: block;
}

:root[data-theme="dark"] .sun-icon {
  display: block;
}

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sun-icon {
    display: block;
  }
  :root:not([data-theme="light"]) .moon-icon {
    display: none;
  }
}

/* Main Container */
.main-content {
  flex: 1;
  max-width: var(--container-max-width);
  width: 100%;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* ==========================================================================
   Book Presentation Page
   ========================================================================== */

.book-hero {
  margin-bottom: 3.5rem;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.book-meta-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--accent-subtle);
  color: var(--accent);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent);
}

.book-genre {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

.book-title {
  font-family: var(--font-serif);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.book-tagline {
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  max-width: 44ch;
}

.book-cta-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--accent);
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.8rem 1.6rem;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.book-stats {
  display: flex;
  gap: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Book Details Grid */
.book-details-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
}

@media (min-width: 768px) {
  .book-details-grid {
    grid-template-columns: 1.6fr 1.2fr;
  }
}

.section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
}

.synopsis-body p {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}

.concept-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
  margin-bottom: 1.5rem;
}

.concept-card h4 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.concept-card p {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* Chapter List / Table of Contents */
.toc-section {
  margin-top: 3.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border-subtle);
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 1.5rem;
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-radius: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  color: inherit;
  transition: all 0.2s ease;
}

.chapter-item.available {
  border-color: color-mix(in srgb, var(--accent) 30%, var(--border-subtle));
}

.chapter-item.available:hover {
  border-color: var(--accent);
  transform: translateX(4px);
  box-shadow: var(--card-shadow);
}

.chapter-item.locked {
  opacity: 0.6;
  cursor: default;
  background: transparent;
}

.chapter-left {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.chapter-num {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.chapter-item.locked .chapter-num {
  color: var(--text-muted);
}

.chapter-title-text {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.chapter-badge {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chapter-badge-muted {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Chapter Reader Page
   ========================================================================== */

.reader-container {
  max-width: var(--reading-max-width);
  margin: 0 auto;
  padding: 2rem 0;
}

.reader-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--accent);
}

.reader-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.chapter-header {
  margin-bottom: 3.5rem;
  text-align: center;
}

.chapter-kicker {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.6rem;
}

.chapter-heading {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 1rem;
}

.chapter-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-family: var(--font-serif);
  font-style: italic;
}

/* Reader Typography */
.prose-body {
  font-family: var(--font-serif);
  font-size: 1.22rem;
  line-height: 1.8;
  color: var(--text-primary);
  letter-spacing: 0.005em;
}

.prose-body p {
  margin-bottom: 1.45em;
  text-rendering: optimizeLegibility;
}

/* Elegant chapter opening styling */
.prose-body > p:first-of-type {
  font-size: 1.28rem;
  line-height: 1.82;
}

/* Scene breaks */
.scene-divider {
  display: block;
  text-align: center;
  margin: 3rem 0;
  color: var(--text-muted);
  letter-spacing: 0.75em;
  font-size: 0.9rem;
  user-select: none;
}

/* Chapter Footer Navigation */
.chapter-footer {
  margin-top: 4.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border-subtle);
}

.chapter-footer-cta {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  box-shadow: var(--card-shadow);
  margin-bottom: 2rem;
}

.chapter-footer-cta h3 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.chapter-footer-cta p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.footer-nav-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: var(--border-subtle);
}

/* Site Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  padding: 2rem 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  html {
    font-size: 16.5px;
  }
  .book-title {
    font-size: 2.25rem;
  }
  .chapter-heading {
    font-size: 2rem;
  }
  .main-content {
    padding: 1.5rem 1rem 3.5rem;
  }
  .chapter-footer-cta {
    padding: 1.5rem 1rem;
  }
}
