/* ============================================================
   Lin's NightRead — Complete Stylesheet
   Dark "NightRead" theme, premium reading experience
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --bg-deep: #0a0a0f;
  --bg-surface: #121218;
  --bg-elevated: #1a1a24;
  --bg-card: #16161e;
  --border-subtle: #252530;
  --border-accent: #334155;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-glow: #3b82f6;
  --accent-soft: rgba(37, 99, 235, 0.15);
  --gold: #e2c870;
  --gold-glow: #f0d78c;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;

  --font-serif: Georgia, 'Times New Roman', 'Noto Serif SC', 'Source Han Serif SC', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --reader-max-width: 620px;
  --sidebar-width: 280px;
  --nav-height: 48px;
  --transition-fast: 0.2s ease;
}

/* --- RESET & BASE --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

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

/* --- TYPOGRAPHY --- */
a { color: var(--accent-glow); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* --- BUTTONS --- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
  box-shadow: none;
}
.btn-primary:hover {
  background: var(--accent-glow);
  box-shadow: 0 0 20px rgba(37, 99, 235, 0.4);
}
.btn-primary:active {
  transform: scale(0.98);
}

.btn-glow {
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.3);
  animation: pulse-glow 2s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 16px rgba(37, 99, 235, 0.3); }
  50% { box-shadow: 0 0 28px rgba(59, 130, 246, 0.5); }
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.btn-secondary:hover {
  border-color: var(--border-accent);
  background: var(--bg-surface);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent-glow);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}
.btn-text:hover { background: var(--accent-soft); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.btn-icon:hover { background: var(--accent-soft); color: var(--accent-glow); }

/* --- INPUTS --- */
.input-dark {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition-fast);
}
.input-dark:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.input-dark::placeholder { color: var(--text-muted); }

select.input-dark {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2371717a' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

textarea.input-dark {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-sans);
}

.form-group {
  margin-bottom: 18px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Combobox: input + datalist styled as a single unit */
.combo-input input {
  width: 100%;
}

/* Preset row: select + button side by side */
.preset-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.preset-row select {
  flex: 1;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 200px;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-glow);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.5);
}

/* --- VIEW SYSTEM --- */
.view {
  display: none;
  animation: fadeSlideIn 0.3s ease;
}
.view.active { display: block; }

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

/* --- SPLASH --- */
#view-splash {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #12121a 0%, var(--bg-deep) 70%);
}
#view-splash.active { display: flex; }
#view-splash:not(.active) { display: none; }
.splash-container {
  text-align: center;
  padding: 40px;
}
.splash-icon {
  margin-bottom: 24px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.splash-title {
  font-family: var(--font-serif);
  font-size: 2.4rem;
  color: var(--gold);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.splash-tagline {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 32px;
  font-style: italic;
}

/* --- TOP NAV --- */
#app-shell { height: 100vh; display: flex; flex-direction: column; }

.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--nav-height);
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.nav-logo { flex-shrink: 0; }
.nav-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--gold);
  font-weight: 600;
}
.nav-tabs {
  display: flex;
  gap: 4px;
}
.nav-tab {
  padding: 6px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.nav-tab:hover { color: var(--text-primary); background: var(--bg-elevated); }
.nav-tab.active { color: var(--accent-glow); background: var(--accent-soft); }

/* --- VIEWS CONTAINER --- */
.view-container { flex: 1; overflow: hidden; position: relative; }

/* --- LIBRARY VIEW --- */
#view-library { padding: 24px 32px; height: 100%; overflow-y: auto; }

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.library-header h2 { font-size: 1.4rem; font-weight: 600; }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.library-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { margin-bottom: 16px; opacity: 0.5; }

/* Novel Card */
.novel-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.novel-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.15);
}
.novel-card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: none;
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}
.novel-card:hover .novel-card-delete { opacity: 1; }
.novel-card-delete:hover { background: rgba(239, 68, 68, 0.3); }

.novel-card-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.novel-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.novel-card-meta span {
  font-size: 0.75rem;
  padding: 2px 8px;
  background: var(--accent-soft);
  color: var(--accent-glow);
  border-radius: 10px;
}
.novel-card-progress {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- SETUP WIZARD --- */
#view-setup { padding: 24px 32px; height: 100%; overflow-y: auto; }
.wizard-container { max-width: 640px; margin: 0 auto; }

.wizard-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}
.step-number {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}
.wizard-step.active { color: var(--text-primary); }
.wizard-step.active .step-number { background: var(--accent); color: white; }
.wizard-step.done { color: var(--success); }
.wizard-step.done .step-number { background: var(--success); color: white; }
.wizard-line {
  width: 48px;
  height: 1px;
  background: var(--border-subtle);
}

.wizard-panel { display: none; }
.wizard-panel.active { display: block; }

.wizard-panel h3 { font-size: 1.2rem; margin-bottom: 4px; }

.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tag {
  display: inline-block;
  padding: 6px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}
.tag:hover { border-color: var(--accent); }
.tag.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-glow); }

.wizard-buttons {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  justify-content: flex-end;
}

.gen-status {
  text-align: center;
  padding: 40px;
}
.gen-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-glow);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.gen-tab {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
}
.gen-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-bottom-color: var(--bg-elevated);
}
.gen-panel { display: none; }
.gen-panel.active { display: block; }
.gen-editable {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  line-height: 1.5;
}
.gen-editable[contenteditable="true"] {
  cursor: text;
  border-color: var(--accent);
}

/* --- READER --- */
#view-reader { padding: 0; }
.reader-layout {
  display: flex;
  height: calc(100vh - var(--nav-height));
  overflow: hidden;
}

/* Reader Main */
.reader-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-deep);
}
.reader-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 44px;
}
.reader-chapter-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
}
.reader-chapter-info .separator {
  margin: 0 8px;
  color: var(--text-muted);
}
.reader-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 32px 24px 24px;
  max-width: var(--reader-max-width);
  margin: 0 auto;
  width: 100%;
  scroll-behavior: smooth;
}
.chapter-title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 28px;
  text-align: center;
  color: var(--gold);
  letter-spacing: 0.03em;
}
.chapter-body {
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 2.0;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}
.chapter-body p {
  margin-bottom: 1.2em;
  text-indent: 2em;
}
.chapter-body p:first-child {
  text-indent: 0;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-family: var(--font-sans);
  font-style: italic;
}
.typing-dots span {
  animation: typingDot 1.4s infinite;
  opacity: 0.3;
  font-weight: bold;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* Reader Bottom (formerly choices) */
.reader-choices {
  padding: 20px 24px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  max-width: var(--reader-max-width);
  margin: 0 auto;
  width: 100%;
}

.next-chapter-btn {
  display: block;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
  padding: 14px 24px;
  text-align: center;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
}
.next-chapter-btn:hover {
  background: var(--accent-glow);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3);
}

/* Reader Sidebar */
.reader-sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
}
.sidebar-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
}
.sidebar-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

/* Outline Progress in Sidebar */
.outline-progress {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.outline-node {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: all var(--transition-fast);
}
.outline-node.current {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--text-primary);
}
.outline-node.done {
  color: var(--success);
  border-left-color: var(--success);
  opacity: 0.8;
}
.outline-node .node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-subtle);
  margin-top: 4px;
  flex-shrink: 0;
}
.outline-node.current .node-dot { background: var(--accent-glow); }
.outline-node.done .node-dot { background: var(--success); }

.outline-node.clickable {
  cursor: pointer;
}
.outline-node.clickable:hover {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.outline-node.clickable.done:hover {
  border-left-color: var(--success);
  background: rgba(34, 197, 94, 0.08);
}
.outline-node .node-title {
  word-break: break-word;
}

.outline-node[data-fork="true"] {
  cursor: context-menu;
}

/* Branch list in sidebar */
.branch-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.branch-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background var(--transition-fast);
  border-left: 2px solid transparent;
}
.branch-item:hover {
  background: var(--accent-soft);
}
.branch-item.current {
  background: var(--accent-soft);
  border-left-color: var(--accent-glow);
}
.branch-item-label {
  font-weight: 600;
  color: var(--text-primary);
}
.branch-item-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Branch badge in reader header */
.branch-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-glow);
  font-family: var(--font-sans);
  margin-left: 6px;
  vertical-align: middle;
}

/* Branch Context Menu */
#branch-context-menu {
  position: fixed;
  z-index: 200;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 6px 0;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.branch-menu-item {
  padding: 10px 16px;
  font-size: 0.9rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
  user-select: none;
}
.branch-menu-item:hover {
  background: var(--accent-soft);
  color: var(--accent-glow);
}

/* Branch Prompt Overlay */
#branch-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.branch-prompt-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 24px;
  max-width: 440px;
  width: 90%;
}
.branch-prompt-card h4 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.branch-prompt-card #branch-prompt-chapter {
  color: var(--gold);
}

/* Character list */
.character-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.character-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.8rem;
}
.character-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.character-detail {
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  color: white;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.3s ease;
  pointer-events: auto;
  text-align: center;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
.toast.info { border-color: var(--accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 20px; font-size: 0.9rem; line-height: 1.6; }
.modal-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
}

/* Sidebar overlay (mobile) */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
}

/* --- SETTINGS VIEW --- */
#view-settings { padding: 24px 32px; height: 100%; overflow-y: auto; }
.settings-container { max-width: 580px; margin: 0 auto; }
.settings-container h2 { margin-bottom: 24px; }
.settings-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}
.settings-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.settings-section .text-muted {
  margin-bottom: 16px;
}

.api-test-result {
  margin-left: 12px;
  font-size: 0.85rem;
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
}

/* --- RESPONSIVE --- */
n/* Custom dropdown (replaces datalist for dark theme compatibility) */
.custom-dropdown {
  position: absolute;
  z-index: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: none;
  min-width: 180px;
}
.custom-dropdown.show { display: block; }
.custom-dropdown-item {
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.custom-dropdown-item:hover {
  background: var(--accent-soft);
  color: var(--accent-glow);
}

@media (max-width: 900px) {
  .reader-layout { position: relative; }
  .reader-sidebar {
    position: fixed;
    top: var(--nav-height);
    right: 0;
    bottom: 0;
    z-index: 160;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
  }
  .reader-sidebar.open { transform: translateX(0); }

  #sidebar-overlay {
    display: block;
  }

  .reader-content {
    padding: 24px 16px;
  }
  .chapter-body {
    font-size: 16px;
    line-height: 1.9;
  }
  .reader-choices {
    padding: 16px;
  }

  .splash-title { font-size: 2rem; }
  .wizard-container { padding: 20px; }
  .wizard-line { width: 36px; }

  .library-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .library-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 480px) {
  .top-nav { padding: 0 12px; }
  .nav-tab { padding: 6px 10px; font-size: 0.8rem; }

  .reader-content { padding: 20px 12px; }
  .chapter-title { font-size: 1.2rem; }
  .chapter-body { font-size: 15px; line-height: 1.8; }

  .splash-title { font-size: 1.6rem; }
  .splash-tagline { font-size: 0.95rem; }

  .wizard-progress { gap: 0; }
  .wizard-line { width: 24px; }
}
