:root {
  --bg: #f6f1ea; --surface: #fffdf9; --surface-2: #efe8de; --ink: #1f1a17; --muted: #6f655c; --line: #e3d9cc;
  --accent: #b4532a; --accent-ink: #fff; --accent-soft: #f3dfd2; --ok: #3f7d4e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px; --tabs-h: 60px; --mini-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f; --surface: #1e1a17; --surface-2: #29231f; --ink: #f1ebe4; --muted: #a39789; --line: #352e28;
    --accent: #e3804f; --accent-ink: #1a0e07; --accent-soft: #3a2519; --ok: #79b98a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--sans); }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
svg { width: 24px; height: 24px; flex: none; }
[hidden] { display: none !important; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

#view { padding: calc(var(--safe-t) + 8px) 16px calc(var(--tabs-h) + var(--safe-b) + 24px); max-width: 1100px; margin: 0 auto; outline: none; }
body.has-mini #view { padding-bottom: calc(var(--tabs-h) + var(--mini-h) + var(--safe-b) + 24px); }
body.fullscreen #view { padding: 0; max-width: none; }
body.fullscreen .tabs, body.fullscreen .mini { display: none !important; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.9rem; line-height: 1.15; }
h2 { font-size: 1.3rem; }
.muted { color: var(--muted); }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0 8px; }

/* ---------- tab bar */
.tabs { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + var(--safe-b));
  padding-bottom: var(--safe-b); display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .72rem; color: var(--muted); font-weight: 500; }
.tabs a.on { color: var(--accent); }

/* ---------- mini player */
.mini { position: fixed; z-index: 21; left: 8px; right: 8px; bottom: calc(var(--tabs-h) + var(--safe-b) + 6px);
  height: var(--mini-h); display: flex; align-items: center; gap: 4px; padding: 0 6px 0 8px; border-radius: 16px;
  background: var(--surface); box-shadow: 0 6px 24px rgb(0 0 0 / .14), 0 0 0 1px var(--line); overflow: hidden;
  max-width: 720px; margin: 0 auto; }
.mini-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; height: 100%; }
.mini-main img { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.mini-text { min-width: 0; display: flex; flex-direction: column; }
.mini-text b, .mini-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-text b { font-size: .92rem; } .mini-text small { color: var(--muted); font-size: .8rem; }
.mini-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--line); }
.mini-bar i { display: block; height: 100%; width: 0; background: var(--accent); }

.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.lg svg { width: 34px; height: 34px; }

/* ---------- buttons, chips, inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 999px; font-weight: 600; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
.btn small { font-weight: 500; opacity: .85; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 16px; margin: 0 -16px; scroll-padding-inline: 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-size: .88rem; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pill { min-height: 40px; padding: 0 16px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 8%, transparent);
  font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; }
.pill svg { width: 18px; height: 18px; }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; color: var(--muted); }
.search input { width: 100%; height: 48px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  padding: 0 16px 0 44px; font-size: 1rem; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: .85rem; color: var(--muted); }
.field input, .field textarea, .field select { border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  padding: 12px; font-size: 1rem; color: var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- covers & shelves */
.cover { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2);
  box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 4px 14px rgb(0 0 0 / .08); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover.gen { display: flex; flex-direction: column; justify-content: space-between; padding: 10%; color: #fff;
  font-family: var(--serif); }
.cover.gen b { font-size: clamp(.8rem, 3.6cqi, 1.2rem); line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 4;
  -webkit-box-orient: vertical; overflow: hidden; }
.cover.gen small { font-family: var(--sans); font-size: .7rem; opacity: .85; }
.cover .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgb(0 0 0 / .35); }
.cover .bar i { display: block; height: 100%; background: var(--accent); }
.cover .done { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 50%; display: grid;
  place-items: center; background: var(--ok); color: #fff; }
.cover .done svg { width: 15px; height: 15px; }
.cover .fmt { position: absolute; top: 6px; left: 6px; display: flex; gap: 3px; }
.cover .fmt span { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center;
  background: rgb(0 0 0 / .55); color: #fff; }
.cover .fmt svg { width: 14px; height: 14px; }

.tile { display: block; min-width: 0; container-type: inline-size; }
.tile .t { margin-top: 8px; font-weight: 600; font-size: .9rem; line-height: 1.25; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .a { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 30%), 1fr)); gap: 18px 12px; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 24px 18px; } }

.shelf { margin: 22px 0 6px; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.shelf-head a { color: var(--accent); font-size: .9rem; font-weight: 600; }
.rail { display: grid; grid-auto-flow: column; grid-auto-columns: min(128px, 34%); gap: 12px; overflow-x: auto;
  scroll-snap-type: x mandatory; scroll-padding-inline: 16px; scrollbar-width: none; padding: 2px 16px 6px; margin: 0 -16px; }
.rail::-webkit-scrollbar { display: none; }
.rail > * { scroll-snap-align: start; }
@media (min-width: 700px) { .rail { grid-auto-columns: 150px; } }

/* continue cards */
.cont-rail { grid-auto-columns: min(300px, 82%); }
.cont { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); }
.cont .cover { width: 84px; flex: none; }
.cont-info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.cont-info b { font-size: .95rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cont-info small { color: var(--muted); font-size: .8rem; }
.progress { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.progress i { display: block; height: 100%; background: var(--accent); }
.cont .resume { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; flex: none; }
.cont .resume svg { width: 20px; height: 20px; }

.hello { padding: 18px 0 4px; }
.hello p { margin: 4px 0 0; color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }

/* ---------- library toolbar */
.lib-tools { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(var(--safe-t) + 8px) 16px 8px;
  margin: calc(-8px - var(--safe-t)) -16px 8px; display: flex; flex-direction: column; gap: 10px; }
.lib-count { display: flex; justify-content: space-between; align-items: center; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.lib-count select { border: 0; background: none; color: var(--ink); font-weight: 600; font-size: .88rem; }

/* ---------- book detail */
.detail-top { position: relative; margin: calc(-8px - var(--safe-t)) -16px 0; padding: calc(var(--safe-t) + 8px) 16px 18px; overflow: hidden; }
.detail-top .backdrop { position: absolute; inset: -40px; background-size: cover; background-position: center;
  filter: blur(40px) saturate(1.3); opacity: .45; }
.detail-top .backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--bg)); }
.detail-nav { position: relative; display: flex; justify-content: space-between; margin: 0 -8px 6px; }
.detail-nav .icon-btn { background: color-mix(in srgb, var(--surface) 70%, transparent); }
.detail-hero { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; }
.detail-hero .cover { width: min(230px, 62vw); }
.detail-hero h1 { font-size: 1.6rem; }
.detail-hero .by { color: var(--muted); margin-top: 4px; }
.detail-hero .by a { color: var(--ink); font-weight: 600; }
.meta-line { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.series-link { color: var(--accent); font-weight: 600; font-size: .9rem; }
.actions { display: grid; gap: 10px; margin: 18px 0 6px; }
.actions.two { grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) {
  .detail-hero { flex-direction: row; align-items: flex-end; text-align: left; }
  .meta-line { justify-content: flex-start; }
  .actions { max-width: 460px; }
}
.desc { position: relative; margin-top: 10px; line-height: 1.6; color: color-mix(in srgb, var(--ink) 85%, var(--muted)); white-space: pre-line; }
.desc.clamp { max-height: 8.2em; overflow: hidden; }
.desc.clamp::after { content: ""; position: absolute; inset: auto 0 0; height: 3em; background: linear-gradient(transparent, var(--bg)); }
.more-link { color: var(--accent); font-weight: 600; margin-top: 4px; padding: 8px 0; }
.section { margin-top: 24px; }
.section h2 { margin-bottom: 8px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags .chip { min-height: 30px; font-size: .8rem; }
.list { list-style: none; margin: 0; padding: 0; }
.list li button, .list li a { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px;
  text-align: left; border-bottom: 1px solid var(--line); }
.list .n { width: 28px; flex: none; color: var(--muted); font-size: .85rem; text-align: right; font-variant-numeric: tabular-nums; }
.list .lbl { flex: 1; min-width: 0; }
.list .r { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.list li.now .lbl { color: var(--accent); font-weight: 600; }

/* ---------- sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-scrim { position: absolute; inset: 0; background: rgb(0 0 0 / .4); animation: fade .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 6px 16px calc(var(--safe-b) + 16px);
  animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 12px; }
.menu button { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 12px; text-align: left; font-size: 1rem;
  border-bottom: 1px solid var(--line); }
.menu button:last-child { border-bottom: 0; }
.menu button.on { color: var(--accent); font-weight: 600; }
.menu button.danger { color: #c0392b; }
.cands { display: flex; flex-direction: column; gap: 8px; }
.cand { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; border: 1px solid var(--line); text-align: left; }
.cand img, .cand .ph { width: 48px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex: none; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; z-index: 60; left: 50%; translate: -50% 0; bottom: calc(var(--tabs-h) + var(--safe-b) + 84px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: .9rem; max-width: 90vw;
  animation: fade .2s; }

/* ---------- full player */
.player { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column;
  padding: var(--safe-t) 20px calc(var(--safe-b) + 16px); animation: up .3s cubic-bezier(.2,.8,.2,1); overflow: hidden; }
.player-bg { position: absolute; inset: -60px; background-size: cover; background-position: center; filter: blur(60px) saturate(1.4);
  opacity: .35; pointer-events: none; }
.player > * { position: relative; }
.player-top { display: flex; align-items: center; justify-content: space-between; height: 56px; margin: 0 -8px; }
.player-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.player-body { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; gap: 10px; max-width: 460px; width: 100%;
  margin: 0 auto; min-height: 0; }
.player-cover { width: min(78vw, 34dvh, 360px); aspect-ratio: 1; object-fit: cover; border-radius: 16px; margin: 0 auto;
  box-shadow: 0 16px 40px rgb(0 0 0 / .25); background: var(--surface-2); }
.player-meta { text-align: center; }
.player-meta h2 { font-size: 1.35rem; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.player-meta p { margin: 4px 0 0; color: var(--muted); }
.player-meta .chapter-name { color: var(--accent); font-weight: 600; font-size: .9rem; }
.scrub input { width: 100%; }
.scrub-times { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.controls { display: flex; align-items: center; justify-content: space-between; }
.play-big { width: 76px; height: 76px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 40%, transparent); }
.play-big svg { width: 34px; height: 34px; }
.play-big:active { transform: scale(.95); }
.book-left { text-align: center; color: var(--muted); font-size: .85rem; margin: 0; }
.player-extras { display: flex; justify-content: center; gap: 10px; }
@media (max-height: 640px) { .player-body { gap: 6px; } .player-cover { width: min(60vw, 26dvh); } }

input[type=range] { -webkit-appearance: none; appearance: none; height: 28px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 5px;
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--p, 0%) 100% no-repeat, var(--line); }
input[type=range]::-moz-range-track { height: 5px; border-radius: 5px; background: var(--line); }
input[type=range]::-moz-range-progress { height: 5px; border-radius: 5px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6.5px; border-radius: 50%; background: var(--accent); border: 0; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 0; }

/* ---------- reader */
.reader { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; background: var(--rbg, #fbf7f0); color: var(--rink, #222); }
.reader.sepia { --rbg: #f4ecd8; --rink: #3b2f22; }
.reader.dark { --rbg: #121212; --rink: #d8d2c8; }
.reader.light { --rbg: #fffefb; --rink: #1d1d1d; }
.reader-bar { position: absolute; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 4px; padding: 0 8px;
  background: var(--rbg); transition: opacity .2s, transform .2s; }
.reader-bar.top { top: 0; padding-top: var(--safe-t); height: calc(52px + var(--safe-t)); border-bottom: 1px solid color-mix(in srgb, var(--rink) 12%, transparent); }
.reader-bar.bottom { bottom: 0; padding-bottom: var(--safe-b); height: calc(56px + var(--safe-b)); flex-direction: column; justify-content: center; gap: 0; }
.reader-bar .icon-btn { color: var(--rink); }
.reader-bar .ttl { flex: 1; min-width: 0; text-align: center; font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-bar.bottom input { width: calc(100% - 24px); }
.reader-bar.bottom small { font-size: .75rem; opacity: .7; }
.reader.chrome-off .reader-bar.top { opacity: 0; transform: translateY(-100%); pointer-events: none; }
.reader.chrome-off .reader-bar.bottom { opacity: 0; transform: translateY(100%); pointer-events: none; }
.reader-stage { flex: 1; margin: calc(var(--safe-t) + 20px) 0 calc(var(--safe-b) + 28px); }
.reader-foot { position: absolute; bottom: calc(var(--safe-b) + 6px); left: 0; right: 0; text-align: center; font-size: .72rem; opacity: .55; pointer-events: none; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 46px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--bg); font-weight: 600; }

/* ---------- profiles */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 18px; margin: 28px 0; }
.profile { display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 600; }
.avatar { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; color: #fff;
  font-family: var(--serif); }
.profile.add .avatar { background: var(--surface-2); color: var(--muted); border: 2px dashed var(--line); }
.welcome { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; text-align: center; max-width: 520px; margin: 0 auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; }
.stat b { display: block; font-size: 1.4rem; font-family: var(--serif); }
.stat small { color: var(--muted); font-size: .8rem; }
.meter { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.meter i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%;
  animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
