/* ---------- Tema ---------- */
:root {
    --bg: #0f1115;
    --surface: #181b22;
    --surface-2: #222631;
    --line: #2c313d;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --accent: #4f8cff;
    --accent-text: #fff;
    --ok: #3fb97c;
    --danger: #ef5b5b;
    --live: #ff5d5d;
    --radius: 10px;
    --nav-h: 58px;
    --page-w: 800px;
    --page-gap: 0px;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f3f4f7; --surface: #fff; --surface-2: #eef0f4; --line: #dde0e6;
        --text: #1d2129; --muted: #687080; --accent: #2f6fe4;
        color-scheme: light;
    }
}
:root[data-theme="light"] {
    --bg: #f3f4f7; --surface: #fff; --surface-2: #eef0f4; --line: #dde0e6;
    --text: #1d2129; --muted: #687080; --accent: #2f6fe4;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }

.nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
}
.nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 11px; color: var(--muted);
}
.nav a svg { width: 22px; height: 22px; }
.nav a.on { color: var(--accent); font-weight: 600; }

@media (min-width: 820px) {
    .nav { top: 0; bottom: auto; height: 52px; padding: 0; justify-content: center; border-top: 0; border-bottom: 1px solid var(--line); }
    .nav a { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 0 18px; font-size: 14px; }
    .nav a svg { width: 18px; height: 18px; }
    main { padding: 72px 24px 32px; }
    #toast { bottom: 24px; }
}

body.reading .nav { display: none; }
body.reading main { max-width: none; padding: 0 0 80px; }

/* ---------- Dasar ---------- */
h2.sec { font-size: 17px; margin: 24px 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
h2.sec:first-child { margin-top: 4px; }
h2.sec a { font-weight: 500; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 10px; }
.mt-xs { margin-top: 3px; }
.mb { margin-bottom: 10px; }
.acc { color: var(--accent); }
.pad { padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 0 16px; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--surface-2); font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { background: none; border: 0; padding: 8px; color: var(--muted); display: inline-flex; align-items: center; }
.more { display: flex; justify-content: center; margin: 18px 0 4px; }

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.input, select.input {
    width: 100%; min-height: 42px; padding: 0 12px;
    border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.card-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px; border-radius: 99px; font-size: 13px; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); white-space: nowrap; }
.chip.on, .chip.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); border-color: transparent; }
.chip i { font-style: normal; color: var(--muted); font-size: 11px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-scroll { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 4px; }
.chips-scroll::-webkit-scrollbar { display: none; }

/* Tombol segmen (Harian/Mingguan, tema, dll) */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 99px; padding: 3px; gap: 2px; border: 1px solid var(--line); }
.seg > * { border: 0; background: none; padding: 5px 12px; border-radius: 99px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.seg > .on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.15); }

/* ---------- Kartu ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
@media (max-width: 380px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.card { position: relative; display: block; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.card > a { display: block; }
/* Ukuran asli tidak diketahui: tampil utuh dalam kotak portrait. Diketahui (.nat): ikut rasio aslinya */
.cover { width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: var(--surface-2); }
.cover.nat { aspect-ratio: auto; height: auto; object-fit: fill; }
.grid.land { grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); }
.card .meta { padding: 8px 9px 10px; }
.card .title { font-size: 13.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { margin-top: 4px; font-size: 12px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub2 { margin-top: 2px; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .x {
    position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 99px;
    border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; line-height: 1;
}
.badges { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; flex-wrap: wrap; pointer-events: none; }
.badges span { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; }
.badges .b-rank { background: var(--accent); }
.badges .b-new { background: var(--ok); }
.badges .b-live::first-letter { color: var(--live); }

.hscroll { display: grid; grid-auto-flow: column; grid-auto-columns: 124px; gap: 10px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll .card { scroll-snap-align: start; }
.hscroll.land { grid-auto-columns: 210px; }
.sk { background: var(--surface-2); border-radius: var(--radius); aspect-ratio: 3 / 4.6; }
.hscroll.land .sk { aspect-ratio: 16 / 13; }

/* Daftar baris (peringkat, A–Z, riwayat) */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .rk { width: 28px; text-align: center; font-weight: 800; color: var(--muted); flex: none; }
.item .rk.top { color: var(--accent); }
.thumb-w { flex: none; width: 52px; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.thumb { display: block; width: 100%; height: 70px; object-fit: contain; }
.thumb.nat { height: auto; }

/* ---------- Mode kantor: cover diburamkan sampai diketuk ---------- */
[data-office] .cover:not(.show), [data-office] .thumb:not(.show) { filter: blur(14px) saturate(.5); transform: scale(1.1); }

/* ---------- Jelajah ---------- */
.filters { display: grid; gap: 10px; margin: 12px 0 16px; }
.filters .row > select { flex: 1; min-width: 130px; }
.letters { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px 12px; padding: 0 16px 4px; }
.letters::-webkit-scrollbar { display: none; }
.letters a { flex: none; min-width: 36px; height: 36px; display: grid; place-items: center; padding: 0 8px; border-radius: 8px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.letters a.on { background: var(--accent); color: var(--accent-text); }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 16px 0 4px; }

/* ---------- Detail ---------- */
.detail { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.detail .cv { border-radius: var(--radius); overflow: hidden; }
.detail h1 { font-size: 19px; line-height: 1.25; margin: 0 0 4px; }
@media (min-width: 640px) { .detail { grid-template-columns: 190px 1fr; gap: 22px; } .detail h1 { font-size: 24px; } }
.synopsis { color: var(--muted); font-size: 14px; margin: 12px 0 0; white-space: pre-line; cursor: pointer; }
.synopsis.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.actions .btn.primary { flex: 1; min-width: 160px; }

.chapters { max-height: 65vh; overflow-y: auto; }
.chapters a { display: flex; justify-content: space-between; gap: 10px; padding: 13px 14px; }
.chapters a.read { color: var(--muted); }
.chapters a.read .t::before { content: "✓ "; color: var(--ok); }
.chapters a.last { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* ---------- Reader ---------- */
.rbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 6px; height: 48px; padding: 0 8px;
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line); transition: transform .2s;
}
.rbar.hide { transform: translateY(-100%); }
.rbar .t { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.rset { position: sticky; top: 48px; z-index: 19; background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 16px; display: grid; gap: 10px; }
.rset .row { justify-content: space-between; }
.pages { max-width: var(--page-w); margin: 0 auto; background: #000; display: flex; flex-direction: column; gap: var(--page-gap); }
.pg { width: 100%; min-height: 70vh; background: #111; }
.pg.ok { min-height: 0; background: none; }
.pg.err { min-height: 120px; cursor: pointer; }
.rnav { display: flex; gap: 8px; max-width: var(--page-w); margin: 16px auto 0; padding: 0 12px; }
.rnav .btn { flex: 1; }
.next-cta { display: block; max-width: var(--page-w); margin: 20px auto 0; padding: 0 12px; }
.next-cta a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 17px; }
.next-cta a span { font-weight: 500; font-size: 13px; opacity: .85; }

/* ---------- Login & akun ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card-box { width: 100%; max-width: 360px; }
.login h1 { margin: 0 0 18px; font-size: 22px; text-align: center; }
.settings > * + * { border-top: 1px solid var(--line); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; }
.setting .d { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.switch { appearance: none; width: 44px; height: 26px; border-radius: 99px; background: var(--line); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
.switch:disabled { opacity: .5; cursor: default; }

.badge { font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.admin { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.badge.off { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.edit { padding: 12px 14px 14px; background: var(--surface-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

/* ---------- Lain-lain ---------- */
.center { display: grid; place-items: center; padding: 60px 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast {
    position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 50;
    transform: translateX(-50%); max-width: calc(100% - 32px);
    padding: 10px 16px; border-radius: 99px; background: var(--text); color: var(--bg); font-size: 14px;
    opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
