/* Water Magician archive reader */
:root {
  --bg: #0b0f1a;
  --paper: #121828;
  --text: #d6d8e0;
  --muted: #8b90a3;
  --accent: #7aa2f7;
  --border: rgba(214, 216, 224, 0.14);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --reader-font: "Charter", "Georgia", "Times New Roman", serif;
  --reader-size: 18px;
  --reader-lh: 1.8;
}
[data-theme="light"] {
  --bg: #f4f4f5;
  --paper: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #3b62d6;
  --border: rgba(31, 41, 55, 0.14);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
[data-theme="sepia"] {
  --bg: #efe6d0;
  --paper: #f8f0dd;
  --text: #4a3a28;
  --muted: #8a7a63;
  --accent: #a26b1f;
  --border: rgba(74, 58, 40, 0.16);
  --shadow: 0 8px 30px rgba(74, 58, 40, 0.12);
}
[data-theme="midnight"] {
  --bg: #0f172a;
  --paper: #1b2540;
  --text: #cbd5e1;
  --muted: #7d8aa5;
  --accent: #818cf8;
  --border: rgba(203, 213, 225, 0.13);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
[data-theme="amoled"] {
  --bg: #000000;
  --paper: #000000;
  --text: #e5e5e5;
  --muted: #8a8a8a;
  --accent: #64b5f6;
  --border: rgba(229, 229, 229, 0.16);
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  transition: background-color 0.2s, color 0.2s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 8px;
}
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar .spacer { flex: 1; }
.topbar .novel-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 14px;
  border-radius: 8px;
  white-space: nowrap;
}
.icon-btn:hover { text-decoration: none; }

/* ---------- reader ---------- */
.reader-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 120px;
}
.paper {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px clamp(18px, 5vw, 48px) 40px;
}
.chapter-heading {
  margin: 0 0 4px;
  font-size: clamp(21px, 4vw, 27px);
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.chapter-sub {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.content {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
}
.content p { margin: 0 0 1.1em; }
.content p.img { text-align: center; }
.content img { max-width: 100%; height: auto; border-radius: 8px; }

/* ---------- bottom nav ---------- */
.bottomnav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.bottomnav a, .bottomnav button {
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 500;
  border-radius: 10px;
  text-align: center;
}
.bottomnav a:hover { text-decoration: none; border-color: var(--accent); }
.bottomnav .disabled { opacity: 0.35; pointer-events: none; }
.bottomnav .jump-label { color: var(--muted); font-size: 13px; }
.bottomnav select { padding: 9px 10px; font-size: 14px; max-width: 46vw; }

/* ---------- settings panel ---------- */
.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  width: min(340px, 88vw);
  background: var(--paper);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
body.panel-open .panel { transform: translateX(0); }
body.panel-open .panel-backdrop { opacity: 1; pointer-events: auto; }
.panel h2 { margin: 0 0 18px; font-size: 17px; }
.panel .group { margin-bottom: 22px; }
.panel .group > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme-swatch {
  padding: 10px 6px;
  font-size: 12.5px;
  border-radius: 10px;
  border: 2px solid var(--border);
  text-align: center;
}
.theme-swatch.active { border-color: var(--accent); }
.swatch-dot {
  display: block;
  width: 100%;
  height: 22px;
  border-radius: 6px;
  margin-bottom: 6px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}
.fontsize-row { display: flex; align-items: center; gap: 10px; }
.fontsize-row button { flex: 1; padding: 8px 0; font-weight: 600; }
.fontsize-row .val { min-width: 44px; text-align: center; color: var(--muted); font-size: 14px; }
.panel select { width: 100%; padding: 9px 10px; }
.panel input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- index page ---------- */
.hero {
  display: flex;
  gap: 22px;
  max-width: 900px;
  margin: 28px auto 8px;
  padding: 0 16px;
}
.hero img.cover {
  width: 130px;
  height: 174px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.hero h1 { margin: 0 0 6px; font-size: clamp(24px, 5vw, 34px); letter-spacing: -0.02em; }
.hero .meta { color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.hero .genres { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.hero .genre {
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
}
.hero .summary { font-size: 14.5px; color: var(--text); opacity: 0.9; max-width: 60ch; }
.continue-btn {
  display: inline-block;
  margin-top: 14px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14.5px;
}
.continue-btn:hover { text-decoration: none; filter: brightness(1.1); }

.list-controls {
  position: sticky;
  top: 49px;
  z-index: 40;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: 900px;
  margin: 22px auto 12px;
  padding: 10px 16px;
  background: var(--bg);
}
.list-controls input[type="search"] {
  flex: 1;
  padding: 10px 14px;
  font-size: 14.5px;
  border-radius: 10px;
}
.list-controls button { padding: 10px 14px; font-size: 13.5px; white-space: nowrap; }
.chapter-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

.chapter-list {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 80px;
  list-style: none;
}
.chapter-list li { border-bottom: 1px solid var(--border); }
.chapter-list a {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 8px;
  color: var(--text);
  border-radius: 8px;
}
.chapter-list a:hover { background: var(--paper); text-decoration: none; }
.chapter-list .num {
  flex-shrink: 0;
  width: 44px;
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.chapter-list .name { font-size: 15px; }
.chapter-list li.read .name { color: var(--muted); }
.chapter-list li.read .name::after {
  content: "✓";
  margin-left: 8px;
  color: var(--accent);
  font-size: 12.5px;
}
.no-results { text-align: center; color: var(--muted); padding: 40px 0; display: none; }

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  padding: 30px 16px 40px;
  border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
  .hero { flex-direction: column; align-items: center; text-align: center; }
  .hero .genres { justify-content: center; }
  .topbar .novel-title { display: none; }
  .list-controls { top: 53px; flex-wrap: wrap; }
}
