:root {
  --bg: #060816;
  --bg-alt: rgba(12, 18, 40, 0.82);
  --panel: rgba(14, 20, 44, 0.72);
  --panel-strong: rgba(18, 25, 54, 0.9);
  --line: rgba(145, 179, 255, 0.22);
  --text: #eef3ff;
  --muted: #a9b5d6;
  --gold: #f2cb78;
  --cyan: #78f0ff;
  --violet: #8f7cff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

body.theme-dawn {
  --bg: #f5f3ff;
  --bg-alt: rgba(255, 255, 255, 0.82);
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(98, 76, 180, 0.18);
  --text: #1c2140;
  --muted: #54607f;
  --gold: #bc7b15;
  --cyan: #0d8da6;
  --violet: #6f55f6;
  --shadow: 0 24px 80px rgba(80, 61, 164, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: radial-gradient(circle at top, rgba(116, 89, 255, 0.18), transparent 30%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

body.story-page {
  background: linear-gradient(180deg, rgba(10, 14, 30, 0.96), rgba(6, 8, 22, 1));
}

body.story-page .stars,
body.story-page .aurora {
  opacity: 0.16;
}

body.theme-dawn.story-page {
  background: linear-gradient(180deg, rgba(248, 246, 255, 0.98), rgba(241, 242, 252, 1));
}

a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.stars,
.aurora {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.stars {
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,.9), transparent 40%),
    radial-gradient(1px 1px at 75% 22%, rgba(255,255,255,.7), transparent 40%),
    radial-gradient(1.5px 1.5px at 62% 70%, rgba(120,240,255,.8), transparent 40%),
    radial-gradient(2px 2px at 40% 85%, rgba(242,203,120,.7), transparent 40%),
    radial-gradient(1px 1px at 82% 58%, rgba(255,255,255,.65), transparent 40%);
  opacity: 0.65;
}

.aurora {
  filter: blur(60px);
  opacity: 0.45;
}
.aurora-a { background: radial-gradient(circle at 15% 20%, rgba(120,240,255,.22), transparent 25%); }
.aurora-b { background: radial-gradient(circle at 85% 15%, rgba(143,124,255,.22), transparent 28%); }

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
  backdrop-filter: blur(18px);
}

.story-page .topbar {
  padding: 14px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.brand strong, h1, h2, h3 { font-family: 'Cinzel', serif; }
.brand small { display: block; color: var(--muted); }
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(242,203,120,.2), rgba(120,240,255,.15));
  border: 1px solid var(--line);
}
nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
nav a, .ghost-button {
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  padding: 10px 14px;
  border-radius: 999px;
}
nav a:hover, .ghost-button:hover { border-color: var(--line); color: var(--text); }
.ghost-button { cursor: pointer; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: 24px;
}

.story-page .panel {
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  margin-top: 28px;
  padding: 42px;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--cyan);
  font-size: 0.78rem;
  margin: 0 0 12px;
}
.hero h1 { font-size: clamp(2.7rem, 4vw, 4.5rem); margin: 0 0 18px; line-height: 1.05; }
.lede { color: var(--muted); font-size: 1.05rem; max-width: 62ch; }
.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 28px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border-radius: 14px;
  border: 1px solid var(--line);
  transition: transform 160ms ease, border-color 160ms ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary {
  background: linear-gradient(135deg, rgba(242,203,120,.28), rgba(143,124,255,.25));
}
.button-secondary { background: rgba(255,255,255,.03); }

.hologram {
  position: relative;
  overflow: hidden;
  padding: 28px;
}
.hologram::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(120,240,255,.09), transparent);
}
.sigil {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  background: linear-gradient(135deg, rgba(242,203,120,.2), rgba(120,240,255,.16));
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.hologram ul { padding-left: 18px; color: var(--muted); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin: 24px auto;
}
.feature-card { padding: 22px; }
.feature-card p { color: var(--muted); }
.stats-strip {
  margin: 0 auto 40px;
  padding: 18px 24px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.stats-strip strong {
  display: block;
  color: var(--gold);
  font-size: 1.2rem;
  margin-bottom: 6px;
}
.stats-strip span { color: var(--muted); }

.story-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 20px;
  align-items: start;
  padding-bottom: 48px;
}

.toc-layout,
.chapter-layout {
  padding-bottom: 48px;
}

.toc-hero {
  padding: 28px;
  margin-bottom: 18px;
}

.toc-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.toc-card {
  display: block;
  padding: 22px;
  transition: transform 160ms ease, border-color 160ms ease;
}

.toc-card:hover {
  transform: translateY(-2px);
  border-color: rgba(120,240,255,.42);
}

.toc-card small,
.toc-card .toc-arc,
.toc-card p {
  color: var(--muted);
}

.toc-card strong {
  display: block;
  margin: 8px 0;
  font-family: 'Cinzel', serif;
  font-size: 1.18rem;
}

.single-chapter-card {
  max-width: 860px;
  margin: 0 auto;
}
.side-panel {
  position: sticky;
  top: 92px;
  padding: 22px;
}
.side-head h1 { margin: 0; font-size: 2rem; }
.search-box { display: grid; gap: 8px; margin: 18px 0 14px; color: var(--muted); }
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  color: var(--text);
  padding: 12px 14px;
}
.toc-list { display: grid; gap: 10px; max-height: calc(100vh - 220px); overflow: auto; padding-right: 4px; }
.toc-item {
  display: block;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
}
.toc-item:hover, .toc-item.active { border-color: rgba(120,240,255,.5); transform: translateY(-1px); }
.toc-item small, .toc-item .toc-arc { display: block; color: var(--muted); }
.toc-item strong { display: block; margin: 6px 0; }

.reader-column { display: grid; gap: 16px; }
.reader-hero { padding: 24px; }
.reader-hero p:last-child { color: var(--muted); }
.story-page .reader-hero {
  background: rgba(255,255,255,.025);
}
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.meta-pill {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.04);
  color: var(--muted);
}
.chapter-container { display: grid; gap: 18px; }
.chapter-card {
  padding: 28px;
  scroll-margin-top: 88px;
}
.chapter-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  flex-wrap: wrap;
}
.chapter-header h2 { margin: 8px 0 10px; font-size: clamp(1.8rem, 3vw, 2.4rem); }
.chapter-header p, .chapter-card p, .chapter-card li { color: var(--muted); }
.chapter-badge {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--gold);
  white-space: nowrap;
}
.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0;
}
.info-box {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: rgba(255,255,255,.03);
}
.info-box strong { display: block; margin-bottom: 8px; }
.info-box ul { margin: 0; padding-left: 18px; }
.chapter-prose {
  margin-top: 20px;
  padding: 26px;
  border: 1px solid rgba(145, 179, 255, 0.14);
  border-radius: 20px;
  background: rgba(255,255,255,.018);
}
.chapter-prose p {
  color: var(--text);
  line-height: 1.9;
  margin: 0 0 1.15rem;
  font-size: 1.02rem;
}
.chapter-prose hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line), transparent);
  margin: 1.8rem 0;
}
.chapter-prose strong { color: var(--gold); }
.chapter-prose em { color: var(--cyan); }
.map-reveal {
  margin: 1.8rem 0;
  --map-scale: 1;
}
.map-reveal-button {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-radius: 999px;
  border: 1px solid rgba(183, 48, 68, 0.58);
  background:
    radial-gradient(circle at 16% 50%, rgba(255, 221, 173, 0.16), transparent 16%),
    radial-gradient(circle at 78% 28%, rgba(155, 18, 38, 0.42), transparent 20%),
    linear-gradient(135deg, rgba(44, 5, 12, 0.96), rgba(105, 13, 26, 0.96) 58%, rgba(34, 4, 10, 0.98));
  color: var(--text);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(242, 203, 120, 0.08), 0 18px 40px rgba(53, 4, 12, 0.44), 0 0 28px rgba(167, 21, 43, 0.2);
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.map-reveal-button::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 12% 70%, rgba(255,255,255,0.08), transparent 14%),
    radial-gradient(circle at 88% 36%, rgba(255,255,255,0.06), transparent 12%),
    linear-gradient(90deg, transparent, rgba(242, 203, 120, 0.08), transparent);
  pointer-events: none;
}
.map-reveal-button:hover {
  transform: translateY(-1px);
  border-color: rgba(242, 203, 120, 0.42);
  box-shadow: 0 0 0 1px rgba(242, 203, 120, 0.14), 0 24px 46px rgba(53, 4, 12, 0.52), 0 0 38px rgba(167, 21, 43, 0.28);
}
.map-reveal-button::after {
  content: '⟡';
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(242, 203, 120, 0.28);
  background: radial-gradient(circle, rgba(242, 203, 120, 0.24), rgba(139, 13, 30, 0.18));
  font-size: 1.15rem;
  color: #ffdca0;
  transition: transform 240ms ease, box-shadow 240ms ease;
  box-shadow: inset 0 0 14px rgba(255, 218, 147, 0.14), 0 0 18px rgba(167, 21, 43, 0.2);
}
.map-reveal.is-open .map-reveal-button::after {
  transform: rotate(180deg) scale(1.06);
  box-shadow: inset 0 0 16px rgba(255, 218, 147, 0.18), 0 0 22px rgba(242, 203, 120, 0.18);
}
.map-reveal-copy {
  position: relative;
  display: block;
  flex: 1 1 auto;
}
.map-reveal-title,
.map-reveal-hint {
  display: block;
}
.map-reveal-title {
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  color: #ffe1a8;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.map-reveal-hint {
  margin-top: 5px;
  font-size: 0.95rem;
  color: rgba(255, 236, 221, 0.74);
}
.map-reveal-panel[hidden] {
  display: none !important;
}
.map-reveal-panel {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transform: translateY(-10px);
  transition: max-height 360ms ease, opacity 240ms ease, transform 240ms ease, margin-top 240ms ease;
  margin-top: 0;
}
.map-reveal.is-open .map-reveal-panel {
  max-height: 1400px;
  opacity: 1;
  transform: translateY(0);
  margin-top: 16px;
}
.map-reveal-panel-inner {
  overflow: hidden;
}
.map-frame {
  margin: 0;
  padding: 16px;
  border-radius: 22px;
  border: 1px solid rgba(183, 48, 68, 0.26);
  background: linear-gradient(180deg, rgba(33, 8, 15, 0.9), rgba(14, 10, 24, 0.88));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 18px 46px rgba(0, 0, 0, 0.26);
}
.map-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.map-toolbar-label {
  font-family: 'Cinzel', serif;
  color: #ffd48c;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.map-zoom-controls {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}
.map-zoom-button {
  min-width: 44px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid rgba(242, 203, 120, 0.2);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  cursor: pointer;
}
.map-zoom-button:hover {
  border-color: rgba(242, 203, 120, 0.48);
  background: rgba(255,255,255,0.08);
}
.map-viewport {
  overflow: auto;
  max-width: 100%;
  max-height: min(72vh, 860px);
  padding: 4px;
  border-radius: 16px;
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(145, 179, 255, 0.12);
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
}
.map-image {
  display: block;
  width: calc(100% * var(--map-scale));
  min-width: 100%;
  max-width: none;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
  transition: width 220ms ease;
}
.map-caption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}
.bionic-focus {
  font-weight: 800;
  color: var(--text);
}
body.bionic-enabled .chapter-prose p,
body.bionic-enabled .chapter-prose li {
  letter-spacing: 0.01em;
}
.single-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
}
.chapter-nav a {
  flex: 1;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.03);
  color: var(--muted);
}
.chapter-nav a:last-child { text-align: right; }
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  z-index: 20;
  background: linear-gradient(90deg, var(--gold), var(--cyan), var(--violet));
}
.hidden { display: none !important; }

@media (max-width: 980px) {
  .hero, .story-layout, .feature-grid, .stats-strip, .chapter-grid, .single-row, .toc-grid { grid-template-columns: 1fr; }
  .side-panel { position: relative; top: 0; }
  .story-layout {
    gap: 14px;
  }
  .toc-list {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .topbar { align-items: start; flex-direction: column; }
  .topbar nav {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .topbar nav a,
  .topbar nav button {
    flex: 0 0 auto;
  }
  .hero { padding: 26px; }
  .chapter-card, .reader-hero, .side-panel { padding: 18px; }
  .story-layout,
  .toc-layout,
  .chapter-layout {
    width: min(100% - 18px, 1180px);
  }
  .chapter-header h2 {
    font-size: 1.55rem;
  }
  .chapter-prose {
    padding: 18px;
    border-radius: 16px;
  }
  .chapter-prose p {
    font-size: 0.99rem;
    line-height: 1.82;
  }
  .map-reveal-button {
    padding: 16px 18px;
    border-radius: 24px;
  }
  .map-frame {
    padding: 12px;
  }
  .map-toolbar {
    align-items: stretch;
  }
  .map-toolbar-label,
  .map-zoom-controls {
    width: 100%;
  }
  .map-zoom-controls {
    justify-content: space-between;
  }
  .map-zoom-button {
    flex: 1 1 0;
  }
  .map-viewport {
    max-height: min(62vh, 560px);
  }
  .chapter-nav {
    flex-direction: column;
  }
  .chapter-nav a:last-child {
    text-align: left;
  }
  .meta-row {
    gap: 8px;
  }
  .meta-pill,
  .chapter-badge,
  .ghost-button,
  nav a {
    font-size: 0.92rem;
  }
}

@media (max-width: 480px) {
  .shell {
    width: min(100% - 14px, 1180px);
  }
  .brand {
    gap: 10px;
  }
  .brand-mark {
    width: 40px;
    height: 40px;
  }
  .side-head h1 {
    font-size: 1.55rem;
  }
  .chapter-card {
    border-radius: 18px;
  }
  .chapter-prose p {
    font-size: 0.97rem;
    line-height: 1.76;
  }
}
