/* ==========================================================================
   বাংলা রিডার — stylesheet
   Kindle/e-ink-inspired: quiet chrome, text-first, generous line-height.
   Themes are driven by [data-theme] on <html>; font family by [data-font].
   Reading size is a CSS custom property so JS can change it live + persist it.
   ========================================================================== */

/* ---- Theme tokens ------------------------------------------------------- */
:root {
  --reading-size: 19px;          /* overridden live by font-control.js */
  --reading-line: 1.9;           /* Bengali reads well at ~1.8–2.0 (§4.2) */
  --measure: 38rem;              /* comfortable reading column width */

  --serif: 'Noto Serif Bengali', 'Solaiman Lipi', serif;
  --sans:  'Hind Siliguri', 'Noto Serif Bengali', sans-serif;
  --solaiman: 'Solaiman Lipi', 'Noto Serif Bengali', serif;

  --radius: 10px;
  --pad: clamp(1rem, 4vw, 2rem);
}

/* Light (soft paper white) */
[data-theme="light"] {
  --bg: #fdfdfb;
  --surface: #ffffff;
  --text: #1b1b1a;
  --muted: #6d6d68;
  --line: #e7e6e0;
  --accent: #3a3a37;             /* grayscale (Kindle e-ink) — no colour accent */
  --accent-contrast: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
}

/* Sepia (warm paper — a requested theme, §4.1) */
[data-theme="sepia"] {
  --bg: #f4ecd8;
  --surface: #fbf5e6;
  --text: #4b3a29;
  --muted: #8a7355;
  --line: #e2d5b8;
  --accent: #6b5842;             /* subdued brown-grey — sepia's grayscale */
  --accent-contrast: #fbf5e6;
  --shadow: 0 1px 3px rgba(90,60,30,.10), 0 8px 24px rgba(90,60,30,.08);
}

/* Dark (dim, low-glare) */
[data-theme="dark"] {
  --bg: #16161a;
  --surface: #1e1e24;
  --text: #dcdcd4;
  --muted: #8f8f88;
  --line: #2c2c34;
  --accent: #c2c2b9;             /* light grey — grayscale night mode */
  --accent-contrast: #16161a;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}

/* ---- Font family switch (data-font on <html>) --------------------------- */
[data-font="serif"]    { --reading-font: var(--serif); }
[data-font="solaiman"] { --reading-font: var(--solaiman); }
[data-font="sans"]     { --reading-font: var(--sans); }
:root                  { --reading-font: var(--serif); } /* default */

/* ---- Base --------------------------------------------------------------- */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  transition: background-color .3s ease, color .3s ease;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* Grayscale image display (§6). Original colour stays intact in R2. */
.card__img, .story__img { filter: grayscale(100%); transition: filter .4s ease; }
/* .card:hover .card__img, .story__hero:hover .story__img { filter: grayscale(0%); } */

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-block; cursor: pointer; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  padding: .55rem 1rem; border-radius: var(--radius);
  font: inherit; font-family: var(--sans); font-weight: 500;
  transition: border-color .2s, background .2s, color .2s;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn--solid { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn--solid:hover { filter: brightness(1.05); }
.btn--ghost { background: transparent; }
.btn--block { width: 100%; text-align: center; }

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem var(--pad);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__brand { display: flex; align-items: center; gap: .5rem; color: var(--text); }
.topbar__brand:hover { text-decoration: none; }
.topbar__mark {
  font-family: var(--serif); font-weight: 600;
  background: var(--accent); color: var(--accent-contrast);
  width: 2rem; height: 2rem; display: grid; place-items: center;
  border-radius: 8px; font-size: .95rem;
}
.topbar__name { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; }
.topbar__actions { display: flex; align-items: center; gap: .75rem; }
.topbar__user { color: var(--muted); font-size: .9rem; }

/* ---- Page --------------------------------------------------------------- */
.page { padding: var(--pad); max-width: 72rem; margin: 0 auto; }

.notice {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 1.25rem; color: var(--muted); background: var(--surface);
}

/* ---- Shelf (home) ------------------------------------------------------- */
.shelf__head { margin: 1rem 0 2rem; }
.shelf__title { font-family: var(--serif); font-size: clamp(1.6rem, 5vw, 2.3rem); margin: 0 0 .35rem; }
.shelf__sub { color: var(--muted); margin: 0; }

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  transition: transform .2s ease, border-color .2s ease;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card__link { display: block; color: var(--text); padding-bottom: .9rem; }
.card__link:hover { text-decoration: none; }
.card__cover { aspect-ratio: 3 / 4; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.card__img { width: 100%; height: 100%; object-fit: cover; }
.card__placeholder { font-family: var(--serif); font-size: 3rem; color: var(--muted); }
.card__title { font-family: var(--serif); font-size: 1.1rem; margin: .8rem .9rem .3rem; }
.card__desc {
  color: var(--muted); font-size: .88rem; margin: 0 .9rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ---- Story detail ------------------------------------------------------- */
.story__hero { display: grid; grid-template-columns: 160px 1fr; gap: 1.5rem; margin: 1rem 0 2.5rem; }
.story__cover { aspect-ratio: 3 / 4; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; overflow: hidden; box-shadow: var(--shadow); }
.story__img { width: 100%; height: 100%; object-fit: cover; }
.story__placeholder { font-family: var(--serif); font-size: 3.5rem; color: var(--muted); }
.story__title { font-family: var(--serif); font-size: clamp(1.5rem, 5vw, 2.2rem); margin: 0 0 .6rem; }
.story__desc { color: var(--muted); line-height: 1.7; margin: 0 0 1.2rem; max-width: 40rem; }

.toc__title { font-family: var(--serif); font-size: 1.3rem; border-bottom: 1px solid var(--line); padding-bottom: .5rem; }
.toc__list { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.toc__item { border-bottom: 1px solid var(--line); }
.toc__link { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem .25rem; color: var(--text); }
.toc__link:hover { text-decoration: none; color: var(--accent); }
.toc__badge { font-size: .72rem; font-weight: 600; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: .1rem .55rem; white-space: nowrap; }

/* ---- Reader (chapter) --------------------------------------------------- */
.progress { position: sticky; top: 0; height: 3px; background: transparent; z-index: 15; }
.progress__bar { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }

.reader { max-width: var(--measure); margin: 0 auto; padding: 1rem 0 5rem; }
.reader__crumb { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.reader__title { font-family: var(--serif); font-size: clamp(1.5rem, 5vw, 2rem); line-height: 1.35; margin: 0 0 1.5rem; }

.reader__body {
  font-family: var(--reading-font);
  font-size: var(--reading-size);
  line-height: var(--reading-line);
}
.reader__body p { margin: 0 0 1.35em; text-align: justify; text-justify: inter-word; }

/* Copy-protection visual side (§4.7). JS also blocks copy/contextmenu. */
.reader__body { -webkit-user-select: none; -moz-user-select: none; user-select: none; }

.reader__nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.reader__nav-slot { flex: 1; }
.reader__nav-slot--right { text-align: right; }

/* Premium lock */
.lock { text-align: center; padding: 3rem 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 1rem 0; }
.lock__icon { font-size: 2.5rem; margin-bottom: .5rem; }
.lock__title { font-family: var(--serif); margin: 0 0 .5rem; }
.lock__text, .lock__note { color: var(--muted); margin: 0 0 1.2rem; }

/* ---- Floating reader controls ------------------------------------------ */
.controls { position: fixed; right: clamp(1rem, 4vw, 2rem); bottom: clamp(1rem, 4vw, 2rem); z-index: 25; }
.controls__toggle {
  width: 3rem; height: 3rem; border-radius: 999px; cursor: pointer;
  background: var(--accent); color: var(--accent-contrast); border: none;
  font-family: var(--serif); font-size: 1.1rem; box-shadow: var(--shadow);
}
.controls__panel {
  position: absolute; right: 0; bottom: 3.75rem; width: min(18rem, 80vw);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.controls__panel[hidden] { display: none; }
.controls__group { display: flex; flex-direction: column; gap: .5rem; }
.controls__label { font-size: .8rem; color: var(--muted); }
.controls__row { display: flex; gap: .5rem; align-items: center; }

.swatch { width: 2rem; height: 2rem; border-radius: 50%; cursor: pointer; border: 2px solid var(--line); }
.swatch--light { background: #fdfdfb; }
.swatch--sepia { background: #f4ecd8; }
.swatch--dark  { background: #16161a; }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.fontpick { flex: 1; cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: .4rem; font-size: .8rem; }
.fontpick[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.sizebtn { cursor: pointer; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; width: 2.4rem; height: 2.4rem; font-family: var(--serif); }
.sizeval { flex: 1; text-align: center; font-family: var(--serif); }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 560px) {
  .story__hero { grid-template-columns: 110px 1fr; gap: 1rem; }
  .topbar__name { font-size: .98rem; }
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .progress__bar { transition: none; }
}

/* ==========================================================================
   Writer dashboard (step 3) — forms, story/chapter management, analytics.
   Reuses the theme tokens above; loaded on writer pages (author-only).
   ========================================================================== */

/* ---- Flash messages ----------------------------------------------------- */
.flashes { max-width: 48rem; margin: 0 auto 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.flash { padding: .7rem 1rem; border-radius: var(--radius); border: 1px solid var(--line); font-size: .92rem; }
.flash--ok { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.flash--error { border-color: var(--text); color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); font-weight: 500; }

/* ---- Dashboard ---------------------------------------------------------- */
.dash { max-width: 48rem; margin: 0 auto; }
.dash__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin: 1rem 0 2rem; }
.dash__title { font-family: var(--serif); font-size: clamp(1.5rem, 5vw, 2.2rem); margin: 0 0 .3rem; }
.dash__sub { color: var(--muted); margin: 0; }
.dash__list { list-style: none; margin: 0; padding: 0; }
.dash__item { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; background: var(--surface); }
.dash__link { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; color: var(--text); }
.dash__link:hover { text-decoration: none; border-color: var(--accent); }
.dash__name { font-family: var(--serif); font-size: 1.1rem; }

/* ---- Badges ------------------------------------------------------------- */
.badge { font-size: .72rem; font-weight: 600; border-radius: 999px; padding: .12rem .6rem; white-space: nowrap; border: 1px solid var(--line); color: var(--muted); }
.badge--published { color: var(--accent); border-color: var(--accent); }
.badge--draft { color: var(--muted); }
.badge--premium { color: var(--text); border-color: var(--muted); }

/* ---- Edit / forms ------------------------------------------------------- */
.edit { max-width: 48rem; margin: 0 auto; }
.edit__crumb { font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.edit__title { font-family: var(--serif); font-size: clamp(1.4rem, 4vw, 1.9rem); margin: 0 0 1.5rem; }
.edit__section { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.edit__section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.edit__h2 { font-family: var(--serif); font-size: 1.25rem; margin: 0 0 1rem; }

.form { display: flex; flex-direction: column; gap: 1rem; max-width: 40rem; }
.form__label { display: flex; flex-direction: column; gap: .4rem; font-size: .9rem; color: var(--muted); }
.form__input {
  font: inherit; font-family: var(--sans); font-size: 1rem;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem;
}
.form__input:focus { outline: none; border-color: var(--accent); }
.form__textarea { resize: vertical; }
.form__hint { font-size: .82rem; color: var(--muted); margin: 0; }
.form__hint--warn { color: var(--text); font-weight: 500; }
.form__file { font: inherit; color: var(--text); }
.form__check { display: flex; align-items: center; gap: .5rem; font-size: .92rem; color: var(--text); }
.form__actions { display: flex; gap: .75rem; align-items: center; }

/* Distraction-free writing textarea (§5.5) */
.writing {
  font-family: var(--serif); font-size: 1.05rem; line-height: 1.8;
  min-height: 24rem; background: var(--bg);
}

/* ---- Cover upload ------------------------------------------------------- */
.cover-row { display: grid; grid-template-columns: 130px 1fr; gap: 1.5rem; align-items: start; }
.cover-preview { aspect-ratio: 3 / 4; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: grid; place-items: center; overflow: hidden; }
.cover-preview img { width: 100%; height: 100%; object-fit: cover; }
.cover-preview__empty { font-family: var(--serif); font-size: 2.5rem; color: var(--muted); }

/* ---- Analytics ---------------------------------------------------------- */
.stats { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.stat { flex: 1; min-width: 6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat__num { display: block; font-family: var(--serif); font-size: 1.8rem; color: var(--accent); }
.stat__lbl { font-size: .82rem; color: var(--muted); }

.dropoff { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.dropoff__row { display: grid; grid-template-columns: 1fr 2fr auto; gap: .75rem; align-items: center; font-size: .88rem; }
.dropoff__name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropoff__track { background: var(--line); border-radius: 999px; height: .7rem; overflow: hidden; }
.dropoff__bar { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.dropoff__val { color: var(--muted); min-width: 2rem; text-align: right; }

/* ---- Chapter list (writer) ---------------------------------------------- */
.chlist { list-style: none; margin: 0; padding: 0; }
.chlist__item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .9rem 0; border-bottom: 1px solid var(--line); }
.chlist__main { display: flex; flex-direction: column; gap: .35rem; }
.chlist__name { font-family: var(--serif); font-size: 1.05rem; }
.chlist__tags { display: flex; gap: .4rem; }
.chlist__actions { display: flex; gap: .5rem; align-items: center; }
.chlist__actions form { margin: 0; }

@media (max-width: 560px) {
  .cover-row { grid-template-columns: 100px 1fr; gap: 1rem; }
  .dropoff__row { grid-template-columns: 1fr 1.5fr auto; }
}

/* ==========================================================================
   Kindle-style library home (mobile-first).
   Base styles target phones; min-width queries scale up for tablet/desktop.
   Replaces the old .shelf/.grid/.card home layout (those rules remain above
   but are no longer referenced by index.html).
   ========================================================================== */

.library { max-width: 72rem; margin: 0 auto; }

.library__head { margin: .5rem 0 1.5rem; }
.library__title {
  font-family: var(--serif);
  font-size: 1.75rem;            /* mobile-first: comfortable, not huge */
  margin: 0 0 .3rem;
}
.library__sub { color: var(--muted); margin: 0; font-size: .95rem; }

/* Bookshelf grid — mobile-first: 2–3 compact columns, scaling up.
   auto-fill + minmax keeps it fluid from phone to desktop. */
.shelf {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 1.1rem .9rem;
}

.book { min-width: 0; }
.book__link {
  display: block; color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.book__link:hover { text-decoration: none; }
.book__link:active { transform: scale(.97); }   /* touch feedback */
.book__link, .book__link:active { transition: transform .12s ease; }

/* Cover — the visual heart of the shelf. 3:4 like a paperback. */
.book__cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.book__img {
  width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(100%);       /* e-ink feel (§6); hover-colour intentionally off */
}

/* Cover-less placeholder: a coloured "book face" with a darker spine on the
   left, so a shelf of cover-less stories still looks like books. */
.book__spine {
  position: absolute; left: 0; top: 0; bottom: 0; width: 12%;
  background: rgba(0, 0, 0, .18);
}
.book__initial {
  font-family: var(--serif); font-size: 2.6rem; color: #fff;
  opacity: .95; padding-left: 8%;
}
/* A few thematic cover tints, rotated so the shelf feels varied but calm. */
/* A few neutral grey shades, rotated so a shelf of cover-less books still has
   gentle variety — no colour (Kindle e-ink feel). */
.book:nth-child(5n+1) .book__cover { background: #55554f; }
.book:nth-child(5n+2) .book__cover { background: #6a6a63; }
.book:nth-child(5n+3) .book__cover { background: #4a4a45; }
.book:nth-child(5n+4) .book__cover { background: #7a7a72; }
.book:nth-child(5n+5) .book__cover { background: #5f5f59; }
/* When a real image exists, let it fill (tint hidden behind the img). */
.book__cover:has(.book__img) { background: var(--surface); }

.book__title {
  font-family: var(--serif);
  font-size: .95rem; font-weight: 500; line-height: 1.35;
  margin: .55rem 0 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Tablet and up: a touch more breathing room + larger heading. */
@media (min-width: 48rem) {
  .library__title { font-size: 2.1rem; }
  .shelf { grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 1.5rem 1.2rem; }
  .book__initial { font-size: 3rem; }
}

/* ==========================================================================
   Search (mobile-first) — bar + results reuse the .shelf/.book grid above.
   ========================================================================== */
.search {
  display: flex; align-items: center; gap: .5rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: .35rem .5rem .35rem .85rem;
  margin: 0 0 1.5rem; max-width: 40rem;
}
.search:focus-within { border-color: var(--accent); }
.search__icon { color: var(--muted); font-size: 1rem; flex: none; }
.search__input {
  flex: 1; min-width: 0; border: none; background: transparent;
  font: inherit; font-family: var(--sans); font-size: 1rem; color: var(--text);
  padding: .5rem 0;
}
.search__input:focus { outline: none; }
.search__input::placeholder { color: var(--muted); }
.search__btn {
  flex: none; cursor: pointer; border: none; border-radius: 8px;
  background: var(--accent); color: var(--accent-contrast);
  font: inherit; font-family: var(--sans); font-weight: 500;
  padding: .5rem 1rem;
}
.search__btn:active { transform: scale(.97); }

.search__count { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; }
.search__hint { color: var(--muted); }

/* On phones the "খোঁজো" button label is redundant next to the icon;
   keep it but let it shrink gracefully. */
@media (max-width: 26rem) {
  .search__btn { padding: .5rem .75rem; }
}

/* The topbar search icon is icon-only; tighten its padding. */
.topbar__search { padding: .5rem .6rem; }

/* ==========================================================================
   Paginated reader (§4.4) — swipe/click page turning, chapter bar, TOC drawer.
   Progressive enhancement: without .pager--on the content is a normal article.
   ========================================================================== */

/* Paged mode (added by pager.js once measured). */
.pager { position: relative; }
.pager--on .pager__viewport {
  overflow: hidden;              /* height set inline by pager.js */
  touch-action: pan-y;          /* allow vertical gestures; we handle horizontal */
}
.pager--on .pager__content {
  /* column-width / column-gap / height set inline by pager.js */
  will-change: transform;
}
.pager--on .pager__content p { break-inside: avoid-column; }

/* Edge click zones — desktop only (mouse). On touch devices we hide them so
   swipes reach the viewport unobstructed. */
.pager__edge {
  position: absolute; top: 0; bottom: 0; width: 15%;
  border: none; background: transparent; cursor: pointer; padding: 0;
  display: none;                 /* shown on fine pointers below */
}
.pager__edge--prev { left: 0; }
.pager__edge--next { right: 0; }
@media (pointer: fine) {
  .pager--on .pager__edge { display: block; }
  .pager--on .pager__edge--prev { cursor: w-resize; }
  .pager--on .pager__edge--next { cursor: e-resize; }
}

/* ---- Chapter bar (bottom) — mobile-first ---- */
.chapterbar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  margin-top: 1rem; padding-top: .75rem; border-top: 1px solid var(--line);
}
.chapterbar__slot { flex: 1 1 0; min-width: 0; }
.chapterbar__slot--right { text-align: right; }
.chapterbar__center { display: flex; align-items: center; gap: .6rem; flex: none; }
.chapterbar__nav {
  display: inline-block; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: .4rem .7rem; font-size: .88rem;
  -webkit-tap-highlight-color: transparent;
}
.chapterbar__nav:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.chapterbar__page { color: var(--muted); font-size: .85rem; font-family: var(--serif); white-space: nowrap; }
.chapterbar__toc {
  cursor: pointer; background: transparent; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: .4rem .7rem;
  font: inherit; font-size: .85rem;
}
.chapterbar__toc:hover { border-color: var(--accent); color: var(--accent); }

/* ---- TOC (সূচি) drawer ---- */
body.drawer-open { overflow: hidden; }
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer__scrim {
  position: absolute; inset: 0; background: rgba(0,0,0,.45);
  animation: drawer-fade .2s ease;
}
.drawer__panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(22rem, 85vw); background: var(--surface);
  border-left: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  animation: drawer-slide .22s ease;
}
@keyframes drawer-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawer-slide { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem; border-bottom: 1px solid var(--line);
}
.drawer__title { font-family: var(--serif); font-size: 1.15rem; margin: 0; }
.drawer__close {
  cursor: pointer; background: transparent; border: none; color: var(--muted);
  font-size: 1.1rem; padding: .25rem .5rem; border-radius: 6px;
}
.drawer__close:hover { color: var(--text); }
.drawer__list { list-style: none; margin: 0; padding: .5rem; overflow-y: auto; }
.drawer__item {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .75rem .85rem; border-radius: 8px; color: var(--text);
}
.drawer__item:hover { text-decoration: none; background: var(--bg); }
.drawer__item--current { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.drawer__item-name { font-family: var(--serif); }
.drawer__item-badge {
  font-size: .68rem; font-weight: 600; color: var(--text);
  border: 1px solid var(--muted); border-radius: 999px; padding: .05rem .5rem; white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .drawer__scrim, .drawer__panel { animation: none; }
  .pager--on .pager__content { transition: none !important; }
}

/* ==========================================================================
   Chapter editor word meter (writer) — live count + soft "too long" warning.
   ========================================================================== */
.wordmeter {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  margin: .25rem 0 0; font-size: .85rem;
}
.wordmeter__count { color: var(--muted); font-family: var(--serif); }
.wordmeter__warn {
  color: var(--text);
  background: color-mix(in srgb, var(--muted) 12%, transparent);
  border: 1px solid var(--muted);
  border-radius: 8px; padding: .3rem .65rem; line-height: 1.4;
}

/* ==========================================================================
   Topbar icon buttons (search + hamburger) and the main menu drawer (§ step 1).
   Mobile-first: generous 44px tap targets; the drawer reuses .drawer styles.
   ========================================================================== */
.topbar__icon {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;      /* comfortable touch target */
  font-size: 1.15rem; color: var(--text);
  background: transparent; border: none; cursor: pointer;
  border-radius: 8px; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.topbar__icon:hover { background: color-mix(in srgb, var(--text) 6%, transparent); text-decoration: none; }
.topbar__icon:active { transform: scale(.94); }

/* Menu drawer contents (inside .drawer__panel). */
.menu { padding: .5rem; }
.menu__user {
  font-family: var(--serif); font-weight: 600; font-size: 1.05rem;
  color: var(--text); padding: .85rem .85rem .6rem;
  border-bottom: 1px solid var(--line); margin-bottom: .4rem;
}
.menu__item {
  display: block; padding: .9rem .85rem; border-radius: 8px;
  color: var(--text); font-size: 1rem;
  -webkit-tap-highlight-color: transparent;
}
.menu__item:hover { text-decoration: none; background: var(--bg); }
.menu__item:active { background: color-mix(in srgb, var(--text) 8%, transparent); }

/* ==========================================================================
   Home (§ step 2) — Kindle/newspaper look: bold section title + thin rule,
   horizontal swipeable cover strips. Mobile-first: narrow covers that scroll;
   more visible on wider screens. Theme-aware (no hard-coded #000/#fff), but
   deliberately flat — no shadows, no rounded cards.
   ========================================================================== */
.home { max-width: 72rem; margin: 0 auto; }

/* Section header: title on the left, a thin rule filling to the row's end. */
.booksec { margin: 0 0 2.5rem; }
.booksec__head { display: flex; align-items: center; gap: 1rem; margin: 0 0 1.1rem; }
.booksec__title {
  font-family: var(--serif); font-weight: 600; font-size: 1.15rem;
  margin: 0; white-space: nowrap; color: var(--text);
}
.booksec__line { flex: 1 1 auto; height: 1px; background: var(--muted); opacity: .55; }
.booksec__empty { color: var(--muted); margin: 0; }

/* Horizontal swipe strip. On phones a narrow cover shows ~2.5 at a time so it
   clearly invites scrolling; wider screens fit more. */
.carousel {
  display: flex; gap: 1rem;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  padding-bottom: .5rem;                 /* room for scrollbar, no clipping */
  scrollbar-width: thin;
}

.coverc {
  flex: 0 0 auto;
  width: 38vw; max-width: 10rem;         /* mobile-first: ~2.5 covers visible */
  scroll-snap-align: start;
  color: var(--text); -webkit-tap-highlight-color: transparent;
}
.coverc:hover { text-decoration: none; }
.coverc:active { opacity: .85; }

/* The cover box: vertical rectangle, thin border, flat (no shadow/radius). */
.coverc__frame {
  display: block; aspect-ratio: 3 / 4;
  border: 1px solid var(--muted);
  background: var(--surface); overflow: hidden;
}
.coverc__img {
  width: 100%; height: 100%; object-fit: cover;
  filter: grayscale(100%);               /* e-ink: covers stay black & white */
  display: block;
}
.coverc__title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  font-family: var(--serif); font-size: .9rem; line-height: 1.35;
  margin-top: .5rem; color: var(--text);
}

/* Wider screens: fixed, slightly larger covers so a row shows four-plus. */
@media (min-width: 48rem) {
  .booksec__title { font-size: 1.3rem; }
  .coverc { width: 10.5rem; max-width: none; }
  .carousel { gap: 1.4rem; }
}

/* ==========================================================================
   Reading settings inside the menu drawer (§ step 3) — reuses the reader's
   .swatch / .fontpick / .sizebtn controls, wired site-wide via app.js.
   ========================================================================== */
.menu__sep { height: 1px; background: var(--line); margin: .5rem .85rem; }
.menu__item--btn {
  width: 100%; text-align: left; background: transparent; border: none;
  font: inherit; font-size: 1rem; color: var(--text); cursor: pointer;
}
.settings { padding: .25rem .85rem .5rem; display: flex; flex-direction: column; gap: 1rem; }
.sizeval { min-width: 2ch; text-align: center; font-family: var(--serif); color: var(--text); }

/* ==========================================================================
   Kindle-style reader (§ step 4) — full-screen, distraction-free. Header and
   footer overlay and toggle on tap; the pager track slides cover → about →
   text. Mobile-first; on wide screens the reader is width-capped for line length.
   ========================================================================== */
.reader {
  position: fixed; inset: 0; z-index: 30;
  background: var(--bg); color: var(--text); overflow: hidden;
}

/* Header + footer: overlay bars that slide in/out with .chrome-on. */
.rhead, .rfoot {
  position: absolute; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: .6rem;
  height: 3rem; padding: 0 .9rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  transition: transform .22s ease, opacity .22s ease;
}
.rhead { top: 0; border-bottom: 1px solid var(--line); transform: translateY(-100%); opacity: 0; }
.rfoot { bottom: 0; border-top: 1px solid var(--line); justify-content: space-between; transform: translateY(100%); opacity: 0; }
.reader.chrome-on .rhead,
.reader.chrome-on .rfoot { transform: none; opacity: 1; }

.rhead__home { font-size: 1.4rem; color: var(--text); text-decoration: none; line-height: 1; padding: .2rem .3rem; }
.rhead__titles { display: flex; flex-direction: column; min-width: 0; }
.rhead__book { font-family: var(--serif); font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rhead__chapter { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.rfoot__author { font-family: var(--serif); font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rfoot__nav { display: flex; align-items: center; gap: .3rem; flex: none; }
.rfoot__btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; font-size: 1.15rem;
  background: transparent; border: none; color: var(--text); cursor: pointer;
  border-radius: 8px; text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.rfoot__btn:active { transform: scale(.92); }

/* Pager fills the space between header and footer (chrome space reserved so
   text never hides under the bars). */
.reader .pager { position: absolute; top: 3rem; bottom: 3rem; left: 0; right: 0; }
.reader .pager__viewport { position: absolute; inset: 0; overflow: hidden; touch-action: pan-y; padding: 0 1.5rem; }
.pager__track { display: flex; height: 100%; align-items: stretch; } /* legacy, unused */
.reader .pager__content { height: 100%; will-change: transform; }
.reader .pager__content p { break-inside: avoid-column; margin: 0 0 1em; }

/* Intro pages live in the same column flow; each forced onto its own column. */
.rpage { break-after: column; break-inside: avoid; height: 100%; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; overflow: hidden; }
.rpage--cover { align-items: center; }
.rpage__cover { max-width: 100%; max-height: 100%; object-fit: contain; filter: grayscale(100%); }
.rpage--about { text-align: center; }
.rpage__title { font-family: var(--serif); font-size: 1.6rem; margin: 0 0 .5rem; }
.rpage__author { color: var(--muted); margin: 0 0 1.25rem; }
.rpage__desc { line-height: 1.8; text-align: left; margin: 0 0 1.5rem; }
.rpage__hint { color: var(--muted); font-size: .85rem; }

/* Desktop page-turn zones (mouse only). */
.pager__edge { position: absolute; top: 0; bottom: 0; width: 15%; border: none; background: transparent; cursor: pointer; padding: 0; display: none; }
.pager__edge--prev { left: 0; } .pager__edge--next { right: 0; }
@media (pointer: fine) {
  .pager--on .pager__edge { display: block; }
  .pager__edge--prev { cursor: w-resize; } .pager__edge--next { cursor: e-resize; }
}

/* Wide screens: cap width for comfortable line length. */
@media (min-width: 48rem) {
  .reader { left: 50%; right: auto; transform: translateX(-50%); width: 46rem; max-width: 100%; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .rpage__title { font-size: 1.9rem; }
}

/* ==========================================================================
   Author profile (§ step 5). Two panels on wide screens (left: photo/name/bio,
   right: books + socials); stacks on mobile. Grayscale, borderless avatar.
   ========================================================================== */
.profile { max-width: 72rem; margin: 0 auto; display: flex; flex-direction: column; gap: 2rem; }
.profile__side { display: flex; flex-direction: column; }
.profile__avatar {
  width: 9rem; height: 11rem; object-fit: cover; filter: grayscale(100%);
  align-self: flex-start; margin-bottom: .75rem;   /* top-left, no border */
}
.profile__avatar--none {
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--muted);
  font-family: var(--serif); font-size: 3rem;
}
.profile__name { font-family: var(--serif); font-size: 1.4rem; margin: 0 0 1rem; }
.profile__bio { line-height: 1.8; color: var(--text); white-space: pre-wrap; }

/* Socials — plain grayscale text links (icons can be added later). */
.socials { display: flex; flex-wrap: wrap; gap: .6rem; }
.socials__link {
  display: inline-block; padding: .5rem .9rem;
  border: 1px solid var(--muted); border-radius: 8px;
  color: var(--text); font-size: .9rem; text-decoration: none;
}
.socials__link:hover { background: var(--bg); text-decoration: none; }

.dash__head-actions { display: flex; gap: .5rem; align-items: center; }
.profile-edit__photo { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }

@media (min-width: 48rem) {
  .profile { flex-direction: row; align-items: flex-start; gap: 3rem; }
  .profile__side { flex: 0 0 16rem; position: sticky; top: 1rem; }
  .profile__main { flex: 1 1 auto; min-width: 0; }
}

/* ==========================================================================
   Bookmarks list (§ step 6) + active bookmark button.
   ========================================================================== */
.bookmarks { max-width: 46rem; margin: 0 auto; }
.bookmarks__nudge {
  color: var(--text); background: color-mix(in srgb, var(--muted) 12%, transparent);
  border: 1px solid var(--muted); border-radius: 8px; padding: .7rem .9rem;
  margin: 0 0 1.25rem; font-size: .92rem;
}
.bookmarks__list { list-style: none; padding: 0; margin: 0; }
.bookmarks__item a {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .9rem .2rem; border-bottom: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.bookmarks__item a:hover { background: var(--bg); text-decoration: none; }
.bookmarks__story { font-family: var(--serif); font-weight: 600; }
.bookmarks__chapter { color: var(--muted); font-size: .9rem; }
.bookmarks__empty { color: var(--muted); }

/* Active bookmark (🔖) in the reader footer — grayscale emphasis. */
.rfoot__btn.is-active { background: color-mix(in srgb, var(--text) 14%, transparent); }

/* ==========================================================================
   Category / genre (§ step: genre). Simple text list; per-genre uses the home
   cover grid but wraps (not a single scroll row).
   ========================================================================== */
.catlist { list-style: none; padding: 0; margin: 0; max-width: 46rem; }
.catlist__item { border-bottom: 1px solid var(--line); }
.catlist__link {
  display: block; padding: .95rem .2rem; color: var(--text);
  font-family: var(--serif); font-size: 1.1rem; text-decoration: none;
}
.catlist__link:hover { background: var(--bg); text-decoration: none; }
.catlist__back { margin: 0 0 1.25rem; }
.catlist__back a { color: var(--muted); text-decoration: none; }
/* Per-genre grid: wrap the covers instead of a single horizontal scroll. */
.carousel--wrap { flex-wrap: wrap; overflow-x: visible; }

/* ==========================================================================
   Legal / informational pages (terms, privacy, help) + small site footer.
   ========================================================================== */
.legal { max-width: 46rem; margin: 0 auto; line-height: 1.85; }
.legal h1 { font-family: var(--serif); font-size: 1.6rem; margin: 0 0 .35rem; }
.legal h2 { font-family: var(--serif); font-size: 1.2rem; margin: 1.75rem 0 .5rem; }
.legal__meta { color: var(--muted); font-size: .88rem; margin: 0 0 1.5rem; }
.legal a { color: var(--text); }

.sitefoot {
  max-width: 72rem; margin: 3rem auto 0; padding: 1.25rem 0;
  border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem 1rem; font-size: .82rem;
}
.sitefoot__links { display: flex; flex-wrap: wrap; gap: 1rem; }
.sitefoot__links a { color: var(--muted); text-decoration: none; }
.sitefoot__links a:hover { color: var(--text); }
.sitefoot__copy { color: var(--muted); margin: 0; }

/* ==========================================================================
   SVG icons (theme-aware via currentColor). Sizes per placement.
   ========================================================================== */
.icon { width: 1.2em; height: 1.2em; fill: currentColor; display: inline-block; vertical-align: -.15em; }
.topbar__mark .icon { width: 26px; height: 26px; }
.topbar__icon .icon { width: 22px; height: 22px; }
.rfoot__btn .icon { width: 22px; height: 22px; }
.menu__item .icon { width: 20px; height: 20px; margin-right: .55rem; vertical-align: -.22em; }
