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

:root {
  --bg-dark: #0d0d0d;
  --bg-sidebar: #111111;
  --bg-content: #141414;
  --bg-card: #1a1a1a;
  --bg-hover: #222222;
  --bg-parchment: #1e1b16;

  --text-primary: #d4c5a9;
  --text-secondary: #a89970;
  --text-dim: #6b5e45;
  --text-heading: #e8dcc6;
  --text-accent: #8fbc5a;

  --green-glow: #5a7a3a;
  --green-bright: #8fbc5a;
  --gold: #c9a84c;
  --gold-dim: #7a6930;
  --red-dark: #6b2020;
  --border-color: #2a2520;

  --font-heading: 'Cinzel', serif;
  --font-body: 'Crimson Text', serif;
  --font-flavor: 'IM Fell English', serif;

  --sidebar-width: 320px;
  --transition: 0.3s ease;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.7;
  min-height: 100vh;
}

/* === Layout === */
#app {
  display: flex;
  min-height: 100vh;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
  z-index: 10;
}

.sidebar-header {
  padding: 24px 20px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(180deg, #1a1510 0%, var(--bg-sidebar) 100%);
}

.logo {
  line-height: 1.1;
}

.logo-call {
  display: block;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.logo-cthulhu {
  display: block;
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.3);
}

.logo-sub {
  font-family: var(--font-flavor);
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
  font-style: italic;
}

/* === Controls === */
.sidebar-controls {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
}

.search-box input:focus {
  border-color: var(--gold-dim);
}

.search-box input::placeholder {
  color: var(--text-dim);
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  opacity: 0.5;
}

.lang-switch {
  display: flex;
  gap: 4px;
}

.lang-btn {
  flex: 1;
  padding: 5px 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  border-radius: 3px;
  transition: all var(--transition);
}

.lang-btn:hover {
  color: var(--text-secondary);
  border-color: var(--gold-dim);
}

.lang-btn.active {
  background: var(--gold-dim);
  color: var(--bg-dark);
  border-color: var(--gold);
  font-weight: 700;
}

/* === Navigation === */
#nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#nav::-webkit-scrollbar {
  width: 4px;
}

#nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.nav-loading {
  padding: 20px;
  text-align: center;
  color: var(--text-dim);
  font-style: italic;
}

.nav-chapter {
  border-bottom: 1px solid var(--border-color);
}

.nav-chapter-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: all var(--transition);
  user-select: none;
}

.nav-chapter-title:hover {
  background: var(--bg-hover);
  color: var(--gold);
}

.nav-chapter-title.active {
  color: var(--gold);
  background: rgba(201, 168, 76, 0.05);
}

.nav-chapter-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-size: 0.65rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.nav-chapter-title.active .nav-chapter-num {
  background: var(--gold-dim);
  color: var(--bg-dark);
  border-color: var(--gold);
}

.nav-arrow {
  margin-left: auto;
  font-size: 0.6rem;
  transition: transform var(--transition);
}

.nav-chapter.expanded .nav-arrow {
  transform: rotate(90deg);
}

.nav-sections {
  display: none;
  padding: 0 0 6px 0;
}

.nav-chapter.expanded .nav-sections {
  display: block;
}

.nav-section {
  display: block;
  padding: 5px 16px 5px 46px;
  color: var(--text-dim);
  font-family: var(--font-body);
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 2px solid transparent;
}

.nav-section:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.nav-section.active {
  color: var(--green-bright);
  border-left-color: var(--green-bright);
  background: rgba(143, 188, 90, 0.05);
}

/* === Main Content === */
#content {
  flex: 1;
  min-width: 0;
  padding: 40px 60px;
  max-width: 900px;
}

/* === Welcome Screen === */
.welcome {
  text-align: center;
  padding: 80px 20px;
}

.welcome-symbol {
  font-size: 4rem;
  color: var(--gold-dim);
  margin-bottom: 20px;
  opacity: 0.6;
}

.welcome h2 {
  font-family: var(--font-heading);
  font-size: 2rem;
  color: var(--gold);
  margin-bottom: 12px;
  letter-spacing: 0.05em;
}

.welcome p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.welcome-quote {
  font-family: var(--font-flavor);
  font-style: italic;
  color: var(--text-dim);
  margin-top: 40px !important;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

.welcome-author {
  font-family: var(--font-flavor);
  color: var(--text-dim);
  font-size: 0.9rem !important;
  margin-top: 8px !important;
}

/* === Chapter Content === */
.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.chapter-number {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.chapter-title {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-shadow: 0 0 30px rgba(201, 168, 76, 0.15);
}

.section {
  margin-bottom: 36px;
  scroll-margin-top: 20px;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  color: var(--text-heading);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
  letter-spacing: 0.03em;
}

.subsection {
  margin-bottom: 24px;
  scroll-margin-top: 20px;
}

.subsection-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.section-content {
  white-space: pre-wrap;
  line-height: 1.8;
  color: var(--text-primary);
}

.section-content p {
  margin-bottom: 12px;
}

/* Markdown tables inside content */
.content-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9rem;
}

.content-table th,
.content-table td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.content-table th {
  background: var(--bg-card);
  color: var(--text-heading);
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.content-table tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

/* === Search Results === */
#search-results {
  padding-bottom: 40px;
}

#search-results h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 8px;
}

#search-count {
  color: var(--text-dim);
  margin-bottom: 24px;
  font-size: 0.9rem;
}

.search-result-item {
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}

.search-result-item:hover {
  border-color: var(--gold-dim);
  background: var(--bg-hover);
}

.search-result-chapter {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.search-result-section {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  color: var(--text-heading);
  margin-bottom: 6px;
}

.search-result-snippet {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.search-result-snippet mark {
  background: rgba(201, 168, 76, 0.3);
  color: var(--gold);
  padding: 0 2px;
  border-radius: 2px;
}

/* === Sidebar Toggle (mobile) === */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 20;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 1.2rem;
  width: 40px;
  height: 40px;
  border-radius: 4px;
  cursor: pointer;
}

/* === Hidden === */
.hidden {
  display: none !important;
}

/* === Scrollbar === */
#content::-webkit-scrollbar {
  width: 6px;
}

#content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* === Responsive === */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 280px;
  }

  #content {
    padding: 24px 24px;
  }

  .chapter-title {
    font-size: 1.6rem;
  }
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -100%;
    transition: left var(--transition);
    width: 85vw;
    min-width: auto;
    max-width: 320px;
  }

  #sidebar.open {
    left: 0;
  }

  #sidebar-toggle {
    display: block;
  }

  #content {
    padding: 60px 16px 24px;
    max-width: 100%;
  }

  .chapter-title {
    font-size: 1.4rem;
  }
}

/* === Fade-in animation === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section {
  animation: fadeIn 0.3s ease forwards;
}

/* === Selection === */
::selection {
  background: rgba(201, 168, 76, 0.3);
  color: var(--text-heading);
}
