:root {
  --bg: #f7f5f0; --panel: #ffffff; --text: #22211f; --muted: #8a867d;
  --line: #e4e0d6; --accent: #b4542c; --accent-text: #fff;
  --read: #b3afa5; --current: #fbeee6;
  --font: 19px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16171a; --panel: #1f2024; --text: #d9d6ce; --muted: #8b8a86;
  --line: #2f3036; --accent: #e07a4f; --accent-text: #16171a;
  --read: #5a5a5e; --current: #33261f;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jump { display: flex; }
.jump input { width: 90px; padding: 6px 8px; border: 1px solid var(--line); border-right: 0;
  border-radius: 8px 0 0 8px; background: var(--bg); }
.jump button { padding: 6px 12px; border: 0; border-radius: 0 8px 8px 0;
  background: var(--accent); color: var(--accent-text); cursor: pointer; font-weight: 600; }
.icon { border: 1px solid var(--line); background: none; border-radius: 8px; padding: 5px 9px; cursor: pointer; }

main { max-width: 820px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 1.6rem; margin: 6px 0 16px; line-height: 1.25; }

.btn { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer; font-weight: 500; text-align: center; user-select: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* Home */
.summary { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
#progressText { margin-bottom: 8px; color: var(--muted); }
.meter { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.meter span { display: block; height: 100%; background: var(--accent); width: 0; }
.markupto { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--muted); font-size: 14px; }
.markupto input { width: 90px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.tabtitle { font-size: 1.1rem; border-bottom: 2px solid var(--accent); display: inline-block; padding-bottom: 4px; margin: 26px 0 12px; }

details.group { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-bottom: 8px; }
details.group > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; justify-content: space-between; font-weight: 600; }
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary .count { color: var(--muted); font-weight: 400; font-size: 13px; }
details.group[open] > summary { border-bottom: 1px solid var(--line); }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 16px; padding: 6px 12px 10px; }
.list a { display: flex; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.list a .num { color: var(--muted); min-width: 3.2em; }
.list a .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list a.read { color: var(--read); }
.list a.read .num { color: var(--read); }
.list a.current { background: var(--current); border-radius: 6px; font-weight: 600; color: var(--text); }
.list a:hover .t { color: var(--accent); }

/* Reader */
.chnav { display: flex; justify-content: space-between; gap: 8px; }
.chnav .btn { flex: 1; }
.chnav.bottom { margin-top: 36px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px; }
.tools .grow { flex: 1; }
#chapter { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: var(--font); line-height: 1.75;
  user-select: text; -webkit-user-select: text; }
#chapter h1 { font-family: system-ui, sans-serif; margin-top: 22px; }
#chBody p { margin: 0 0 1em; overflow-wrap: break-word; }
#chapter.is-read h1::after { content: "  ✓ read"; font-size: .55em; color: var(--muted); font-weight: 400; vertical-align: middle; }
#endMark { height: 1px; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px; z-index: 10; }
