:root {
  --teal: #0095A2;
  --gold: #CBA431;
  --navy: #0D4887;
  --magenta: #D91B5C;

  --bg: #FCFAF5;
  --panel: #FFFFFF;
  --soft: #F3EEE3;
  --rule: #E3DCCD;
  --ink: #16212E;
  --muted: #5C6570;
  --accent: #0D4887;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3ECF6;
  --focus: #0095A2;
  --stage: #E6E0D3;
  --page-bg: #FFFFFF;
  --shadow: 0 1px 2px rgba(22, 33, 46, .06), 0 8px 24px rgba(22, 33, 46, .08);
  --shadow-page: 0 1px 3px rgba(22, 33, 46, .12), 0 6px 18px rgba(22, 33, 46, .10);

  --display: "Fredoka", "Heebo", "Arial Hebrew", Arial, sans-serif;
  --sans: "Heebo", "Arial Hebrew", Arial, sans-serif;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --t-fast: 140ms;
  --t-med: 240ms;
  --side-w: 300px;
  --cmt-w: 360px;
  --danger: #B3164B;
  --bar-h: 60px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10151C;
    --panel: #171E27;
    --soft: #1D2630;
    --rule: #2A3542;
    --ink: #ECE8E0;
    --muted: #9BA5B0;
    --accent: #5BC2CC;
    --accent-ink: #0B1016;
    --accent-soft: #17323A;
    --focus: #5BC2CC;
    --stage: #0A0E13;
    --page-bg: #F4F1EA;
    --danger: #FF8FB1;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-page: 0 2px 10px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #10151C;
  --panel: #171E27;
  --soft: #1D2630;
  --rule: #2A3542;
  --ink: #ECE8E0;
  --muted: #9BA5B0;
  --accent: #5BC2CC;
  --accent-ink: #0B1016;
  --accent-soft: #17323A;
  --focus: #5BC2CC;
  --stage: #0A0E13;
  --page-bg: #F4F1EA;
  --danger: #FF8FB1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-page: 0 2px 10px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html.viewing { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
button, input { font: inherit; color: inherit; }
a { color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

[hidden] { display: none !important; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.skip {
  position: absolute; inset-inline-start: 12px; top: -60px; z-index: 50;
  background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: var(--r-sm);
  text-decoration: none; font-weight: 500;
}
.skip:focus { top: 12px; }

/* ───────── buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--panel); color: var(--ink);
  font-size: 15px; font-weight: 500; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--soft); border-color: color-mix(in srgb, var(--rule) 60%, var(--ink) 20%); }
.btn small { font-size: 12px; color: var(--muted); font-weight: 400; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none;
  transition: background var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--soft); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }

/* ───────── library ───────── */
.stripe { display: flex; height: 6px; }
.stripe i { flex: 1; }
.stripe i:nth-child(1) { background: var(--teal); }
.stripe i:nth-child(2) { background: var(--gold); }
.stripe i:nth-child(3) { background: var(--navy); }
.stripe i:nth-child(4) { background: var(--magenta); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

.masthead { padding: 36px 0 8px; }
.mast-inner { display: flex; align-items: center; gap: 32px; }
.logo { width: 260px; height: auto; flex: none; }
.logo-plate { flex: none; border-radius: var(--r-lg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-plate { background: #FFFFFF; padding: 10px 14px; }
}
:root[data-theme="dark"] .logo-plate { background: #FFFFFF; padding: 10px 14px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 14px; font-weight: 500; letter-spacing: .01em; }
.masthead h1 {
  margin: 0; font-family: var(--display); font-weight: 600;
  font-size: clamp(34px, 4.8vw, 54px); line-height: 1.1; text-wrap: balance;
}
.lede { margin: 12px 0 0; max-width: 56ch; color: var(--muted); font-size: 17px; }
.stats { margin: 14px 0 0; display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 14px; }
.stats b { color: var(--ink); font-weight: 700; }

.tools {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  margin-top: 28px; padding: 12px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.tools .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.search { position: relative; flex: 1 1 280px; max-width: 460px; }
.search .ic { position: absolute; inset-inline-start: 12px; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 44px; padding: 0 42px 0 14px;
  border: 1px solid var(--rule); border-radius: var(--r-md); background: var(--panel);
  font-size: 16px;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.chip:hover { background: var(--soft); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

main.library-main { padding: 8px 0 72px; }

.hits { margin: 24px 0 8px; padding: 18px 20px; border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--panel); }
.hits h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; color: var(--muted); }
.hits ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 2px 20px; }
.hits a {
  display: flex; align-items: baseline; gap: 10px; padding: 7px 8px; margin: 0 -8px;
  border-radius: var(--r-sm); text-decoration: none;
}
.hits a:hover { background: var(--soft); }
.hits .doc { flex: none; font-size: 13px; color: var(--muted); }
.hits .t { flex: 1; min-width: 0; }
.hits .pg { flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hits mark { background: color-mix(in srgb, var(--gold) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.empty { margin: 48px 0; text-align: center; color: var(--muted); }

.shelf { padding-top: 40px; }
.shelf-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 18px; }
.shelf-head h2 { margin: 0; font-family: var(--display); font-size: 28px; font-weight: 600; line-height: 1.2; text-wrap: balance; }
.shelf-head p { margin: 0; color: var(--muted); font-size: 15px; }

.grid { display: grid; gap: 22px; }
.g-portrait { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.g-landscape { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--r-lg);
  overflow: hidden;
  transition: box-shadow var(--t-med) var(--ease), transform var(--t-med) var(--ease);
}
.card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.cover { position: relative; display: block; background: var(--soft); overflow: hidden; }
.card.portrait .cover { aspect-ratio: 1 / 1.414; }
.card.landscape .cover { aspect-ratio: 16 / 9; }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: top center; }
.badge {
  position: absolute; inset-inline-start: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; border-radius: 999px;
  background: rgba(13, 22, 33, .78); color: #FFFFFF; font-size: 13px; font-weight: 500;
  backdrop-filter: blur(4px);
}
.badge .ic { width: 15px; height: 15px; }

.card-body { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px 16px; flex: 1; }
.card-label { margin: 0; font-size: 13px; font-weight: 500; color: var(--muted); }
.card-title { margin: 0; font-family: var(--display); font-size: 23px; font-weight: 600; line-height: 1.2; }
.card-title a { text-decoration: none; }
.card-title a:hover { text-decoration: underline; text-underline-offset: 3px; }
.tagline { margin: 2px 0 0; font-size: 14.5px; line-height: 1.45; }

.card-toc { margin-top: 8px; border-top: 1px solid var(--rule); }
.card-toc summary {
  display: flex; align-items: center; gap: 8px; padding: 10px 0 6px;
  font-size: 14px; font-weight: 500; color: var(--accent); cursor: pointer; list-style: none;
}
.card-toc summary::-webkit-details-marker { display: none; }
.card-toc summary .ic { width: 16px; height: 16px; transition: rotate var(--t-fast) var(--ease); }
.card-toc[open] summary .ic { rotate: 180deg; }
.card-toc summary .n { margin-inline-start: auto; color: var(--muted); font-weight: 400; font-size: 13px; }
.card-toc ol { list-style: none; margin: 0 0 4px; padding: 0; max-height: 260px; overflow: auto; overscroll-behavior: contain; }

.toc-link {
  display: flex; align-items: baseline; gap: 10px;
  width: 100%; padding: 5px 8px; border: 0; border-radius: 6px; background: transparent;
  text-align: start; text-decoration: none; font-size: 14px; line-height: 1.4; cursor: pointer;
}
.toc-link:hover { background: var(--soft); }
.toc-link .t { flex: 1; min-width: 0; }
.toc-link .pg { flex: none; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.l0 > .toc-link { font-weight: 700; margin-top: 6px; }
.l2 > .toc-link { padding-inline-start: 22px; color: var(--muted); font-size: 13px; }

.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 14px; }
.card-actions .btn { flex: 1 1 auto; }

.site-foot { border-top: 1px solid var(--rule); padding: 24px 0 40px; color: var(--muted); font-size: 14px; }
.site-foot .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; }

/* ───────── viewer ───────── */
.viewer {
  position: fixed; inset: 0; z-index: 20;
  display: grid; grid-template-rows: auto 1fr;
  background: var(--stage);
}

.vbar {
  display: flex; align-items: center; gap: 6px;
  min-height: var(--bar-h); padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: var(--panel); border-bottom: 1px solid var(--rule);
  position: relative; z-index: 3;
}
.vbar .back { gap: 6px; padding: 0 12px 0 10px; }
.vtitle { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; padding-inline: 8px; }
.vtitle strong { font-family: var(--display); font-size: 19px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtitle span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vgroup { display: flex; align-items: center; gap: 2px; padding-inline: 6px; border-inline-start: 1px solid var(--rule); }
.vgroup:first-of-type { border: 0; }
.pageno { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; padding-inline: 4px; }
.pageno input {
  width: 52px; height: 34px; text-align: center;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--bg); color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.zoomval {
  min-width: 56px; height: 34px; padding: 0 6px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink);
}
.zoomval:hover { background: var(--soft); }
.vbar .dl { margin-inline-start: 6px; }

.vbody {
  --sw: var(--side-w); --cw: 0px;
  display: grid; grid-template-columns: var(--sw) minmax(0, 1fr) var(--cw);
  min-height: 0; position: relative;
}
.viewer.no-side .vbody { --sw: 0px; }
.viewer.cmt-open .vbody { --cw: var(--cmt-w); }
.vbody > .vside { grid-column: 1; grid-row: 1; }
.vbody > .vmain { grid-column: 2; grid-row: 1; }
.vbody > .vcmt { grid-column: 3; grid-row: 1; }
.vmain { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; }
.vmain > .chapbar { grid-row: 1; }
.vmain > .vstage { grid-row: 2; }

.chapbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: var(--soft); border-bottom: 1px solid var(--rule);
}
.chap-info {
  flex: 1; min-width: 0;
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 2px 12px;
  text-align: center;
}
.chap-k, .chap-pages { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.chap-info strong {
  font-family: var(--display); font-size: 17px; font-weight: 600;
  min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chap-btn, .chap-mode {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 38px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink);
  font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.chap-btn:hover, .chap-mode:hover { background: var(--bg); border-color: color-mix(in srgb, var(--rule) 60%, var(--ink) 20%); }
.chap-btn:disabled { opacity: .4; cursor: default; background: var(--panel); }
.chap-btn .ic { width: 18px; height: 18px; }
.chap-mode { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--rule)); }
.viewer.no-side .vside { display: none; }

.vside {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-inline-end: 1px solid var(--rule);
}
.tabs { display: flex; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--rule); }
.tab {
  height: 38px; padding: 0 12px; border: 0; background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); border-color: var(--accent); }
.tabpanel { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.side-toc { list-style: none; margin: 0; padding: 10px 8px 24px; }
.side-toc .toc-link { padding: 7px 10px; }
.side-toc .toc-link[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.side-toc .toc-link[aria-current="true"] .pg { color: var(--accent); }

.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 12px; padding: 14px 14px 24px; }
.thumb { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0; border: 0; background: transparent; cursor: pointer; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.thumb .tc { width: 100%; aspect-ratio: 1 / var(--r, 1.414); background: var(--page-bg); border-radius: 3px; box-shadow: 0 0 0 1px var(--rule); overflow: hidden; display: block; }
.thumb canvas { width: 100%; height: 100%; display: block; }
.thumb:hover .tc { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent); }
.thumb[aria-current="true"] { color: var(--accent); font-weight: 700; }
.thumb[aria-current="true"] .tc { box-shadow: 0 0 0 3px var(--accent); }

.vstage { position: relative; overflow: auto; min-height: 0; overscroll-behavior: contain; }
.vstage:focus { outline: none; }
.pages {
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 24px 16px 48px; width: max-content; min-width: 100%;
}
.page {
  position: relative; width: var(--pw, 800px); aspect-ratio: 1 / var(--r, 1.414);
  background: var(--page-bg); box-shadow: var(--shadow-page); border-radius: 2px; overflow: hidden;
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page:not(.ready)::after {
  content: attr(data-n); position: absolute; inset: 0; display: grid; place-items: center;
  color: #B8B0A0; font-size: 28px; font-weight: 300; font-variant-numeric: tabular-nums;
}

.vframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--panel); }

.vstatus {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  color: var(--muted); font-size: 15px;
}
.vstatus .box { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: var(--r-md); background: var(--panel); box-shadow: var(--shadow); }
.spin { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--rule); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }

.scrim { display: none; }

/* comments */
html:not(.has-cmt) #v-cmt, html:not(.has-cmt) .card-cmt { display: none; }
.cmt-btn { min-height: 38px; padding: 0 10px; gap: 6px; }
.cmt-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.cmt-n:empty { display: none; }
.cmt-n {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}

.vcmt {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel); border-inline-start: 1px solid var(--rule);
}
.cmt-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 16px 12px 10px; border-bottom: 1px solid var(--rule); }
.cmt-head-text { flex: 1; min-width: 0; }
.cmt-head h2 { margin: 0; font-family: var(--display); font-size: 19px; font-weight: 600; line-height: 1.25; }
.cmt-head h2:focus { outline: none; }
.cmt-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.cmt-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 14px 16px 28px; display: flex; flex-direction: column; gap: 14px; }

.cmt-form { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--r-md); background: var(--soft); }
.cmt-note { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
.fld input, .fld textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--panel); color: var(--ink); font: inherit; font-size: 15px; font-weight: 400; line-height: 1.5;
}
.fld textarea { resize: vertical; min-height: 96px; }
.fld input:focus, .fld textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.hp { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cmt-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cmt-len { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cmt-status { margin: 0; font-size: 13.5px; }
.cmt-status:empty { display: none; }
.cmt-status.err { color: var(--danger); }

.cmt-list-h { margin: 6px 0 0; font-size: 14px; font-weight: 700; color: var(--muted); }
.cmt-list-h:empty { display: none; }
.cmt-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cmt { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.cmt:first-child { padding-top: 0; }
.cmt-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.cmt-name { font-weight: 700; font-size: 14.5px; }
.cmt-time { font-size: 12.5px; color: var(--muted); }
.cmt-del { margin-inline-start: auto; padding: 2px 6px; border: 0; border-radius: 6px; background: transparent; color: var(--danger); font-size: 12.5px; cursor: pointer; }
.cmt-del:hover { background: var(--soft); }
.cmt-text { margin: 4px 0 0; font-size: 15px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmt-text a { color: var(--accent); }
.cmt-state { margin: 0; font-size: 14px; color: var(--muted); text-align: center; padding: 8px 0; }
.cmt-admin { margin: 10px 0 0; text-align: center; }
.linkish { padding: 4px; border: 0; background: none; color: var(--muted); font-size: 12.5px; text-decoration: underline; cursor: pointer; }

.card-cmt {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  margin-top: 10px; padding: 4px 2px; border: 0; background: none;
  color: var(--muted); font-size: 13.5px; font-weight: 500; cursor: pointer;
}
.card-cmt:hover { color: var(--accent); }
.card-cmt .ic { width: 16px; height: 16px; }

/* small screens */
@media (max-width: 860px) {
  .vbody, .viewer.no-side .vbody, .viewer.cmt-open .vbody { --sw: 0px; --cw: 0px; }
  .vbody > .vcmt {
    position: absolute; inset-block: 0; inset-inline-end: 0; z-index: 4;
    width: min(100vw, 420px); box-shadow: var(--shadow);
  }
  .viewer.cmt-open .scrim { display: block; position: absolute; inset: 0; z-index: 3; background: rgba(10, 14, 19, .35); }
  .vside {
    position: absolute; inset-block: 0; inset-inline-start: 0; z-index: 4;
    width: min(86vw, 340px); box-shadow: var(--shadow);
    transform: translateX(100%); visibility: hidden;
    transition: transform var(--t-med) var(--ease), visibility 0s linear var(--t-med);
  }
  .viewer.no-side .vside { display: flex; }
  .viewer.drawer-open .vside { transform: none; visibility: visible; transition: transform var(--t-med) var(--ease); }
  .viewer.drawer-open .scrim { display: block; position: absolute; inset: 0; z-index: 3; background: rgba(10, 14, 19, .35); }
  .hide-sm { display: none !important; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .masthead { padding-top: 22px; }
  .mast-inner { flex-direction: column; align-items: flex-start; gap: 18px; }
  .logo { width: 210px; }
  .lede { font-size: 16px; }
  .tools { margin-top: 20px; }
  .search { max-width: none; flex-basis: 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin-inline: -16px; padding-inline: 16px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .shelf { padding-top: 32px; }
  .shelf-head h2 { font-size: 24px; }
  .g-portrait { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .g-landscape { grid-template-columns: 1fr; }
  .card-body { padding: 12px 12px 14px; }
  .card-title { font-size: 20px; }
  .tagline { font-size: 13.5px; }
  .card-actions .btn { padding: 0 10px; }
  .card-actions .btn small { display: none; }
  .hits ol { grid-template-columns: 1fr; }

  .vbar { padding: calc(6px + env(safe-area-inset-top, 0px)) 6px 6px; gap: 2px; }
  .vbar .back span { display: none; }
  .vbar .back { padding: 0; width: 40px; }
  .vtitle strong { font-size: 16px; }
  .vtitle span { display: none; }
  .vgroup { padding-inline: 2px; border: 0; }
  .pageno input { width: 44px; }
  .hide-xs { display: none !important; }
  .pages { padding: 12px 8px 32px; gap: 10px; }
  .chapbar { padding: 6px 8px; gap: 6px; }
  .chap-btn { padding: 0; width: 38px; justify-content: center; }
  .chap-btn span, .chap-k { display: none; }
  .chap-info { flex-direction: column; align-items: center; gap: 0; }
  .chap-info strong { font-size: 15px; }
  .chap-pages { font-size: 12px; }
  .chap-mode { padding: 0 10px; font-size: 13px; }
}

@media (max-width: 480px) {
  #v-prev, #v-next { display: none; }
  .vbar .dl { padding: 0 10px; margin-inline-start: 2px; }
  .cmt-btn { padding: 0 8px; }
  .pageno { padding-inline: 2px; }
}

@media (max-width: 380px) {
  .g-portrait { gap: 10px; }
  .card-actions .btn span { font-size: 14px; }
}

html.no-dl a[download] { display: none !important; }
a[aria-busy="true"] { opacity: .6; cursor: progress; }

.toast {
  position: fixed; z-index: 40; left: 50%; translate: -50% 0;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--r-md);
  background: var(--ink); color: var(--bg); font-size: 14.5px; box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
  .card:hover { transform: none; }
}
