/* =========================================================
   Pendekar Sadis — pembaca novel
   Tema via html[data-theme], tipografi baca via CSS variable
   ========================================================= */

:root {
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --radius: 14px;
  --radius-sm: 10px;

  /* pengaturan pembaca (diubah oleh JS) */
  --reader-font-size: 19px;
  --reader-line-height: 1.75;
  --reader-width: 38rem;
  --reader-font: var(--font-serif);
  --reader-para-gap: 0.15em;
}

html[data-theme="light"] {
  --bg: #fdfdfc;
  --bg-elev: #ffffff;
  --fg: #1b1b1b;
  --fg-muted: #6b6b6b;
  --accent: #9a3412;
  --accent-soft: #fdece2;
  --border: #e6e3dd;
  --shadow: 0 10px 40px rgba(0,0,0,.10);
  --overlay: rgba(20,20,20,.4);
}

html[data-theme="sepia"] {
  --bg: #f4ecd8;
  --bg-elev: #fbf5e6;
  --fg: #3b3226;
  --fg-muted: #857a66;
  --accent: #8a5a2b;
  --accent-soft: #efe0c6;
  --border: #e2d7bd;
  --shadow: 0 10px 40px rgba(80,60,20,.16);
  --overlay: rgba(60,45,20,.4);
}

html[data-theme="dark"] {
  --bg: #14161a;
  --bg-elev: #1c1f25;
  --fg: #cdd2d9;
  --fg-muted: #858c96;
  --accent: #e0a06a;
  --accent-soft: #2a2520;
  --border: #2a2e36;
  --shadow: 0 10px 40px rgba(0,0,0,.5);
  --overlay: rgba(0,0,0,.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { transition: background-color .25s ease, color .25s ease; }

.view { min-height: 100dvh; }
[hidden] { display: none !important; }

a { color: inherit; text-decoration: none; cursor: pointer; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- tombol ---------- */
.btn-primary, .btn-ghost, .icon-btn {
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  transition: background-color .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn-primary {
  display: inline-block;
  padding: .7rem 1.35rem;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border: none;
}
html[data-theme="dark"] .btn-primary { color: #14161a; }
.btn-primary:hover { opacity: .88; }

.btn-ghost {
  display: inline-block;
  padding: .6rem 1.1rem;
  border: 1px solid var(--border);
  color: var(--fg);
}
.btn-ghost:hover { background: var(--bg-elev); }
.btn-ghost.full { width: 100%; margin-top: .5rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem; height: 2.6rem;
  font-size: 1.05rem;
  border-radius: 12px;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn .aa { font-family: var(--font-serif); font-weight: 600; font-size: 1rem; }

/* =========================================================
   TAMPILAN DAFTAR ISI
   ========================================================= */
.lib-wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

.lib-hero {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2.75rem;
  align-items: center;
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--border);
}

/* sampul */
.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 6px 14px 14px 6px;
  background:
    radial-gradient(120% 80% at 0% 0%, #b3371f 0%, #7a1f12 55%, #521009 100%);
  color: #f7e3c4;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  padding: 1.4rem 1.2rem;
  overflow: hidden;
}
.cover::before {
  content: "";
  position: absolute; inset: 0 auto 0 0; width: 10px;
  background: linear-gradient(90deg, rgba(0,0,0,.45), transparent);
}
.cover::after {
  content: "";
  position: absolute; inset: 14px;
  border: 1px solid rgba(247,227,196,.4);
  border-radius: 4px;
  pointer-events: none;
}
.cover-series { font-size: .62rem; letter-spacing: .16em; text-transform: uppercase; opacity: .85; }
.cover-no { font-size: .72rem; letter-spacing: .3em; opacity: .7; margin-top: .15rem; }
.cover-title {
  margin: auto 0;
  font-family: var(--font-serif);
  font-size: 2.1rem;
  line-height: 1.06;
  font-weight: 700;
  letter-spacing: .01em;
}
.cover-author { font-size: .68rem; letter-spacing: .04em; opacity: .9; line-height: 1.4; }
.cover-author small { opacity: .7; }

.lib-meta .eyebrow {
  margin: 0 0 .4rem;
  font-size: .7rem; letter-spacing: .18em; text-transform: uppercase;
  color: var(--fg-muted);
}
.lib-title { margin: 0; font-family: var(--font-serif); font-size: clamp(2rem, 5vw, 3rem); line-height: 1.05; }
.lib-author { margin: .4rem 0 1.4rem; color: var(--fg-muted); }

.stats { display: flex; gap: 1.75rem; margin: 0 0 1.6rem; padding: 0; list-style: none; }
.stats li { display: flex; flex-direction: column; }
.stats b { font-family: var(--font-serif); font-size: 1.35rem; }
.stats span { font-size: .72rem; color: var(--fg-muted); letter-spacing: .04em; }

.overall { margin-top: 1.5rem; max-width: 22rem; }
.overall .bar, .progress-track { background: var(--border); overflow: hidden; }
.overall .bar { height: 6px; border-radius: 999px; }
.overall .bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }
.overall span { display: block; margin-top: .45rem; font-size: .76rem; color: var(--fg-muted); }

/* daftar bab */
.toc { margin-top: 2.5rem; }
.toc-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toc-head h3 { margin: 0; font-family: var(--font-serif); font-size: 1.3rem; }
#search {
  padding: .55rem .95rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--fg);
  min-width: 14rem;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.toc-hint { margin: -0.2rem 0 1.1rem; font-size: .78rem; color: var(--fg-muted); max-width: 42rem; }

.chapter-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: .65rem; }
.chapter-list li { display: flex; }
.jilid-card {
  display: flex; flex-direction: column;
  width: 100%;
  padding: .75rem .85rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  transition: border-color .15s ease, transform .15s ease;
}
.jilid-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.jilid-card.reading { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }

.jilid-main { display: flex; align-items: center; gap: .8rem; }
.chapter-list .num {
  flex: 0 0 2.1rem; height: 2.1rem;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  font-family: var(--font-serif); font-weight: 700;
}
.jilid-main .txt { flex: 1; min-width: 0; }
.jilid-main .txt b { display: block; font-weight: 600; }
.jilid-main .txt span { font-size: .74rem; color: var(--fg-muted); }
.jilid-main .done { color: var(--accent); font-size: 1.05rem; }

/* chip nomor bagian */
.parts { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .65rem; }
.chip {
  display: inline-grid; place-items: center;
  min-width: 1.75rem; height: 1.75rem;
  padding: 0 .45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  transition: border-color .12s ease, background-color .12s ease, color .12s ease;
}
.chip:hover { border-color: var(--accent); color: var(--fg); }
.chip.done { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip.current { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
html[data-theme="dark"] .chip.current { color: #14161a; }

.lib-footer { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.lib-footer p { margin: 0; font-size: .76rem; color: var(--fg-muted); }

/* =========================================================
   TAMPILAN PEMBACA
   ========================================================= */
#view-reader { display: flex; flex-direction: column; height: 100dvh; }

.progress-track { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 40; }
.progress-track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

.reader-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  transition: transform .28s ease, opacity .28s ease;
}
.reader-bar.hidden { transform: translateY(-102%); opacity: 0; }
.reader-bar-mid { flex: 1; min-width: 0; text-align: center; line-height: 1.15; }
.reader-bar-mid b { display: block; font-family: var(--font-serif); font-size: .95rem; }
.reader-bar-mid span { font-size: .7rem; color: var(--fg-muted); }

.reader-scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.reader-col { max-width: var(--reader-width); margin: 0 auto; padding: 3rem 1.5rem 8rem; }

.chapter-kicker { margin: 0 0 .35rem; font-size: .72rem; letter-spacing: .2em; text-transform: uppercase; color: var(--fg-muted); }
.chapter-heading { margin: 0 0 1.6rem; font-family: var(--font-serif); font-size: 1.9rem; font-weight: 700; }
.chapter-heading::after { content: ""; display: block; width: 3rem; height: 3px; margin-top: .8rem; background: var(--accent); border-radius: 2px; }

.chapter-body {
  font-family: var(--reader-font);
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  overflow-wrap: break-word;
}
.chapter-body p { margin: 0 0 0.85em; text-indent: 1.6em; }
.chapter-body p:first-child { text-indent: 0; }
.chapter-body p:first-child::first-letter {
  float: left;
  font-size: 3.1em;
  line-height: .82;
  padding: .06em .12em 0 0;
  font-weight: 700;
  color: var(--accent);
}
.chapter-body p:first-of-type { margin-bottom: 1.1em; }

.chapter-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.chapter-nav a { flex: 1 1 12rem; text-align: center; }
.chapter-nav a[aria-disabled="true"] { opacity: .35; pointer-events: none; }

.reader-dock {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: .35rem;
  padding: .45rem .75rem calc(.45rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-top: 1px solid var(--border);
}
.reader-dock .icon-btn:last-child { margin-left: auto; }
.dock-progress { flex: 1; text-align: center; font-size: .78rem; color: var(--fg-muted); font-variant-numeric: tabular-nums; }

/* =========================================================
   PANEL BAWAH (sheet)
   ========================================================= */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  background: var(--overlay);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet-panel {
  width: 100%; max-width: 30rem;
  max-height: 88dvh; overflow-y: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 1.2rem 1.25rem calc(1.4rem + env(safe-area-inset-bottom));
  animation: slideup .24s cubic-bezier(.2,.8,.2,1);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.sheet-head h3 { margin: 0; font-family: var(--font-serif); font-size: 1.15rem; }

.field { margin: 1.15rem 0; }
.field > label { display: flex; justify-content: space-between; font-size: .82rem; color: var(--fg-muted); margin-bottom: .55rem; }
.field output { color: var(--fg); font-variant-numeric: tabular-nums; }

.seg { display: flex; gap: .4rem; border: 1px solid var(--border); border-radius: 999px; padding: .25rem; }
.seg button { flex: 1; padding: .5rem; border: none; border-radius: 999px; background: transparent; font-size: .85rem; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
html[data-theme="dark"] .seg button[aria-pressed="true"] { color: #14161a; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { padding: .55rem 0; border-bottom: 1px solid var(--border); }
.toc-list li:last-child { border-bottom: none; }
.toc-jilid-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; font-size: .9rem; }
.toc-jilid-head span { font-size: .72rem; color: var(--fg-muted); white-space: nowrap; }
.toc-list li.reading .toc-jilid-head b { color: var(--accent); }
.toc-list .parts { margin-top: .45rem; }

@keyframes fade { from { opacity: 0; } }
@keyframes slideup { from { transform: translateY(12%); opacity: .4; } }

/* =========================================================
   RESPONSIF
   ========================================================= */
@media (max-width: 720px) {
  .lib-wrap { padding: 1.5rem 1rem 3rem; }
  .lib-hero { grid-template-columns: 1fr; gap: 1.75rem; text-align: center; justify-items: center; }
  .cover { width: 190px; }
  .stats { justify-content: center; }
  .overall { margin-left: auto; margin-right: auto; }
  .chapter-list { grid-template-columns: 1fr; }
  .reader-col { padding: 1.75rem 1.15rem 7rem; }
  .chapter-body { text-align: left; }
  .lib-footer { justify-content: center; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .reader-scroll { scroll-behavior: auto; }
}
