:root {
  --bg: #000; --s1: #121316; --s2: #1d1f24; --s3: #2a2d33;
  --tx: #e3e3e6; --mu: #9a9ca3; --ac: #adc6ff; --ac-on: #102f60; --ac-bg: #283a5a;
  --r: 8px; --nav: 56px;
  --sl: env(safe-area-inset-left); --sr: env(safe-area-inset-right);
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--tx); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--nav) + var(--sb)); padding-left: var(--sl); padding-right: var(--sr); overscroll-behavior-y: none; }
#app > div { max-width: 760px; margin-inline: auto; }
/* iOS zooms into inputs under 16px */
input, select, textarea { font-size: 16px; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }
body.sub { padding-bottom: calc(24px + var(--sb)); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--mu); }

/* header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--st) + 6px) 8px 6px 16px; min-height: calc(56px + var(--st)); background: rgba(0,0,0,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.top:has(.ib[data-back]) { padding-left: 4px; }
.top h1 { flex: 1; margin: 0; font-size: 22px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .acts { display: flex; align-items: center; gap: 2px; }
.top.clear { position: fixed; left: 0; right: 0; padding-left: calc(4px + var(--sl)); padding-right: calc(8px + var(--sr)); background: linear-gradient(rgba(0,0,0,.6), transparent); backdrop-filter: none; -webkit-backdrop-filter: none; transition: background .2s; }
.top.clear h1 { font-size: 18px; opacity: 0; transition: opacity .2s; }
.top.clear.solid { background: var(--bg); }
.top.clear.solid h1 { opacity: 1; }
.ib { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--tx); }
.ib:active { background: var(--s2); }
.ib:disabled { opacity: .3; }
.tbtn { min-height: 36px; display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 99px; background: var(--ac-bg); color: var(--ac); font-size: 14px; font-weight: 500; white-space: nowrap; }
.tbtn.ghost { background: var(--s2); color: var(--tx); }

/* bottom tabs */
#tabs { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: flex; background: var(--s1);
  padding: 0 var(--sr) var(--sb) var(--sl); height: calc(var(--nav) + var(--sb)); }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; color: var(--mu); }
#tabs a svg { width: 56px; height: 30px; padding: 4px 16px; border-radius: 99px; transition: background .2s; }
#tabs a.on { color: var(--tx); }
#tabs a.on svg { background: var(--ac-bg); color: var(--ac); }
body.sub #tabs, body.reading #tabs { display: none; }

/* lists */
.sec { padding: 16px 16px 6px; font-size: 13px; font-weight: 600; color: var(--ac); }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 16px; min-height: 60px; text-align: left; }
.row:active { background: var(--s1); }
.row .rt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row b, .ch b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row span, .ch span { color: var(--mu); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .go { color: var(--mu); }
.row.danger b { color: #ffb4ab; }
.thumb { width: 44px; height: 62px; border-radius: 4px; object-fit: cover; background: var(--s2); flex: none; }
.icon { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; background: var(--s2); flex: none; }
.dim { opacity: .62; }
.empty { padding: 64px 32px; text-align: center; color: var(--mu); }
.btn { display: inline-block; padding: 10px 20px; border-radius: 99px; background: var(--ac); color: var(--ac-on); font-weight: 600; margin: 4px; }
.btn.ghost { background: var(--s2); color: var(--tx); }
.spin { width: 32px; height: 32px; margin: 48px auto; border: 3px solid var(--s3); border-top-color: var(--ac); border-radius: 50%; animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* search + chips */
.searchbar { display: none; padding: 4px 16px 8px; }
.searchbar.show { display: flex; align-items: center; position: relative; }
.searchbar .clear { position: absolute; right: 22px; width: 36px; height: 36px; border-radius: 50%; color: var(--mu); }
.searchbar input { width: 100%; padding: 11px 44px 11px 16px; border: 0; border-radius: 99px; background: var(--s2); outline: none; -webkit-appearance: none; }
.chips { display: flex; gap: 8px; padding: 4px 16px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { flex: none; min-height: 38px; display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--s3); font-size: 14px; color: var(--mu); }
.chip.on { background: var(--ac-bg); border-color: var(--ac-bg); color: var(--ac); }
.chip i { font-style: normal; opacity: .7; margin-left: 2px; }

/* cover grid (Mihon compact grid) */
.grid { display: grid; gap: 8px; padding: 0 8px 8px; }
.grid.c2 { grid-template-columns: repeat(2, 1fr); } .grid.c3 { grid-template-columns: repeat(3, 1fr); } .grid.c4 { grid-template-columns: repeat(4, 1fr); }
@media (min-width: 700px) { .grid.c3 { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.card { position: relative; aspect-ratio: 2 / 3; border-radius: var(--r); overflow: hidden; background: var(--s1); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ct { position: absolute; inset: auto 0 0; padding: 24px 8px 6px; font-size: 12.5px; font-weight: 500; line-height: 1.25;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .badge { position: absolute; top: 6px; left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--ac); color: var(--ac-on); font-size: 12px; font-weight: 700; }
.card .badge.lib { background: rgba(0,0,0,.7); color: var(--tx); font-weight: 500; font-size: 11px; }
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px 8px; scrollbar-width: none; }
.hscroll .card { flex: 0 0 110px; }
.hscroll .spin { margin: 24px; }
.hscroll p { padding: 8px 0; margin: 0; }

/* manga detail */
.hero { position: relative; display: flex; gap: 16px; align-items: flex-end; padding: calc(var(--st) + 72px) 16px 16px; overflow: hidden; }
.hero-bg { position: absolute; inset: 0; background: center/cover; opacity: .35; filter: blur(14px); transform: scale(1.2); }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, var(--bg)); }
.hero > * { position: relative; z-index: 1; }
.hero-cover { width: 110px; aspect-ratio: 2 / 3; border-radius: var(--r); object-fit: cover; background: var(--s2); box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.hero-info h2 { margin: 0 0 6px; font-size: 20px; font-weight: 600; line-height: 1.25; }
.hero-info p { margin: 0; color: var(--mu); font-size: 13px; text-transform: capitalize; }
.actions { display: flex; justify-content: space-around; padding: 4px 16px 8px; }
.act { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--mu); padding: 6px 16px; }
.act.on { color: var(--ac); }
.desc { margin: 0; padding: 4px 16px 12px; color: var(--mu); font-size: 14px; white-space: pre-line; }
.desc.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.ch { display: flex; align-items: center; padding-left: 16px; min-height: 60px; }
.ch > a { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 0; }
.ch .st { color: var(--mu); display: grid; } .ch .st svg { width: 18px; height: 18px; }
.ch .ib { color: var(--mu); }
.fab { position: fixed; z-index: 6; right: calc(16px + var(--sr)); bottom: calc(20px + var(--sb)); display: flex; align-items: center; gap: 8px;
  padding: 16px 22px 16px 18px; border-radius: 16px; background: var(--ac-bg); color: var(--ac); font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,.4); }

/* settings */
.form { padding: 0 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--mu); }
.form input:not([type=checkbox]), .form select { padding: 11px 14px; border: 0; border-radius: var(--r); background: var(--s2); color: var(--tx); outline: none; -webkit-appearance: none; }
.form label.sw { flex-direction: row; align-items: center; justify-content: space-between; color: var(--tx); }
.form label.sw small { display: block; color: var(--mu); font-size: 12px; }
.sw input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; border-radius: 99px; background: var(--s3); position: relative; transition: .2s; flex: none; }
.sw input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--mu); transition: .2s; }
.sw input:checked { background: var(--ac); } .sw input:checked::after { left: 23px; background: var(--ac-on); }
.seg { display: flex; background: var(--s2); border-radius: 99px; padding: 3px; }
.seg button { flex: 1; min-height: 40px; padding: 8px; border-radius: 99px; color: var(--mu); font-size: 14px; }
.seg button.on { background: var(--ac-bg); color: var(--ac); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--mu); }
#srv { display: flex; flex-direction: column; gap: 12px; }
#cred { display: flex; flex-direction: column; gap: 12px; }
.note { margin: 8px 16px; padding: 12px 14px; border-radius: var(--r); background: var(--ac-bg); color: var(--tx); font-size: 14px; }
.foot { text-align: center; font-size: 12px; padding: 24px; }

/* sheet + toast */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,0); transition: background .2s; display: flex; align-items: flex-end; }
.sheet-bg.open { background: rgba(0,0,0,.55); }
.sheet { width: 100%; background: var(--s1); border-radius: 20px 20px 0 0; padding: 8px 0 calc(8px + var(--sb)); transform: translateY(100%); transition: transform .2s; }
.sheet-bg.open .sheet { transform: none; }
.sheet-title { padding: 12px 20px; color: var(--mu); font-size: 13px; }
.sheet button { display: block; width: 100%; padding: 15px 20px; text-align: left; font-size: 16px; }
.sheet button:active { background: var(--s2); }
.sheet button.danger { color: #ffb4ab; }
.sheet button.cancel { color: var(--mu); }
#toast { position: fixed; z-index: 60; left: 16px; right: 16px; margin-inline: auto; width: max-content; bottom: calc(var(--nav) + var(--sb) + 16px); transform: translateY(20px); opacity: 0;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px; background: #e3e3e6; color: #111; font-size: 14px; transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
body.reading #toast, body.sub #toast { bottom: calc(var(--sb) + 90px); }

/* reader */
body.reading { padding: 0; overflow: hidden; }
.reader { position: fixed; inset: 0; background: #000; z-index: 20; }
.reader > .spin { margin-top: 45vh; }
.r-body { position: absolute; inset: 0; overflow-y: auto; overflow-anchor: none; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.r-body.webtoon .pg { min-height: 140vw; background: #0a0a0a; display: flex; align-items: center; justify-content: center; }
.r-body.webtoon .pg.ok { min-height: 0; background: none; }
.r-body.webtoon .pg img { display: block; width: 100%; height: auto; max-width: 900px; margin: 0 auto; }
.r-body.webtoon .pg:not(.ok) img { display: none; }
.r-body.paged { overflow: hidden; touch-action: pan-y pinch-zoom; }
.slot { position: absolute; inset: 0; display: grid; place-items: center; }
.slot img { max-width: 100%; max-height: 100%; object-fit: contain; }
.r-end { min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 48px 24px calc(48px + var(--sb)); text-align: center; color: var(--mu); }
.r-end b { color: var(--tx); }
.r-top, .r-bot { position: absolute; left: 0; right: 0; z-index: 2; display: flex; align-items: center; gap: 4px; background: rgba(18,19,22,.94);
  transition: transform .2s, opacity .2s; }
.r-top { top: 0; padding: calc(var(--st) + 4px) calc(4px + var(--sr)) 4px calc(4px + var(--sl)); transform: translateY(-100%); opacity: 0; }
.r-bot { bottom: 0; padding: 8px calc(8px + var(--sr)) calc(var(--sb) + 8px) calc(8px + var(--sl)); transform: translateY(100%); opacity: 0; }
.reader.ui .r-top, .reader.ui .r-bot { transform: none; opacity: 1; }
.r-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.r-title b, .r-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-title b { font-weight: 500; } .r-title span { font-size: 13px; color: var(--mu); }
.r-slider { flex: 1; display: flex; align-items: center; gap: 10px; }
.r-num { font-size: 13px; color: var(--mu); min-width: 52px; text-align: center; }
.r-slider input { flex: 1; height: 44px; accent-color: var(--ac); }
.reader .empty { color: var(--mu); }
.tbtn.mode { display: flex; align-items: center; gap: 6px; margin-right: 6px; padding: 6px 12px 6px 10px; }
.tbtn.mode svg { width: 18px; height: 18px; }
.card img.broken { opacity: 0; }

/* manga detail: keep the last chapter clear of the Resume button */
#chs { padding-bottom: calc(88px + var(--sb)); }
/* reader: page counter while the bars are hidden (like Mihon) */
.r-pill { position: absolute; z-index: 1; left: 50%; transform: translateX(-50%); bottom: calc(var(--sb) + 4px);
  padding: 2px 8px; border-radius: 99px; background: rgba(0,0,0,.6); color: #ddd; font-size: 11px; pointer-events: none; transition: opacity .2s; }
.reader.ui .r-pill { opacity: 0; }
.r-top.static { transform: none; opacity: 1; position: relative; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; } }
