:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --border: #2d3045;
  --text: #e2e4ef;
  --muted: #8b8fa8;
  --accent: #7c6af7;
  --accent2: #5b9cf6;
  --success: #4caf7d;
  --error: #e05c5c;
  --font-size: 1rem;
}
[data-theme="light"] {
  --bg: #f5f5f0;
  --bg2: #ffffff;
  --border: #d0d0cc;
  --text: #1a1a1a;
  --muted: #666660;
  --accent: #5b4de0;
  --accent2: #2563eb;
  --success: #2e7d4f;
  --error: #c0392b;
}
[data-theme="sepia"] {
  --bg: #f4efe6;
  --bg2: #fdf8f0;
  --border: #d6c9ae;
  --text: #3b2f1e;
  --muted: #7a6a55;
  --accent: #8b5e3c;
  --accent2: #6b4c2a;
  --success: #3a6b3a;
  --error: #a83232;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: "Noto Sans TC", "Source Han Sans", system-ui, sans-serif; line-height: 1.7; font-size: var(--font-size); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 2rem; background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-size: 1.1rem; font-weight: 600; color: var(--text); }
nav a:not(.logo) { font-size: 0.9rem; background: var(--accent); color: #fff; padding: 0.4rem 0.9rem; border-radius: 6px; }
nav a:not(.logo):hover { text-decoration: none; opacity: 0.85; }

main { max-width: 860px; margin: 2rem auto; padding: 0 1.5rem; }
h1 { font-size: 1.6rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; }

.novel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.novel-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 1.2rem; display: flex; flex-direction: column; gap: 0.6rem;
}
.novel-card h2 { font-size: 1rem; margin: 0; }
.novel-card h2 a { color: var(--text); }
.novel-card h2 a:hover { color: var(--accent2); }
.progress-bar { background: var(--border); border-radius: 4px; height: 6px; overflow: hidden; }
.progress-fill { background: linear-gradient(90deg, var(--accent), var(--accent2)); height: 100%; border-radius: 4px; transition: width 0.5s; }
.progress-text { font-size: 0.82rem; color: var(--muted); }
.source-link { font-size: 0.82rem; color: var(--muted); }

.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-bottom: 1rem; }
.breadcrumb a { color: var(--muted); }

.chapter-list { list-style: none; display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.5rem; }
.chapter-list li a {
  display: block; padding: 0.5rem 0.75rem; border-radius: 6px;
  color: var(--text); font-size: 0.92rem; border: 1px solid transparent;
}
.chapter-list li a:hover { background: var(--bg2); border-color: var(--border); text-decoration: none; }

.chapter-content {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 2rem; margin: 1rem 0;
}
.chapter-content pre {
  white-space: pre-wrap; word-break: break-word;
  font-family: inherit; font-size: inherit; line-height: 2;
}
.chapter-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 1.5rem; gap: 0.5rem; }
.nav-btn {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  padding: 0.5rem 1.2rem; border-radius: 6px; font-size: 0.9rem;
}
.nav-btn:hover { background: var(--border); text-decoration: none; }
.nav-btn.center { color: var(--accent2); }

.subscribe-form { display: flex; flex-direction: column; gap: 0.7rem; max-width: 480px; margin-bottom: 1.5rem; }
.subscribe-form label { font-size: 0.9rem; color: var(--muted); }
.subscribe-form input {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  padding: 0.6rem 0.9rem; border-radius: 6px; font-size: 0.95rem; width: 100%;
}
.subscribe-form input:focus { outline: none; border-color: var(--accent); }
.subscribe-form button {
  background: var(--accent); color: #fff; border: none;
  padding: 0.6rem 1.5rem; border-radius: 6px; cursor: pointer; font-size: 0.95rem; align-self: flex-start;
}
.subscribe-form button:hover { opacity: 0.85; }
.msg { padding: 0.6rem 0.9rem; border-radius: 6px; font-size: 0.9rem; }
.msg.success { background: #1a3d2b; color: var(--success); }
.msg.error { background: #3d1a1a; color: var(--error); }

/* Settings panel */
.settings-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 0.35rem 0.7rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.settings-btn:hover { border-color: var(--accent); color: var(--text); }
.settings-panel {
  display: none; position: absolute; top: 100%; right: 0; z-index: 100;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px;
  padding: 1rem; min-width: 220px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.settings-panel.open { display: block; }
.settings-panel label { font-size: 0.8rem; color: var(--muted); display: block; margin-bottom: 0.4rem; }
.settings-panel .row { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.theme-btn, .font-btn {
  flex: 1; padding: 0.4rem 0; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.theme-btn:hover, .font-btn:hover { border-color: var(--accent); }
.theme-btn.active, .font-btn.active { border-color: var(--accent); background: var(--accent); color: #fff; }
nav { position: relative; }

/* Backfill panel */
.backfill-panel { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; margin: 1.5rem 0; }
.backfill-panel h2 { font-size: 1rem; margin: 0 0 0.8rem; color: var(--muted); }
.backfill-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.backfill-panel input[type=number] { width: 80px; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 0.4rem 0.6rem; border-radius: 6px; font-size: 0.9rem; }
.backfill-panel input[type=number]:focus { outline: none; border-color: var(--accent); }
.bf-btn { background: var(--accent); color: #fff; border: none; padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.bf-btn.stop { background: var(--error); }
.bf-btn:hover { opacity: 0.85; }
.bf-status { font-size: 0.85rem; color: var(--muted); }
.bf-status span.running { color: var(--success); }
.bf-status span.paused { color: var(--accent2); }
.bf-status span.completed { color: var(--success); }
.bf-status span.stopped { color: var(--error); }

/* Reading progress */
.last-read-banner { background: var(--bg2); border: 1px solid var(--accent); border-radius: 8px; padding: 0.6rem 1rem; margin-bottom: 1rem; font-size: 0.9rem; }
.last-read-banner a { color: var(--accent); font-weight: 600; }
.chapter-list li.read a { color: var(--muted); }
.chapter-list li.current a { color: var(--accent2); font-weight: 600; }
.chapter-list li.current a::after { content: " ◀ 上次讀到"; font-size: 0.78rem; color: var(--accent); }
