/* ── Google Fonts are loaded via <link> in BaseLayout ── */

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
img, video { max-width: 100%; display: block; }
body { min-height: 100vh; }
a { color: inherit; }

/* ── Theme Variables ── */
:root,
[data-theme="sepia"] {
  --bg: #f4ede0;
  --bg-surface: #ede3ce;
  --text: #3b2f1e;
  --text-muted: #6b5744;
  --border: #c9a97a;
  --accent: #7c5c2e;
  --accent-hover: #5e4420;
  --toc-active-bg: #e6d9c2;
  --shadow: rgba(60,40,10,0.12);
  /* Landing warm tokens */
  --lw-bg: var(--bg);
  --lw-surface: var(--bg-surface);
  --lw-border: var(--border);
  --lw-accent: var(--accent);
  --lw-accent-hover: var(--accent-hover);
  --lw-sidebar: var(--bg-surface);
}

[data-theme="dark"] {
  --bg: #1e1408;
  --bg-surface: #281c0e;
  --text: #e8d5b0;
  --text-muted: #9e7c54;
  --border: #3d2910;
  --accent: #c8862a;
  --accent-hover: #d9973d;
  --toc-active-bg: #2e1a08;
  --shadow: rgba(0,0,0,0.5);
  /* Landing warm tokens */
  --lw-bg: var(--bg);
  --lw-surface: var(--bg-surface);
  --lw-border: var(--border);
  --lw-accent: #d4922e;
  --lw-accent-hover: #e0a84a;
  --lw-sidebar: var(--bg-surface);
}

/* ── Base ── */
body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  transition: background-color 0.2s, color 0.2s;
  line-height: 1.6;
}

/* ── Site Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 1px 4px var(--shadow);
}

.site-header a { text-decoration: none; }

.site-header .header-left { display: flex; align-items: center; gap: 0.75rem; }
.site-header .site-name { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.site-header .chapter-title { font-size: 0.9rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30ch; }

/* ── Theme Switcher ── */
.theme-switcher { display: flex; gap: 0.4rem; align-items: center; }
.theme-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
  position: relative;
}
.theme-btn:hover { transform: scale(1.1); border-color: var(--accent); }
.theme-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.theme-btn[data-theme-value="sepia"] { background: #f4ede0; }
.theme-btn[data-theme-value="dark"]  { background: #1e1408; }

/* ── App Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 1fr;
  min-height: calc(100vh - 57px);
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }
}

/* ── Sidebar / TOC ── */
.toc-sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 1.5rem 1rem;
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
}

@media (max-width: 768px) {
  .toc-sidebar {
    position: fixed;
    top: 57px;
    left: 0;
    width: 280px;
    height: calc(100vh - 57px);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 12px var(--shadow);
  }
  .toc-sidebar.open { transform: translateX(0); }
  .toc-overlay {
    display: none;
    position: fixed; inset: 57px 0 0 0;
    background: rgba(0,0,0,0.4);
    z-index: 89;
  }
  .toc-overlay.open { display: block; }
}

.toc-heading {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.toc-story-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text);
  text-decoration: none;
}

.toc-list { list-style: none; }
.toc-list li { margin-bottom: 0.2rem; }
.toc-list a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
}
.toc-list a:hover { background: var(--border); color: var(--text); }
.toc-list li.active a { background: var(--toc-active-bg); color: var(--accent); font-weight: 600; }

/* ── TOC Toggle (mobile) ── */
.toc-toggle {
  display: none;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
}
@media (max-width: 768px) { .toc-toggle { display: flex; } }

/* ── Reader Main ── */
.reader-main {
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Prose (Chapter Content) ── */
.prose {
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: clamp(1rem, 2.5vw, 1.15rem);
  line-height: 1.85;
  max-width: 65ch;
  width: 100%;
  color: var(--text);
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.3;
  margin: 2rem 0 0.75rem;
  color: var(--text);
  font-weight: 700;
}
.prose h1 { font-size: 1.8rem; }
.prose h2 { font-size: 1.35rem; }
.prose h3 { font-size: 1.1rem; }

.prose p { margin-bottom: 1.25rem; }
.prose p:last-child { margin-bottom: 0; }

.prose em { font-style: italic; }
.prose strong { font-weight: 700; }

.prose a { color: var(--accent); text-underline-offset: 3px; }
.prose a:hover { color: var(--accent-hover); }

.prose blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  color: var(--text-muted);
  font-style: italic;
}

.prose ul, .prose ol { margin: 1rem 0 1.25rem 1.5rem; }
.prose li { margin-bottom: 0.35rem; }

.prose hr { border: none; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.prose img {
  display: block;
  margin: 2rem auto;
  max-width: 100%;
  border-radius: 6px;
  box-shadow: 0 2px 12px var(--shadow);
}

.prose code {
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

.prose pre {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
  margin: 1.5rem 0;
}
.prose pre code { background: none; border: none; padding: 0; }

/* ── Chapter Header ── */
.chapter-header {
  max-width: 65ch;
  width: 100%;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.chapter-header .story-name {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-decoration: none;
  display: block;
}
.chapter-header .story-name:hover { color: var(--accent); }
.chapter-header h1 {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--text);
}

/* ── Chapter Navigation ── */
.chapter-nav {
  max-width: 65ch;
  width: 100%;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  gap: 0.25rem;
}
.chapter-nav a:hover { border-color: var(--accent); box-shadow: 0 2px 8px var(--shadow); }
.chapter-nav .nav-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.chapter-nav .nav-title { font-size: 0.9rem; color: var(--text); font-weight: 500; }
.chapter-nav .nav-next { text-align: right; }
.chapter-nav .nav-placeholder { /* empty cell */ }

/* ── Library / Story List ── */
.library-header {
  max-width: 900px;
  margin: 3rem auto 2rem;
  padding: 0 1.5rem;
}
.library-header h1 { font-size: 2rem; font-weight: 800; margin-bottom: 0.4rem; }
.library-header p { color: var(--text-muted); }

.story-grid {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.story-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-surface);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.story-card:hover { box-shadow: 0 4px 16px var(--shadow); border-color: var(--accent); }

.story-card-cover { aspect-ratio: 3/2; overflow: hidden; background: var(--border); }
.story-card-cover img { width: 100%; height: 100%; object-fit: cover; }
.story-card-cover .cover-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem;
  color: var(--text-muted);
  background: linear-gradient(135deg, var(--bg-surface), var(--border));
}

.story-card-body { padding: 1.1rem 1.2rem; flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }
.story-card-body h2 { font-size: 1.05rem; font-weight: 700; line-height: 1.3; color: var(--text); }
.story-card-body p { font-size: 0.875rem; color: var(--text-muted); line-height: 1.5; flex: 1; }
.story-card-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.25rem; }
.story-card-chapters { font-size: 0.78rem; color: var(--text-muted); }
.story-tag { font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 99px; background: var(--border); color: var(--text-muted); font-weight: 500; }

/* ── Story Overview Page ── */
.story-overview {
  max-width: 720px;
  margin: 3rem auto;
  padding: 0 1.5rem 4rem;
}
.story-overview-header { margin-bottom: 2rem; }
.story-overview-header .back-link { font-size: 0.85rem; color: var(--text-muted); text-decoration: none; display: inline-flex; align-items: center; gap: 0.3rem; margin-bottom: 1rem; }
.story-overview-header .back-link:hover { color: var(--accent); }
.story-overview-header h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); font-weight: 800; line-height: 1.2; margin-bottom: 0.75rem; }
.story-overview-header .description { font-size: 1rem; color: var(--text-muted); line-height: 1.65; margin-bottom: 1rem; }
.story-overview-header .tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

.story-overview-cover {
  width: 100%; border-radius: 10px; overflow: hidden;
  margin-bottom: 2rem; aspect-ratio: 16/7;
  background: var(--border);
}
.story-overview-cover img { width: 100%; height: 100%; object-fit: cover; }

.chapter-list { list-style: none; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.chapter-list-heading { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); padding: 0.85rem 1.25rem; background: var(--bg-surface); border-bottom: 1px solid var(--border); }
.chapter-list li a {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  transition: background 0.12s;
}
.chapter-list li:last-child a { border-bottom: none; }
.chapter-list li a:hover { background: var(--bg-surface); }
.chapter-num { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); min-width: 2rem; }
.chapter-name { font-size: 0.95rem; color: var(--text); }
.chapter-date { font-size: 0.78rem; color: var(--text-muted); margin-left: auto; }

.start-reading-btn {
  display: inline-block;
  margin-bottom: 2rem;
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.15s;
}
.start-reading-btn:hover { background: var(--accent-hover); }

/* ── Simple Page (login/admin) ── */
.simple-page {
  max-width: 480px;
  margin: 4rem auto;
  padding: 0 1.5rem;
}
.simple-page h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 0.5rem; }
.simple-page p { color: var(--text-muted); margin-bottom: 2rem; }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 0.4rem; }
.form-group input[type="password"],
.form-group input[type="text"] {
  width: 100%;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus { border-color: var(--accent); }

.btn-primary {
  display: inline-block;
  padding: 0.7rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.btn-primary:hover { background: var(--accent-hover); }

.error-msg { color: #dc2626; font-size: 0.875rem; margin-bottom: 1rem; padding: 0.6rem 0.9rem; background: #fee2e2; border-radius: 6px; }

/* ── Admin Page ── */
.admin-table { width: 100%; border-collapse: collapse; margin-top: 1.5rem; }
.admin-table th, .admin-table td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.admin-table th { font-weight: 700; color: var(--text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.admin-table tbody tr:hover { background: var(--bg-surface); }
.admin-actions { display: flex; gap: 0.5rem; }
.admin-actions a { font-size: 0.82rem; color: var(--accent); text-decoration: none; }

.admin-logout {
  font-size: 0.85rem; color: var(--text-muted);
  text-decoration: none; padding: 0.4rem 0.8rem;
  border: 1px solid var(--border); border-radius: 6px;
  transition: color 0.15s, border-color 0.15s;
}
.admin-logout:hover { color: #dc2626; border-color: #dc2626; }

.admin-nav-link {
  font-size: 0.8rem; font-weight: 600; color: var(--text-muted);
  text-decoration: none; padding: 0.3rem 0.7rem;
  border: 1px solid var(--border); border-radius: 5px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.admin-nav-link:hover { color: var(--accent); border-color: var(--accent); background: var(--bg-surface); }

/* ── TipTap Toolbar ── */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.tiptap-toolbar-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 0.45rem;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--text);
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.tiptap-toolbar-btn:hover { background: var(--border); }
.tiptap-toolbar-btn.active { background: var(--toc-active-bg); border-color: var(--accent); color: var(--accent); }
.tiptap-divider { width: 1px; background: var(--border); margin: 0.25rem 0.2rem; align-self: stretch; }

/* ── Editor Top Bar ── */
.editor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.editor-topbar-info { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; color: var(--text); flex-wrap: wrap; }
.editor-topbar-actions { display: flex; align-items: center; gap: 0.6rem; }

/* ── Editor Body / Content ── */
.editor-body { display: flex; flex: 1; overflow: hidden; position: relative; }
.editor-content-area { flex: 1; overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; }
.tiptap-editor {
  flex: 1;
  min-height: 400px;
  outline: none;
  max-width: 65ch;
  width: 100%;
  margin: 0 auto;
  font-family: 'Lora', Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text);
}
.tiptap-editor .ProseMirror { outline: none; min-height: 300px; }
.tiptap-editor .ProseMirror p { margin-bottom: 1.1rem; }
.tiptap-editor .ProseMirror h1, .tiptap-editor .ProseMirror h2, .tiptap-editor .ProseMirror h3 {
  font-family: 'Inter', system-ui, sans-serif; font-weight: 700; line-height: 1.3; margin: 1.75rem 0 0.6rem;
}
.tiptap-editor .ProseMirror h1 { font-size: 1.7rem; }
.tiptap-editor .ProseMirror h2 { font-size: 1.3rem; }
.tiptap-editor .ProseMirror h3 { font-size: 1.1rem; }
.tiptap-editor .ProseMirror blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; color: var(--text-muted); font-style: italic; margin: 1rem 0; }
.tiptap-editor .ProseMirror ul, .tiptap-editor .ProseMirror ol { padding-left: 1.5rem; margin: 0.75rem 0; }
.tiptap-editor .ProseMirror code { background: var(--bg-surface); border: 1px solid var(--border); padding: 0.1em 0.3em; border-radius: 3px; font-size: 0.88em; }
.tiptap-editor .ProseMirror pre { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.85rem; overflow-x: auto; margin: 1rem 0; }
.tiptap-editor .ProseMirror pre code { background: none; border: none; padding: 0; }
.tiptap-editor .ProseMirror hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.tiptap-editor .ProseMirror img { max-width: 100%; border-radius: 4px; margin: 1rem 0; }
.tiptap-editor .ProseMirror a { color: var(--accent); text-underline-offset: 3px; }
.tiptap-editor .ProseMirror p.is-editor-empty:first-child::before {
  content: 'Start writing…'; float: left; color: var(--text-muted); pointer-events: none; height: 0;
}

/* ── History Panel ── */
.history-panel {
  width: 0;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease;
}
.history-panel.open { width: 260px; }
@media (max-width: 768px) {
  .history-panel { position: absolute; right: 0; top: 0; height: 100%; z-index: 50; width: 0; }
  .history-panel.open { width: min(260px, 90vw); }
}
.history-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--border);
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); flex-shrink: 0;
}
.history-close-btn {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 0.85rem; padding: 0.15rem 0.3rem; border-radius: 3px; line-height: 1;
}
.history-close-btn:hover { background: var(--border); color: var(--text); }
.history-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.history-empty { font-size: 0.82rem; color: var(--text-muted); padding: 0.75rem 0.5rem; text-align: center; line-height: 1.5; }
.history-entry {
  padding: 0.5rem 0.6rem; border-radius: 6px; margin-bottom: 0.35rem;
  border: 1px solid var(--border); background: var(--bg);
}
.history-entry:hover { border-color: var(--accent); }
.history-entry-time { font-size: 0.82rem; color: var(--text); font-weight: 600; margin-bottom: 0.15rem; }
.history-entry-date { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.history-entry-actions { display: flex; gap: 0.4rem; }
.history-preview-btn, .history-restore-btn {
  font-size: 0.72rem; padding: 0.2rem 0.5rem;
  border-radius: 4px; border: 1px solid var(--border);
  background: none; cursor: pointer; color: var(--text-muted);
  transition: color 0.1s, border-color 0.1s;
}
.history-preview-btn:hover { color: var(--text); border-color: var(--text-muted); }
.history-restore-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── Source badges & delete button (admin table) ── */
.source-badge {
  font-size: 0.68rem; padding: 0.1rem 0.4rem; border-radius: 99px;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.source-badge.file { background: var(--bg-surface); color: var(--text-muted); border: 1px solid var(--border); }
.source-badge.kv { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
[data-theme="dark"] .source-badge.kv { background: #1e3a5f; color: #93c5fd; border-color: #1d4ed8; }
.delete-chapter-btn {
  font-size: 0.82rem; color: #dc2626; background: none; border: none;
  cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px;
}
.delete-chapter-btn:hover { color: #991b1b; }
.delete-chapter-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.delete-story-btn {
  font-size: 0.78rem; color: #dc2626; background: none;
  border: 1px solid #fca5a5; border-radius: 5px;
  cursor: pointer; padding: 0.25rem 0.65rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.delete-story-btn:hover { background: #fee2e2; border-color: #dc2626; }
.delete-story-btn:disabled { opacity: 0.4; cursor: not-allowed; }
[data-theme="dark"] .delete-story-btn { border-color: #7f1d1d; color: #f87171; }
[data-theme="dark"] .delete-story-btn:hover { background: #450a0a; border-color: #ef4444; }

/* ══════════════════════════════════════════════════════════════
   Landing Page  (mobile-first)
   Two-column grid: [Logo + Sidebar] | [Nav + Main]
   ══════════════════════════════════════════════════════════════ */

/* ── Page wrapper ── */
.lp-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

@media (min-width: 900px) {
  .lp-page {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 1fr;
    align-items: start;
    min-height: 100vh;
  }
}

/* ══════════════
   LEFT COLUMN
   ══════════════ */

/* Hidden on mobile — logo lives in the nav bar */
.lp-left {
  display: none;
}

@media (min-width: 900px) {
  .lp-left {
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    background: var(--lw-sidebar);
    border-right: 1px solid var(--lw-border);
  }
}

/* Logo area — top of left column, same height as nav */
.lp-logo-area {
  height: 58px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--lw-border);
  background: var(--lw-bg);
}

.lp-logo {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--lw-accent);
  text-decoration: none;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  transition: opacity 0.15s;
}
.lp-logo::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lw-accent);
  flex-shrink: 0;
}
.lp-logo:hover { opacity: 0.7; }

/* Sidebar scroll area */
.lp-sidebar {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0.85rem 4rem;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: var(--lw-border) transparent;
}
/* Fade at bottom */
.lp-left::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 240px;
  height: 3.5rem;
  background: linear-gradient(to bottom, transparent, var(--lw-sidebar));
  pointer-events: none;
  z-index: 2;
}

.lp-sidebar-heading {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--lw-accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--lw-border);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.lp-sidebar-heading::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--lw-accent);
  flex-shrink: 0;
}

.lp-recent-list { list-style: none; }

/* Sidebar chapter row — animated left-edge accent bar */
.lp-recent-item {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.5rem 0.5rem 0.5rem 0.8rem;
  border-radius: 7px;
  text-decoration: none;
  cursor: pointer;
  position: relative;
  transition: background 0.14s;
  min-height: 44px;
  justify-content: center;
  margin-bottom: 0.05rem;
}
.lp-recent-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%) scaleY(0);
  width: 2px;
  height: 60%;
  background: var(--lw-accent);
  border-radius: 2px;
  transition: transform 0.16s ease;
}
.lp-recent-item:hover { background: var(--lw-surface); }
.lp-recent-item:hover::before { transform: translateY(-50%) scaleY(1); }

.lp-recent-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lp-recent-meta {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.05rem;
}
.lp-recent-story {
  font-size: 0.7rem;
  color: var(--lw-accent);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.lp-recent-dot { font-size: 0.7rem; color: var(--lw-border); flex-shrink: 0; line-height: 1; }
.lp-recent-date { font-size: 0.67rem; color: var(--text-muted); flex-shrink: 0; }
.lp-sidebar-empty { font-size: 0.85rem; color: var(--text-muted); padding: 0.25rem 0.5rem; }

/* ══════════════
   RIGHT COLUMN
   ══════════════ */

.lp-right {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Sticky Nav ── */
.lp-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 1rem;
  /* glassmorphism */
  background: rgba(253, 248, 242, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(217, 184, 154, 0.55);
  box-shadow: 0 1px 0 rgba(217,184,154,0.3), 0 4px 18px rgba(0,0,0,0.06);
}
[data-theme="dark"] .lp-nav {
  background: rgba(24, 24, 27, 0.88);
  border-bottom-color: rgba(63, 63, 70, 0.6);
  box-shadow: 0 1px 0 rgba(63,63,70,0.4), 0 4px 18px rgba(0,0,0,0.3);
}
[data-theme="sepia"] .lp-nav {
  background: rgba(244, 237, 224, 0.9);
  border-bottom-color: rgba(201, 169, 122, 0.5);
}

/* Logo inside nav — mobile only; hidden on desktop (logo is in lp-left) */
.lp-nav-logo {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--lw-accent);
  text-decoration: none;
  letter-spacing: -0.03em;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: opacity 0.15s;
}
.lp-nav-logo::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lw-accent);
  flex-shrink: 0;
}
.lp-nav-logo:hover { opacity: 0.7; }

@media (min-width: 900px) {
  /* Logo moves to lp-left on desktop; hide it from nav */
  .lp-nav-logo { display: none; }
  /* But keep it visible when nav is used standalone (no sidebar) */
  .lp-nav--standalone .lp-nav-logo { display: flex; }
}

/* Story links — scrollable row */
.lp-nav-links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to right, black 90%, transparent 100%);
  -webkit-mask-image: linear-gradient(to right, black 90%, transparent 100%);
}
.lp-nav-links::-webkit-scrollbar { display: none; }

.lp-nav-link {
  padding: 0.35rem 0.8rem;
  border-radius: 99px;
  border: 1px solid transparent;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.16s, color 0.16s, border-color 0.16s;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.lp-nav-link:hover {
  background: var(--lw-surface);
  border-color: var(--lw-border);
  color: var(--lw-accent);
}

.lp-nav-end { flex-shrink: 0; }

/* ── Recent strip (mobile / tablet only) ── */
.lp-strip {
  background: var(--lw-sidebar);
  border-bottom: 1px solid var(--lw-border);
  padding: 0.85rem 0 1rem 1rem;
}
@media (min-width: 900px) {
  .lp-strip { display: none; }
}

.lp-strip-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--lw-accent);
  margin-bottom: 0.65rem;
  padding-right: 1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.lp-strip-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--lw-border);
  max-width: 3rem;
}

.lp-strip-scroll {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-right: 1rem;
  -webkit-overflow-scrolling: touch;
}
.lp-strip-scroll::-webkit-scrollbar { display: none; }

.lp-strip-card {
  flex-shrink: 0;
  width: 148px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--lw-border);
  border-top: 2px solid transparent;
  border-radius: 10px;
  background: var(--lw-bg);
  text-decoration: none;
  cursor: pointer;
  transition: border-top-color 0.2s, box-shadow 0.2s, transform 0.15s;
  min-height: 44px;
}
.lp-strip-card:hover {
  border-top-color: var(--lw-accent);
  box-shadow: 0 4px 14px var(--shadow);
  transform: translateY(-2px);
}

.lp-strip-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lp-strip-story {
  font-size: 0.7rem;
  color: var(--lw-accent);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lp-strip-date { font-size: 0.67rem; color: var(--text-muted); margin-top: 0.1rem; }
.lp-strip-empty { font-size: 0.85rem; color: var(--text-muted); padding-right: 1rem; }

/* ── Main content ── */
.lp-main {
  padding: 1.5rem 1rem 4rem;
  min-width: 0;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}
@media (min-width: 600px) { .lp-main { padding: 2rem 1.5rem 4rem; } }
@media (min-width: 900px) { .lp-main { padding: 2.25rem 1.75rem 5rem; } }

.lp-main-header { margin-bottom: 1.5rem; }
.lp-main-header h1 {
  font-size: clamp(1.35rem, 5vw, 2.1rem);
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.3rem;
}
.lp-main-header p { color: var(--text-muted); font-size: 0.95rem; }
.lp-rule {
  display: block;
  width: 2.5rem;
  height: 3px;
  background: var(--lw-accent);
  border-radius: 2px;
  margin-top: 0.6rem;
}

.lp-sort-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Mobile-first grid: 1 col → 2 col → auto-fill */
.lp-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 540px) { .lp-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .lp-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); } }

.lp-empty { padding: 3rem 0; color: var(--text-muted); font-size: 0.95rem; }

/* ── Sidebar collection dropdowns ── */
.lp-coll-dropdown { border-bottom: 1px solid var(--lw-border); }
.lp-coll-dropdown:last-child { border-bottom: none; }
.lp-coll-summary {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.55rem 0.5rem; cursor: pointer; list-style: none;
  border-radius: 6px; transition: background 0.12s; min-height: 44px;
}
.lp-coll-summary::-webkit-details-marker, .lp-coll-summary::marker { display: none; }
.lp-coll-summary:hover { background: var(--lw-surface); }
.lp-coll-summary-title { font-size: 0.82rem; font-weight: 600; color: var(--text); flex: 1; line-height: 1.3; }
.lp-coll-summary-count {
  font-size: 0.65rem; font-weight: 700; color: var(--lw-accent);
  background: var(--lw-surface); border: 1px solid var(--lw-border);
  border-radius: 99px; padding: 0.05rem 0.45rem; flex-shrink: 0;
}
.lp-coll-dropdown[open] .lp-coll-summary-title { color: var(--lw-accent); }
.lp-coll-chapter-list { list-style: none; padding: 0.15rem 0 0.5rem 0.6rem; }
.lp-coll-chapter-link {
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.3rem 0.4rem; border-radius: 5px; text-decoration: none;
  transition: background 0.1s; min-height: 32px;
}
.lp-coll-chapter-link:hover { background: var(--lw-surface); }
.lp-coll-ch-num { font-size: 0.65rem; font-weight: 700; color: var(--text-muted); min-width: 1.2rem; text-align: right; flex-shrink: 0; }
.lp-coll-ch-title { font-size: 0.8rem; color: var(--text); line-height: 1.3; }

/* ── Main collection sections ── */
.lp-collection-section {
  padding-bottom: 2.5rem; margin-bottom: 2rem;
  border-bottom: 1px solid var(--lw-border);
}
.lp-collection-section:last-child { border-bottom: none; margin-bottom: 0; }
.lp-collection-header { margin-bottom: 1rem; }
.lp-collection-title {
  display: block; font-size: clamp(1.25rem, 4vw, 1.75rem); font-weight: 800;
  color: var(--text); text-decoration: none; line-height: 1.2;
  margin-bottom: 0.4rem; transition: color 0.15s;
}
.lp-collection-title:hover { color: var(--lw-accent); }
.lp-collection-desc { font-size: 0.9rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 0.6rem; max-width: 60ch; }
.lp-collection-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.lp-collection-ch-list {
  list-style: none; border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; margin-bottom: 1.25rem;
}
.lp-collection-ch-item {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.85rem 1.25rem; border-bottom: 1px solid var(--border);
  text-decoration: none; transition: background 0.12s;
}
.lp-collection-ch-list li:last-child .lp-collection-ch-item { border-bottom: none; }
.lp-collection-ch-item:hover { background: var(--bg-surface); }
.lp-collection-start-btn {
  display: inline-block; padding: 0.6rem 1.25rem; background: var(--lw-accent);
  color: #fff; border-radius: 8px; text-decoration: none;
  font-weight: 600; font-size: 0.9rem; transition: background 0.15s;
}
.lp-collection-start-btn:hover { background: var(--lw-accent-hover); }

/* ── Search ── */
.lp-search {
  position: relative;
  margin-bottom: 1.75rem;
}
.lp-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.lp-search-icon {
  position: absolute;
  left: 0.75rem;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
.lp-search-input {
  width: 100%;
  padding: 0.65rem 1rem 0.65rem 2.4rem;
  border: 1px solid var(--lw-border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lp-search-input::placeholder { color: var(--text-muted); }
.lp-search-input:focus {
  border-color: var(--lw-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--lw-accent) 18%, transparent);
}
.lp-search-results {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--lw-border);
  border-radius: 10px;
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 200;
  overflow: hidden;
}
.lp-search-section { padding: 0.6rem 0; }
.lp-search-section + .lp-search-section { border-top: 1px solid var(--border); }
.lp-search-section-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0 1rem 0.4rem;
}
.lp-search-list { list-style: none; }
.lp-search-item {
  display: block;
  padding: 0.45rem 1rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.1s;
  cursor: pointer;
}
.lp-search-item:hover { background: var(--bg-surface); }
.lp-search-item-title { font-size: 0.9rem; font-weight: 600; line-height: 1.3; }
.lp-search-item-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; }
.lp-search-mark { background: transparent; color: var(--lw-accent); font-weight: 700; }
.lp-search-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ══════════════════════════════════════════════════════════════
   Reader Area Theme  (independent from site chrome)
   Applies only to .reader-main and its descendants.
   Scoped via [data-reader-theme] on <html> — set by anti-FOUC
   script in <head> and updated by ReaderThemeSwitcher.
   ══════════════════════════════════════════════════════════════ */

/* Default: sepia reading area */
.reader-main {
  background: #f4ede0;
  transition: background 0.25s, color 0.25s;
  /* Override all inherited CSS vars so every descendant uses reader colors */
  --bg:           #f4ede0;
  --bg-surface:   #ede3ce;
  --text:         #3b2f1e;
  --text-muted:   #6b5744;
  --border:       #c9a97a;
  --accent:       #7c5c2e;
  --accent-hover: #5e4420;
  --toc-active-bg:#e6d9c2;
  --shadow:       rgba(60,40,10,0.12);
}

/* Dark reading area (warm sepia-dark) */
[data-reader-theme="dark"] .reader-main {
  background: #1e1408;
  --bg:           #1e1408;
  --bg-surface:   #281c0e;
  --text:         #e8d5b0;
  --text-muted:   #9e7c54;
  --border:       #3d2910;
  --accent:       #c8862a;
  --accent-hover: #d9973d;
  --toc-active-bg:#2e1a08;
  --shadow:       rgba(0,0,0,0.5);
}

/* ── Chapter header controls row ── */
.chapter-header-controls {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ── Reader Theme Switcher ── */
.reader-theme-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reader-theme-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-right: 0.25rem;
  user-select: none;
}

.reader-theme-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  padding: 0;
  flex-shrink: 0;
}
.reader-theme-btn:hover { transform: scale(1.12); border-color: var(--text-muted); }
.reader-theme-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.reader-theme-btn[data-reader-theme-value="sepia"] { background: #f4ede0; }
.reader-theme-btn[data-reader-theme-value="dark"]  { background: #1e1408; }
