:root {
  --fs: 20px; --lh: 1.7; --w: 680px; --m: 18px;
  --bg: #0f0e0c; --panel: #1a1814; --text: #e9e4d8; --muted: #9a9384; --gold: #d4a937; --line: #2e2a22;
  --on-gold: #1a1406; --danger: #e0614f;
}
html[data-theme="light"] { --bg: #faf8f3; --panel: #ffffff; --text: #1d1b17; --muted: #6f695c; --gold: #9a7410; --line: #e3ddcf; --on-gold: #fff; }
html[data-theme="sepia"] { --bg: #f2e6cc; --panel: #eadcbc; --text: #3b2f1c; --muted: #7a6a4b; --gold: #8a5a12; --line: #d8c79f; --on-gold: #fff; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--gold); }
h1, h2, h3 { line-height: 1.25; }

.screen { max-width: 760px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; border-bottom: 1px solid var(--line); }
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1 span { color: var(--gold); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 14px; cursor: pointer; }
.btn:active { opacity: .7; }
.btn.gold { background: var(--gold); color: var(--on-gold); border-color: var(--gold); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.icon { padding: 8px 12px; font-size: 1.1rem; line-height: 1; }
.btn[disabled] { opacity: .45; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

input[type=text], input[type=url], input[type=search], select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.section { margin-top: 18px; }
.section > h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.msg { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-size: .92rem; }
.msg.err { border-color: var(--danger); }
.hint { color: var(--muted); font-size: .88rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.card .cover { aspect-ratio: 3 / 4; width: 100%; object-fit: cover; background: #2a2620; display: block; }
.card .meta { padding: 8px 10px 10px; }
.card .t { font-weight: 600; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .a { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--gold); }
.pct { font-size: .75rem; color: var(--muted); margin-top: 3px; }

.cont { display: flex; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; cursor: pointer; align-items: center; }
.cont img { width: 48px; height: 64px; object-fit: cover; border-radius: 6px; background: #2a2620; }
.cont .t { font-weight: 600; }
.cont .a { color: var(--muted); font-size: .85rem; }

.hero { display: flex; gap: 14px; margin-top: 14px; }
.hero img { width: 112px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; background: #2a2620; flex: none; }
.hero h2 { margin: 0 0 4px; font-size: 1.25rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: .75rem; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--muted); }
.desc { white-space: pre-line; color: var(--text); opacity: .9; font-size: .95rem; max-height: 9em; overflow: hidden; position: relative; }
.desc.open { max-height: none; }

.chlist { list-style: none; margin: 8px 0 0; padding: 0; }
.chlist li { display: flex; gap: 10px; align-items: center; padding: 11px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.chlist li .n { color: var(--muted); font-size: .8rem; min-width: 2.6em; text-align: right; }
.chlist li .ti { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chlist li.read .ti { color: var(--muted); }
.chlist li.read::after { content: "✓"; color: var(--gold); }
.chlist li.cur { background: color-mix(in srgb, var(--gold) 16%, transparent); border-radius: 8px; }
.chlist li.cur .ti { font-weight: 700; }

.chlist li .box { font-size: 1.15rem; color: var(--muted); }
.chlist li.sel { background: color-mix(in srgb, var(--gold) 22%, transparent); border-radius: 8px; }
.chlist li.sel .box { color: var(--gold); }
.selbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; background: var(--bg); border-top: 1px solid var(--line);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px;
  max-width: 760px; margin: 0 auto; }
.selbar[hidden] { display: none; }
.selbar .selcount { font-size: .85rem; color: var(--muted); }
body.selecting .screen { padding-bottom: 190px; }

/* Reader */
.reader { min-height: 100vh; }
.rbar { position: fixed; left: 0; right: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(6px);
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; transition: transform .2s ease; }
.rbar.top { top: 0; padding-top: calc(8px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.rbar.bottom { bottom: 0; padding-bottom: calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.hidden-ui .rbar.top { transform: translateY(-110%); }
.hidden-ui .rbar.bottom { transform: translateY(110%); }
.rbar .ttl { flex: 1; min-width: 0; text-align: center; font-size: .85rem; line-height: 1.25; }
.rbar .ttl b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rbar .ttl span { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rbar .prog { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--gold); width: 0; }

.page { max-width: var(--w); margin: 0 auto; padding: calc(70px + env(safe-area-inset-top)) var(--m) calc(110px + env(safe-area-inset-bottom)); }
.page h1.ch { font-size: 1.5em; margin: 0 0 1.2em; }
.prose { font-family: Georgia, "Times New Roman", serif; font-size: var(--fs); line-height: var(--lh); overflow-wrap: break-word; }
.prose p { margin: 0 0 1em; }
.prose img { max-width: 100%; height: auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
.prose blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--gold); }
.prose table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.prose td, .prose th { border: 1px solid var(--line); padding: 4px 8px; }
.endnav { display: flex; gap: 10px; margin-top: 2em; }
.endnav .btn { flex: 1; }

.panel-back { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.panel { width: 100%; max-width: 640px; max-height: 82vh; overflow: auto; background: var(--bg); border: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.panel h3 { margin: 0 0 10px; }
.field { margin: 14px 0; }
.field label { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: .9rem; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--gold); }
.seg { display: flex; gap: 8px; }
.seg .btn { flex: 1; text-align: center; }
.seg .btn.on { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }

.state { text-align: center; padding: 60px 10px; color: var(--muted); }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; margin: 0 auto 12px; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--gold); color: var(--on-gold); padding: 9px 16px; border-radius: 999px; font-size: .9rem; opacity: 0;
  pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.chlist li .dlm { color: var(--gold); font-size: .85rem; }
body.selecting .screen { padding-bottom: 240px; }
