/* Self-Hosted Fonts (Lora + Outfit, latin & latin-ext subsets) */
@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora-italic-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora-italic-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url('fonts/outfit-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url('fonts/outfit-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Color Themes Configuration */
:root {
  /* Default Obsidian Dark Mode */
  --bg-color: #0b0c10;
  --bg-gradient: radial-gradient(circle at top right, #1f2833 0%, #0b0c10 80%);
  --panel-bg: rgba(31, 40, 51, 0.45);
  --panel-bg-solid: #151b24;
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-border-hover: rgba(102, 252, 241, 0.3);
  --text-color: #c5c6c7;
  --text-heading: #ffffff;
  --text-muted: #8d99ae;
  --accent-color: #66fcf1;
  --accent-rgb: 102, 252, 241;
  --accent-hover: #45e3d7;
  --accent-secondary: #8860d0;
  --accent-secondary-rgb: 136, 96, 208;
  --shadow-color: rgba(102, 252, 241, 0.15);
  --divider: rgba(255, 255, 255, 0.08);
  --font-sans: 'Outfit', sans-serif;
  --font-serif: 'Lora', Georgia, serif;
}

body.theme-sepia {
  --bg-color: #f4ecd8;
  --bg-gradient: linear-gradient(135deg, #FAF4E5 0%, #f4ecd8 100%);
  --panel-bg: rgba(240, 227, 202, 0.65);
  --panel-bg-solid: #ebe0c7;
  --panel-border: rgba(139, 101, 71, 0.15);
  --panel-border-hover: rgba(200, 121, 65, 0.4);
  --text-color: #4a3f35;
  --text-heading: #2e251e;
  --text-muted: #7a6b5d;
  --accent-color: #c87941;
  --accent-rgb: 200, 121, 65;
  --accent-hover: #af6028;
  --accent-secondary: #565d47;
  --accent-secondary-rgb: 86, 93, 71;
  --shadow-color: rgba(200, 121, 65, 0.15);
  --divider: rgba(139, 101, 71, 0.12);
}

body.theme-light {
  --bg-color: #f7f9fb;
  --bg-gradient: linear-gradient(135deg, #ffffff 0%, #f7f9fb 100%);
  --panel-bg: rgba(255, 255, 255, 0.8);
  --panel-bg-solid: #ffffff;
  --panel-border: rgba(0, 0, 0, 0.08);
  --panel-border-hover: rgba(49, 130, 206, 0.3);
  --text-color: #2d3748;
  --text-heading: #1a202c;
  --text-muted: #718096;
  --accent-color: #3182ce;
  --accent-rgb: 49, 130, 206;
  --accent-hover: #2b6cb0;
  --accent-secondary: #805ad5;
  --accent-secondary-rgb: 128, 90, 213;
  --shadow-color: rgba(49, 130, 206, 0.15);
  --divider: rgba(0, 0, 0, 0.08);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-padding-top: 100px; /* Account for sticky header height */
  scroll-behavior: smooth;
}

body {
  background: var(--bg-color);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-color);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease, background-image 0.3s ease;
}

.transition-main {
  opacity: 1;
}

html.is-changing .transition-main {
  transition: opacity 160ms ease;
}

html.is-animating .transition-main {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  html.is-changing .transition-main {
    transition: none;
  }
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading);
  font-family: var(--font-sans);
  font-weight: 700;
  line-height: 1.25;
}

a {
  color: var(--accent-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

/* General Layout utilities */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.reader-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

/* Glassmorphism Panel style */
.glass-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel:hover {
  border-color: var(--panel-border-hover);
}

/* Base Header / Navbar */
.navbar {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar-brand {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-heading);
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.navbar-brand span {
  color: var(--accent-color);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.navbar-link {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.navbar-link:hover,
.navbar-link[aria-current="page"] {
  color: var(--accent-color);
}

/* Pagefind search */
.archive-search-trigger,
.archive-search-modal {
  --pf-text: var(--text-color);
  --pf-text-secondary: var(--text-muted);
  --pf-text-muted: var(--text-muted);
  --pf-background: var(--panel-bg-solid);
  --pf-border: var(--panel-border);
  --pf-border-focus: var(--accent-color);
  --pf-skeleton: rgba(var(--accent-rgb), 0.08);
  --pf-skeleton-shine: rgba(var(--accent-rgb), 0.15);
  --pf-hover: rgba(var(--accent-rgb), 0.08);
  --pf-mark: var(--accent-color);
  --pf-outline-focus: var(--accent-color);
  --pf-font: var(--font-sans);
  --pf-border-radius: 10px;
  --pf-modal-backdrop: rgba(3, 5, 9, 0.78);
  --pf-modal-max-width: 720px;
  --pf-modal-top: 8dvh;
}

.archive-search-trigger {
  display: block;
  flex: 0 0 auto;
  --pf-input-height: 36px;
  --pf-border-radius: 999px;
}

.archive-search-modal {
  --pf-input-height: 44px;
  --pf-result-title-font-size: 1rem;
  --pf-result-excerpt-font-size: 0.86rem;
  --pf-results-gap: 0.65rem;
}

/* Optional site soundtrack */
.music-player {
  position: relative;
}

.music-toggle,
.music-close,
.music-transport button {
  border: 1px solid var(--panel-border);
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  font: inherit;
  cursor: pointer;
}

.music-toggle {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.music-toggle:hover,
.music-toggle[aria-expanded="true"] {
  color: var(--accent-color);
  border-color: rgba(var(--accent-rgb), 0.4);
  background: rgba(var(--accent-rgb), 0.08);
}

.music-toggle-bars {
  width: 15px;
  height: 14px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
}

.music-toggle-bars i {
  display: block;
  width: 3px;
  height: 45%;
  border-radius: 2px;
  background: currentColor;
  transform-origin: bottom;
}

.music-toggle-bars i:nth-child(2) { height: 85%; }
.music-toggle-bars i:nth-child(3) { height: 65%; }

.music-player.is-playing .music-toggle-bars i {
  animation: musicBars 0.75s ease-in-out infinite alternate;
}

.music-player.is-playing .music-toggle-bars i:nth-child(2) { animation-delay: -0.5s; }
.music-player.is-playing .music-toggle-bars i:nth-child(3) { animation-delay: -0.25s; }

@keyframes musicBars {
  from { transform: scaleY(0.4); }
  to { transform: scaleY(1); }
}

.music-panel {
  position: absolute;
  top: calc(100% + 0.75rem);
  right: 0;
  width: min(350px, calc(100vw - 2rem));
  padding: 1rem;
  border: 1px solid rgba(var(--accent-rgb), 0.24);
  border-radius: 14px;
  background:
    radial-gradient(circle at 90% 0%, rgba(var(--accent-secondary-rgb), 0.13), transparent 45%),
    var(--panel-bg-solid);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.music-panel[hidden] {
  display: none;
}

.music-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--divider);
}

.music-kicker,
.music-track-picker > span,
.music-volume > span {
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.music-album {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  margin-top: 0.2rem;
}

.music-album a {
  font-weight: 700;
  color: var(--text-heading);
}

.music-album a:hover { color: var(--accent-color); }

.music-album span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.music-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.25rem;
  line-height: 1;
}

.music-close:hover,
.music-transport button:hover {
  color: var(--accent-color);
  border-color: rgba(var(--accent-rgb), 0.4);
}

.music-track-picker,
.music-volume {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.music-track-picker select {
  min-width: 0;
  width: 100%;
  padding: 0.45rem 2rem 0.45rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: var(--bg-color);
  color: var(--text-color);
  font: 500 0.78rem var(--font-sans);
}

.music-transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin: 1rem 0 0.8rem;
}

.music-transport button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.35rem;
  line-height: 1;
}

.music-transport .music-play {
  width: 44px;
  height: 44px;
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.12);
  color: var(--accent-color);
  font-size: 0.9rem;
}

.music-timeline {
  display: grid;
  grid-template-columns: 2.5rem 1fr 2.5rem;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.68rem;
}

.music-timeline span:last-child { text-align: right; }

.music-panel input[type="range"] {
  width: 100%;
  height: 4px;
  accent-color: var(--accent-color);
  cursor: pointer;
}

.music-credit {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--divider);
  color: var(--text-muted);
  font-size: 0.67rem;
  line-height: 1.45;
}

.music-credit a { color: var(--text-muted); }
.music-credit a:hover { color: var(--accent-color); }

/* Theme Toggle Control */
.theme-picker {
  display: flex;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 30px;
  padding: 3px;
  border: 1px solid var(--panel-border);
}

.theme-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.theme-btn:hover {
  color: var(--text-heading);
}

.theme-btn.active {
  background: var(--accent-color);
  color: var(--bg-color);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.4);
}

/* Library Shelf Layout */
.shelf-header {
  text-align: center;
  margin-bottom: 3.5rem;
  margin-top: 1rem;
}

.shelf-title {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--text-heading) 30%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.shelf-subtitle {
  font-size: 1.15rem;
  color: var(--text-muted);
}

.shelf-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 2rem;
}

.book-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.book-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: linear-gradient(to bottom, var(--accent-color), var(--accent-secondary));
}

.book-card-title {
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.book-card-desc {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
  flex-grow: 1;
}

.book-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--divider);
  padding-top: 1rem;
  margin-top: auto;
}

.book-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-read {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent-color);
  padding: 0.5rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  transition: all 0.25s ease;
}

.btn-read:hover {
  background: var(--accent-color);
  color: var(--bg-color);
  box-shadow: 0 0 15px rgba(var(--accent-rgb), 0.35);
  transform: translateY(-1px);
}

/* Shared contextual back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  transition: color 0.2s ease;
}

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

.back-link:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 4px;
  border-radius: 2px;
}

.back-link-icon {
  transition: transform 0.2s ease;
}

.back-link:hover .back-link-icon {
  transform: translateX(-2px);
}

/* Book Portal Interface */
.book-header {
  margin-bottom: 2.5rem;
}

.book-title {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  letter-spacing: -0.5px;
}

.book-description {
  color: var(--text-muted);
  font-size: 1.1rem;
  max-width: 800px;
}

/* Tab Layout System */
.tabs-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 2rem;
  padding-bottom: 3px;
}

.tab-link {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1.5rem;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease;
}

.tab-link:hover {
  color: var(--text-heading);
}

.tab-link.active {
  color: var(--accent-color);
}

.tab-link.active::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--accent-color);
  border-radius: 30px;
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.5);
}

.tab-panel {
  display: none;
  animation: fadeIn 0.3s ease forwards;
}

.tab-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Chapters Table of Contents List */
.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chapter-item-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.75rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  transition: all 0.25s ease;
}

.chapter-item-link:hover {
  border-color: var(--panel-border-hover);
  transform: translateX(6px);
  background: rgba(var(--accent-rgb), 0.03);
}

.chapter-info {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.chapter-number {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-muted);
  min-width: 2.5rem;
}

.chapter-item-link:hover .chapter-number {
  color: var(--accent-color);
}

.chapter-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-heading);
}

.chapter-arrow {
  color: var(--text-muted);
  transition: transform 0.2s ease, color 0.2s ease;
}

.chapter-item-link:hover .chapter-arrow {
  color: var(--accent-color);
  transform: translateX(4px);
}

/* Character Profiles Grid & Cards */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.character-card {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  text-align: left;
  transition: all 0.25s ease;
}

.character-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.character-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.character-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-heading);
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 30px;
  letter-spacing: 0.5px;
}

.badge-shared {
  background: rgba(var(--accent-rgb), 0.15);
  color: var(--accent-color);
  border: 1px solid rgba(var(--accent-rgb), 0.25);
}

.badge-overridden {
  background: rgba(var(--accent-secondary-rgb), 0.15);
  color: var(--accent-secondary);
  border: 1px solid rgba(var(--accent-secondary-rgb), 0.25);
}

.character-meta-item {
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
}

.character-meta-item strong {
  color: var(--text-color);
}

.character-card-desc {
  font-size: 0.9rem;
  margin-top: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text-color);
  opacity: 0.8;
}

.character-card-more {
  margin-top: auto;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-color);
  padding-top: 1rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Codex & Worldbuilding Document List */
.codex-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.codex-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  border-radius: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  transition: all 0.25s ease;
}

.codex-card:hover {
  border-color: var(--panel-border-hover);
  transform: translateY(-2px);
  background: rgba(var(--accent-rgb), 0.02);
}

.codex-card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-heading);
}

.codex-card-icon {
  color: var(--text-muted);
  transition: color 0.2s ease, transform 0.2s ease;
}

.codex-card:hover .codex-card-icon {
  color: var(--accent-color);
  transform: translateX(2px);
}

/* Reader Typography and Layout */
.reader-header {
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--divider);
  padding-bottom: 2rem;
}

.reader-book-title {
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  margin-bottom: 0.75rem;
}

.reader-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.reader-content {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  line-height: 1.75;
  color: var(--text-color);
}

.reader-content > h1:first-child {
  display: none;
}

.reader-content p {
  margin-bottom: 1.75rem;
}

.reader-content h2 {
  font-family: var(--font-sans);
  font-size: 1.65rem;
  margin-top: 3rem;
  margin-bottom: 1.25rem;
  position: relative;
  display: inline-block;
}

.reader-content h2::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 40px;
  height: 3px;
  background: var(--accent-color);
  border-radius: 30px;
}

.reader-content h3 {
  font-family: var(--font-sans);
  font-size: 1.3rem;
  margin-top: 2rem;
  margin-bottom: 1rem;
}

.reader-content blockquote {
  border-left: 4px solid var(--accent-color);
  background: rgba(var(--accent-rgb), 0.05);
  padding: 1.5rem 1.75rem;
  margin: 2rem 0;
  border-radius: 0 12px 12px 0;
  font-style: italic;
  font-size: 1.05rem;
}

.reader-content blockquote p {
  margin-bottom: 0;
}

.reader-content blockquote p:not(:last-child) {
  margin-bottom: 1rem;
}

.reader-content hr {
  border: none;
  height: 1px;
  background: var(--divider);
  margin: 3rem 0;
}

.reader-content ul, .reader-content ol {
  margin-left: 2rem;
  margin-bottom: 1.75rem;
}

.reader-content li {
  margin-bottom: 0.5rem;
}

.reader-content strong {
  color: var(--text-heading);
}

/* Custom Alert Styling for markdown blockquotes (alerts) */
.reader-content blockquote p:first-child strong:first-child {
  color: var(--accent-color);
}

/* Chapter Footer Navigation */
.reader-footer {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--divider);
}

.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.chapter-nav-link {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  transition: all 0.25s ease;
}

.chapter-nav-link:hover {
  border-color: var(--panel-border-hover);
  background: rgba(var(--accent-rgb), 0.02);
}

.chapter-nav-link.next {
  text-align: right;
  align-items: flex-end;
}

.chapter-nav-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 0.4rem;
}

.chapter-nav-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.chapter-nav-link:hover .chapter-nav-title {
  color: var(--accent-color);
}

/* Floating Controls (Reader Page Settings) */
.reader-controls {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 90;
}

.control-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--panel-bg-solid);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.control-btn:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(var(--accent-rgb), 0.25);
}

/* Font Size Adjustment Classes */
.font-size-s .reader-content { font-size: 1rem; }
.font-size-m .reader-content { font-size: 1.125rem; }
.font-size-l .reader-content { font-size: 1.25rem; }
.font-size-xl .reader-content { font-size: 1.35rem; }

/* Sticky Top Reading Progress Bar */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(to right, var(--accent-color), var(--accent-secondary));
  width: 0%;
  z-index: 101;
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.5);
}

/* Premium Character Modal Interface */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.3s ease;
  padding: 1.5rem;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--panel-bg-solid);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  width: 100%;
  max-width: 900px;
  height: 90vh;
  max-height: 700px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal-container {
  transform: translateY(0);
}

.modal-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.modal-title {
  font-size: 1.8rem;
  font-weight: 800;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-heading);
}

.modal-body {
  flex-grow: 1;
  display: flex;
  overflow: hidden;
}

/* Modal Inner Columns: Left sidebar for tabs, right side for content */
.modal-sidebar {
  width: 250px;
  border-right: 1px solid var(--divider);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  background: rgba(0,0,0,0.15);
}

.modal-sidebar-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
  padding-left: 0.75rem;
}

.modal-tab-btn {
  background: transparent;
  border: none;
  text-align: left;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-tab-btn:hover {
  background: rgba(255,255,255,0.03);
  color: var(--text-heading);
}

.modal-tab-btn.active {
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent-color);
}

.modal-content-panel {
  flex-grow: 1;
  padding: 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-attributes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  background: rgba(0,0,0,0.1);
  padding: 1.25rem 1.5rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  margin-bottom: 1.5rem;
}

.modal-attr-item {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.modal-attr-item strong {
  color: var(--text-color);
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.1rem;
}

.modal-section-panel {
  display: none;
  font-size: 1rem;
  line-height: 1.6;
}

.modal-section-panel.active {
  display: block;
  animation: fadeIn 0.2s ease forwards;
}

.modal-section-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-heading);
  border-bottom: 1px solid var(--divider);
  padding-bottom: 0.5rem;
}

.modal-section-text {
  color: var(--text-color);
}

.modal-section-text p {
  margin-bottom: 1rem;
}

/* Sidebar Toggle for Reader Table of Contents Drawer */
.drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  z-index: 150;
  transition: opacity 0.3s ease;
}

.drawer-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100%;
  background: var(--panel-bg-solid);
  border-right: 1px solid var(--panel-border);
  box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  z-index: 160;
  transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
}

.toc-drawer.active {
  left: 0;
}

.toc-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--divider);
  padding-bottom: 1rem;
}

.toc-drawer-title {
  font-size: 1.25rem;
  font-weight: 800;
}

.toc-drawer-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  flex-grow: 1;
}

.toc-drawer-item {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s ease;
}

.toc-drawer-item:hover {
  background: rgba(255,255,255,0.03);
  color: var(--text-heading);
  transform: translateX(4px);
}

.toc-drawer-item.active {
  background: rgba(var(--accent-rgb), 0.1);
  color: var(--accent-color);
}

.toc-drawer-num {
  font-weight: 800;
  opacity: 0.7;
}

/* Responsiveness adjustments */
@media (max-width: 768px) {
  .shelf-title {
    font-size: 2.25rem;
  }
  .book-grid {
    grid-template-columns: 1fr;
  }
  .navbar-container {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }
  .nav-controls {
    width: 100%;
    justify-content: flex-end;
    gap: 0.75rem;
  }
  .navbar-link {
    margin-right: auto;
  }
  .music-panel {
    position: fixed;
    top: 7.25rem;
    right: 1rem;
    left: 1rem;
    width: auto;
  }
  .tabs-nav {
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 8px;
  }
  .modal-container {
    height: 95vh;
    max-height: none;
  }
  .modal-body {
    flex-direction: column;
  }
  .modal-sidebar {
    width: 100%;
    height: 140px;
    border-right: none;
    border-bottom: 1px solid var(--divider);
    flex-direction: row;
    padding: 1rem;
  }
  .modal-tab-btn {
    white-space: nowrap;
    padding: 0.5rem 1rem;
  }
  .chapter-nav {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .nav-controls {
    gap: 0.5rem;
  }

  .music-toggle {
    width: 36px;
    justify-content: center;
    padding-inline: 0;
  }

  .music-toggle > span:last-child {
    display: none;
  }
}

/* GitHub Alerts Styling */
.markdown-alert {
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  color: inherit;
  border-left: .25em solid #888;
  background: rgba(128, 128, 128, 0.1);
  border-radius: 0 12px 12px 0;
}

.markdown-alert>:first-child { margin-top: 0; }
.markdown-alert>:last-child { margin-bottom: 0; }

.markdown-alert .markdown-alert-title {
  display: flex;
  font-weight: 700;
  align-items: center;
  line-height: 1;
  margin-bottom: 0.75rem;
  font-family: var(--font-sans);
  font-size: 1.1rem;
}

.markdown-alert .markdown-alert-title .octicon {
  margin-right: 0.5rem;
  display: inline-block;
  overflow: visible !important;
  vertical-align: text-bottom;
  fill: currentColor;
}

.markdown-alert.markdown-alert-note { border-left-color: #0969da; background: rgba(9, 105, 218, 0.1); }
.markdown-alert.markdown-alert-note .markdown-alert-title { color: #3b8bed; }

.markdown-alert.markdown-alert-important { border-left-color: #8250df; background: rgba(130, 80, 223, 0.1); }
.markdown-alert.markdown-alert-important .markdown-alert-title { color: #a371f7; }

.markdown-alert.markdown-alert-warning { border-left-color: #9a6700; background: rgba(154, 103, 0, 0.1); }
.markdown-alert.markdown-alert-warning .markdown-alert-title { color: #d4a72c; }

.markdown-alert.markdown-alert-tip { border-left-color: #1a7f37; background: rgba(26, 127, 55, 0.1); }
.markdown-alert.markdown-alert-tip .markdown-alert-title { color: #2ea043; }

.markdown-alert.markdown-alert-caution { border-left-color: #d1242f; background: rgba(209, 36, 47, 0.1); }
.markdown-alert.markdown-alert-caution .markdown-alert-title { color: #f85149; }

/* ==========================================================================
   Custom Tooltips and Dictionary Definitions
   ========================================================================== */

.dictionary-definition {
  font-style: normal;
  border-bottom: 1px dotted var(--accent-color);
  cursor: help;
  position: relative;
  font-weight: 600;
  color: var(--text-heading);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.dictionary-definition:hover {
  color: var(--accent-color);
  border-bottom-style: solid;
}

.dictionary-link {
  border-bottom: 1px dashed transparent;
  transition: all 0.2s ease;
}

.dictionary-link:hover {
  border-bottom-color: var(--accent-hover);
}

.custom-tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--panel-bg-solid);
  border: 1px solid var(--accent-color);
  color: var(--text-color);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.4;
  max-width: 300px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, left 0.1s ease, top 0.1s ease;
}

.custom-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   Translatascan — foreign-language phrases with an on-hover translation scan
   ========================================================================== */

/* Inline phrase: a foreign tongue, marked in the secondary accent with a wavy
   "scannable" underline so it reads distinctly from a dictionary term. */
.translatascan {
  font-style: italic;
  color: var(--accent-secondary);
  text-decoration: underline;
  text-decoration-style: wavy;
  text-decoration-color: rgba(var(--accent-secondary-rgb), 0.55);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  cursor: help;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.translatascan:hover {
  color: var(--accent-secondary);
  text-decoration-color: var(--accent-secondary);
}

/* Later references link back to the first appearance. */
.translatascan--ref { cursor: pointer; }

/* The translation readout: styled like a small translator-device panel. */
.translatascan-tooltip {
  position: fixed;
  z-index: 1000;
  min-width: 220px;
  max-width: 340px;
  background:
    linear-gradient(180deg, rgba(var(--accent-secondary-rgb), 0.12), transparent 55%),
    var(--panel-bg-solid);
  border: 1px solid var(--accent-secondary);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font-family: var(--font-sans);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(var(--accent-secondary-rgb), 0.15);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease, left 0.1s ease, top 0.1s ease;
  overflow: hidden;
}

.translatascan-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.translatascan-tooltip .tsn-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.translatascan-tooltip .tsn-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-secondary);
  background: rgba(var(--accent-secondary-rgb), 0.14);
  border: 1px solid rgba(var(--accent-secondary-rgb), 0.3);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.translatascan-tooltip .tsn-langs {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}

.translatascan-tooltip .tsn-arrow { color: var(--accent-secondary); }

.translatascan-tooltip .tsn-phrase {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-heading);
}

.translatascan-tooltip .tsn-line {
  height: 1px;
  margin: 0.55rem 0;
  background: linear-gradient(90deg, var(--accent-secondary), rgba(var(--accent-secondary-rgb), 0.05));
  position: relative;
  overflow: hidden;
}

/* A single-pass scan sweep across the divider. */
.translatascan-tooltip .tsn-line::after {
  content: '';
  position: absolute;
  top: 0;
  left: -40%;
  width: 40%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(var(--accent-secondary-rgb), 0.9), transparent);
  animation: tsnScan 2.4s ease-in-out infinite;
}

@keyframes tsnScan {
  0% { left: -40%; }
  60%, 100% { left: 110%; }
}

.translatascan-tooltip .tsn-translation {
  font-size: 0.98rem;
  line-height: 1.4;
  color: var(--text-color);
}

.translatascan-tooltip .tsn-translation::before { content: '\201C'; color: var(--accent-secondary); }
.translatascan-tooltip .tsn-translation::after  { content: '\201D'; color: var(--accent-secondary); }

.translatascan-tooltip .tsn-note {
  margin-top: 0.55rem;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .music-player.is-playing .music-toggle-bars i { animation: none; }
  .translatascan-tooltip .tsn-line::after { animation: none; }
}
