:root {
	--bg: #0f1115;
	--bg-2: #161922;
	--bg-3: #1e2230;
	--line: #2a2f3e;
	--text: #e9eaee;
	--muted: #9aa0b0;
	--accent: #f2a541;
	--accent-ink: #1a1203;
	--danger: #e5534b;
	--ok: #57ab5a;
	--radius: 10px;
	--top-h: 60px;
	--bottom-h: 0px;
	--mini-h: 0px;
	--safe-b: env(safe-area-inset-bottom, 0px);
	color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
	font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- Topbar ---------- */
.topbar {
	position: sticky; top: 0; z-index: 30;
	height: var(--top-h);
	display: flex; align-items: center; gap: 18px;
	padding: 0 20px; padding-top: env(safe-area-inset-top, 0);
	background: rgba(15, 17, 21, .92);
	backdrop-filter: blur(12px);
	border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.search { flex: 1; max-width: 460px; }
.search input {
	width: 100%; height: 38px; padding: 0 14px;
	background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topnav a:hover { color: var(--text); }
.topnav a.active { color: var(--text); background: var(--bg-3); }
.avatar {
	width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
	background: var(--accent); color: var(--accent-ink); font-weight: 800;
}
.menu {
	position: absolute; right: 16px; top: calc(var(--top-h) - 4px);
	min-width: 240px; padding: 6px;
	background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
	box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.menu-head { padding: 10px 12px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu a, .menu button {
	display: block; width: 100%; text-align: left; padding: 10px 12px;
	background: none; border: 0; border-radius: 6px; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--bg-3); }

.offline-banner { background: #3b2a10; color: #ffd28a; text-align: center; padding: 8px; font-size: 14px; }

/* ---------- Layout ---------- */
main {
	max-width: 1500px; margin: 0 auto;
	padding: 24px 20px calc(40px + var(--mini-h) + var(--bottom-h) + var(--safe-b));
	outline: none;
}
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; margin-right: auto; }
.section { margin-bottom: 36px; }
.section h2 { font-size: 19px; margin-bottom: 14px; display: flex; align-items: baseline; gap: 10px; }
.section h2 a { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: auto; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.spinner {
	width: 34px; height: 34px; margin: 60px auto;
	border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
	animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons & inputs ---------- */
.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px;
	height: 40px; padding: 0 18px; border-radius: 999px;
	border: 1px solid var(--line); background: var(--bg-3); cursor: pointer; font-weight: 600;
	white-space: nowrap;
}
.btn:hover { border-color: #3a4154; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 40px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.seg { display: inline-flex; background: var(--bg-3); border: 1px solid var(--line); border-radius: 999px; padding: 3px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--bg); color: var(--text); }
select, .input, textarea {
	height: 40px; padding: 0 12px; border-radius: 8px;
	background: var(--bg-3); border: 1px solid var(--line); outline: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
select:focus, .input:focus, textarea:focus { border-color: var(--accent); }
label.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
label.field .input, label.field select { color: var(--text); width: 100%; }

/* ---------- Cover grid ---------- */
.grid {
	display: grid; gap: 22px 18px;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.row {
	display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 18px;
	overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity;
	scrollbar-width: thin;
}
.row > * { scroll-snap-align: start; }
.card { display: block; min-width: 0; }
.cover {
	position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden;
	background: linear-gradient(135deg, #252a3a, #171a24);
	box-shadow: 0 6px 18px rgba(0,0,0,.35);
	transition: transform .15s ease;
}
.card:hover .cover { transform: translateY(-3px); }
.cover img { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; object-fit: cover; }
.cover .badges, .cover .badge.seq, .cover .progress, .cover .done-mark { z-index: 2; }
.cover.square { aspect-ratio: 1; }
.cover .ph {
	position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center;
	padding: 12px; text-align: center; font-weight: 700; font-size: 14px; color: #cfd3de;
}
.cover .ph small { font-weight: 400; color: var(--muted); margin-top: 6px; }
.badges { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; }
.badge {
	display: inline-flex; align-items: center; justify-content: center;
	height: 22px; min-width: 22px; padding: 0 6px; border-radius: 6px;
	background: rgba(10,12,16,.82); font-size: 11px; font-weight: 700;
}
.badge svg { width: 13px; height: 13px; fill: currentColor; }
.badge.seq { position: absolute; top: 6px; right: 6px; background: var(--accent); color: var(--accent-ink); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(0,0,0,.5); }
.progress > i { display: block; height: 100%; background: var(--accent); }
.done-mark {
	position: absolute; right: 6px; bottom: 10px; width: 24px; height: 24px; border-radius: 50%;
	background: var(--ok); display: grid; place-items: center;
}
.done-mark svg { width: 14px; fill: #fff; }
.card .t { margin-top: 8px; font-weight: 600; font-size: 14px; line-height: 1.3;
	display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .a { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Series stack */
.stack { position: relative; aspect-ratio: 2 / 3; }
.stack .cover { position: absolute; inset: 0; }
.stack .cover:nth-child(2) { transform: translate(8px, -8px) scale(.94); opacity: .55; z-index: -1; }
.stack .cover:nth-child(3) { transform: translate(16px, -16px) scale(.88); opacity: .3; z-index: -2; }
.stack-wrap { position: relative; z-index: 0; padding: 16px 16px 0 0; }

/* ---------- Detail ---------- */
.detail { display: grid; grid-template-columns: 280px 1fr; gap: 36px; align-items: start; }
.detail .cover { box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.detail h1 { font-size: 30px; margin-bottom: 6px; }
.detail .sub { color: var(--muted); font-size: 17px; margin-bottom: 14px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.meta b { color: var(--text); font-weight: 600; }
.meta a { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 22px; }
.desc { max-width: 780px; color: #cfd2db; }
.desc p { margin: 0 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.chip { padding: 4px 10px; border-radius: 999px; background: var(--bg-3); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.progress-line { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.bar { flex: 1; max-width: 360px; height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list > *:last-child { border-bottom: 0; }
.list button.li { width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; cursor: pointer; }
.list button.li:hover { background: var(--bg-2); }
.list .grow { flex: 1; min-width: 0; }
.list .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
details.more { margin-top: 26px; }
details.more summary { cursor: pointer; font-weight: 700; margin-bottom: 10px; }

/* ---------- Login ---------- */
.login {
	min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px;
	background: radial-gradient(1200px 600px at 20% -10%, #2a2135 0, transparent 60%),
	            radial-gradient(1000px 500px at 110% 110%, #1a2a2a 0, transparent 60%), var(--bg);
}
.login form {
	width: 100%; max-width: 380px; padding: 32px; border-radius: 16px;
	background: rgba(22,25,34,.85); border: 1px solid var(--line); display: grid; gap: 16px;
	box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.login .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.login h1 { font-size: 22px; }
.login .err { color: var(--danger); font-size: 14px; min-height: 1em; }
.login .btn { height: 44px; }

/* ---------- Mini player ---------- */
.miniplayer {
	position: fixed; left: 0; right: 0; z-index: 25;
	bottom: calc(var(--bottom-h) + var(--safe-b));
	height: 68px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
	background: rgba(22,25,34,.97); border-top: 1px solid var(--line);
	backdrop-filter: blur(12px);
}
.miniplayer .mp-cover { width: 44px; height: 44px; border-radius: 6px; overflow: hidden; background: var(--bg-3); flex: none; cursor: pointer; }
.miniplayer .mp-cover img { width: 100%; height: 100%; object-fit: cover; }
.miniplayer .mp-info { flex: 1; min-width: 0; cursor: pointer; }
.miniplayer .mp-t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.miniplayer .mp-s { font-size: 12px; color: var(--muted); }
.miniplayer .mp-bar { position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: transparent; }
.miniplayer .mp-bar i { display: block; height: 100%; background: var(--accent); }
.pbtn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: none; cursor: pointer; display: grid; place-items: center; flex: none; }
.pbtn svg { width: 26px; height: 26px; fill: currentColor; }
.pbtn.big { width: 72px; height: 72px; background: var(--accent); color: var(--accent-ink); }
.pbtn.big svg { width: 36px; height: 36px; }
.pbtn:hover { background: var(--bg-3); }
.pbtn.big:hover { background: var(--accent); filter: brightness(1.08); }

/* ---------- Full player ---------- */
.sheet {
	position: fixed; inset: 0; z-index: 50; overflow-y: auto;
	background: linear-gradient(180deg, #1c1f2b 0%, var(--bg) 70%);
	padding: calc(14px + env(safe-area-inset-top, 0)) 20px calc(24px + var(--safe-b));
	animation: up .22s ease;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; max-width: 560px; margin: 0 auto; }
.player { max-width: 560px; margin: 0 auto; text-align: center; }
.player .cover { width: min(320px, 74vw); margin: 18px auto 22px; aspect-ratio: 1; box-shadow: 0 24px 60px rgba(0,0,0,.6); }
.player h2 { font-size: 21px; }
.player .who { color: var(--muted); margin: 4px 0 2px; }
.player .chap { color: var(--accent); font-size: 14px; min-height: 1.4em; }
.scrub { margin: 18px 0 4px; }
.scrub input { width: 100%; accent-color: var(--accent); }
.times { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 12px 0 18px; }
.controls .skip { position: relative; }
.controls .skip span { position: absolute; font-size: 10px; font-weight: 800; top: 50%; left: 50%; transform: translate(-50%, -38%); }
.tools { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.panel { margin-top: 22px; text-align: left; }

/* ---------- Reader ---------- */
.reader { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; background: var(--r-bg, #14161c); color: var(--r-fg, #ddd); }
.reader[data-theme="sepia"] { --r-bg: #f4ecd8; --r-fg: #3b2f1e; }
.reader[data-theme="light"] { --r-bg: #fbfbf8; --r-fg: #1b1b1b; }
.reader[data-theme="dark"] { --r-bg: #14161c; --r-fg: #d8d8d8; }
.reader-bar {
	display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top, 0));
	transition: opacity .2s; color: var(--r-fg);
}
.reader-bar .ttl { flex: 1; min-width: 0; text-align: center; font-size: 14px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader .pbtn { width: 40px; height: 40px; color: var(--r-fg); }
.reader .pbtn:hover { background: rgba(127,127,127,.15); }
.reader .pbtn svg { width: 22px; height: 22px; }
.reader .pbtn.on { color: var(--accent); }
.reader-stage { flex: 1; position: relative; min-height: 0; }
#epub { position: absolute; inset: 0 max(12px, calc((100vw - 900px) / 2)); }
.tapzone { position: absolute; top: 0; bottom: 0; width: 18%; z-index: 2; }
.tapzone.l { left: 0; } .tapzone.r { right: 0; }
.reader-foot { display: flex; align-items: center; gap: 12px; padding: 8px 18px calc(10px + var(--safe-b)); font-size: 12px; opacity: .7; }
.reader-foot input { flex: 1; accent-color: var(--accent); }
.reader.chrome-off .reader-bar, .reader.chrome-off .reader-foot { opacity: 0; pointer-events: none; }
.drawer {
	position: absolute; top: 0; bottom: 0; right: 0; width: min(380px, 92vw); z-index: 5;
	background: var(--bg-2); color: var(--text); border-left: 1px solid var(--line);
	display: flex; flex-direction: column; animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.drawer header h3 { flex: 1; font-size: 16px; }
.drawer .body { overflow-y: auto; padding: 8px; flex: 1; }
.drawer .toc a, .drawer .note { display: block; padding: 9px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.drawer .toc a:hover, .drawer .note:hover { background: var(--bg-3); }
.drawer .toc .sub { padding-left: 26px; color: var(--muted); }
.drawer .note q { display: block; color: #cfd2db; font-style: italic; margin-bottom: 4px; }
.drawer .note .row-a { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.drawer .note .del { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: 12px; }
.settings { display: grid; gap: 18px; padding: 10px; }
.settings .seg { width: 100%; }
.settings .seg button { flex: 1; }
.selpop {
	position: absolute; z-index: 6; display: flex; gap: 4px; padding: 4px;
	background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
	transform: translate(-50%, -100%);
}

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 26;
	display: none; padding-bottom: var(--safe-b);
	background: rgba(15,17,21,.97); border-top: 1px solid var(--line);
}
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--muted); }
.bottomnav a svg { width: 22px; height: 22px; fill: currentColor; }
.bottomnav a.active { color: var(--accent); }

/* ---------- Upload ---------- */
.drop {
	border: 2px dashed var(--line); border-radius: 14px; padding: 36px; text-align: center; color: var(--muted);
	cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: rgba(242,165,65,.06); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 18px 0; }
.files { margin-top: 14px; }
.uprog { height: 8px; border-radius: 4px; background: var(--bg-3); overflow: hidden; margin: 14px 0; }
.uprog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.card-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.card-box + .card-box { margin-top: 16px; }
.steps { padding-left: 20px; } .steps li { margin-bottom: 8px; }
code.inline { background: var(--bg-3); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
	position: fixed; left: 50%; bottom: calc(90px + var(--mini-h) + var(--bottom-h) + var(--safe-b)); z-index: 100;
	transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
	background: #2b3040; color: var(--text); padding: 10px 18px; border-radius: 999px; font-size: 14px;
	box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: all .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
	.topnav { display: none; }
	.bottomnav { display: flex; }
	:root { --bottom-h: 58px; }
	.search { max-width: none; }
}
@media (max-width: 640px) {
	:root { --top-h: 56px; }
	.topbar { padding: 0 12px; gap: 10px; }
	.brand span { display: none; }
	main { padding-left: 16px; padding-right: 16px; padding-top: 18px; }
	.grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; }
	.row { grid-auto-columns: 112px; gap: 12px; }
	.card .t { font-size: 13px; }
	.detail { grid-template-columns: 1fr; gap: 20px; }
	.detail .cover-col { max-width: 220px; margin: 0 auto; width: 100%; }
	.detail h1 { font-size: 24px; text-align: center; }
	.detail .sub { text-align: center; }
	.detail .meta, .detail .actions { justify-content: center; }
	.page-head h1 { font-size: 22px; }
}
body.has-mini { --mini-h: 68px; }

/* Långa titlar utan mellanslag (t.ex. filnamn) får inte göra sidan bredare än skärmen. */
.detail > *, .player, .page-head h1 { min-width: 0; }
.detail h1, .player h2, .page-head h1, .card .t, .miniplayer .mp-t { overflow-wrap: anywhere; }
