:root {
  --accent: #5b5bd6; --accent-soft: #ededff; --on-accent: #fff;
  --bg: #f3f4f8; --stage: #e9ebf1; --surface: #fff; --soft: #f8f9fb;
  --text: #222534; --muted: #7b8194; --border: #e4e6ed;
  --shadow: 0 14px 40px rgba(25, 28, 50, .14);
}
body[data-theme="dark"] {
  --accent: #9292f7; --accent-soft: #292b45; --on-accent: #141526;
  --bg: #12141a; --stage: #0d0f14; --surface: #1b1e27; --soft: #232733;
  --text: #eaecf4; --muted: #9ca3b6; --border: #303542;
  --shadow: 0 14px 40px rgba(0, 0, 0, .4);
}
body[data-theme="sepia"] {
  --accent: #9a6b3f; --accent-soft: #f1e4cf; --on-accent: #fffaf2;
  --bg: #efe6d5; --stage: #e5d9c1; --surface: #fbf5e9; --soft: #f5ecdb;
  --text: #4b3a26; --muted: #8c7759; --border: #e0d0b4;
  --shadow: 0 14px 40px rgba(94, 69, 34, .16);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden; -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 22px; height: 22px; fill: currentColor; display: block; flex: none; }
.app { height: 100dvh; display: flex; flex-direction: column; }

/* 顶栏 */
.topbar {
  flex: none; height: 58px; padding: 0 12px; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top);
  height: calc(58px + env(safe-area-inset-top)); position: relative; z-index: 4;
}
.brand { display: flex; align-items: center; gap: 7px; font-size: 14px; white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.tabs { display: flex; gap: 3px; padding: 3px; margin-left: auto; background: var(--bg); border-radius: 10px; }
.tab { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: 6px 11px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tab.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 5px rgba(0,0,0,.08); }
.icon-btn { width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); display: grid; place-items: center; }
.icon-btn .icon { width: 19px; height: 19px; }

/* 主体 */
.stage { flex: 1; min-height: 0; position: relative; background: var(--stage); }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

.urlbar { flex: none; margin: 10px 12px 0; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; padding: 5px 5px 5px 11px; }
.urlbar .url-icon { width: 17px; height: 17px; color: var(--muted); }
.urlbar input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font-size: 13px; }
.urlbar button { border: 0; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600; padding: 8px 14px; flex: none; }
.chapter-bar { flex: none; display: flex; align-items: center; gap: 8px; padding-right: 12px; }
.status { flex: 1; min-width: 0; padding: 7px 0 5px 14px; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-next { flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--accent); border-radius: 999px; padding: 5px 11px; font-size: 11px; font-weight: 700; }

.comic-stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y; }
.comic-stage img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; background: var(--surface); box-shadow: var(--shadow); }
.comic-stage img.pop { animation: pop .25s ease-out; }
@keyframes pop { from { opacity: .3; transform: scale(.99); } to { opacity: 1; transform: none; } }
.comic-scroll {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--stage);
}
.comic-scroll img { width: 100%; height: auto; display: block; background: var(--surface); }
body[data-read="scroll"] .tap-side { display: none; }
.tap-side { position: absolute; top: 0; bottom: 0; width: 26%; z-index: 2; }
.tap-side.left { left: 0; } .tap-side.right { right: 0; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.empty-icon { width: 66px; height: 66px; margin: 0 auto 16px; border: 2px dashed var(--accent); border-radius: 18px; display: grid; place-items: center; color: var(--accent); font-size: 24px; font-weight: 700; opacity: .75; }
.empty h2 { margin: 0 0 8px; font-size: 16px; color: var(--text); }
.empty p { margin: 0; font-size: 12px; line-height: 1.7; }
.loading { position: absolute; z-index: 3; background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--text); border: 1px solid var(--border); padding: 10px 18px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); }

.thumbs { flex: none; height: 74px; display: flex; align-items: center; gap: 7px; padding: 8px 12px; overflow-x: auto; background: var(--surface); border-top: 1px solid var(--border); }
.thumb { flex: none; width: 42px; height: 56px; padding: 0; border: 2px solid transparent; border-radius: 5px; overflow: hidden; background: var(--bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.active { border-color: var(--accent); }

/* 小说 */
.novel-form { padding: 14px; display: flex; flex-direction: column; gap: 10px; height: 100%; }
.novel-form input, .novel-form textarea { width: 100%; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); padding: 11px 12px; outline: none; font-size: 14px; }
.novel-form textarea { flex: 1; resize: none; line-height: 1.7; }
.novel-form input:focus, .novel-form textarea:focus { border-color: var(--accent); }
.primary { border: 0; border-radius: 11px; background: var(--accent); color: var(--on-accent); padding: 13px; font-size: 14px; font-weight: 700; }
.novel-wrap { flex: 1; min-height: 0; overflow: hidden; padding: 10px 20px; }
.novel-title { text-align: center; font-size: 12px; color: var(--muted); letter-spacing: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.novel-title:empty { display: none; }
.novel-content { white-space: pre-wrap; word-break: break-word; overflow: hidden; font-family: "Songti SC", "STSong", "Noto Serif SC", serif; font-size: var(--novel-font, 19px); line-height: 1.85; height: calc(100% - 40px); }
.novel-content.pop { animation: fade .25s ease-out; }
@keyframes fade { from { opacity: .3; } to { opacity: 1; } }

/* 控制栏 */
.controlbar { flex: none; position: relative; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); z-index: 4; }
.timebar { position: absolute; top: -1px; left: 0; right: 0; height: 3px; overflow: hidden; }
.timebar span { display: block; height: 100%; width: 0; background: var(--accent); }
.ctrl-row { height: 64px; display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.ctrl { width: 40px; height: 40px; flex: none; border: 1px solid var(--border); border-radius: 11px; background: var(--soft); color: var(--text); display: grid; place-items: center; }
.ctrl:disabled { opacity: .4; }
.ctrl-play { width: 48px; height: 48px; border: 0; border-radius: 14px; background: var(--accent); color: var(--on-accent); }
.ctrl-play .icon { width: 23px; height: 23px; }
.progress-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.progress-wrap input { flex: 1; min-width: 30px; width: 100%; accent-color: var(--accent); }
.progress-wrap span { font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.countdown { font-size: 11px; color: var(--muted); width: 26px; text-align: center; font-variant-numeric: tabular-nums; }
.full-btn { width: 36px; height: 36px; }
.full-btn .icon { width: 19px; height: 19px; }
body.is-fullscreen .topbar, body.is-fullscreen .urlbar, body.is-fullscreen .status { display: none; }
body.is-fullscreen .controlbar { padding-bottom: 6px; }

/* 设置面板 */
.scrim { position: fixed; inset: 0; background: rgba(10,12,20,.38); z-index: 20; }
.panel { position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(340px, 88vw); background: var(--surface); box-shadow: -10px 0 36px rgba(0,0,0,.16); transform: translateX(105%); transition: transform .25s ease; display: flex; flex-direction: column; }
.panel.open { transform: none; }
.panel-head { height: 58px; flex: none; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.field { margin-bottom: 20px; }
.field label { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.field label strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: var(--bg); }
.seg button { flex: 1; border: 0; border-radius: 7px; background: transparent; color: var(--muted); padding: 8px 4px; font-size: 12px; font-weight: 600; }
.seg button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 5px rgba(0,0,0,.08); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.switch span { display: flex; flex-direction: column; gap: 2px; }
.switch strong { font-size: 13px; }
.switch small { font-size: 11px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 42px; height: 24px; border-radius: 999px; background: var(--border); position: relative; flex: none; transition: background .2s; }
.switch i::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.danger { width: 100%; margin-top: 12px; padding: 11px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: #d9534f; font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.danger .icon { width: 17px; height: 17px; }
.note { font-size: 11px; line-height: 1.7; color: var(--muted); margin-top: 18px; }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 40; background: rgba(28,30,42,.94); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; max-width: 86vw; text-align: center; box-shadow: var(--shadow); }
