:root {
  --bg: #0f0e13; --bg2: #17161d; --bg3: #211f2a; --line: #2c2a37;
  --fg: #f1eef7; --muted: #8f8aa3; --accent: #ff7a59; --accent2: #ffb199; --ok: #5ed39a;
  --radius: 14px; --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
body { min-height: 100dvh; overscroll-behavior-y: contain; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.err { color: var(--accent); min-height: 1.4em; margin: 8px 0 0; font-size: 14px; }
[hidden] { display: none !important; }

/* ---------- auth ---------- */
body.auth { display: grid; place-items: center; padding: var(--pad); }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.auth-card .logo { font-size: 56px; margin-bottom: 4px; }
.auth-card h1 { margin: 0 0 6px; font-size: 28px; }
.auth-card form { display: grid; gap: 12px; margin-top: 24px; }
input[type=text], input[type=password], input[type=search] {
  width: 100%; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg2); outline: none; font-size: 16px;
}
input:focus { border-color: var(--accent); }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--bg3); padding: 10px 16px; border-radius: 999px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1b0d08; }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 20px; font-size: 17px; }
.btn.icon { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; font-size: 20px; }
.btn:active { transform: scale(.97); }

/* ---------- layout ---------- */
#app { padding-bottom: calc(72px + var(--safe-bottom)); }
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); padding: calc(10px + var(--safe-top)) var(--pad) 10px; display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.section { padding: 8px var(--pad); }
.section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 12px 0 10px; }
.empty { text-align: center; padding: 48px var(--pad); color: var(--muted); }
.empty .big { font-size: 48px; margin-bottom: 8px; }

/* tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: color-mix(in srgb, var(--bg2) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0 8px; font-size: 11px; color: var(--muted); }
.tabbar a .ic { font-size: 22px; line-height: 1; }
.tabbar a.on { color: var(--accent); }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 12px; }
.card { display: block; }
.card .cover { aspect-ratio: 3/4.3; background: var(--bg3); border-radius: 10px; overflow: hidden; position: relative; border: 1px solid var(--line); }
.card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .cover .badge { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #1b0d08; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.card .cover .heart { position: absolute; top: 6px; right: 6px; font-size: 14px; filter: drop-shadow(0 1px 2px #000); }
.card .t { font-size: 13px; font-weight: 600; margin-top: 6px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { font-size: 12px; color: var(--muted); }

/* continue row */
.hscroll { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; margin: 0 calc(-1 * var(--pad)); padding-left: var(--pad); padding-right: var(--pad); }
.hscroll::-webkit-scrollbar { display: none; }
.cont { scroll-snap-align: start; flex: 0 0 auto; width: 78%; max-width: 320px; display: flex; gap: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.cont img { width: 64px; height: 88px; object-fit: cover; border-radius: 8px; background: var(--bg3); }
.cont .t { font-weight: 700; font-size: 15px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cont .s { color: var(--muted); font-size: 13px; margin-top: 2px; }
.cont .btn { margin-top: auto; align-self: flex-start; padding: 6px 12px; min-height: 36px; font-size: 13px; }
.cont .r { display: flex; flex-direction: column; min-width: 0; flex: 1; }

/* series page */
.hero { display: flex; gap: 14px; padding: 8px var(--pad); }
.hero img { width: 118px; height: 168px; object-fit: cover; border-radius: 12px; background: var(--bg3); border: 1px solid var(--line); }
.hero .info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.hero h1 { font-size: 20px; margin: 0; line-height: 1.2; }
.hero .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.tag { background: var(--bg3); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--muted); }
.chlist { list-style: none; margin: 0; padding: 0 var(--pad); }
.chlist li a { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); min-height: 56px; }
.chlist .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.chlist .dot.read { background: var(--line); }
.chlist .dot.part { background: var(--accent2); }
.chlist .n { flex: 1; font-weight: 600; }
.chlist .n small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.chlist .pg { color: var(--muted); font-size: 13px; }

/* history */
.hist { list-style: none; margin: 0; padding: 0 var(--pad); }
.hist li a { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hist img { width: 44px; height: 60px; object-fit: cover; border-radius: 6px; background: var(--bg3); }
.hist .t { font-weight: 600; }
.hist .s { color: var(--muted); font-size: 13px; }

/* upload */
.drop { margin: 8px var(--pad); border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center; color: var(--muted); background: var(--bg2); }
.drop.over { border-color: var(--accent); color: var(--fg); }
.drop .big { font-size: 40px; }
.form { display: grid; gap: 12px; padding: 8px var(--pad); }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.filelist { font-size: 13px; color: var(--muted); padding: 0 var(--pad); }
.progress { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin: 8px var(--pad); }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.help { padding: 8px var(--pad); color: var(--muted); font-size: 14px; }
.help code { background: var(--bg3); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

/* ---------- reader ---------- */
body.reading { background: #000; }
body.reading #app { padding-bottom: 0; }
.reader { min-height: 100dvh; background: #000; }
.reader .pages img { width: 100%; display: block; max-width: 900px; margin: 0 auto; background: #0b0b0b; min-height: 40vh; }
.reader.strip .pages img { margin-bottom: 0; }
.reader.paged .pages { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; height: 100dvh; align-items: center; }
.reader.paged .pages::-webkit-scrollbar { display: none; }
.reader.paged .pages img { flex: 0 0 100%; height: 100dvh; width: 100vw; object-fit: contain; scroll-snap-align: center; min-height: 0; }
.rbar { position: fixed; left: 0; right: 0; z-index: 8; background: color-mix(in srgb, #000 75%, transparent); backdrop-filter: blur(12px); color: #fff; display: flex; align-items: center; gap: 8px; padding: 10px 12px; transition: transform .2s, opacity .2s; }
.rbar.top { top: 0; padding-top: calc(10px + var(--safe-top)); }
.rbar.bottom { bottom: 0; padding-bottom: calc(10px + var(--safe-bottom)); }
.rbar.hide.top { transform: translateY(-100%); opacity: 0; }
.rbar.hide.bottom { transform: translateY(100%); opacity: 0; }
.rbar .title { flex: 1; min-width: 0; }
.rbar .title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar .title span { font-size: 12px; opacity: .7; }
.rbar .btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
.rbar .btn.primary { background: var(--accent); color: #1b0d08; }
.rbar .pg { font-size: 13px; opacity: .8; min-width: 56px; text-align: center; }
.endcard { max-width: 900px; margin: 0 auto; padding: 40px 20px calc(120px + var(--safe-bottom)); text-align: center; color: #fff; }
.endcard .btn { margin: 6px; }
.tapzone { position: fixed; inset: 0; z-index: 7; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; z-index: 20; font-size: 14px; animation: fade 2.4s forwards; }
@keyframes fade { 0%,70% { opacity: 1 } 100% { opacity: 0 } }
