/* GODWRITER READER — Premium Reading Experience
   Dark/Light mode, typography controls, chapter nav
   Overrides book-specific CSS when loaded */

/* ═══ THEME VARIABLES ═══ */
:root {
  --r-bg: #0a0a0f;
  --r-bg2: #12121a;
  --r-text: #c8c8d0;
  --r-text-bright: #e8e8f0;
  --r-text-dim: #555568;
  --r-surface: rgba(255,255,255,0.03);
  --r-surface-hover: rgba(255,255,255,0.06);
  --r-border: rgba(255,255,255,0.06);
  --r-border-hover: rgba(255,255,255,0.12);
  --r-shadow: 0 8px 32px rgba(0,0,0,0.3);
  --r-font-size: 19px;
  --r-line-height: 1.85;
  --r-max-width: 720px;
  --r-transition: 0.35s cubic-bezier(0.4,0,0.2,1);
}

html[data-theme="light"] {
  --r-bg: #faf9f7;
  --r-bg2: #f0eeea;
  --r-text: #2a2a32;
  --r-text-bright: #111118;
  --r-text-dim: #888898;
  --r-surface: rgba(0,0,0,0.03);
  --r-surface-hover: rgba(0,0,0,0.06);
  --r-border: rgba(0,0,0,0.08);
  --r-border-hover: rgba(0,0,0,0.14);
  --r-shadow: 0 8px 32px rgba(0,0,0,0.08);
}

html[data-theme="sepia"] {
  --r-bg: #f4ead5;
  --r-bg2: #ebe0c8;
  --r-text: #3d3427;
  --r-text-bright: #1a1510;
  --r-text-dim: #8a7d6b;
  --r-surface: rgba(60,40,10,0.04);
  --r-surface-hover: rgba(60,40,10,0.07);
  --r-border: rgba(60,40,10,0.1);
  --r-border-hover: rgba(60,40,10,0.16);
  --r-shadow: 0 8px 32px rgba(60,40,10,0.08);
}

/* ═══ BASE OVERRIDES ═══ */
body {
  background: var(--r-bg) !important;
  color: var(--r-text) !important;
  font-size: var(--r-font-size) !important;
  line-height: var(--r-line-height) !important;
  transition: background var(--r-transition), color var(--r-transition) !important;
}

/* ═══ NAV OVERRIDE ═══ */
nav {
  background: color-mix(in srgb, var(--r-bg) 88%, transparent) !important;
  backdrop-filter: blur(20px) saturate(1.3) !important;
  border-bottom: 1px solid var(--r-border) !important;
  transition: background var(--r-transition), border var(--r-transition) !important;
}

/* ═══ READER TOOLBAR ═══ */
.gw-reader-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: color-mix(in srgb, var(--r-bg2) 92%, transparent);
  backdrop-filter: blur(24px) saturate(1.4);
  border: 1px solid var(--r-border);
  border-radius: 999px;
  box-shadow: var(--r-shadow);
  transition: all var(--r-transition);
  opacity: 0;
  pointer-events: none;
}

.gw-reader-toolbar.visible {
  opacity: 1;
  pointer-events: auto;
}

.gw-reader-toolbar button,
.gw-reader-toolbar a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--r-text-dim);
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: 'Space Grotesk', system-ui, sans-serif;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.gw-reader-toolbar button:hover,
.gw-reader-toolbar a:hover {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
}

.gw-reader-toolbar button.active {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
}

.gw-toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--r-border);
  margin: 0 4px;
}

/* Theme icons */
.gw-reader-toolbar .theme-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--r-border);
  transition: all 0.2s;
}

.gw-reader-toolbar button:hover .theme-dot {
  border-color: var(--r-text-dim);
}

.theme-dot.dark { background: #0a0a0f; }
.theme-dot.light { background: #faf9f7; }
.theme-dot.sepia { background: #f4ead5; }

/* ═══ CHAPTER NAV PANEL ═══ */
.gw-chapter-panel {
  position: fixed;
  top: 0;
  right: -360px;
  width: 340px;
  height: 100vh;
  z-index: 1002;
  background: var(--r-bg2);
  border-left: 1px solid var(--r-border);
  padding: 24px;
  overflow-y: auto;
  transition: right var(--r-transition);
  box-shadow: -8px 0 32px rgba(0,0,0,0.2);
}

.gw-chapter-panel.open {
  right: 0;
}

.gw-chapter-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--r-border);
}

.gw-chapter-panel-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--r-text-dim);
}

.gw-chapter-panel-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--r-surface);
  color: var(--r-text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.gw-chapter-panel-close:hover {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
}

.gw-chapter-link {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 4px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--r-text);
  transition: all 0.2s;
  font-size: 15px;
  line-height: 1.4;
}

.gw-chapter-link:hover {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
}

.gw-chapter-link.current {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
}

.gw-chapter-link .ch-num {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--r-text-dim);
  min-width: 24px;
}

.gw-chapter-link .ch-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
}

.gw-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 1001;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--r-transition);
}

.gw-panel-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ═══ READING PROGRESS ═══ */
.gw-reading-info {
  position: fixed;
  top: 52px;
  right: 20px;
  z-index: 998;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--r-text-dim);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.gw-reading-info.visible {
  opacity: 1;
}

/* ═══ TEXT CONTAINER OVERRIDES ═══ */
.container {
  max-width: var(--r-max-width) !important;
  transition: max-width var(--r-transition) !important;
}

/* ═══ CHAPTER STYLING ═══ */
.chapter {
  border-top-color: var(--r-border) !important;
  transition: border-color var(--r-transition) !important;
}

.chapter h2 {
  color: var(--r-text-bright) !important;
  transition: color var(--r-transition) !important;
}

.chapter p {
  color: var(--r-text) !important;
  transition: color var(--r-transition) !important;
}

/* ═══ SCAN / TERMINAL BLOCKS ═══ */
.scan, .data-block, .terminal-block, [class*="scan"] {
  background: var(--r-surface) !important;
  border-color: var(--r-border) !important;
  transition: background var(--r-transition), border var(--r-transition) !important;
}

/* ═══ QUOTE BLOCKS ═══ */
.quote, blockquote {
  border-left-color: var(--r-border-hover) !important;
  background: var(--r-surface) !important;
  transition: all var(--r-transition) !important;
}

/* ═══ COVER ═══ */
.cover {
  background: var(--r-bg) !important;
  transition: background var(--r-transition) !important;
}

.cover::before {
  transition: opacity var(--r-transition) !important;
}

html[data-theme="light"] .cover::before,
html[data-theme="sepia"] .cover::before {
  opacity: 0.3 !important;
}

/* ═══ CHARACTER CARDS ═══ */
.char-card, [class*="char-card"], [class*="character"] {
  background: var(--r-surface) !important;
  border-color: var(--r-border) !important;
  transition: all var(--r-transition) !important;
}

/* ═══ FINAL SECTION ═══ */
.final {
  transition: all var(--r-transition) !important;
}

/* ═══ STARS OVERRIDE ═══ */
html[data-theme="light"] .stars,
html[data-theme="sepia"] .stars {
  opacity: 0 !important;
  transition: opacity var(--r-transition) !important;
}

html[data-theme="dark"] .stars {
  opacity: 1 !important;
}

/* ═══ LINKS IN LIGHT MODE ═══ */
html[data-theme="light"] a,
html[data-theme="sepia"] a {
  color: var(--r-text) !important;
}

/* ═══ NAV TEXT IN LIGHT ═══ */
html[data-theme="light"] nav *,
html[data-theme="sepia"] nav * {
  color: var(--r-text) !important;
}

html[data-theme="light"] nav .series-badge,
html[data-theme="sepia"] nav .series-badge {
  border-color: var(--r-border-hover) !important;
}

/* ═══ SCROLL TO TOP ═══ */
.gw-scroll-top {
  position: fixed;
  bottom: 80px;
  right: 24px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--r-border);
  background: color-mix(in srgb, var(--r-bg2) 90%, transparent);
  backdrop-filter: blur(12px);
  color: var(--r-text-dim);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 999;
}

.gw-scroll-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.gw-scroll-top:hover {
  background: var(--r-surface-hover);
  color: var(--r-text-bright);
  border-color: var(--r-border-hover);
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .gw-reader-toolbar {
    bottom: 16px;
    padding: 6px 10px;
    gap: 2px;
  }

  .gw-reader-toolbar button,
  .gw-reader-toolbar a {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .gw-chapter-panel {
    width: 280px;
    right: -300px;
  }

  .gw-reading-info {
    display: none;
  }
}

/* ═══ SMOOTH TEXT SELECTION ═══ */
html[data-theme="dark"] ::selection {
  background: rgba(0, 212, 255, 0.2);
}

html[data-theme="light"] ::selection {
  background: rgba(0, 100, 200, 0.15);
}

html[data-theme="sepia"] ::selection {
  background: rgba(160, 120, 40, 0.15);
}

/* ═══ SCROLLBAR ═══ */
html[data-theme="light"] ::-webkit-scrollbar-thumb,
html[data-theme="sepia"] ::-webkit-scrollbar-thumb {
  background: #bbb;
}

html[data-theme="light"] ::-webkit-scrollbar-track,
html[data-theme="sepia"] ::-webkit-scrollbar-track {
  background: var(--r-bg);
}

/* ═══ PRINT ═══ */
@media print {
  .gw-reader-toolbar, .gw-chapter-panel, .gw-panel-overlay,
  .gw-scroll-top, .gw-reading-info, nav, .progress-bar, #progress-bar,
  .stars { display: none !important; }
  body { background: #fff !important; color: #111 !important; }
}
