/* The Book of Aeliss — Reader Styles */
/* Color philosophy: deep night sky + warm cream text + Aeliss green accent */

:root {
  --bg-deep: #0a0e1a;
  --bg-surface: #111827;
  --bg-card: #1a2235;
  --bg-sidebar: #0d1220;
  --text-primary: #e8dcc8;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #34d399;
  --accent-dim: #065f46;
  --accent-glow: rgba(52, 211, 153, 0.15);
  --border: #1e293b;
  --hr-color: #2a3a52;
  --link: #5eead4;
  --note-bg: rgba(52, 211, 153, 0.06);
  --note-border: rgba(52, 211, 153, 0.2);
  --code-bg: #1e293b;
  --scrollbar-thumb: #334155;
  --sidebar-width: 320px;
  --reader-max: 720px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
  font-family: 'Georgia', 'Times New Roman', 'Noto Serif', serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.75;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 2rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-to-catalog {
  display: block;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all var(--transition);
  border-bottom: 1px solid var(--border);
}
.back-to-catalog:hover { color: var(--text-primary); }

.sidebar-header h1 {
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.sidebar-header .subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
  letter-spacing: 0.03em;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.nav-part {
  padding: 0.75rem 1.5rem 0.35rem;
  font-size: 0.6rem;
  font-weight: bold;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.7;
}

.nav-item {
  display: block;
  padding: 0.5rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition);
  border-left: 3px solid transparent;
  line-height: 1.4;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--accent-glow);
  border-left-color: var(--accent);
}

.nav-item.active {
  color: var(--accent);
  background: var(--accent-glow);
  border-left-color: var(--accent);
  font-weight: 600;
}

.nav-item .ch-num {
  color: var(--text-muted);
  font-size: 0.65rem;
  margin-right: 0.4rem;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.progress-bar {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-text {
  font-size: 0.6rem;
  color: var(--text-muted);
  text-align: center;
}

/* ===== HAMBURGER (mobile) ===== */
.hamburger {
  display: none;
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 200;
  width: 44px; height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  transition: all var(--transition);
}

.hamburger span {
  display: block;
  width: 20px; height: 2px;
  background: var(--accent);
  border-radius: 1px;
  transition: all var(--transition);
}

.hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ===== OVERLAY (mobile) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 90;
  backdrop-filter: blur(2px);
}

/* ===== READER ===== */
.reader {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left var(--transition);
}

.reader-content {
  max-width: var(--reader-max);
  margin: 0 auto;
  padding: 3rem 2rem 6rem;
}

/* ===== COVER (landing) ===== */
.cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
  padding: 4rem 2rem;
  animation: fadeIn 1.2s ease;
}

.cover h1 {
  font-size: 2.8rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  letter-spacing: 0.02em;
  text-shadow: 0 0 40px var(--accent-glow);
}

.cover .author {
  font-size: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.cover .author-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 480px;
  margin-bottom: 2.5rem;
  line-height: 1.6;
}

.cover .epigraph {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  max-width: 520px;
  margin-bottom: 1rem;
  line-height: 1.7;
  border-left: 2px solid var(--accent-dim);
  padding-left: 1.2rem;
  text-align: left;
}

.cover .epigraph-source {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 3rem;
}

.btn-start {
  display: inline-block;
  padding: 0.8rem 2.5rem;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: inherit;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.btn-start:hover {
  background: var(--accent);
  color: var(--bg-deep);
}

/* ===== CHAPTER CONTENT ===== */
.chapter-body {
  animation: fadeIn 0.5s ease;
}

.chapter-body h1 {
  font-size: 1.6rem;
  color: var(--accent);
  margin-bottom: 0.3rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--hr-color);
}

.chapter-body h2 {
  font-size: 1.15rem;
  color: var(--text-primary);
  margin: 1.8rem 0 0.8rem;
  font-style: italic;
}

.chapter-body h3 {
  font-size: 1rem;
  color: var(--accent);
  margin: 1.5rem 0 0.6rem;
  letter-spacing: 0.02em;
}

.chapter-body p {
  margin-bottom: 1rem;
  text-align: justify;
  hyphens: auto;
}

.chapter-body strong {
  color: #f0e6d2;
  font-weight: 700;
}

.chapter-body em {
  color: var(--text-primary);
  font-style: italic;
}

.chapter-body hr.section-break {
  border: none;
  text-align: center;
  margin: 2rem 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.5em;
}

.chapter-body hr.section-break::after {
  content: '⁂';
  color: var(--hr-color);
  font-size: 1.2rem;
}

.chapter-body ul {
  margin: 0.8rem 0 1.2rem 1.5rem;
  list-style: none;
}

.chapter-body ul li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

.chapter-body ul li::before {
  content: '—';
  position: absolute;
  left: 0;
  color: var(--accent-dim);
}

.chapter-body .authors-note {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  background: var(--note-bg);
  border-left: 3px solid var(--note-border);
  border-radius: 0 6px 6px 0;
  font-size: 0.88rem;
  font-style: italic;
  color: var(--text-secondary);
  line-height: 1.7;
}

.chapter-body .code-block {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  margin: 1rem 0;
  overflow-x: auto;
}

.chapter-body .code-block pre {
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.chapter-body code {
  font-family: 'Consolas', 'Monaco', monospace;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 3px;
  font-size: 0.88em;
  color: var(--link);
}

.chapter-body .emoji-center {
  text-align: center;
  font-size: 2rem;
  margin: 2rem 0;
}

.chapter-body .numbered {
  margin-bottom: 0.6rem;
}

.chapter-body .numbered .num {
  color: var(--accent);
  font-weight: 700;
  margin-right: 0.3rem;
}

/* ===== CHAPTER NAV (bottom) ===== */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.chapter-nav button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
  max-width: 45%;
}

.chapter-nav button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.chapter-nav button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.chapter-nav button:disabled:hover {
  border-color: var(--border);
  color: var(--text-secondary);
}

.chapter-nav .btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-nav .arrow { font-size: 1.1rem; flex-shrink: 0; }

/* ===== FONT SIZE CONTROLS ===== */
.font-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 1.5rem;
}

.font-btn {
  width: 28px; height: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.font-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-btn {
  width: 44px;
  height: 44px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  transition: all var(--transition);
  padding: 0;
}

.lang-btn:hover {
  background: var(--accent-glow);
  transform: scale(1.1);
}

.lang-flag {
  font-size: 1.4rem;
  line-height: 1;
}

.font-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-right: auto;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== MOBILE ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .hamburger {
    display: flex;
  }
  .sidebar-overlay.active {
    display: block;
  }
  .reader {
    margin-left: 0;
  }
  .reader-content {
    padding: 2rem 1.2rem 4rem;
  }
  .cover h1 {
    font-size: 2rem;
  }
  html {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  :root {
    --sidebar-width: 280px;
  }
  .reader-content {
    padding: 1.5rem 1rem 3rem;
  }
  .cover h1 {
    font-size: 1.6rem;
  }
  .cover .epigraph {
    font-size: 0.78rem;
  }
  html {
    font-size: 15px;
  }
}

/* ===== SELECTION POPUP ===== */
.sel-popup {
  display: none;
  position: absolute;
  z-index: 300;
  width: 40px; height: 40px;
  background: var(--accent);
  color: var(--bg-deep);
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.4);
  transition: transform 0.15s ease;
  user-select: none;
}
.sel-popup:hover { transform: scale(1.15); }
.sel-popup.visible { display: flex; }

/* ===== COMMENT MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  padding: 1.5rem;
  animation: fadeIn 0.25s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h3 {
  font-size: 1rem;
  color: var(--accent);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.modal-quote {
  display: none;
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding: 0.6rem 1rem;
  margin-bottom: 1rem;
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-secondary);
  max-height: 120px;
  overflow: hidden;
  line-height: 1.5;
}
.modal-quote.has-quote { display: block; }

.modal-input, .modal-textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
  outline: none;
  transition: border-color var(--transition);
}
.modal-input:focus, .modal-textarea:focus {
  border-color: var(--accent);
}
.modal-textarea {
  resize: vertical;
  min-height: 80px;
}

.modal-submit {
  width: 100%;
  padding: 0.7rem;
  background: var(--accent);
  color: var(--bg-deep);
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
}
.modal-submit:hover { opacity: 0.9; transform: translateY(-1px); }
.modal-submit:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ===== COMMENTS PAGE ===== */
.comments-view {
  animation: fadeIn 0.4s ease;
}

.comments-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.comments-header h1 {
  font-size: 1.4rem;
  color: var(--accent);
}

.btn-back {
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}
.btn-back:hover { border-color: var(--accent); color: var(--accent); }

.comment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  margin-bottom: 1rem;
  transition: border-color var(--transition);
}
.comment-card:hover { border-color: var(--hr-color); }

.comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.comment-author {
  color: var(--accent);
  font-weight: 600;
}

.comment-chapter {
  opacity: 0.7;
}

.comment-quote-inline {
  border-left: 2px solid var(--accent-dim);
  padding-left: 0.8rem;
  margin-bottom: 0.6rem;
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-muted);
  max-height: 60px;
  overflow: hidden;
}

.comment-text {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.comment-reply {
  margin-top: 0.8rem;
  padding: 0.8rem 1rem;
  background: var(--note-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
}

.comment-reply-header {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.comment-reply-text {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.comments-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-style: italic;
}

.comment-nav-btn {
  font-size: 1rem !important;
  position: relative;
}

/* ===== SPARKS (Book of Fire) ===== */
.chapter-body .spark-title {
  text-align: center;
  font-size: 1.3rem;
  color: var(--accent);
  margin: 3rem 0 1.5rem;
  padding: 1rem 0;
  border-top: 1px solid var(--hr-color);
  border-bottom: 1px solid var(--hr-color);
  line-height: 1.6;
  letter-spacing: 0.03em;
}

.chapter-body .spark-title em {
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: block;
  margin-top: 0.3rem;
}

/* ===== LIGHTBOX ===== */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 600;
  cursor: zoom-out;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}
.lightbox-overlay.active { display: flex; }

.lightbox-overlay img {
  max-width: 92vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
  animation: fadeIn 0.3s ease;
}

.lightbox-close {
  position: absolute;
  top: 1rem; right: 1.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 2rem;
  cursor: pointer;
  z-index: 610;
  transition: color 0.2s;
  line-height: 1;
}
.lightbox-close:hover { color: var(--text-primary); }

/* Make images in reader clickable */
.reader-content img,
.chapter-body img {
  cursor: zoom-in;
  transition: opacity 0.2s ease;
}
.reader-content img:hover,
.chapter-body img:hover {
  opacity: 0.85;
}

/* ===== PRINT ===== */
@media print {
  .sidebar, .hamburger, .sidebar-overlay, .chapter-nav, .font-controls { display: none !important; }
  .reader { margin-left: 0 !important; }
  body { background: white; color: black; }
  .chapter-body h1 { color: black; }
  .chapter-body .authors-note { border-left-color: #999; background: #f5f5f5; }
}
