:root {
  --bg-color: #080708;
  --primary-color: #449cb9;
  --primary-glow: rgba(68, 156, 185, 0.3);
  --text-main: #ffffff;
  --text-muted: #b0b0b0;
  --card-bg: rgba(255, 255, 255, 0.05);
  --border-glow: 1px solid rgba(68, 156, 185, 0.2);
  --font-main: 'Inter', sans-serif;
  --font-heading: 'Montserrat', sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-main);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  background: radial-gradient(circle at top right, #111, var(--bg-color));
}

/* Progress Bar */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  background: var(--primary-color);
  width: 0%;
  z-index: 1000;
  box-shadow: 0 0 10px var(--primary-color);
  transition: width 0.1s;
}

.codex-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

/* Layout for Long-Form */
.codex-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 60px;
  align-items: start;
  margin-top: 40px;
}

@media (max-width: 1000px) {
  .codex-grid {
    grid-template-columns: 1fr;
  }

  .tome-sidebar {
    display: none;
  }
}

.tome-sidebar {
  position: sticky;
  top: 100px;
  padding: 24px;
  background: var(--card-bg);
  border: var(--border-glow);
  border-radius: 16px;
  backdrop-filter: blur(10px);
}

.tome-sidebar h4 {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 20px;
  color: var(--primary-color);
}

.tome-toc {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tome-toc li {
  margin-bottom: 12px;
  position: relative;
  padding-left: 15px;
}

.tome-toc li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 6px;
  height: 1px;
  background: var(--primary-glow);
}

.tome-toc a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.3s;
}

.tome-toc a:hover {
  color: var(--primary-color);
  padding-left: 5px;
}

/* Video Container */
.video-container {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  /* 16:9 */
  height: 0;
  margin-bottom: 60px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8);
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.tome-header {
  text-align: center;
  margin-bottom: 60px;
}

.tome-badge {
  display: inline-block;
  background: var(--primary-glow);
  color: var(--primary-color);
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 20px;
  border: var(--border-glow);
}

h1.tome-title {
  font-family: var(--font-heading);
  font-size: 3.5rem;
  margin: 10px 0;
  background: linear-gradient(135deg, #fff 0%, var(--primary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.tome-cover {
  width: 100%;
  max-width: 600px;
  height: auto;
  border-radius: 20px;
  margin: 0 auto 30px;
  display: block;
  border: var(--border-glow);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  transition: transform 0.3s ease;
}

.tome-sidebar-cover {
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin-bottom: 20px;
  border: var(--border-glow);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
  display: block;
}

.tome-cover:hover {
  transform: scale(1.02);
}

.tome-meta {
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: 1px;
}

/* Audio Player */
.audio-anchor {
  position: sticky;
  top: 20px;
  z-index: 100;
  margin-bottom: 60px;
}

.audio-player {
  background: rgba(8, 7, 8, 0.85);
  backdrop-filter: blur(15px);
  border: var(--border-glow);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 25px;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.6);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-shrink: 0;
}

.visualizer-container {
  background: var(--primary-glow);
  height: 24px;
  width: 100%;
  max-width: 800px;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.visualizer-progress {
  background: var(--primary-color);
  height: 100%;
  width: 0%;
  position: absolute;
  left: 0;
  top: 0;
  box-shadow: 0 0 15px var(--primary-color);
  transition: width 0.1s linear;
  z-index: 1;
}

.player-title-overlay {
  position: relative;
  z-index: 2;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.9);
  pointer-events: none;
  white-space: nowrap;
  mix-blend-mode: difference;
  display: inline-block;
  padding: 0 40px;
  mask-image: linear-gradient(to right, transparent, black 15%, black 85%, transparent);
}

@keyframes scroll-title {
  0% {
    transform: translateX(0);
  }

  15% {
    transform: translateX(0);
  }

  85% {
    transform: translateX(calc(-100% + 400px));
  }

  100% {
    transform: translateX(0);
  }
}

/* Key Points Box */
.key-points-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 2rem;
  margin: 2rem 0;
}

.key-points-box h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: var(--primary-color);
  margin-bottom: 1.5rem;
  letter-spacing: 1px;
}

.key-points-box ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.key-points-box li {
  position: relative;
  padding-left: 2rem;
  margin-bottom: 1rem;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.8);
}

.key-points-box li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--primary-color);
  font-weight: bold;
}

/* Content Sections */
.tome-section {
  margin-bottom: 100px;
}

h2.section-title {
  font-family: var(--font-heading);
  padding-left: 0;
  margin-bottom: 40px;
  font-size: 2rem;
  display: flex;
  align-items: center;
  gap: 20px;
}

h2.section-title::before {
  content: "";
  display: block;
  width: 40px;
  height: 2px;
  background: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-color);
}

.wisdom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 25px;
}

.tome-content {
  font-size: 1.15rem;
  color: #d1d5db;
  line-height: 1.8;
}

.tome-content p {
  margin-bottom: 2rem;
}

.wisdom-card {
  background: var(--card-bg);
  border: var(--border-glow);
  border-radius: 16px;
  padding: 30px;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.wisdom-card:hover {
  transform: translateY(-10px);
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-color);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 20px var(--primary-glow);
}

.wisdom-card i {
  color: var(--primary-color);
  font-size: 1.8rem;
  margin-bottom: 20px;
  display: block;
}

.glossary-term {
  color: var(--primary-color);
  border-bottom: 1px dashed var(--primary-color);
  cursor: help;
  font-weight: 600;
}

.tome-footer {
  text-align: center;
  padding: 80px 40px;
  background: linear-gradient(180deg, transparent, var(--card-bg));
  border-radius: 30px;
  border: var(--border-glow);
  margin-top: 60px;
}

.btn-primary {
  background: var(--primary-color);
  color: #fff;
  text-decoration: none;
  padding: 18px 50px;
  border-radius: 40px !important;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  display: inline-block !important;
  transition: all 0.3s;
}

.btn-primary:hover {
  box-shadow: 0 0 40px var(--primary-glow);
  transform: scale(1.05);
}

/* Tome Navigation Footer */
.tome-navigation {
  margin-top: 80px;
  padding-top: 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.nav-tome-card {
  background: var(--card-bg);
  border: var(--border-glow);
  border-radius: 16px;
  padding: 24px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.nav-tome-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary-color);
  transform: translateY(-5px);
}

.nav-tome-card span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--primary-color);
  margin-bottom: 8px;
}

.nav-tome-card h4 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: #fff;
  margin: 0;
}

.nav-tome-card.prev {
  text-align: left;
  padding-left: 50px;
}

.nav-tome-card.next {
  text-align: right;
  padding-right: 50px;
}

.nav-tome-card.prev::before {
  content: "←";
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  color: var(--primary-color);
}

.nav-tome-card.next::after {
  content: "→";
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.5rem;
  color: var(--primary-color);
}

@media (max-width: 600px) {
  .tome-navigation {
    grid-template-columns: 1fr;
  }
}

/* --- Library Overlay --- */
.library-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95);
  backdrop-filter: blur(20px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.library-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.library-modal {
  width: 90%;
  max-width: 900px;
  height: 80vh;
  background: var(--bg-color);
  border: var(--border-glow);
  border-radius: 24px;
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 100px rgba(0, 0, 0, 0.8), 0 0 40px var(--primary-glow);
}

.library-header {
  padding: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.library-header h3 {
  margin: 0;
  font-family: var(--font-heading);
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--primary-color);
}

.library-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.3s;
}

.library-close:hover {
  opacity: 1;
}

.library-search-box {
  padding: 20px 30px;
  position: relative;
}

.library-search-box input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 15px 50px;
  border-radius: 12px;
  color: #fff;
  font-family: var(--font-main);
  font-size: 1.1rem;
  box-sizing: border-box;
}

.library-search-box input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-glow);
}

.library-search-box .search-icon {
  position: absolute;
  left: 45px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--primary-color);
  opacity: 0.7;
}

.library-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0 30px 30px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 15px;
}

.library-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 20px;
  border-radius: 12px;
  text-decoration: none;
  display: flex;
  gap: 15px;
  align-items: center;
  transition: all 0.3s ease;
}

.library-card:hover {
  background: var(--primary-glow);
  border-color: var(--primary-color);
  transform: translateX(5px);
}

.lib-num {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 1.5rem;
  color: var(--primary-color);
  opacity: 0.5;
}

.lib-info h4 {
  margin: 0;
  font-size: 0.9rem;
  color: #fff;
}

.lib-info p {
  margin: 5px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Códice Components --- */
.codice-section {
  margin-top: 60px;
  padding: 40px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.codice-body {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.8;
}

.btn-library-trigger {
  background: transparent;
  border: var(--border-glow);
  color: var(--primary-color);
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 0.7rem;
  letter-spacing: 1px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  transition: all 0.3s;
}

.btn-library-trigger:hover {
  background: var(--primary-glow);
  transform: translateY(-2px);
}

/* Global Search Modal Overlay */
.search-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 0.3s ease;
}

.search-modal.active {
  display: flex;
}

.search-content {
  background: var(--bg-color);
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  border-radius: 24px;
  border: var(--border-glow);
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8), 0 0 40px var(--primary-glow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.search-header {
  padding: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  gap: 15px;
  align-items: center;
}

.search-header input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 15px 20px;
  border-radius: 12px;
  color: #fff;
  font-family: inherit;
  font-size: 1.1rem;
  outline: none;
  transition: all 0.3s;
}

.search-header input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-glow);
}

.btn-close-search {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.3s;
}

.btn-close-search:hover {
  color: #fff;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-item {
  padding: 15px 20px;
  border-radius: 12px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 15px;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.02);
}

.search-item:hover {
  background: var(--primary-glow);
  transform: translateX(5px);
}

.search-item-num {
  font-weight: 800;
  color: var(--primary-color);
  opacity: 0.5;
  font-size: 0.9rem;
}

.search-item-title {
  color: #fff;
  font-weight: 600;
}

.btn-search-trigger {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-search-trigger:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: scale(1.1);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* --- Gallery / Index Styles --- */
.index-header {
  text-align: center;
  margin-bottom: 60px;
  padding: 60px 20px;
  background: radial-gradient(circle at center, var(--primary-glow), transparent);
}

.index-header h1 {
  font-family: var(--font-heading);
  font-size: 3.5rem;
  font-weight: 900;
  margin: 0;
  letter-spacing: -1px;
  background: linear-gradient(to bottom, #fff, #aaa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.index-header p {
  color: var(--text-muted);
  font-size: 1.2rem;
  max-width: 600px;
  margin: 20px auto 0;
}

.codex-index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 30px;
  padding: 20px;
}

.index-card {
  background: var(--card-bg);
  border: var(--border-glow);
  border-radius: 20px;
  overflow: hidden;
  text-decoration: none;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  display: flex;
  flex-direction: column;
}

.index-card:hover {
  transform: translateY(-10px) scale(1.02);
  border-color: var(--primary-color);
  box-shadow: 0 20px 40px rgba(0,0,0,0.4), 0 0 20px var(--primary-glow);
}

.index-card-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  position: relative;
}

.index-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.index-card:hover .index-card-thumb img {
  transform: scale(1.1);
}

.index-card-badge {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(5px);
  color: var(--primary-color);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 800;
  border: 1px solid var(--primary-glow);
}

.index-card-content {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.index-card h3 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: #fff;
  line-height: 1.4;
  margin-bottom: 10px;
}

.index-card .card-meta {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.index-card .card-meta span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.index-card-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 60px;
  height: 60px;
  background: var(--primary-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: 0 0 20px var(--primary-glow);
}

.index-card:hover .index-card-play {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}