:root {
  --brand: #d67b22;
  --brand-dark: #b5651a;
  --brand-soft: #fdf3e7;
  --ink: #1b1b1f;
  --ink-2: #55555f;
  --ink-3: #8a8a95;
  --line: #e6e6ec;
  --bg: #ffffff;
  --bg-2: #f7f7fa;
  --card: #ffffff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 8px 24px -12px rgba(20, 20, 30, .18);
  --shadow-lg: 0 2px 6px rgba(20, 20, 30, .06), 0 22px 50px -20px rgba(20, 20, 30, .28);
  --wrap: 1200px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f2f2f5;
    --ink-2: #b3b3bd;
    --ink-3: #85858f;
    --line: #2b2b34;
    --bg: #131317;
    --bg-2: #1a1a20;
    --card: #1c1c22;
    --brand-soft: #2a1f12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .7);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 22px 50px -20px rgba(0, 0, 0, .8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.22; margin: 0 0 .5em; letter-spacing: -.015em; }

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 20px; }

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--brand); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip:focus { left: 0; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- header ---------- */
.site-head {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.head-inner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 18px; min-height: 66px;
}
/* Without this a wide child (the nav) can push the grid past the viewport
   instead of the track shrinking. */
.head-inner > * { min-width: 0; }

/* ---- narrow header ----------------------------------------------------
   The three-column grid (brand | search | nav) cannot fit 390px: the `auto`
   nav track grew, the `1fr` search track collapsed to zero, and the nav
   wrapped above the brand. Replaced with explicit areas:
       brand nav
       search search
   The nav becomes a single horizontally scrollable strip so all five
   destinations stay reachable without a menu, and its links get 40px targets
   (they measured 17px and 34px before). */
@media (max-width: 720px) {
  /* Flexbox, not grid areas. The grid version measured a 0px brand track and a
     nav that wrapped to 94px, because `.head-inner > * { min-width: 0 }` also
     applies here and let the `auto` brand track collapse while the nav took
     the whole row. Here the brand is flex:0 0 auto so it keeps its width, and
     the nav is flex:1 1 0 with min-width:0 so it shrinks and scrolls instead. */
  .head-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    min-height: 0;
    padding: 10px 0;
  }
  .brand { order: 1; flex: 0 0 auto; white-space: nowrap; }
  .head-inner .search { order: 3; flex: 1 1 100%; max-width: none; }
  /* Scoped to .head-inner so it outranks the base .site-nav rule, which sits
     later in this file and would otherwise re-apply flex-wrap: wrap. */
  .head-inner .site-nav { order: 2;
    /* flex-start, not flex-end: in a scrollable flex row, justifying to the end
       makes the overflowing start unreachable. */
    flex: 1 1 0;
    min-width: 0;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Fade the right edge so it reads as scrollable. */
    mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);
  }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav > a, .drop > button {
    min-height: 40px;
    white-space: nowrap;
    padding-inline: 10px;
  }
  /* The homepage has a large hero search immediately below the header; a
     second identical field above it is clutter. The search is already
     flex:1 1 100%, so hiding it leaves the brand and nav alone on one row. */
  .is-home .search { display: none; }
}

/* Below 560px the wordmark costs 183px of a 390px row, leaving the nav 195px
   for 452px of links - two of five destinations visible. The logo mark carries
   the identity, and the footer still spells the name out in full. */
@media (max-width: 560px) {
  .head-inner .brand span { display: none; }
  .head-inner .brand img { width: 30px; height: 30px; }
  .head-inner .site-nav > a,
  .head-inner .drop > button { padding-inline: 8px; }
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; font-size: 1.06rem; }
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: var(--brand); }
.brand img { border-radius: 7px; }

.search { display: flex; gap: 8px; justify-self: center; width: 100%; max-width: 460px; }
.search input {
  flex: 1; min-width: 0; font: inherit; font-size: .92rem; color: var(--ink);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 16px;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { background: var(--bg); border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.search button {
  font: inherit; font-size: .9rem; font-weight: 600; color: #fff; cursor: pointer;
  background: var(--brand); border: 0; border-radius: 999px; padding: 9px 20px;
}
.search button:hover { background: var(--brand-dark); }

/* flex-wrap matters on phones: five nav links plus the category dropdown are
   wider than a 390px viewport, and an unwrapped flex row stretches the whole
   header grid instead of wrapping. */
.site-nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.site-nav > a, .drop > button {
  font: inherit; font-size: .92rem; font-weight: 500; color: var(--ink-2);
  background: none; border: 0; cursor: pointer; padding: 8px 12px; border-radius: var(--radius-sm);
}
.site-nav > a:hover, .drop > button:hover, .site-nav .on { color: var(--ink); background: var(--bg-2); text-decoration: none; }
.drop { position: relative; }
.drop-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 268px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: none; z-index: 60;
}
.drop:hover .drop-menu, .drop:focus-within .drop-menu { display: block; }
.drop-menu a {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 8px 12px; border-radius: var(--radius-sm); color: var(--ink); font-size: .9rem;
}
.drop-menu a:hover { background: var(--brand-soft); text-decoration: none; }
.n { font-size: .76rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---------- hero ---------- */
.hero {
  margin: 28px 0 8px; padding: clamp(28px, 5vw, 56px);
  background: linear-gradient(135deg, var(--brand-soft), color-mix(in srgb, var(--brand-soft) 30%, var(--bg)));
  border: 1px solid var(--line); border-radius: var(--radius-lg, 22px); text-align: center;
}
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); }
.hero p { color: var(--ink-2); margin: 0 auto 22px; max-width: 52ch; }
.hero-search { max-width: 520px; margin-inline: auto; }

/* ---------- sections ---------- */
.sec { margin: 40px 0; }
.sec-h { font-size: 1.3rem; }
.page-h1 { font-size: clamp(1.5rem, 3vw, 2rem); margin-bottom: .2em; }
.lede { color: var(--ink-2); margin: 0 0 22px; }

.grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}

/* ---------- card ---------- */
.card {
  display: flex; flex-direction: column; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); }
.card-media {
  display: block; background: var(--bg-2); aspect-ratio: 5 / 7; overflow: hidden;
  position: relative;
}
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-nocover {
  display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--ink-3); font-size: .85rem; background: var(--bg-2);
}
.card-body { padding: 13px 14px 15px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.card-title { font-size: .95rem; margin: 0; font-weight: 600; }
.card-title a { color: var(--ink); }
.card-title a:hover { color: var(--brand-dark); text-decoration: none; }
.card-author { margin: 0; font-size: .84rem; color: var(--ink-2); }
.card-price { margin: 6px 0 0; display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.now { font-weight: 700; font-size: 1.02rem; }
.card-price s { color: var(--ink-3); font-size: .85rem; }
.off, .book-price .off {
  background: var(--brand-soft); color: var(--brand-dark);
  font-size: .74rem; font-weight: 700; padding: 2px 7px; border-radius: 999px;
}
.card-stock { margin: 6px 0 0; font-size: .78rem; color: #17803d; }
.card-stock.out { color: #c0392b; }
.book-stock { font-weight: 600; }
.book-stock.out { color: #c0392b; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 9px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: 7px 15px; font-size: .89rem;
}
.chip:hover { border-color: var(--brand); background: var(--brand-soft); text-decoration: none; }

/* ---------- sortbar ---------- */
.sortbar { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 0 0 20px; }
.sortbar-label { font-size: .84rem; color: var(--ink-3); margin-right: 3px; }
.sortbar button {
  font: inherit; font-size: .84rem; color: var(--ink-2); cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px;
}
.sortbar button:hover { border-color: var(--brand); color: var(--ink); }
.sortbar button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- filterbar ---------- */
.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 9px;
  margin: 0 0 18px; padding: 13px 15px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.filterbar-label { font-size: .84rem; color: var(--ink-3); margin-right: 3px; }
/* Desktop: the controls are unwrapped so they stay flex items of .filterbar. */
.filter-controls { display: contents; }
.filter-toggle { display: none; }
.filter { display: inline-flex; }
.filter select, .filter input[type="search"] {
  font: inherit; font-size: .84rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; min-width: 132px;
}
.filter select:focus-visible, .filter input:focus-visible,
.filter-check input:focus-visible, .filter-clear:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.filter-check { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; color: var(--ink-2); cursor: pointer; }
.filter-clear {
  font: inherit; font-size: .8rem; cursor: pointer; color: var(--brand);
  background: none; border: 0; padding: 4px 2px; text-decoration: underline;
}
.filter-count { font-size: .82rem; color: var(--ink-3); margin-left: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

/* ---------- script badge, overlaid on the cover ---------- */
.script-tag {
  position: absolute; bottom: 7px; right: 7px; z-index: 1;
  border-radius: 999px; padding: 2px 9px;
  font-size: .68rem; font-weight: 600; letter-spacing: .02em; line-height: 1.6;
  color: #fff; background: rgba(20, 22, 26, .72);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.script-tag[data-script="gurmukhi"] { background: rgba(178, 46, 20, .88); }
.script-tag[data-script="mixed"]   { background: rgba(140, 74, 12, .86); }
.script-tag[data-script="roman"]   { background: rgba(28, 60, 92, .84); }
.script-tag[data-script="unknown"] { background: rgba(60, 60, 66, .8); }

/* ---------- section note under a heading ---------- */
.sec-note { font-size: .86rem; color: var(--ink-3); margin: -6px 0 14px; }
.more-link { margin: 16px 0 0; }

/* ---------- catalogue pager ---------- */
.pager {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 6px; margin: 34px 0 12px; padding-top: 22px; border-top: 1px solid var(--line);
}
.pager a, .pager span {
  min-width: 38px; padding: 7px 11px; text-align: center;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: .86rem; color: var(--ink-2); background: var(--card);
}
.pager a:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.pager .pg-on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.pager .pg-gap { border-color: transparent; background: none; }
.pager .pg-prev, .pager .pg-next { font-weight: 600; }
@media print { .pager { display: none; } }

/* ---------- book page ---------- */
.crumbs { display: flex; flex-wrap: wrap; gap: 8px; font-size: .85rem; color: var(--ink-3); margin: 22px 0; }
.crumbs a { color: var(--ink-2); }
.crumbs span { color: var(--ink-3); }

.book { display: grid; grid-template-columns: minmax(0, 300px) 1fr; gap: clamp(24px, 4vw, 48px); align-items: start; }
.book-media {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.book-media img { width: 100%; }
.book-main h1 { font-size: clamp(1.5rem, 3vw, 2.1rem); }
.book-by { color: var(--ink-2); margin: 0 0 14px; }
.book-price { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 0 0 8px; }
.book-price .now { font-size: 1.7rem; }
.book-price s { color: var(--ink-3); }
.book-stock { margin: 0 0 20px; font-size: .92rem; }

.spec { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; margin: 0; font-size: .92rem; }
.spec dt { color: var(--ink-3); }
.spec dd { margin: 0; }

.desc, .rel { margin: 48px 0; }
.desc h2, .rel h2 { font-size: 1.2rem; }
.desc p { color: var(--ink-2); max-width: 78ch; }

/* ---------- search ---------- */
.search-page { max-width: 640px; margin: 0 auto 28px; }
.empty { color: var(--ink-2); text-align: center; padding: 48px 0; grid-column: 1 / -1; }
mark { background: var(--brand-soft); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- footer ---------- */
.site-foot { border-top: 1px solid var(--line); background: var(--bg-2); margin-top: 64px; }
.foot-inner { padding: 36px 20px; text-align: center; color: var(--ink-2); font-size: .9rem; }
.foot-brand { font-size: 1.05rem; font-weight: 700; color: var(--ink); margin: 0 0 6px; }
.foot-brand em { font-style: normal; color: var(--brand); }
.foot-note { color: var(--ink-3); font-size: .82rem; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .head-inner { grid-template-columns: 1fr auto; row-gap: 12px; padding-block: 12px; }
  .search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .book { grid-template-columns: 1fr; }
  .book-media { max-width: 260px; }
}
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 14px; }
  .site-nav { font-size: .85rem; }
  .spec { grid-template-columns: 1fr; gap: 2px 0; }
  .spec dt { margin-top: 8px; }

  /* Five filter controls wrap into a tall stack on a phone, so they collapse
     behind one button and the bar keeps its height to a single row. */
  .filterbar { padding: 10px 12px; gap: 8px; }
  .filter-toggle {
    display: inline-flex; align-items: center; gap: 7px;
    font: inherit; font-size: .88rem; cursor: pointer; color: var(--ink);
    background: var(--card); border: 1px solid var(--line);
    border-radius: 8px; padding: 8px 14px;
  }
  .filter-toggle-n {
    background: var(--brand); color: #fff; border-radius: 999px;
    padding: 0 7px; font-size: .74rem; line-height: 1.5;
  }
  .filter-controls { display: none; }
  .filterbar.open .filter-controls {
    display: flex; flex-wrap: wrap; align-items: center; gap: 9px;
    flex-basis: 100%; padding-top: 4px;
  }
  .filterbar-label { display: none; }
  .filter select, .filter input[type="search"] { min-width: 0; flex: 1 1 132px; }
  .filter-count { margin-left: 0; flex-basis: 100%; }
}

@media print {
  .site-head, .site-foot, .sortbar, .search, .hero-search { display: none; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* ---------- free-to-read library ---------- */

.tag-free {
  display: inline-block;
  background: #e7f6ec;
  color: #12683a;
  border: 1px solid #b9e2c9;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.card-free {
  margin: 8px 0 0;
  font-size: .82rem;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 7px;
}

.card-nocover span {
  display: block;
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 6px;
}

.book-free {
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: .95rem;
  color: var(--ink-2);
}

.read-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 22px;
}

.read-actions a {
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 9px 15px;
  font-size: .9rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
}

.btn-read {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-read:hover { background: var(--brand-dark); }

.btn-dl {
  background: #12683a;
  border-color: #12683a;
  color: #fff;
}
/* The size inside the dark green button needs to be lighter than the label to
   stay legible, so it gets its own tint rather than inheriting #fff. */
.dl-size {
  color: #7ee2a8;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.btn-dl:hover { background: #0d522d; }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-2);
}

.btn-ghost:hover { background: var(--bg-2); color: var(--ink); }

.spec-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 18px;
}

.spec-block h2 {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-3);
  margin: 0 0 10px;
}

.reader {
  margin: 48px 0 0;
}

.reader h2 {
  font-size: 1.2rem;
  margin: 0 0 12px;
}

.reader iframe {
  display: block;
  width: 100%;
  height: 78vh;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
}

.reader p { font-size: .85rem; margin: 8px 0 0; }

@media print {
  .site-head, .site-foot, .read-actions, .reader, .sortbar, .rel { display: none !important; }
  body { background: #fff; }
}

@media (prefers-color-scheme: dark) {
  .tag-free { background: #10331f; color: #7ee2a8; border-color: #23543a; }
  .btn-read { background: var(--brand); border-color: var(--brand); color: #1b1b1f; }
  .btn-read:hover { background: var(--brand-dark); color: #fff; }
  .btn-dl { background: #14603a; border-color: #2b8a55; color: #eafff1; }
  .btn-dl:hover { background: #1a7a49; }
  .card-nocover { background: var(--card); }
}

/* ---------- reader ---------- */
.reader-shell { display: block; }
.reader-top {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  position: sticky; top: 0; z-index: 20;
  padding: .6rem .7rem; margin: -.5rem -.5rem .75rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.reader-tools { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.reader-tools button, .reader-tools input {
  font: inherit; font-size: .85rem; padding: .3rem .55rem; min-height: 2rem;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.reader-tools button:hover { background: var(--brand); border-color: var(--brand); color: #1b1b1f; }
.reader-tools #pgNum { width: 4rem; text-align: center; }
.reader-tools .zoom-val { font-variant-numeric: tabular-nums; min-width: 3.2rem; text-align: center; }
.reader-tools .sep { width: 1px; height: 1.4rem; background: var(--line); margin: 0 .2rem; }
.reader-links { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-left: auto; }
.src-tag {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .05em;
  padding: .2rem .45rem; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); white-space: nowrap;
}
.src-tag.local { background: #e7f6ec; border-color: #2b8a55; color: #14603a; }
.src-tag.remote { background: #eef1fb; border-color: #8fa3e0; color: #2b3a72; }
.reader-meta { color: var(--muted); font-size: .9rem; margin: 0 0 .6rem; }
.reader-status { padding: 1rem; color: var(--muted); }
.reader-stage {
  display: flex; justify-content: center; gap: 1rem; overflow: auto;
  /* Positioned ancestor for .textLayer, which is placed on the canvas box. */
  position: relative;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; min-height: 60vh; max-height: 88vh;
  /* Clearance for the sticky page-turn bar, which overlays the stage while
     scrolling. Without this the last lines of a page sit behind it. */
  padding-bottom: 76px;
}
#pdfCanvas { background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,.22); max-width: none; }

/* ---------- reader page-turn bar ---------- */
.reader-bottom {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding: 12px 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 -2px 14px rgba(0, 0, 0, .07);
}
.pg-turn {
  font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
  color: var(--ink); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 20px; min-width: 128px;
  display: inline-flex; align-items: center; gap: 8px;
}
.pg-turn:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.pg-turn:disabled { opacity: .38; cursor: not-allowed; }
.pg-turn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.pg-turn-mid {
  font-size: .88rem; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px;
}
.pg-turn-mid input {
  font: inherit; font-size: .88rem; text-align: center;
  width: 58px; padding: 6px 4px;
  color: var(--ink); background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
@media (max-width: 560px) {
  .reader-bottom { padding: 10px 12px; }
  .pg-turn { min-width: 0; padding: 12px 14px; font-size: .88rem; }
  .pg-turn-mid { font-size: .8rem; }
}

.reader-fallback {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 1.4rem; max-width: 46rem;
}
.reader-fallback h2 { margin-top: 0; }
.reader-fallback-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.reader-lede { color: var(--muted); }
.reader-cta { display: flex; flex-wrap: wrap; gap: .5rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .8rem; }
.crumbs a { color: var(--muted); }
@media (max-width: 640px) {
  .reader-links { width: 100%; margin-left: 0; }
  .reader-stage { max-height: 72vh; }
}
@media (prefers-color-scheme: dark) {
  .src-tag.local { background: #10331f; color: #7ee2a8; border-color: #23543a; }
  .src-tag.remote { background: #171c33; color: #a9b8f0; border-color: #2f3b63; }
}
@media print {
  .reader-top, .reader-links, .reader-status, .crumbs, .reader-fallback-actions { display: none !important; }
  .reader-bottom { border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
  .reader-stage { max-height: none; border: 0; padding: 0; }
  #pdfCanvas { box-shadow: none; }
}

/* ==========================================================================
   READER — chrome-free mode
   On /read/* the site header and footer are removed: the reader's own toolbar
   becomes the header, so the page controls, zoom, full screen and the download
   actions are all in one place and the scan gets the whole viewport.
   ========================================================================== */

.is-reader .site-head,
.is-reader .site-foot,
.is-reader .crumbs { display: none; }

.is-reader main#main { padding: 0; }
.is-reader .wrap { max-width: 1180px; padding: 10px 14px 20px; }

.is-reader .reader-shell { display: block; }

/* The toolbar is the header: slim, single row, always reachable. */
.is-reader .reader-top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .5rem;
  flex-wrap: wrap;
  margin: 0 0 10px; padding: .45rem .6rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .06);
}
.is-reader .reader-tools { display: flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.is-reader .reader-tools button {
  font: inherit; font-size: .84rem; line-height: 1;
  min-height: 34px; min-width: 34px; padding: 0 .55rem;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--ink); cursor: pointer;
}
.is-reader .reader-tools button:hover { border-color: var(--brand); color: var(--brand); }
.is-reader .reader-tools #pgNum {
  width: 52px; min-height: 34px; text-align: center;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: .84rem;
  font-variant-numeric: tabular-nums;
}
.is-reader .reader-tools .zoom-val { font-size: .8rem; color: var(--ink-3); min-width: 42px; text-align: center; }
.is-reader .reader-tools .sep { display: none; }

/* Back to the book, always first. */
.is-reader .reader-top .btn-ghost { font-size: .84rem; min-height: 34px; padding: 0 .7rem; }

/* Title line is context, not chrome: one quiet line, truncated. */
.is-reader .reader-meta {
  margin: 0 0 8px; font-size: .8rem; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Downloads and source links stay on the right of the toolbar. */
.is-reader .reader-links {
  display: flex; align-items: center; gap: .4rem;
  margin-left: auto; flex-wrap: wrap;
}
.is-reader .reader-links a { font-size: .82rem; min-height: 34px; padding: 0 .7rem; }
.is-reader .src-tag { font-size: .7rem; padding: 2px 8px; }

.is-reader .reader-status { margin: 0 0 10px; }
/* The scan gets the space the header and footer used to take. */
.is-reader .reader-stage { max-height: calc(100vh - 190px); }

@media (max-width: 720px) {
  .is-reader .reader-links { margin-left: 0; flex-basis: 100%; }
  .is-reader .reader-stage { max-height: calc(100vh - 250px); }
  .is-reader .reader-tools { flex: 1 1 100%; justify-content: space-between; }
}

/* Phone: the toolbar was wrapping to three rows and eating 214px of an 844px
   screen. Shrink the controls so it settles at two compact rows. */
@media (max-width: 720px) {
  .is-reader .reader-top { gap: .35rem; padding: .4rem .45rem; margin-bottom: 8px; }
  .is-reader .reader-tools button,
  .is-reader .reader-tools #pgNum,
  .is-reader .reader-top .btn-ghost,
  .is-reader .reader-links a {
    min-height: 30px; font-size: .78rem; padding: 0 .45rem;
  }
  .is-reader .reader-tools #pgNum { width: 42px; }
  .is-reader .reader-tools .zoom-val { min-width: 36px; font-size: .74rem; }
  .is-reader .reader-meta { font-size: .74rem; margin-bottom: 6px; }
  .is-reader .reader-stage { max-height: calc(100vh - 210px); padding-bottom: 66px; }
  .pg-turn { padding: 9px 12px; font-size: .82rem; }
}

/* The source tag is diagnostic, not something a reader needs on a phone; it was
   pushing the toolbar to a fifth row. */
@media (max-width: 720px) {
  .is-reader .src-tag { display: none; }
}

/* The reader toolbar is one row by design (~50px). At 1200px its content was
   1212px + 24px of gaps against 1181px of usable width, so it wrapped to 92px.
   The src-tag badge is 86px of purely informational text - "streaming" versus
   "on this device" - and is the cheapest thing to give up: the download button
   beside it already tells the reader the file is not local. */
@media (max-width: 1279px) {
  .is-reader .reader-links .src-tag { display: none; }
}

/* ===================== mobile polish =====================
   Measured at 390x844 before this block: card-title links 17-34px, book-page
   action buttons 22px, reader toolbar controls 30px, header nav 17px. All well
   under the 44px that a thumb needs, and the primary "Read online" button was
   one of them. */
@media (max-width: 720px) {
  /* Standalone controls only. Inline text links - breadcrumbs, the author line -
     keep their natural line height; padding them to 44px would break the text
     flow they sit in. */
  .btn,
  .chip,
  .pager a,
  .pager span,
  .filter select,
  .filter input[type="search"],
  .sortbar button,
  .search button,
  .reader-tools button,
  .reader-tools input,
  .reader-find button,
  .reader-find input,
  /* Scoped like the rules they must beat: `.is-reader .reader-tools button`
     is 0,2,1 and outranked the unscoped selector above, so the reader's
     controls stayed at 30px. */
  .is-reader .reader-tools button,
  .is-reader .reader-tools input,
  .is-reader .reader-top .btn-ghost,
  .is-reader .reader-links a,
  .is-reader .reader-find button,
  .is-reader .reader-find input,
  .is-reader .reader-bottom button,
  .is-reader .reader-bottom .pg-turn-mid input,
  .is-reader .reader-tools #pgNum,
  .is-reader .reader-tools #pgNumB {
    min-height: 44px;
  }

  /* The logo mark alone is the home link on narrow screens; give it a real
     target rather than the 30px box. */
  .head-inner .brand { min-width: 44px; min-height: 44px; justify-content: center; }

  /* The cover is the card's real tap target; the title is a second link, so it
     needs its own reach. A height floor rather than padding, so a one-line
     title and a two-line one both reach 44px instead of 29px and 46px. The
     negative margin keeps the visual gap to the cover unchanged. */
  .card-title a {
    display: block;
    min-height: 44px;
    padding-block: 6px;
    margin-block: -6px;
  }

  /* Breadcrumbs, the author line and the "view all" link are text links, so
     they keep their line height and get vertical padding instead - enough reach
     without breaking the text flow they sit in. */
  .crumbs a,
  .book-by a,
  .more-link a {
    display: inline-block;
    padding-block: 9px;
  }

  /* Cards are links you press, not hover. */
  .card:active .card-media,
  .card-media:active {
    transform: scale(.985);
  }
  .card-media { transition: transform .12s ease; }

  /* Notched phones: the reader's sticky page-turn bar and the footer sit under
     the home indicator without this. */
  .reader-bottom {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .site-foot {
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
  /* And the sticky header must not run under the notch. */
  .site-head { padding-top: env(safe-area-inset-top); }

  /* Rubber-banding the page sideways while reading feels broken. */
  .reader-shell { overscroll-behavior-x: none; }
}

/* Highlight colour is a purple box on Android unless removed. */
a, button, .chip, .card-media {
  -webkit-tap-highlight-color: rgb(178 46 20 / 14%);
}

/* Respect a stated preference for less motion - the card lift and the
   highlight fade are the only animations on the site. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- collections ------------------------------------------------------ */

.prose {
  max-width: 68ch;
  margin: 0 0 1.75rem;
}
.prose p {
  margin: 0;
  color: var(--ink-2);
  line-height: 1.65;
}

.sec-sub {
  margin: -0.35rem 0 1rem;
  color: var(--ink-3);
  font-size: 0.95rem;
}

.sub-h {
  margin: 1.5rem 0 0.6rem;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* Collections index: one card per collection, not a bare chip list. */
.coll-card {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}
.coll-card:last-child { border-bottom: 0; }
.coll-h {
  margin: 0 0 0.2rem;
  font-size: 1.1rem;
}
.coll-h a { color: inherit; }
.coll-blurb {
  margin: 0 0 0.3rem;
  color: var(--ink-2);
}
.coll-n {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.lede.note {
  margin-top: 1.75rem;
  font-size: 0.92rem;
  color: var(--ink-3);
}

/* Homepage collection tiles. */
.coll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.6rem;
}
.coll-tile {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: inherit;
  text-decoration: none;
}
.coll-tile:hover { border-color: var(--brand); }
.coll-tile-h { font-weight: 600; font-size: 0.95rem; line-height: 1.25; }
.coll-tile-n { font-size: 0.78rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* ---- author profile --------------------------------------------------- */

.author-profile {
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card);
}
.author-facts {
  margin: 0 0 0.4rem;
  font-size: 1.02rem;
}
.author-note {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink-3);
  line-height: 1.55;
}
.author-profile .chips { margin-top: 0.4rem; }

/* ---- external references --------------------------------------------- */

.reflist {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}
.reflist li { font-size: 0.95rem; }
.reflist .ext {
  color: var(--ink-3);
  font-size: 0.8em;
}

@media (max-width: 480px) {
  .coll-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .author-profile { padding: 0.9rem 1rem; }
}

/* ---- opening-of-book excerpt ------------------------------------------ */

.book-opening { margin: 1.5rem 0; }
.book-excerpt {
  margin: 0;
  padding: 0.9rem 1.1rem;
  border-left: 3px solid var(--brand);
  background: var(--bg-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.98rem;
  line-height: 1.7;
  color: var(--ink);
}
.ocr-note {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-3);
  line-height: 1.5;
}
.ocr-note a { color: var(--brand-dark); }

@media (max-width: 480px) {
  .book-excerpt { padding: 0.75rem 0.9rem; font-size: 0.94rem; }
}

/* ---- "what this book is about" ---------------------------------------- */

.book-about { margin: 1.5rem 0; }
.book-summary {
  margin: 0;
  max-width: 70ch;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink);
}
