/* =============================================================================
   Inkwell — bright, playful e-book store (Epic!-inspired)
   ============================================================================= */
:root {
  --brand: #16a6e0;
  --brand-d: #0d8cc2;
  --pink: #ff5c8a;
  --yellow: #ffc83d;
  --green: #28c76f;
  --purple: #8b5cf6;
  --radius: 18px;
  --maxw: 1240px;
  font-synthesis: none;

  /* light theme (default) */
  --ink: #2a2d43;
  --muted: #7a8095;
  --line: #eceef3;
  --bg: #ffffff;
  --bg-soft: #f6f8fb;
  --card: #ffffff;
  --hairline: rgba(31,45,80,.06);
  --shadow: 0 10px 30px rgba(31, 45, 80, 0.10);
  --shadow-sm: 0 4px 14px rgba(31, 45, 80, 0.08);
  --input-bg: #ffffff;
}
html[data-theme="dark"] {
  --ink: #e8eaf2;
  --muted: #9aa1b7;
  --line: #272b38;
  --bg: #0f1118;
  --bg-soft: #1a1d28;
  --card: #181b25;
  --hairline: rgba(0,0,0,.4);
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.4);
  --input-bg: #11141c;
}
html, body, .topbar, .modal, .demo-menu, .field input { transition: background .22s ease, color .22s ease, border-color .22s ease; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img, svg { display: block; }
::selection { background: #cdeefb; }

/* scrollbars on shelves */
.shelf-scroll::-webkit-scrollbar { height: 0; }
.app-scroll::-webkit-scrollbar { width: 10px; }
.app-scroll::-webkit-scrollbar-thumb { background: #d7dbe6; border-radius: 8px; }

/* ============================ TOP BAR ===================================== */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--bg); border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 var(--hairline);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 12px 22px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 0; line-height: 1; cursor: pointer; user-select: none; }
.brand b {
  font-family: 'Fraunces', Georgia, serif; font-weight: 600;
  font-size: 26px; letter-spacing: -0.5px; color: var(--brand); line-height: 1;
}
.brand b span { color: var(--pink); }
.brand i {
  font-style: normal; font-size: 11px; font-weight: 600; color: var(--muted);
  letter-spacing: .4px; margin-top: 3px; margin-left: 1px;
}
.nav-tabs { display: flex; gap: 6px; margin-left: 8px; }
.nav-tabs button {
  font-weight: 700; font-size: 14px; color: var(--muted);
  padding: 8px 14px; border-radius: 10px; letter-spacing: 0.3px;
}
.nav-tabs button:hover { background: var(--bg-soft); color: var(--ink); }
.nav-tabs button.on { color: var(--brand); }
.nav-tabs button.on::after {
  content: ''; display: block; height: 3px; border-radius: 3px;
  background: var(--brand); margin-top: 5px;
}
.search {
  flex: 1; max-width: 460px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-soft); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 9px 16px; transition: border-color .15s, background .15s;
}
.search:focus-within { border-color: var(--brand); background: #fff; }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; border: none; outline: none; background: none; font-size: 14px; color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.trial-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: linear-gradient(135deg, #fff3d6, #ffe3ec);
  border: 1.5px solid #ffd98a; color: #b06a00;
  font-weight: 700; font-size: 13px; padding: 7px 13px; border-radius: 999px;
}
.trial-pill.expired { background: #ffecec; border-color: #ffc2c2; color: #c0392b; }
.trial-pill.premium { background: #e7f8ee; border-color: #aee6c6; color: #1c854f; }
.trial-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.icon-btn {
  display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 10px;
}
.icon-btn:hover { color: var(--brand); background: var(--bg-soft); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--purple));
  color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 14px;
}

/* ============================ TRIAL STRIP ================================= */
.trial-strip {
  background: linear-gradient(100deg, var(--brand), #4ec3f0);
  color: #fff; text-align: center; font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; display: flex; align-items: center; justify-content: center; gap: 14px;
}
.trial-strip.warn { background: linear-gradient(100deg, #ff8a3d, var(--pink)); }
.trial-strip.expired { background: linear-gradient(100deg, #e23b3b, #b21f1f); }
.trial-strip button {
  background: #fff; color: var(--brand); font-weight: 800; font-size: 13px;
  padding: 6px 14px; border-radius: 999px;
}
.trial-strip.warn button, .trial-strip.expired button { color: #c0392b; }

/* ============================ PAGE LAYOUT ================================ */
.page { max-width: var(--maxw); margin: 0 auto; padding: 26px 22px 80px; }
.hero {
  margin: 6px 0 26px; border-radius: 26px; padding: 34px 38px; color: #fff;
  background: linear-gradient(120deg, #2657d6, var(--brand) 60%, #4ec3f0);
  position: relative; overflow: hidden;
}
.hero::after {
  content: '📚✨'; position: absolute; right: 28px; bottom: -10px; font-size: 120px; opacity: .18;
}
.hero h1 { margin: 0 0 8px; font-family: 'Fraunces', serif; font-size: 34px; font-weight: 600; }
.hero p { margin: 0 0 18px; font-size: 15.5px; max-width: 540px; opacity: .95; }
.hero .cta {
  background: #fff; color: var(--brand); font-weight: 800; font-size: 15px;
  padding: 12px 22px; border-radius: 999px; box-shadow: var(--shadow-sm);
}
.hero small { display: block; margin-top: 10px; opacity: .85; font-size: 12.5px; }

/* ----- shelves ----- */
.shelf { margin-bottom: 34px; position: relative; }
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.shelf-head h2 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -0.3px; }
.shelf-head .see { color: var(--brand); font-weight: 700; font-size: 13px; }
.shelf-scroll {
  display: flex; gap: 18px; overflow-x: auto; scroll-behavior: smooth;
  padding: 4px 4px 14px; scroll-snap-type: x proximity;
}
.shelf-arrow {
  position: absolute; top: 46%; right: -6px; z-index: 5;
  width: 44px; height: 44px; border-radius: 50%; background: var(--card);
  box-shadow: var(--shadow); color: var(--brand); display: grid; place-items: center;
}
.shelf-arrow.left { left: -6px; right: auto; }
.shelf-arrow:hover { background: var(--brand); color: #fff; }

/* ----- series (landscape) cards ----- */
.series-card {
  flex: none; width: 230px; height: 134px; border-radius: var(--radius);
  scroll-snap-align: start; position: relative; overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: transform .15s, box-shadow .15s;
  color: #fff; display: flex; align-items: flex-end; padding: 14px;
}
.series-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.series-card .bgsvg { position: absolute; inset: 0; }
.series-card .lbl { position: relative; z-index: 2; }
.series-card .lbl b { display: block; font-family: 'Fraunces', serif; font-size: 19px; line-height: 1.05; text-shadow: 0 2px 8px rgba(0,0,0,.35); }
.series-card .lbl span { font-size: 11.5px; font-weight: 700; opacity: .92; text-transform: uppercase; letter-spacing: .5px; }
.series-card .tag {
  position: absolute; top: 10px; left: 10px; z-index: 2; font-size: 10px; font-weight: 800;
  background: rgba(255,255,255,.92); color: var(--ink); padding: 3px 8px; border-radius: 999px; text-transform: uppercase;
}

/* ----- book (portrait) cards ----- */
.book-card {
  flex: none; width: 150px; scroll-snap-align: start; cursor: pointer; position: relative;
}
.grid .book-card { width: auto; }
.cover-wrap {
  position: relative; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm);
  aspect-ratio: 2/3; background: #e9edf4; transition: transform .15s, box-shadow .15s;
}
.book-card:hover .cover-wrap { transform: translateY(-4px); box-shadow: var(--shadow); }
.cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.cover-badge {
  position: absolute; top: 8px; left: 8px; font-size: 10px; font-weight: 800;
  padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; color: #fff;
  background: rgba(20,25,40,.62); backdrop-filter: blur(2px);
}
.cover-badge.comic { background: rgba(139,92,246,.9); }
.cover-badge.manga { background: rgba(255,92,138,.92); }
.cover-badge.anime { background: rgba(58,109,240,.92); }
.lock-chip {
  position: absolute; bottom: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(20,25,40,.72); color: #fff; display: grid; place-items: center;
}
.progress-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.4); }
.progress-bar i { display: block; height: 100%; background: var(--green); }
.book-meta { padding: 9px 2px 0; }
.book-meta b { font-size: 13.5px; font-weight: 700; line-height: 1.25; display: block;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta span { font-size: 12px; color: var(--muted); }
.stars { color: var(--yellow); font-size: 12px; margin-top: 2px; }

/* ----- explore grid + filters ----- */
.filters { display: flex; flex-wrap: wrap; gap: 9px; margin: 4px 0 26px; }
.chip {
  font-weight: 700; font-size: 13px; padding: 8px 15px; border-radius: 999px;
  background: var(--bg-soft); border: 1.5px solid var(--line); color: var(--muted);
}
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 24px 18px;
}
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
.empty .big { font-size: 52px; }

/* ============================ COLLECTIONS ================================ */
.col-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; margin-bottom: 34px; }
.col-card {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; cursor: pointer; transition: transform .15s, box-shadow .15s, border-color .15s; text-align: left;
}
.col-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--brand); }
.col-covers {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; height: 96px; overflow: hidden;
  border-radius: 10px; background: var(--card);
}
.col-covers img { width: 100%; height: 96px; object-fit: cover; border-radius: 6px; }
.col-covers img:only-child { grid-column: span 4; object-position: top; }
.col-empty-thumb { grid-column: span 4; display: grid; place-items: center; font-size: 34px; height: 96px; opacity: .5; }
.col-card-meta { padding: 10px 4px 2px; }
.col-card-meta b { display: block; font-size: 15px; font-weight: 700; }
.col-card-meta span { font-size: 12.5px; color: var(--muted); }
.col-new-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-style: dashed; color: var(--muted); min-height: 142px; font-weight: 700; }
.col-new-card:hover { color: var(--brand); }
.col-new-card .plus { font-size: 30px; line-height: 1; }

.col-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.col-title-input {
  flex: 1; font-family: 'Fraunces', serif; font-size: 26px; font-weight: 600; color: var(--ink);
  background: none; border: none; border-bottom: 2px solid transparent; outline: none; padding: 4px 2px;
}
.col-title-input:focus { border-bottom-color: var(--brand); }
.col-item { position: relative; }
.col-remove {
  position: absolute; top: 6px; right: 6px; z-index: 4; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(20,25,40,.72); color: #fff; display: grid; place-items: center; opacity: 0; transition: opacity .15s;
}
.col-item:hover .col-remove { opacity: 1; }

.col-picker {
  margin-top: 14px; border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--bg-soft);
}
.col-picker h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.col-picker-list { display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow-y: auto; margin-bottom: 10px; }
.muted-note { color: var(--muted); font-size: 13px; margin: 2px 0 6px; }
.col-row {
  display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 14px; color: var(--ink);
}
.col-row:hover { border-color: var(--brand); }
.col-row .mark { font-size: 12.5px; color: var(--muted); font-weight: 700; }
.col-row.on { border-color: var(--green); }
.col-row.on .mark { color: var(--green); }
.col-new { display: flex; gap: 8px; }
.col-new input { flex: 1; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 14px; font-family: inherit; background: var(--input-bg); color: var(--ink); outline: none; }
.col-new input:focus { border-color: var(--brand); }
.col-new .btn { padding: 10px 16px; font-size: 14px; }

/* ============================ MODALS ===================================== */
.scrim {
  position: fixed; inset: 0; z-index: 60; background: rgba(20,26,44,.55);
  backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--card); border-radius: 22px; width: 100%; max-width: 760px;
  max-height: 90vh; overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.4);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-close {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: 50%;
  background: var(--card); color: var(--ink); font-size: 18px; display: grid; place-items: center; z-index: 3;
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}

/* ----- book detail ----- */
.detail { display: grid; grid-template-columns: 230px 1fr; gap: 28px; padding: 30px; position: relative; }
.detail .dcover { border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); aspect-ratio: 2/3; }
.detail .dcover img { width: 100%; height: 100%; }
.detail h2 { margin: 4px 0 4px; font-family: 'Fraunces', serif; font-size: 27px; font-weight: 600; }
.detail .by { color: var(--muted); font-weight: 600; margin-bottom: 12px; }
.detail .pills { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.detail .pills span { font-size: 12px; font-weight: 700; background: var(--bg-soft); color: var(--muted); padding: 5px 11px; border-radius: 999px; }
.detail .pills span.age { background: #eef4ff; color: #2657d6; }
.detail p.blurb { line-height: 1.6; color: #44495f; font-size: 15px; margin: 0 0 20px; }
.detail .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  font-weight: 800; font-size: 15px; padding: 12px 22px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 8px; transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: var(--bg-soft); color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-lock { background: linear-gradient(135deg, var(--yellow), #ffac3d); color: #6a4500; }
.detail .locknote { margin-top: 14px; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* ----- paywall ----- */
.paywall { padding: 34px; text-align: center; position: relative; }
.paywall .kbig { font-size: 46px; }
.paywall h2 { font-family: 'Fraunces', serif; font-size: 28px; margin: 8px 0 6px; }
.paywall .sub { color: var(--muted); max-width: 460px; margin: 0 auto 24px; line-height: 1.5; }
.plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 600px; margin: 0 auto 18px; text-align: left; }
.plan {
  border: 2px solid var(--line); border-radius: 16px; padding: 16px 14px; cursor: pointer; position: relative; transition: border-color .15s, transform .1s;
}
.plan:hover { transform: translateY(-2px); }
.plan.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 8%, var(--card)); }
.plan .save { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); white-space: nowrap; background: var(--green); color: #fff; font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 999px; }
.plan b { font-size: 14px; }
.plan .price { font-size: 23px; font-weight: 800; margin: 6px 0 2px; font-family: 'Fraunces', serif; }
.plan .per { color: var(--muted); font-size: 11.5px; line-height: 1.35; }
@media (max-width: 560px) { .plans { grid-template-columns: 1fr; } }
.checkout-form { max-width: 520px; margin: 0 auto; text-align: left; }
.checkout-form .row { display: flex; gap: 12px; }
.field { margin-bottom: 12px; flex: 1; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  font-size: 15px; font-family: inherit; outline: none; background: var(--input-bg); color: var(--ink);
}
.field input:focus { border-color: var(--brand); }
.fineprint { font-size: 11.5px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
.success { padding: 50px 34px; text-align: center; }
.success .check { width: 76px; height: 76px; border-radius: 50%; background: var(--green); color: #fff; font-size: 40px; display: grid; place-items: center; margin: 0 auto 18px; }

/* ============================ READER ===================================== */
.reader { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: var(--r-bg); }
.reader[data-theme="light"] { --r-bg: #ffffff; --r-ink: #23262e; --r-soft: #f4f5f8; }
.reader[data-theme="sepia"] { --r-bg: #f6ecd9; --r-ink: #4a3f2c; --r-soft: #efe2c8; }
.reader[data-theme="dark"]  { --r-bg: #15171d; --r-ink: #d6d8de; --r-soft: #21242c; }
.reader-top, .reader-bottom {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px;
  background: var(--r-bg); color: var(--r-ink); border-color: rgba(127,127,127,.14);
}
.reader-top { border-bottom: 1px solid rgba(127,127,127,.14); }
.reader-bottom { border-top: 1px solid rgba(127,127,127,.14); flex-direction: column; gap: 8px; padding: 12px 18px 16px; }
.reader-top .rtitle { flex: 1; min-width: 0; }
.reader-top .rtitle b { display: block; font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-top .rtitle small { color: var(--muted); }
.rbtn { width: 38px; height: 38px; border-radius: 10px; color: var(--r-ink); display: grid; place-items: center; opacity: .8; }
.rbtn:hover { background: var(--r-soft); opacity: 1; }
.reader-stage { flex: 1; overflow: hidden; position: relative; }

/* text reader */
.text-scroll { height: 100%; overflow-y: auto; scroll-behavior: smooth; }
.text-col {
  max-width: 680px; margin: 0 auto; padding: 40px 26px 120px; color: var(--r-ink);
  font-family: var(--r-font, 'Literata', Georgia, serif);
  font-size: var(--r-size, 19px); line-height: var(--r-lh, 1.7);
}
.text-col h3 { font-family: 'Fraunces', serif; font-weight: 600; font-size: 1.5em; margin: 0 0 .8em; }
.text-col p { margin: 0 0 1.15em; text-align: justify; }
.text-col p:first-of-type::first-letter {
  font-family: 'Fraunces', serif; font-size: 3.1em; float: left; line-height: .8; padding: 6px 10px 0 0; color: var(--brand);
}
.chap-end { text-align: center; margin: 48px 0; color: var(--muted); }
.chap-end .btn { margin-top: 12px; }
.sample-gate {
  max-width: 560px; margin: 30px auto; text-align: center; padding: 30px;
  border: 2px dashed rgba(127,127,127,.3); border-radius: 18px;
}
.sample-gate .kbig { font-size: 40px; }
.sample-gate h3 { font-family: 'Fraunces', serif; margin: 8px 0; color: var(--r-ink); }
.sample-gate p { color: var(--muted); margin: 0 0 16px; }

/* comic reader */
.comic-stage { height: 100%; display: flex; align-items: center; justify-content: center; background: #1a1c22; }
.comic-page { height: 100%; max-width: 100%; display: flex; align-items: center; justify-content: center; padding: 12px; }
.comic-page svg, .comic-page img { max-height: 100%; max-width: 100%; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.comic-nav { position: absolute; top: 0; bottom: 0; width: 32%; display: grid; place-items: center; color: #fff; opacity: 0; transition: opacity .15s; }
.comic-nav:hover { opacity: 1; background: linear-gradient(90deg, rgba(0,0,0,.35), transparent); }
.comic-nav.right { right: 0; background: linear-gradient(270deg, rgba(0,0,0,.35), transparent); }
.comic-nav.left { left: 0; }

/* reader settings popover */
.rpop {
  position: absolute; top: 60px; right: 14px; z-index: 5; width: 300px;
  background: var(--r-bg); color: var(--r-ink); border: 1px solid rgba(127,127,127,.18);
  border-radius: 16px; box-shadow: var(--shadow); padding: 18px;
}
.rpop h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.rpop .grp { margin-bottom: 18px; }
.theme-row { display: flex; gap: 10px; }
.swatch { width: 42px; height: 42px; border-radius: 12px; border: 2px solid rgba(127,127,127,.2); }
.swatch.on { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22,166,224,.25); }
.swatch.light { background: #fff; } .swatch.sepia { background: #f6ecd9; } .swatch.dark { background: #15171d; }
.seg { display: flex; background: var(--r-soft); border-radius: 10px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 8px; border-radius: 7px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--r-bg); color: var(--r-ink); box-shadow: var(--shadow-sm); }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 38px; height: 38px; border-radius: 10px; background: var(--r-soft); font-weight: 800; font-size: 16px; color: var(--r-ink); }
.stepper input { flex: 1; }

/* range slider */
input[type=range] { -webkit-appearance: none; appearance: none; height: 5px; border-radius: 3px; background: rgba(127,127,127,.25); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--brand); cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.progress-row { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 680px; margin: 0 auto; }
.progress-row input { flex: 1; }
.progress-row span { font-size: 12px; color: var(--muted); min-width: 38px; }

/* TOC drawer */
.toc-drawer {
  position: absolute; top: 0; bottom: 0; left: 0; width: 320px; z-index: 6;
  background: var(--r-bg); color: var(--r-ink); border-right: 1px solid rgba(127,127,127,.18);
  box-shadow: var(--shadow); padding: 18px; overflow-y: auto; animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(-100%); } }
.toc-drawer h4 { margin: 0 0 14px; }
.toc-item { display: flex; align-items: center; gap: 10px; padding: 12px 10px; border-radius: 10px; cursor: pointer; text-align: left; width: 100%; color: var(--r-ink); }
.toc-item:hover { background: var(--r-soft); }
.toc-item.on { background: var(--r-soft); font-weight: 700; }
.toc-item small { color: var(--muted); margin-left: auto; }

/* demo menu */
.demo-menu {
  position: absolute; top: 56px; right: 22px; z-index: 50; width: 280px;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 8px;
}
.demo-menu .head { padding: 10px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 800; }
.demo-menu button.item { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 11px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }
.demo-menu button.item:hover { background: var(--bg-soft); }
.demo-menu .sep { height: 1px; background: var(--line); margin: 6px 8px; }

/* toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 90;
  background: #2a2d43; color: #fff; padding: 13px 22px; border-radius: 999px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); animation: pop .2s ease;
}

/* responsive */
@media (max-width: 720px) {
  .nav-tabs, .topbar-right .icon-btn span { display: none; }
  .search { max-width: none; }
  .detail { grid-template-columns: 1fr; }
  .detail .dcover { width: 170px; margin: 0 auto; }
  .plans { grid-template-columns: 1fr; }
  .hero h1 { font-size: 26px; }
  .checkout-form .row { flex-direction: column; }
}

/* ============================ NEW FEATURES =============================== */
/* kids mode */
.kids-pill {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: linear-gradient(135deg, #ffe3ec, #e7f8ee); border: 1.5px solid #ffc6df;
  color: #c0397f; font-weight: 800; font-size: 12.5px; padding: 6px 12px; border-radius: 999px;
}
.kids-pill:hover { filter: brightness(1.04); }
.hero-kids { background: linear-gradient(120deg, #ff8fb3, #ffb84d 55%, #ffd83d); }
.hero-kid-tag {
  display: inline-block; background: rgba(255,255,255,.9); color: #c0397f; font-weight: 800;
  font-size: 12px; padding: 4px 12px; border-radius: 999px; margin-bottom: 10px;
}

/* reader active buttons + read-to-me */
.rbtn.on { background: var(--brand); color: #fff; opacity: 1; }
.tts-bar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 10px; background: var(--brand); color: #fff;
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow);
}
.tts-bar button { background: rgba(255,255,255,.25); color: #fff; font-weight: 800; padding: 3px 12px; border-radius: 999px; font-size: 12px; }
.tts-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.text-col p.speaking { background: color-mix(in srgb, var(--brand) 16%, transparent); border-radius: 6px; box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 16%, transparent); transition: background .2s; }

/* toc drawer tabs + bookmarks */
.toc-drawer .drawer-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.toc-drawer .drawer-tabs button { flex: 1; padding: 8px; border-radius: 9px; font-weight: 700; font-size: 13px; color: var(--muted); background: var(--r-soft); }
.toc-drawer .drawer-tabs button.on { background: var(--brand); color: #fff; }
.mark-item { display: flex; align-items: center; gap: 4px; padding: 0; }
.mark-go { flex: 1; display: flex; align-items: center; gap: 8px; padding: 12px 10px; border-radius: 10px; color: var(--r-ink); text-align: left; }
.mark-go:hover { background: var(--r-soft); }
.mark-go small { margin-left: auto; color: var(--muted); }
.mark-del { width: 30px; height: 30px; border-radius: 8px; color: var(--muted); }
.mark-del:hover { background: var(--r-soft); color: var(--pink); }

/* rewards */
.rewards { padding: 34px; text-align: center; }
.rw-flame { font-size: 46px; }
.rewards h2 { font-family: 'Fraunces', serif; font-size: 26px; margin: 6px 0 6px; }
.rewards .sub { color: var(--muted); max-width: 420px; margin: 0 auto 22px; }
.rw-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 440px; margin: 0 auto 26px; }
.rw-stat { background: var(--bg-soft); border-radius: 14px; padding: 16px 8px; }
.rw-stat b { display: block; font-family: 'Fraunces', serif; font-size: 26px; color: var(--brand); }
.rw-stat span { font-size: 12px; color: var(--muted); }
.rw-h { text-align: left; margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.rw-badges { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; text-align: left; }
.rw-badge { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--bg-soft); opacity: .55; }
.rw-badge.on { opacity: 1; border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, var(--card)); }
.rw-icon { font-size: 26px; margin-bottom: 4px; }
.rw-badge b { font-size: 14px; }
.rw-badge span { font-size: 11.5px; color: var(--muted); }
@media (max-width: 560px) { .rw-badges { grid-template-columns: 1fr; } }

/* ============================ SETTINGS PAGE ============================== */
.settings-page { max-width: 760px; }
.settings-title { font-family: 'Fraunces', serif; font-size: 28px; margin: 4px 0 22px; }
.set-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 6px 22px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.set-card h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  margin: 18px 0 4px; font-weight: 800;
}
.set-row {
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 16px 0; border-top: 1px solid var(--line);
}
.set-card h3 + .set-row { border-top: none; }
.set-row > div:first-child { min-width: 0; }
.set-row b { display: block; font-size: 15px; }
.set-row span { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.set-actions { display: flex; gap: 8px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.set-row .btn { padding: 10px 16px; font-size: 13.5px; white-space: nowrap; }
.btn.danger { color: var(--pink); border-color: color-mix(in srgb, var(--pink) 40%, var(--line)); }
.btn.danger:hover { background: color-mix(in srgb, var(--pink) 10%, var(--card)); color: var(--pink); }
.set-foot { color: var(--muted); font-size: 12.5px; text-align: center; margin-top: 8px; }

/* toggle switch */
.switch {
  flex: none; width: 50px; height: 28px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .18s; cursor: pointer;
}
.switch.on { background: var(--brand); }
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.3); transition: left .18s;
}
.switch.on .knob { left: 25px; }

@media (max-width: 560px) {
  .set-row { flex-direction: column; align-items: stretch; }
  .set-row .switch, .set-actions { align-self: flex-end; }
}

/* ============================ WRITE A BOOK =============================== */
.create-page { max-width: 880px; }
.rules-box { background: color-mix(in srgb, var(--brand) 7%, var(--card)); border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--line)); border-radius: 16px; padding: 16px 20px; margin-bottom: 22px; }
.rules-box b { font-size: 14px; }
.rules-box ul { margin: 8px 0 0; padding-left: 20px; }
.rules-box li { font-size: 13.5px; color: var(--ink); margin: 4px 0; line-height: 1.5; }
.create-grid { display: grid; grid-template-columns: 1fr 200px; gap: 24px; align-items: start; }
.create-form .field select, .create-form .field textarea { width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; font-size: 15px; font-family: inherit; background: var(--input-bg); color: var(--ink); outline: none; }
.create-form .field select:focus, .create-form .field textarea:focus { border-color: var(--brand); }
.create-form textarea { resize: vertical; line-height: 1.5; }
.swatch-row { display: flex; gap: 10px; }
.cover-swatch { width: 40px; height: 40px; border-radius: 10px; border: 2px solid var(--line); cursor: pointer; }
.cover-swatch.on { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent); }
.create-preview { display: flex; flex-direction: column; align-items: center; gap: 8px; position: sticky; top: 90px; }
.create-preview span { font-size: 12px; color: var(--muted); }
.create-err { background: #fff0f0; border: 1.5px solid #ffc2c2; color: #c0392b; padding: 12px 16px; border-radius: 12px; margin: 14px 0; font-weight: 600; font-size: 14px; }
html[data-theme="dark"] .create-err { background: #2a1414; border-color: #5a2a2a; color: #ff9b9b; }
@media (max-width: 640px) { .create-grid { grid-template-columns: 1fr; } .create-preview { flex-direction: row; position: static; } }

/* free badge */
.cover-badge.free { background: linear-gradient(135deg, #28c76f, #1c9e57); left: 8px; top: 8px; }
