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

:root {
  --primary: #8B0000;
  --primary-light: #a52a2a;
  --accent: #C0C0C0;
  --bg: #0a0a0a;
  --bg-card: #141414;
  --bg-elevated: #1a1a1a;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #2a2a2a;
  --radius: 8px;
  --radius-lg: 12px;
  --max-width: 1100px;
  --nav-height: 56px;
  /* Chapter theme vars (overridden by JS) */
  --chapter-bg: #1a1a1a;
  --chapter-text: #d4d4d4;
  --chapter-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --chapter-size: 18px;
  --chapter-lh: 1.8;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* === Nav === */
.site-nav {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,10,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: var(--max-width); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: var(--nav-height);
}
.nav-logo {
  font-size: 1.25rem; font-weight: 700;
  color: var(--primary-light);
  letter-spacing: -0.02em;
}
.nav-links { display: flex; gap: 24px; }
.nav-links a { color: var(--text-muted); font-size: 0.9rem; transition: color 0.2s; }
.nav-links a:hover { color: var(--text); }
.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 4px; }
.nav-toggle span { display: block; width: 20px; height: 2px; background: var(--text); margin: 4px 0; transition: 0.2s; }

@media (max-width: 640px) {
  .nav-links { display: none; position: absolute; top: var(--nav-height); left: 0; right: 0; background: var(--bg-elevated); flex-direction: column; padding: 16px; gap: 16px; border-bottom: 1px solid var(--border); }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
}

/* === Buttons === */
.btn {
  display: inline-block; padding: 10px 24px;
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-align: center;
}
.btn:hover { background: var(--primary-light); }
.btn:active { transform: scale(0.98); }
.btn-large { padding: 14px 32px; font-size: 1rem; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--text-muted); background: var(--bg-elevated); }
.btn-outline.active { border-color: var(--primary); color: var(--primary-light); }
.btn-nav { padding: 8px 16px; font-size: 0.85rem; background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-nav:hover { background: var(--bg-card); }
.btn-nav.disabled { opacity: 0.3; pointer-events: none; }

/* === Hero === */
.hero {
  text-align: center; padding: 80px 16px 60px;
  background: linear-gradient(180deg, rgba(139,0,0,0.15) 0%, transparent 100%);
}
.hero h1 { font-size: 2.5rem; font-weight: 700; letter-spacing: -0.03em; margin-bottom: 8px; }
.hero-tagline { color: var(--text-muted); font-size: 1.1rem; }

/* === Sections === */
.section { max-width: var(--max-width); margin: 0 auto; padding: 40px 16px; }
.section-title { font-size: 1.3rem; font-weight: 600; margin-bottom: 20px; letter-spacing: -0.02em; }

/* === Novel Cards === */
.novel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.novel-card {
  display: flex; gap: 14px; padding: 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); transition: border-color 0.2s, transform 0.2s;
}
.novel-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.novel-card-cover { flex-shrink: 0; width: 80px; height: 110px; border-radius: var(--radius); overflow: hidden; }
.novel-card-placeholder {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--primary) 0%, #2a0a0a 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: rgba(255,255,255,0.6);
}
.novel-card-placeholder.large { width: 200px; height: 280px; font-size: 4rem; }
.novel-card-placeholder.small { width: 50px; height: 70px; font-size: 1.2rem; }
.novel-card-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.novel-card-info h3 { font-size: 0.95rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.novel-card-meta { font-size: 0.8rem; color: var(--text-muted); text-transform: capitalize; }
.novel-card-stats { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 12px; margin-top: auto; }
.star { color: #f5a623; }

/* === Genre Tags === */
.genre-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.genre-tag {
  padding: 8px 18px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; font-size: 0.85rem; text-transform: capitalize;
  transition: border-color 0.2s, background 0.2s;
}
.genre-tag:hover { border-color: var(--primary); background: var(--bg-elevated); }

/* === CTA Box === */
.cta-box {
  text-align: center; padding: 48px 24px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.cta-box h2 { font-size: 1.5rem; margin-bottom: 12px; }
.cta-box p { color: var(--text-muted); margin-bottom: 24px; max-width: 500px; margin-left: auto; margin-right: auto; }

/* === Badge / Tag === */
.badge { display: inline-block; padding: 4px 10px; font-size: 0.75rem; border-radius: 4px; background: var(--bg-elevated); border: 1px solid var(--border); text-transform: capitalize; }
.badge-status { background: rgba(139,0,0,0.2); border-color: var(--primary); color: var(--primary-light); }
.tag { font-size: 0.8rem; color: var(--text-muted); }

/* === Novel Detail === */
.novel-detail { max-width: var(--max-width); margin: 0 auto; padding: 32px 16px; }
.novel-header { display: flex; gap: 24px; margin-bottom: 32px; }
.novel-cover-large { flex-shrink: 0; }
.novel-info { display: flex; flex-direction: column; gap: 12px; }
.novel-info h1 { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.novel-author a { color: var(--primary-light); }
.novel-author a:hover { text-decoration: underline; }
.novel-meta-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 0.85rem; }
.novel-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.novel-synopsis { margin-bottom: 32px; }
.novel-synopsis h2 { font-size: 1.2rem; margin-bottom: 12px; }
.novel-synopsis p { color: var(--text-muted); line-height: 1.7; }

@media (max-width: 640px) {
  .novel-header { flex-direction: column; align-items: center; text-align: center; }
  .novel-meta-row { justify-content: center; }
  .novel-tags { justify-content: center; }
}

/* === Chapter List === */
.chapter-list-section h2 { font-size: 1.2rem; margin-bottom: 16px; }
.chapter-list { display: flex; flex-direction: column; gap: 2px; }
.chapter-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--bg-card); border-radius: var(--radius);
  transition: background 0.15s;
}
.chapter-list-item:hover { background: var(--bg-elevated); }
.chapter-num { font-size: 0.9rem; }
.chapter-words { font-size: 0.8rem; color: var(--text-muted); }

/* === Chapter Reading Page === */
.chapter-progress-bar {
  position: fixed; top: 0; left: 0; height: 3px; width: 0%;
  background: var(--primary); z-index: 200; transition: width 0.1s linear;
}

.chapter-header {
  position: sticky; top: 0; z-index: 150;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: rgba(10,10,10,0.95);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--border);
  font-size: 0.85rem; transition: transform 0.3s;
}
.chapter-header.hidden { transform: translateY(-100%); }
.chapter-header-title { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70%; }
.chapter-header-num { color: var(--text-muted); flex-shrink: 0; }

.chapter-content {
  max-width: 720px; margin: 0 auto; padding: 32px 16px 100px;
  background: var(--chapter-bg); color: var(--chapter-text);
  font-family: var(--chapter-font); font-size: var(--chapter-size);
  line-height: var(--chapter-lh); min-height: 80vh;
}
.chapter-title { font-size: 1.4rem; font-weight: 600; margin-bottom: 24px; text-align: center; }
.chapter-body p { margin-bottom: 1.2em; }
.chapter-body em { font-style: italic; }

.chapter-bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  display: flex; justify-content: center; gap: 8px;
  padding: 10px 16px; background: rgba(10,10,10,0.95);
  backdrop-filter: blur(12px); border-top: 1px solid var(--border);
}

/* === Settings FAB & Panel === */
.settings-fab {
  position: fixed; bottom: 70px; right: 16px; z-index: 160;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text); font-size: 1.2rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.settings-fab:hover { background: var(--bg-card); }

.settings-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
  background: var(--bg-elevated); border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0; transform: translateY(100%);
  transition: transform 0.3s ease; max-height: 70vh; overflow-y: auto;
}
.settings-panel.open { transform: translateY(0); }
.settings-panel-inner { padding: 20px 16px 32px; max-width: 500px; margin: 0 auto; }
.settings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.settings-header h3 { font-size: 1rem; font-weight: 600; }
.settings-close { background: none; border: none; color: var(--text); font-size: 1.5rem; cursor: pointer; padding: 4px; }

.setting-group { margin-bottom: 18px; }
.setting-group label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.setting-options { display: flex; flex-wrap: wrap; gap: 6px; }
.setting-options button {
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); font-size: 0.85rem; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.setting-options button.active { border-color: var(--primary); background: rgba(139,0,0,0.2); color: var(--primary-light); }
.setting-options button:hover { border-color: var(--text-muted); }

.theme-swatch { min-width: 60px; text-align: center; }
.theme-swatch.light { background: #fff; color: #1a1a1a; border-color: #ccc; }
.theme-swatch.sepia { background: #f4ecd8; color: #5b4636; border-color: #d4c4a8; }
.theme-swatch.amoled { background: #000; color: #ccc; border-color: #333; }
.theme-swatch.dark { background: #1a1a1a; color: #d4d4d4; border-color: #444; }

/* === Ranking === */
.page-header { max-width: var(--max-width); margin: 0 auto; padding: 40px 16px 20px; }
.page-header h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 4px; }
.page-header p { color: var(--text-muted); }

.ranking-tabs { max-width: var(--max-width); margin: 0 auto; padding: 0 16px 16px; display: flex; gap: 8px; }
.ranking-tab {
  padding: 8px 18px; border-radius: 20px; font-size: 0.85rem;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; transition: 0.2s;
}
.ranking-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.ranking-list { max-width: var(--max-width); margin: 0 auto; padding: 0 16px 40px; display: flex; flex-direction: column; gap: 8px; }
.ranking-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); transition: border-color 0.2s;
}
.ranking-item:hover { border-color: var(--primary); }
.ranking-num { font-size: 1.1rem; font-weight: 700; color: var(--text-muted); min-width: 36px; text-align: center; }
.ranking-cover { flex-shrink: 0; }
.ranking-info { min-width: 0; }
.ranking-info h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 2px; }

/* === Author === */
.author-profile { max-width: var(--max-width); margin: 0 auto; padding: 40px 16px; }
.author-header { display: flex; gap: 20px; align-items: center; margin-bottom: 20px; }
.author-avatar {
  width: 80px; height: 80px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary) 0%, #2a0a0a 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; font-weight: 700; color: rgba(255,255,255,0.6);
}
.author-info h1 { font-size: 1.5rem; font-weight: 700; }
.author-stats { font-size: 0.85rem; color: var(--text-muted); }
.author-bio { color: var(--text-muted); line-height: 1.7; margin-bottom: 32px; }

/* === Blog === */
.blog-grid { max-width: var(--max-width); margin: 0 auto; padding: 0 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.blog-card {
  display: block; padding: 24px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  transition: border-color 0.2s;
}
.blog-card:hover { border-color: var(--primary); }
.blog-card h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 6px; }
.blog-card-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }
.blog-card-desc { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }

.blog-article { max-width: 720px; margin: 0 auto; padding: 40px 16px; }
.blog-header { margin-bottom: 32px; }
.blog-header h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 8px; }
.blog-meta { font-size: 0.85rem; color: var(--text-muted); }
.blog-footer { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--border); }

/* === Prose (blog/page content) === */
.prose h2 { font-size: 1.3rem; font-weight: 600; margin: 24px 0 12px; }
.prose h3 { font-size: 1.1rem; font-weight: 600; margin: 20px 0 8px; }
.prose p { margin-bottom: 16px; line-height: 1.7; color: var(--text-muted); }
.prose ul, .prose ol { margin: 0 0 16px 24px; color: var(--text-muted); }
.prose li { margin-bottom: 6px; line-height: 1.6; }
.prose strong { color: var(--text); font-weight: 600; }

/* === Static Page === */
.static-page { max-width: 720px; margin: 0 auto; padding: 40px 16px; }
.static-page h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 24px; }

/* === 404 === */
.error-page { text-align: center; padding: 120px 16px; }
.error-page h1 { font-size: 6rem; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.error-page p { color: var(--text-muted); margin-bottom: 24px; font-size: 1.1rem; }

/* === Footer === */
.site-footer { border-top: 1px solid var(--border); margin-top: 60px; }
.footer-inner { max-width: var(--max-width); margin: 0 auto; padding: 40px 16px; text-align: center; }
.footer-brand a { font-size: 1.1rem; font-weight: 700; color: var(--primary-light); }
.footer-brand p { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.footer-links { display: flex; justify-content: center; gap: 20px; margin: 20px 0; }
.footer-links a { font-size: 0.85rem; color: var(--text-muted); transition: color 0.2s; }
.footer-links a:hover { color: var(--text); }
.footer-copy { font-size: 0.75rem; color: var(--text-muted); }

/* === Chapter Theme Overrides === */
body.theme-light { --chapter-bg: #ffffff; --chapter-text: #1a1a1a; }
body.theme-light .chapter-header { background: rgba(255,255,255,0.95); border-color: #e0e0e0; }
body.theme-light .chapter-header-title, body.theme-light .chapter-header-num { color: #666; }
body.theme-light .chapter-bottom-nav { background: rgba(255,255,255,0.95); border-color: #e0e0e0; }
body.theme-light .btn-nav { background: #f5f5f5; color: #1a1a1a; border-color: #e0e0e0; }
body.theme-light .settings-fab { background: #f5f5f5; border-color: #e0e0e0; color: #1a1a1a; }
body.theme-light .settings-panel { background: #fff; border-color: #e0e0e0; }
body.theme-light .setting-options button { background: #f5f5f5; border-color: #e0e0e0; color: #1a1a1a; }
body.theme-light .settings-close { color: #1a1a1a; }
body.theme-light .settings-header h3 { color: #1a1a1a; }
body.theme-light .setting-group label { color: #666; }
body.theme-light { background: #ffffff; }

body.theme-sepia { --chapter-bg: #f4ecd8; --chapter-text: #5b4636; }
body.theme-sepia .chapter-header { background: rgba(244,236,216,0.95); border-color: #d4c4a8; }
body.theme-sepia .chapter-header-title, body.theme-sepia .chapter-header-num { color: #8b7355; }
body.theme-sepia .chapter-bottom-nav { background: rgba(244,236,216,0.95); border-color: #d4c4a8; }
body.theme-sepia .btn-nav { background: #ede5d0; color: #5b4636; border-color: #d4c4a8; }
body.theme-sepia .settings-fab { background: #ede5d0; border-color: #d4c4a8; color: #5b4636; }
body.theme-sepia .settings-panel { background: #f4ecd8; border-color: #d4c4a8; }
body.theme-sepia .setting-options button { background: #ede5d0; border-color: #d4c4a8; color: #5b4636; }
body.theme-sepia .settings-close { color: #5b4636; }
body.theme-sepia .settings-header h3 { color: #5b4636; }
body.theme-sepia .setting-group label { color: #8b7355; }
body.theme-sepia { background: #f4ecd8; }

body.theme-amoled { --chapter-bg: #000000; --chapter-text: #cccccc; }
body.theme-amoled .chapter-header { background: rgba(0,0,0,0.98); border-color: #1a1a1a; }
body.theme-amoled .chapter-bottom-nav { background: rgba(0,0,0,0.98); border-color: #1a1a1a; }
body.theme-amoled .btn-nav { background: #0a0a0a; border-color: #1a1a1a; }
body.theme-amoled .settings-fab { background: #0a0a0a; border-color: #1a1a1a; }
body.theme-amoled .settings-panel { background: #0a0a0a; border-color: #1a1a1a; }
body.theme-amoled .setting-options button { background: #111; border-color: #222; color: #ccc; }
body.theme-amoled { background: #000000; }
/* Cross-links */
.related-novels { margin-top: 3rem; }
.related-novels h2 { margin-bottom: 1rem; font-size: 1.3rem; }
.novel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.novel-card-link { text-decoration: none; color: inherit; }
.novel-card-link:hover .novel-card { opacity: 0.85; }
.chapter-related { margin: 2rem auto; max-width: 700px; padding: 1.5rem; border-top: 1px solid rgba(255,255,255,0.1); }
.chapter-related h3 { margin-bottom: 0.8rem; font-size: 1.1rem; opacity: 0.7; }
.chapter-related-list { display: flex; flex-direction: column; gap: 0.6rem; }
.chapter-related-item { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.8rem; border-radius: 6px; background: rgba(255,255,255,0.04); text-decoration: none; color: inherit; transition: background 0.2s; }
.chapter-related-item:hover { background: rgba(255,255,255,0.08); }
.chapter-related-item strong { font-size: 0.95rem; }
.chapter-related-item span { font-size: 0.8rem; opacity: 0.6; white-space: nowrap; margin-left: 1rem; }

/* Blog → Novel internal links */
.blog-novel-picks { margin-top: 2rem; padding: 1.5rem; background: rgba(99,102,241,0.08); border-radius: 10px; border-left: 3px solid #6366f1; }
.blog-novel-picks h3 { margin: 0 0 0.8rem; font-size: 1.1rem; }
.blog-novel-picks ul { margin: 0; padding-left: 1.2rem; }
.blog-novel-picks li { margin-bottom: 0.4rem; }
.blog-novel-picks a { color: #818cf8; text-decoration: none; font-weight: 500; }
.blog-novel-picks a:hover { text-decoration: underline; }
