/* ============ Brand tokens ============ */
:root {
  --purple-950: #1d0b38;
  --purple-900: #2a1250;
  --purple-800: #3e1a6b;
  --purple-700: #4b2180;
  --purple-600: #5b2c91;   /* royal purple */
  --purple-500: #7444ad;
  --purple-300: #b99be0;
  --purple-100: #efe7fa;
  --purple-50: #f7f3fc;
  --green-700: #157a4c;
  --green-600: #1f9d63;    /* brand green */
  --green-100: #e2f5eb;
  --yellow-500: #edb51a;
  --yellow-400: #f7c631;   /* brand yellow */
  --yellow-100: #fff5d1;
  --red-600: #c9372c;
  --red-100: #fde8e6;

  --bg: #f6f2fb;
  --surface: #ffffff;
  --surface-2: #faf8fd;
  --text: #1f1830;
  --muted: #655d78;
  --border: #e6dfef;
  --primary: var(--purple-600);
  --primary-strong: var(--purple-800);
  --primary-soft: var(--purple-100);
  --link: var(--purple-600);
  --on-primary: #ffffff;
  --cta: var(--yellow-400);
  --on-cta: #2a1250;
  --success: var(--green-600);
  --success-soft: var(--green-100);
  --stage: radial-gradient(120% 90% at 50% 0%, #f3ecfb 0%, #e9e0f5 100%);
  --shadow-sm: 0 1px 2px rgb(42 18 80 / 6%), 0 1px 6px rgb(42 18 80 / 5%);
  --shadow: 0 6px 24px rgb(42 18 80 / 10%);
  --shadow-lg: 0 18px 60px rgb(42 18 80 / 22%);
  --radius: 18px;
  --radius-sm: 12px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --series-1: #6c3aa8;     /* chart purple, validated for colour-blind separation */
  --series-2: #1f9d63;     /* chart green */
  --head-h: 60px;
  --nav-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #130d1e;
    --surface: #1d1630;
    --surface-2: #231b39;
    --text: #f2edf9;
    --muted: #aea4c2;
    --border: #322849;
    --primary: #7a49b8;
    --primary-strong: #c9aef0;
    --primary-soft: #2c2045;
    --link: #c3a4ef;
    --success-soft: #133524;
    --stage: radial-gradient(120% 90% at 50% 0%, #2a1f40 0%, #120c1c 100%);
    --series-1: #9b6bd6;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
    --shadow: 0 6px 24px rgb(0 0 0 / 35%);
    --shadow-lg: 0 18px 60px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; color: var(--text); }
h1 { font-size: clamp(24px, 4vw, 32px); font-weight: 800; }
h2 { font-size: 21px; font-weight: 800; }
h3 { font-size: 18px; font-weight: 700; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.tiny { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 14px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--yellow-400); outline-offset: 2px; border-radius: 6px; }

/* Printing the app is turned off. */
@media print {
  body * { display: none !important; }
  body::after { content: 'Printing is turned off for this book.'; display: block !important; font: 20px sans-serif; padding: 40px; }
}
body.is-protected .reader { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: 999px; border: 2px solid transparent;
  font-weight: 800; font-size: 16px; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform .12s ease, background-color .15s ease, box-shadow .15s ease;
  background: var(--primary); color: var(--on-primary);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 14px rgb(91 44 145 / 28%); }
.btn-primary:hover { background: var(--purple-700); }
.btn-cta { background: var(--cta); color: var(--on-cta); box-shadow: 0 4px 14px rgb(237 181 26 / 35%); }
.btn-cta:hover { background: var(--yellow-500); }
.btn-green { background: var(--green-600); color: #fff; box-shadow: 0 4px 14px rgb(31 157 99 / 28%); }
.btn-green:hover { background: var(--green-700); }
.btn-outline { background: transparent; color: var(--primary-strong); border-color: var(--primary); }
.btn-ghost { background: transparent; color: var(--primary-strong); }
.btn-ghost:hover, .btn-outline:hover { background: var(--primary-soft); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-lg { min-height: 56px; font-size: 18px; padding: 0 28px; }
.btn-sm { min-height: 38px; font-size: 14px; padding: 0 14px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 46px; height: 46px; flex: none;
  border-radius: 50%; border: 0; background: transparent; color: var(--text); cursor: pointer; position: relative;
  text-decoration: none;
}
.icon-btn:hover { background: var(--primary-soft); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.icon-btn.on-dark { color: #fff; }
.icon-btn.on-dark:hover { background: rgb(255 255 255 / 12%); }
.icon-btn.filled { background: var(--surface); box-shadow: var(--shadow-sm); }
.icon-btn .count {
  position: absolute; top: 4px; right: 2px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: var(--yellow-400); color: var(--purple-900);
  font-size: 11px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--surface);
}

/* ============ Forms ============ */
.field { display: block; margin-bottom: 16px; }
.label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 16px; }
.help { color: var(--muted); font-size: 14px; margin-top: 5px; }
.input, .textarea, .select {
  width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--surface); font-size: 17px; transition: border-color .15s;
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
.error-box { background: var(--red-100); color: var(--red-600); border-radius: 12px; padding: 10px 14px; font-size: 15px; margin-bottom: 14px; font-weight: 600; }
.ok-box { background: var(--success-soft); color: var(--green-700); border-radius: 12px; padding: 10px 14px; font-size: 15px; margin-bottom: 14px; font-weight: 600; }

.switch { display: flex; align-items: center; gap: 14px; padding: 14px 0; cursor: pointer; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 52px; height: 30px; border-radius: 999px; background: var(--border); position: relative; flex: none; transition: background .2s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s; }
.switch input:checked + .track { background: var(--green-600); }
.switch input:checked + .track::after { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 3px solid var(--yellow-400); outline-offset: 2px; }
.switch .text { flex: 1; }
.switch .text b { display: block; font-weight: 700; }
.switch .text span { color: var(--muted); font-size: 14px; }

/* ============ Cards, avatars, misc ============ */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.card-pad { padding: 20px; }
.avatar {
  --s: 42px; width: var(--s); height: var(--s); border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: calc(var(--s) * .38);
  letter-spacing: .3px; position: relative;
}
.avatar.sm { --s: 32px; }
.avatar.lg { --s: 64px; }
.avatar .crown { position: absolute; bottom: -3px; right: -4px; font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--yellow-100); color: #7a5600; }
.badge.purple { background: var(--primary-soft); color: var(--primary-strong); }
.badge.green { background: var(--success-soft); color: var(--green-700); }
.badge.red { background: var(--red-100); color: var(--red-600); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--purple-100); border-top-color: var(--purple-600); animation: spin .8s linear infinite; display: inline-block; }
.spinner.light { border-color: rgb(255 255 255 / 25%); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { min-height: 60vh; display: grid; place-items: center; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.progress { height: 10px; border-radius: 999px; background: var(--primary-soft); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--purple-600), var(--green-600)); border-radius: inherit; transition: width .4s; }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: 0; }

/* ============ Toasts, modals, sheets ============ */
.toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top, 0px) + 10px); z-index: 1000; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 12px; }
.toast {
  pointer-events: auto; max-width: 520px; width: 100%; background: var(--purple-900); color: #fff;
  border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow-lg); display: flex; gap: 12px; align-items: center;
  font-weight: 600; animation: toast-in .25s ease-out;
}
.toast.success { background: var(--green-700); }
.toast.error { background: var(--red-600); }
.toast button { background: var(--yellow-400); color: var(--purple-900); border: 0; border-radius: 999px; padding: 8px 14px; font-weight: 800; cursor: pointer; white-space: nowrap; }
@keyframes toast-in { from { transform: translateY(-14px); opacity: 0; } }

.backdrop { position: fixed; inset: 0; background: rgb(20 8 40 / 55%); z-index: 900; display: grid; place-items: center; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 24px; width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; padding: 24px; box-shadow: var(--shadow-lg); animation: pop .22s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.modal-head h2 { flex: 1; margin: 0; }
@media (max-width: 640px) {
  .backdrop.sheet-mode { place-items: end stretch; padding: 0; }
  .backdrop.sheet-mode .modal { max-width: none; border-radius: 24px 24px 0 0; padding-bottom: calc(24px + var(--safe-b)); animation: sheet-up .25s ease-out; }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }

/* ============ App shell ============ */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--head-h); padding: 0 8px 0 14px;
  display: flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--text); text-decoration: none; min-width: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--purple-600); display: grid; place-items: center; flex: none; position: relative; }
.brand-mark::before, .brand-mark::after { content: ''; position: absolute; width: 9px; height: 9px; border-radius: 50%; bottom: 6px; }
.brand-mark::before { background: var(--yellow-400); right: 6px; }
.brand-mark::after { background: var(--green-600); right: 17px; }
.brand-mark svg { color: #fff; position: absolute; top: 5px; left: 7px; width: 20px; height: 20px; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: none; gap: 4px; margin-left: 18px; }
.topnav a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 700; display: flex; gap: 6px; align-items: center; }
.topnav a.active, .topnav a:hover { background: var(--primary-soft); color: var(--primary-strong); }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgb(42 18 80 / 6%);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none;
  color: var(--muted); font-size: 12.5px; font-weight: 700; position: relative;
}
.bottomnav a.active { color: var(--primary-strong); }
.bottomnav a.active .nav-ico { background: var(--primary-soft); }
.bottomnav .nav-ico { width: 56px; height: 32px; border-radius: 999px; display: grid; place-items: center; transition: background .2s; }
.bottomnav .count { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; background: var(--yellow-400); color: var(--purple-900); font-size: 11px; font-weight: 800; display: grid; place-items: center; }
.with-bottomnav { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px); }
@media (min-width: 1000px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  .with-bottomnav { padding-bottom: 24px; }
}

.page-wrap { max-width: 760px; margin: 0 auto; padding: 18px 16px; }
.page-wrap.wide { max-width: 1100px; }
.page-title { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; }
.page-title h1 { margin: 0; flex: 1; }

/* ============ Entry (email) screen ============ */
.entry { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(60% 50% at 10% 0%, rgb(247 198 49 / 28%), transparent 60%),
  radial-gradient(50% 50% at 100% 100%, rgb(31 157 99 / 22%), transparent 60%),
  linear-gradient(160deg, var(--purple-800), var(--purple-950)); }
.entry-card { width: 100%; max-width: 920px; background: var(--surface); border-radius: 28px; box-shadow: var(--shadow-lg); overflow: hidden; display: grid; }
.entry-visual { background: linear-gradient(160deg, var(--purple-600), var(--purple-800)); padding: 22px; display: grid; place-items: center; position: relative; overflow: hidden; }
.entry-visual::before { content: ''; position: absolute; width: 220px; height: 220px; border-radius: 50%; background: var(--yellow-400); opacity: .9; top: -80px; right: -60px; }
.entry-visual::after { content: ''; position: absolute; width: 140px; height: 140px; border-radius: 50%; background: var(--green-600); bottom: -50px; left: -40px; }
.entry-cover { position: relative; z-index: 1; width: min(150px, 38vw); aspect-ratio: 2/3; border-radius: 6px 14px 14px 6px; object-fit: cover; box-shadow: -10px 16px 40px rgb(0 0 0 / 35%), inset 4px 0 8px rgb(0 0 0 / 15%); transform: rotate(-3deg); background: var(--purple-100); }
.entry-form { padding: 28px 24px 30px; }
.entry-form h1 { color: var(--primary-strong); }
.entry-form .lead { color: var(--muted); font-size: 17px; }
.entry-perks { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 8px; }
.entry-perks li { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.entry-perks .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 16px; }
.privacy { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; margin-top: 14px; }
@media (min-width: 760px) {
  .entry-card { grid-template-columns: 1fr 1.1fr; }
  .entry-visual { padding: 48px; }
  .entry-cover { width: 230px; }
  .entry-form { padding: 44px 40px; }
}

/* ============ Library ============ */
.library { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.lib-book { text-decoration: none; color: var(--text); }
.lib-book img { width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 6px 12px 12px 6px; box-shadow: var(--shadow); background: var(--primary-soft); }
.lib-book b { display: block; margin-top: 10px; }

/* ============ Reader ============ */
.reader { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.r-head { position: sticky; top: 0; z-index: 40; height: var(--head-h); display: flex; align-items: center; gap: 2px; padding: 0 6px; background: var(--surface); border-bottom: 1px solid var(--border); }
.r-titles { flex: 1; min-width: 0; padding: 0 6px; }
.r-title { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-chapter { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.r-head .hide-sm { display: none; }
@media (min-width: 600px) { .r-head .hide-sm { display: inline-grid; } }

.r-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.r-main { display: flex; flex-direction: column; background: var(--stage); position: relative; }
.stage-wrap { position: relative; display: flex; align-items: stretch; }
.stage {
  flex: 1; height: var(--stage-h, 70vh); min-height: 260px; display: grid; place-items: center; padding: 10px 8px;
  position: relative; touch-action: pan-y; overflow: hidden;
}
.fb-sizer { max-width: 100%; margin: 0 auto; filter: drop-shadow(0 14px 28px rgb(42 18 80 / 22%)); }
.fb-book { margin: 0 auto; }
.fb-page { background: #fff; overflow: hidden; }
.fb-page canvas { width: 100%; height: 100%; display: block; }
.fb-page-wait { position: absolute; inset: 0; display: grid; place-items: center; background: #fff; transition: opacity .25s; }
.fb-page.is-ready .fb-page-wait { opacity: 0; pointer-events: none; }
.stf__parent { margin: 0 auto; }

.side-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 5; width: 56px; height: 56px; border-radius: 50%;
  border: 0; background: var(--surface); color: var(--primary-strong); box-shadow: var(--shadow); display: none; place-items: center; cursor: pointer;
}
.side-arrow:hover { background: var(--primary-soft); }
.side-arrow:disabled { opacity: 0; pointer-events: none; }
.side-arrow.left { left: 10px; }
.side-arrow.right { right: 10px; }
@media (min-width: 760px) and (hover: hover), (min-width: 900px) { .side-arrow { display: grid; } .stage { padding: 14px 76px; } }

.r-controls { display: flex; align-items: center; gap: 8px; padding: 8px 12px 10px; }
.nav-btn { width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--purple-600); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; box-shadow: 0 4px 14px rgb(91 44 145 / 28%); }
.nav-btn:disabled { background: var(--border); color: var(--muted); box-shadow: none; }
.nav-btn:active:not(:disabled) { transform: scale(.94); }
.scrub { flex: 1; min-width: 0; text-align: center; }
.scrub-label { font-weight: 800; font-size: 15px; display: flex; justify-content: center; gap: 6px; align-items: baseline; }
.scrub-label .muted { font-weight: 600; font-size: 13px; }
.scrub input[type='range'] { width: 100%; accent-color: var(--purple-600); height: 30px; margin: 0; cursor: pointer; }
.r-cta { padding: 0 12px 12px; }
.r-cta .btn { width: 100%; }
.r-cta .note { text-align: center; font-size: 13px; color: var(--muted); margin-top: 6px; }
@media (min-width: 760px) { .r-cta { display: flex; justify-content: center; } .r-cta .btn { width: auto; min-width: 320px; } }

.r-side { padding: 16px 12px calc(var(--nav-h) + var(--safe-b) + 24px); display: grid; gap: 14px; align-content: start; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .r-side { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); padding-left: 20px; padding-right: 20px; } }
.side-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.side-card h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 17px; }

.print-card { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--yellow-100), #fff8e2); border-color: #f3dd8c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .print-card { background: linear-gradient(135deg, #3a2f12, #2a2210); border-color: #5a4a1a; } }
.print-card img { width: 64px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px 8px 8px 3px; box-shadow: 0 6px 16px rgb(0 0 0 / 22%); flex: none; transform: rotate(-4deg); }
.print-card b { display: block; font-size: 17px; }
.print-card p { margin: 2px 0 10px; font-size: 14px; color: var(--muted); }

.ad-card { padding: 0; overflow: hidden; position: relative; }
.ad-card .ad-label { position: absolute; top: 8px; left: 8px; background: rgb(0 0 0 / 55%); color: #fff; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; letter-spacing: .4px; text-transform: uppercase; z-index: 1; }
.ad-card a { display: block; text-decoration: none; color: inherit; }
.ad-card img { width: 100%; height: auto; }
.ad-image-wrap { display: block; position: relative; }
/* The tap cue on artwork that has no text beside it. */
.ad-cta { position: absolute; right: 10px; bottom: 10px; display: inline-flex; align-items: center; background: var(--green-600); color: #fff;
  font-weight: 800; font-size: 14px; line-height: 1; padding: 9px 15px; border-radius: 999px; box-shadow: 0 4px 16px rgb(0 0 0 / 30%); }
.adbar-image .ad-cta { right: 7px; bottom: 7px; font-size: 12.5px; padding: 7px 12px; }
.ad-card .ad-text { padding: 14px 16px 16px; }
.ad-card .ad-text b { display: block; font-size: 17px; }
.ad-card .ad-text p { margin: 4px 0 10px; color: var(--muted); font-size: 14px; }
.ad-card.text-only { background: linear-gradient(135deg, var(--primary-soft), var(--surface)); }


.discuss-card .mini-post { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: inherit; }
.discuss-card .mini-post:last-of-type { border-bottom: 0; }
.mini-post .who { font-weight: 800; font-size: 14px; }
.mini-post .what { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

@media (min-width: 1000px) {
  .r-body { grid-template-columns: minmax(0, 1fr) 360px; height: calc(100dvh - var(--head-h)); }
  .r-main { overflow: hidden; }
  .r-side { overflow-y: auto; border-left: 1px solid var(--border); background: var(--surface-2); padding: 16px; grid-template-columns: minmax(0, 1fr); }
  .reader.no-side .r-body { grid-template-columns: minmax(0, 1fr); }
  .reader.no-side .r-side { display: none; }
}

/* Focus mode: just the book */
.reader.is-focus .r-side, .reader.is-focus .r-cta, .reader.is-focus ~ .bottomnav { display: none; }
.reader.is-focus .r-body { grid-template-columns: minmax(0, 1fr); height: auto; }
.reader.is-focus .r-main { min-height: calc(100dvh - var(--head-h)); }

/* First-time hint */
.flip-hint { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: rgb(29 11 56 / 55%); color: #fff; text-align: center; padding: 20px; cursor: pointer; animation: fade .3s; }
.flip-hint-box { max-width: 340px; }
.flip-hint .hand { font-size: 56px; display: inline-block; animation: swipe 1.6s ease-in-out infinite; }
.flip-hint b { display: block; font-size: 21px; margin: 10px 0 6px; }
.flip-hint p { color: rgb(255 255 255 / 85%); margin-bottom: 16px; }
@keyframes swipe { 0%, 100% { transform: translateX(40px) rotate(10deg); } 50% { transform: translateX(-40px) rotate(-10deg); } }

/* Contents */
.toc { list-style: none; padding: 0; margin: 0; }
.toc li button { width: 100%; text-align: left; display: flex; gap: 12px; align-items: center; padding: 14px 10px; border: 0; background: transparent; border-radius: 12px; cursor: pointer; font-weight: 700; }
.toc li button:hover { background: var(--primary-soft); }
.toc li.current button { background: var(--primary-soft); color: var(--primary-strong); }
.toc .num { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); border: 2px solid var(--border); display: grid; place-items: center; font-size: 14px; flex: none; }
.toc .done .num { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.toc .title { flex: 1; }
.toc .pg { color: var(--muted); font-size: 14px; font-weight: 600; }

/* Finish celebration */
.finish { text-align: center; }
.finish .big { font-size: 64px; line-height: 1; margin-bottom: 8px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 950; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* Zoom viewer */
.zoom { position: fixed; inset: 0; z-index: 980; background: #120a1f; display: flex; flex-direction: column; color: #fff; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.zoom-top, .zoom-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.zoom-top { padding-top: calc(env(safe-area-inset-top, 0px) + 8px); }
.zoom-title { flex: 1; font-weight: 800; padding-left: 8px; }
.zoom-bar { justify-content: center; gap: 18px; padding-bottom: calc(var(--safe-b) + 4px); }
.zoom-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; cursor: grab; }
.zoom-canvas { position: absolute; top: 0; left: 0; transform-origin: 0 0; box-shadow: 0 10px 50px rgb(0 0 0 / 50%); }
.zoom-loading { position: absolute; inset: 0; display: grid; place-items: center; }
.zoom-hint { text-align: center; font-size: 13px; color: rgb(255 255 255 / 60%); margin: 0 0 calc(var(--safe-b) + 8px); }

/* ============ Community ============ */
.comm-hero { background: linear-gradient(135deg, var(--purple-600), var(--purple-800)); color: #fff; border-radius: 22px; padding: 20px; display: flex; gap: 16px; align-items: center; position: relative; overflow: hidden; margin-bottom: 18px; }
.comm-hero::after { content: ''; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: var(--yellow-400); opacity: .9; }
.comm-hero img { width: 60px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px 8px 8px 3px; box-shadow: 0 8px 20px rgb(0 0 0 / 30%); flex: none; position: relative; z-index: 1; }
.comm-hero h1 { color: #fff; font-size: 22px; margin: 0 0 4px; position: relative; z-index: 1; }
.comm-hero p { margin: 0; color: rgb(255 255 255 / 85%); font-size: 15px; position: relative; z-index: 1; }
.faces { display: flex; margin-top: 10px; position: relative; z-index: 1; }
.faces .avatar { --s: 30px; border: 2px solid var(--purple-700); margin-right: -8px; font-size: 11px; }

.section-label { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); margin: 22px 4px 10px; }
.channel-list { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.channel-item { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); box-shadow: var(--shadow-sm); transition: transform .12s; }
.channel-item:active { transform: scale(.99); }
.channel-item:hover { border-color: var(--purple-300); }
.channel-emoji { width: 48px; height: 48px; border-radius: 14px; background: var(--primary-soft); display: grid; place-items: center; font-size: 24px; flex: none; }
.channel-item.chapter .channel-emoji { background: var(--success-soft); }
.channel-info { flex: 1; min-width: 0; }
.channel-info b { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 17px; }
.channel-info > span { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-pill { background: var(--yellow-400); color: var(--purple-900); font-weight: 800; font-size: 13px; border-radius: 999px; padding: 3px 10px; }

.channel-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.channel-head .channel-emoji { width: 54px; height: 54px; font-size: 28px; }
.channel-head h1 { font-size: 23px; margin: 0 0 2px; }
.channel-head p { margin: 0; color: var(--muted); font-size: 15px; }

.composer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.composer-top { display: flex; gap: 12px; align-items: flex-start; }
.composer .textarea { min-height: 52px; border-radius: 16px; transition: min-height .2s; }
.composer.open .textarea { min-height: 120px; }
.composer-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { border: 1.5px dashed var(--purple-300); background: var(--purple-50); color: var(--primary-strong); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 700; cursor: pointer; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .chip { background: var(--primary-soft); } }

.post { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); margin-bottom: 12px; }
.post.pinned { border-color: var(--yellow-400); box-shadow: 0 0 0 3px var(--yellow-100); }
.post-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.post-who { flex: 1; min-width: 0; }
.post-who b { font-size: 16px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.post-who span { font-size: 13px; color: var(--muted); }
.post-body { white-space: pre-wrap; word-wrap: break-word; font-size: 17px; line-height: 1.55; }
.post-body.clamp { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.post-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.react { border: 1.5px solid var(--border); background: var(--surface); border-radius: 999px; min-height: 38px; padding: 0 12px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-weight: 800; font-size: 14px; color: var(--muted); }
.react.on { border-color: var(--purple-300); background: var(--primary-soft); color: var(--primary-strong); }
.react .e { font-size: 17px; }
.reply-link { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; font-weight: 800; color: var(--primary-strong); text-decoration: none; padding: 8px 12px; border-radius: 999px; font-size: 15px; }
.reply-link:hover { background: var(--primary-soft); }
.new-posts { position: sticky; top: calc(var(--head-h) + 8px); z-index: 30; display: flex; justify-content: center; margin-bottom: 8px; }

.thread-replies { margin: 6px 0 0 18px; padding-left: 16px; border-left: 3px solid var(--primary-soft); }
.reply { padding: 12px 0; }
.reply .post-body { font-size: 16px; }
.reply-composer { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b)); background: var(--bg); padding: 10px 0; margin-top: 10px; z-index: 20; }
@media (min-width: 1000px) { .reply-composer { bottom: 0; } }
.reply-composer form { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border: 2px solid var(--border); border-radius: 22px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow); }
.reply-composer textarea { flex: 1; border: 0; background: transparent; resize: none; min-height: 44px; max-height: 160px; padding: 10px 0; outline: none; font-size: 17px; }
.send-btn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--purple-600); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn:disabled { background: var(--border); }

/* ============ Notifications & profile ============ */
.push-card { display: flex; gap: 14px; align-items: center; background: linear-gradient(135deg, var(--green-100), var(--surface)); border-color: #bfe6d0; margin-bottom: 16px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .push-card { background: var(--success-soft); border-color: #1f4d35; } }
.push-card .ico { width: 48px; height: 48px; border-radius: 14px; background: var(--green-600); color: #fff; display: grid; place-items: center; flex: none; }
.notif { display: flex; gap: 12px; padding: 14px; border-radius: 16px; text-decoration: none; color: var(--text); align-items: flex-start; }
.notif:hover { background: var(--surface); }
.notif.unread { background: var(--surface); box-shadow: var(--shadow-sm); }
.notif .n-ico { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); font-size: 20px; flex: none; }
.notif .n-text { flex: 1; min-width: 0; }
.notif .n-text b { display: block; font-weight: 700; }
.notif.unread .n-text b { font-weight: 800; }
.notif .n-text span { display: block; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif .n-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--yellow-400); margin-top: 8px; flex: none; }

.profile-head { display: flex; gap: 16px; align-items: center; margin-bottom: 18px; }
.profile-head b { font-size: 21px; display: block; }

/* ============ Admin ============ */
.admin { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; }
.admin-shell { display: grid; grid-template-columns: minmax(0, 1fr); }
.admin-nav { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: var(--head-h); z-index: 30; scrollbar-width: none; }
.admin-nav a { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 12px; text-decoration: none; color: var(--muted); font-weight: 700; white-space: nowrap; }
.admin-nav a.active, .admin-nav a:hover { background: var(--primary-soft); color: var(--primary-strong); }
.admin-main { padding: 18px 16px 60px; min-width: 0; max-width: 1240px; width: 100%; margin: 0 auto; }
@media (min-width: 1000px) {
  .admin-shell { grid-template-columns: 240px minmax(0, 1fr); }
  .admin-nav { flex-direction: column; overflow: visible; height: calc(100dvh - var(--head-h)); padding: 16px 12px; border-bottom: 0; border-right: 1px solid var(--border); }
  .admin-main { padding: 26px 32px 60px; }
}
.admin-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head h1 { flex: 1; margin: 0; font-size: 26px; min-width: 200px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.select { min-height: 44px; padding: 8px 36px 8px 14px; font-size: 15px; font-weight: 700; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23655d78' stroke-width='2.5' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; width: auto; }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 18px; }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow-sm); }
.kpi .k-label { font-size: 13px; font-weight: 700; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi .k-value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 13px; color: var(--muted); }
.kpi.live .k-value { color: var(--green-600); }
.kpi.live .k-label::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--green-600); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.grid-2 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); margin-bottom: 14px; }
@media (min-width: 1000px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2.wide-left { grid-template-columns: 1.6fr 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); min-width: 0; margin-bottom: 14px; }
.grid-2 .panel { margin-bottom: 0; }
.panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.panel-head h2 { font-size: 18px; margin: 0; flex: 1; }
.panel-sub { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-line { stroke: var(--border); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart-tip { position: fixed; z-index: 999; pointer-events: none; background: var(--purple-950); color: #fff; padding: 8px 10px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap; }
.chart-tip b { display: block; }

.bars { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.bar-row { display: grid; grid-template-columns: minmax(80px, 140px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .bar-label { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { display: block; height: 14px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-row .bar-fill { display: block; height: 100%; border-radius: 999px; background: var(--series-1); min-width: 6px; }
.bar-row .bar-val { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; background: var(--surface); }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 11px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 800; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--purple-50); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .table tr.click:hover td { background: var(--primary-soft); } }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .who b { display: block; }
.table .who span { color: var(--muted); font-size: 13px; }
.mini-progress { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.mini-progress .progress { flex: 1; height: 8px; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14.5px; align-items: flex-start; }
.activity li:last-child { border-bottom: 0; }
.activity .a-ico { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); flex: none; font-size: 15px; }
.activity .a-when { color: var(--muted); font-size: 12.5px; white-space: nowrap; margin-left: auto; padding-left: 8px; }

.book-rows { display: grid; gap: 12px; }
.book-row { display: flex; gap: 16px; align-items: center; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: inherit; box-shadow: var(--shadow-sm); }
.book-row img, .book-row .cover-ph { width: 62px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px 8px 8px 3px; background: var(--primary-soft); box-shadow: var(--shadow-sm); flex: none; }
.book-row .info { flex: 1; min-width: 0; }
.book-row .info b { font-size: 17px; display: block; }

.dropzone { border: 2.5px dashed var(--purple-300); border-radius: 20px; padding: 30px 20px; text-align: center; background: var(--purple-50); cursor: pointer; transition: background .15s, border-color .15s; display: block; }
.dropzone:hover, .dropzone.over { background: var(--primary-soft); border-color: var(--purple-600); }
.dropzone .ico { width: 60px; height: 60px; border-radius: 18px; background: var(--purple-600); color: #fff; display: inline-grid; place-items: center; margin-bottom: 10px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .dropzone { background: var(--surface-2); } }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 2px; scrollbar-width: none; }
.tab { border: 0; background: var(--surface); border: 1px solid var(--border); padding: 10px 16px; border-radius: 999px; font-weight: 800; cursor: pointer; white-space: nowrap; color: var(--muted); }
.tab.active { background: var(--purple-600); border-color: var(--purple-600); color: #fff; }
.form-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 14px; }
.form-section h2 { font-size: 19px; display: flex; gap: 8px; align-items: center; }
.form-section .lead { color: var(--muted); font-size: 15px; margin-top: -4px; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.save-bar { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); padding: 12px 0; display: flex; gap: 10px; align-items: center; z-index: 10; }
.chapter-row { display: grid; grid-template-columns: 1fr 96px 46px; gap: 8px; margin-bottom: 8px; align-items: center; }
.chapter-row .input { min-height: 46px; padding: 8px 12px; font-size: 16px; }
.share-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; }
.merge-table td:first-child { font-weight: 700; }
.merge-table code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.preview-frame { border: 1px dashed var(--border); border-radius: 16px; padding: 12px; background: var(--surface-2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 999px; }
.status.ready { background: var(--success-soft); color: var(--green-700); }
.status.processing { background: var(--yellow-100); color: #7a5600; }
.status.error { background: var(--red-100); color: var(--red-600); }
.status.draft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.page-heat { display: flex; flex-wrap: wrap; gap: 3px; }
.page-heat i { width: 14px; height: 18px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.page-heat i.r1 { background: #d9c8f0; border-color: #d9c8f0; }
.page-heat i.r2 { background: #a982da; border-color: #a982da; }
.page-heat i.r3 { background: var(--purple-600); border-color: var(--purple-600); }

.drawer-backdrop { position: fixed; inset: 0; background: rgb(20 8 40 / 45%); z-index: 900; animation: fade .2s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 901; overflow-y: auto; box-shadow: var(--shadow-lg); animation: slide-in .25s ease-out; padding: 0 0 40px; }
.drawer-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 12px 12px 18px; display: flex; gap: 10px; align-items: center; z-index: 2; }
.drawer-head h2 { flex: 1; margin: 0; font-size: 19px; }
.drawer-body { padding: 16px 18px; }
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--purple-800), var(--purple-950)); }
.login-card { width: 100%; max-width: 440px; background: var(--surface); border-radius: 26px; padding: 30px 26px; box-shadow: var(--shadow-lg); }
.login-card .brand { margin-bottom: 18px; }

.show-wide { display: none !important; }
@media (min-width: 1000px) { .show-wide { display: inline-flex !important; } }
.r-brand { display: inline-grid; place-items: center; width: 46px; height: 46px; flex: none; }
@media (max-width: 480px) { .hide-xs { display: none; } }

/* Ad: slim banner at the top on phones and upright tablets; card beside the book on wide screens */
/* Stays under the header while the reader scrolls, so the ad never leaves the screen. */
.r-adbar { position: sticky; top: var(--head-h); z-index: 30; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.adbar { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 8px 6px 6px; border-radius: 12px; text-decoration: none; color: var(--text);
  background: linear-gradient(135deg, var(--primary-soft), var(--surface)); border: 1px solid var(--border); position: relative; overflow: hidden; }
.adbar-thumb { width: 42px; height: 42px; border-radius: 9px; object-fit: cover; flex: none; }
.adbar-text { flex: 1; min-width: 0; line-height: 1.25; }
.adbar-text b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adbar-text .t { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adbar-tag { display: block; font-size: 10px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.adbar .btn { flex: none; min-height: 36px; padding: 0 14px; }
/* The box hugs the artwork, so a tall poster isn't stranded in a wide empty strip. */
.adbar-image { position: relative; display: block; width: fit-content; max-width: 100%; margin: 0 auto; padding: 0; min-height: 0; background: transparent; overflow: hidden; }
/* Never crop the artwork: it keeps its own shape, capped so the book still gets the screen. */
.adbar-image img { display: block; width: auto; height: auto; max-width: 100%; max-height: min(26vh, 210px); }
.adbar-image .adbar-tag { position: absolute; bottom: 4px; right: 6px; background: rgb(0 0 0 / 45%); color: #fff; padding: 0 6px; border-radius: 999px; font-size: 9px; }
.reader.is-focus .r-adbar { display: none; }
@media (min-width: 1000px) { .r-adbar { display: none; } }
@media (max-width: 999px) { .r-side .ad-card { display: none; } }

/* ============ Community feed ============ */
.feed-head { display: flex; gap: 14px; align-items: center; margin: 4px 0 14px; }
.feed-head img { width: 46px; aspect-ratio: 2/3; object-fit: cover; border-radius: 3px 7px 7px 3px; box-shadow: var(--shadow-sm); flex: none; }
.feed-head h1 { font-size: 21px; margin: 0; }
.feed-head p { margin: 0; color: var(--muted); font-size: 14px; }
.feed-head .faces { margin: 0; }
.feed-head .faces .avatar { border-color: var(--bg); }
@media (max-width: 480px) { .feed-head .faces { display: none; } }

.starters { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -16px 6px; padding-left: 16px; padding-right: 16px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.starters::-webkit-scrollbar { display: none; }
.starter { flex: none; width: 168px; scroll-snap-align: start; text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 18px; padding: 14px; cursor: pointer; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 2px; transition: transform .12s, border-color .15s; }
.starter:hover { border-color: var(--purple-300); }
.starter:active { transform: scale(.97); }
.starter-emoji { font-size: 26px; line-height: 1; margin-bottom: 6px; }
.starter b { font-size: 15px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.starter span:last-child { font-size: 13px; color: var(--muted); }
.starter:first-child { background: linear-gradient(150deg, var(--green-100), var(--surface)); border-color: #bfe6d0; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .starter:first-child { background: var(--success-soft); border-color: #1f4d35; } }

.fchips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 12px; padding: 6px 16px; scrollbar-width: none; position: sticky; top: var(--head-h); z-index: 20; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(8px); }
.fchips::-webkit-scrollbar { display: none; }
.fchip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; font-weight: 700; font-size: 14px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.fchip.on { background: var(--purple-600); border-color: var(--purple-600); color: #fff; }
.fchip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--yellow-400); flex: none; }
.filter-info { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin: -2px 0 14px; color: var(--muted); font-size: 15px; }

.composer.welcome { border: 2px solid var(--green-600); box-shadow: 0 0 0 4px var(--green-100); }
.welcome-line { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--border); }
.welcome-line > span:first-child, .welcome-line { font-size: 15px; }
.posting-in { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; color: var(--muted); }
.posting-in .select { min-height: 40px; font-size: 14px; max-width: 220px; }

.post-where { color: var(--primary-strong); font-weight: 700; text-decoration: none; }
.post-where:hover { text-decoration: underline; }
.reply-preview { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); display: grid; gap: 8px; }
.more-replies { font-size: 14px; font-weight: 800; color: var(--primary-strong); text-decoration: none; }
.mini-reply { display: flex; gap: 8px; align-items: flex-start; text-decoration: none; color: var(--text); }
.mini-reply .bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px 16px 16px 16px; padding: 8px 12px; font-size: 15px; line-height: 1.45; min-width: 0; overflow-wrap: anywhere; }
.mini-reply .bubble b { font-size: 14px; }
.mini-reply .when { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.inline-reply { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.inline-reply input { flex: 1; min-width: 0; min-height: 42px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--surface-2); padding: 0 16px; font-size: 16px; }
.inline-reply input:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.send-btn.sm { width: 40px; height: 40px; }

/* Chapter conversation box on the reading page */
.quick-post { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.quick-post textarea { flex: 1; min-width: 0; min-height: 46px; max-height: 140px; border-radius: 16px; border: 1.5px solid var(--border);
  background: var(--surface-2); padding: 11px 14px; font-size: 16px; line-height: 1.35; resize: none; overflow-y: auto; transition: min-height .15s; }
/* Opens up when tapped, so there is room to write. */
.quick-post textarea:focus { outline: none; border-color: var(--primary); background: var(--surface); min-height: 86px; }
