/* ------------------------------------------------------------------ fonts */
/* Bodoni Moda (SIL OFL), self-hosted – no requests to Google. */
@font-face {
  font-family: "Bodoni Moda"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bodoni Moda"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-ext-400-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bodoni Moda"; font-style: italic; font-weight: 400; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-400-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bodoni Moda"; font-style: italic; font-weight: 400; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-ext-400-italic.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Bodoni Moda"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bodoni Moda"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(../fonts/bodoni-moda-latin-ext-600-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ----------------------------------------------------------------- tokens */
:root {
  --espresso-950: #140d08;
  --espresso-900: #1c120c;
  --espresso-800: #26180f;
  --espresso-700: #352215;
  --espresso-600: #4a301c;
  --cream-50: #fbf7f1;
  --cream-100: #f5ede2;
  --cream-200: #ece0cf;
  --cream-300: #dccab2;
  --gold-300: #e3cd9b;
  --gold-500: #c8a96a;
  --gold-600: #a7864a;
  --ink: #2a1a10;
  --ink-soft: #6b5442;

  --serif: "Bodoni Moda", "Didot", "Bodoni 72", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --topbar-h: 56px;
  --toolbar-h: 76px;
  --radius: 14px;
  --shadow-lg: 0 24px 60px rgba(8, 4, 2, .55), 0 6px 16px rgba(8, 4, 2, .35);
  --ease: cubic-bezier(.2, .7, .2, 1);

  /* faint damask-ish quatrefoil, echoing the back cover */
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23c8a96a' stroke-opacity='.045' stroke-width='1'%3E%3Cpath d='M28 10c4 6 4 10 0 18-4-8-4-12 0-18zM28 46c4-6 4-10 0-18-4 8-4 12 0 18zM10 28c6-4 10-4 18 0-8 4-12 4-18 0zM46 28c-6-4-10-4-18 0 8 4 12 4 18 0z'/%3E%3Ccircle cx='0' cy='0' r='3'/%3E%3Ccircle cx='56' cy='0' r='3'/%3E%3Ccircle cx='0' cy='56' r='3'/%3E%3Ccircle cx='56' cy='56' r='3'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
}

/* ------------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) var(--toolbar-h);
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--cream-100);
  background:
    radial-gradient(ellipse 80% 70% at 50% 45%, rgba(120, 78, 40, .28), transparent 70%),
    var(--pattern),
    linear-gradient(180deg, var(--espresso-800), var(--espresso-950));
  background-color: var(--espresso-900);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 2px; border-radius: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ----------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(200, 169, 106, .14);
}
.brand { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.brand__title {
  font-family: var(--serif); font-weight: 400; font-size: 17px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--gold-300); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand__subtitle { font-family: var(--serif); font-style: italic; font-size: 15px; color: rgba(245, 237, 226, .66); white-space: nowrap; }
.topbar__download {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 8px 14px; border-radius: 999px; border: 1px solid rgba(200, 169, 106, .45);
  color: var(--gold-300); text-decoration: none; font-size: 14px; letter-spacing: .02em;
  transition: background .2s, color .2s, border-color .2s;
}
.topbar__download svg { width: 18px; height: 18px; }
.topbar__download:hover { background: var(--gold-500); border-color: var(--gold-500); color: var(--espresso-900); }

/* ------------------------------------------------------------------ stage */
.stage {
  position: relative; display: grid; place-items: center;
  padding: 20px 76px 8px;
  min-width: 0; overflow: hidden;
  transition: padding .35s var(--ease);
  min-height: 0;
  touch-action: pan-y;
}
.book-shift { transition: transform .55s var(--ease); will-change: transform; }
.book { position: relative; }
.book .stf__block { filter: drop-shadow(0 18px 30px rgba(6, 3, 1, .5)); }

.page { background: var(--cream-100); overflow: hidden; }
.page__img {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  opacity: 0; transition: opacity .35s ease; user-select: none; -webkit-user-drag: none; pointer-events: none;
}
.page.is-ready .page__img { opacity: 1; }
.page::before {   /* placeholder shimmer while the page renders */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .5) 50%, transparent 70%) var(--cream-200);
  background-size: 250% 100%;
  animation: shimmer 1.6s linear infinite;
}
.page.is-ready::before { display: none; }
.page::after {    /* spine shading */
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.page--left::after  { background: linear-gradient(to left,  rgba(20, 10, 4, .28), rgba(20, 10, 4, .06) 3%, transparent 9%); }
.page--right::after { background: linear-gradient(to right, rgba(20, 10, 4, .28), rgba(20, 10, 4, .06) 3%, transparent 9%); }
.book.is-portrait .page::after { display: none; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -150% 0; } }

.side-nav {
  position: absolute; top: 50%; translate: 0 -50%;
  width: 52px; height: 52px; border-radius: 50%;
  display: none; place-items: center;
  color: var(--cream-100); background: rgba(28, 18, 12, .45); border: 1px solid rgba(200, 169, 106, .25);
  transition: background .2s, color .2s, opacity .2s, border-color .2s;
}
.side-nav svg { width: 26px; height: 26px; }
.side-nav--prev { left: 14px; }
.side-nav--next { right: 14px; }
.side-nav:hover { background: var(--gold-500); color: var(--espresso-900); border-color: var(--gold-500); }
.side-nav:disabled { opacity: 0; pointer-events: none; }
@media (hover: hover) and (min-width: 760px) { .side-nav { display: grid; } }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  justify-self: center; align-self: center;
  display: flex; align-items: center; gap: 2px;
  padding: 6px; margin-bottom: env(safe-area-inset-bottom);
  max-width: calc(100vw - 16px);
  background: var(--cream-100); color: var(--ink);
  border-radius: 999px; box-shadow: var(--shadow-lg);
}
.tb {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; flex: none;
  color: var(--ink); transition: background .15s, color .15s;
}
.tb:hover { background: var(--cream-200); }
.tb:active { background: var(--cream-300); }
.tb:disabled { color: var(--cream-300); pointer-events: none; }
.tb[aria-pressed="true"], .tb.is-active { background: var(--ink); color: var(--gold-300); }
.tb-sep { width: 1px; height: 24px; margin: 0 6px; background: var(--cream-300); flex: none; }
.tb-indicator {
  min-width: 96px; height: 42px; padding: 0 12px; border-radius: 999px;
  font-family: var(--serif); font-size: 17px; font-variant-numeric: lining-nums tabular-nums; letter-spacing: .02em;
  color: var(--ink); white-space: nowrap;
}
.tb-indicator:hover { background: var(--cream-200); }
.tb--narrow-only { display: none; }
#i-sound .mute { display: none; }
.tb[data-action="sound"][aria-pressed="false"] .wave { display: none; }
.tb[data-action="sound"][aria-pressed="false"] .mute { display: inline; }
.toolbar a.tb { text-decoration: none; }

/* --------------------------------------------------------- panel / drawer */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(10, 6, 3, .4); animation: fade .2s ease; }
.panel {
  position: fixed; z-index: 21; top: 0; right: 0; bottom: 0;
  width: min(400px, 100vw);
  display: flex; flex-direction: column;
  background: var(--cream-50); color: var(--ink);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%); transition: transform .35s var(--ease);
  visibility: hidden;
}
.panel.is-open { transform: none; visibility: visible; }
/* Wide screens: the drawer docks beside the book instead of covering it. */
body.panel-docked .panel { top: var(--topbar-h); box-shadow: -1px 0 0 rgba(200, 169, 106, .2); }
body.panel-docked .stage { padding-right: 420px; }
body.panel-docked .side-nav--next { right: 414px; }
body.panel-docked .toolbar { translate: -210px 0; }
.toolbar { transition: translate .35s var(--ease); }
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--cream-200);
}
.panel__tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--cream-200); }
.panel__tab {
  padding: 7px 16px; border-radius: 999px; font-family: var(--serif); font-size: 16px; color: var(--ink-soft);
}
.panel__tab[aria-selected="true"] { background: var(--cream-50); color: var(--ink); box-shadow: 0 1px 3px rgba(42, 26, 16, .15); }
.panel__body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px 28px; }

.thumbs { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 14px; }
.thumbs li:first-child { grid-column: 2; }   /* cover sits on the right, like the book */
.thumb { display: block; width: 100%; text-align: center; }
.thumb__img {
  display: block; width: 100%; aspect-ratio: var(--page-ratio, .707);
  background: var(--cream-200); border-radius: 3px; object-fit: cover;
  box-shadow: 0 2px 8px rgba(42, 26, 16, .18);
  outline: 2px solid transparent; outline-offset: 3px; transition: outline-color .15s, transform .2s var(--ease);
}
.thumb:hover .thumb__img { transform: translateY(-2px); }
.thumb.is-current .thumb__img { outline-color: var(--gold-500); }
.thumb__num { display: block; margin-top: 6px; font-family: var(--serif); font-size: 14px; color: var(--ink-soft); }
.thumb.is-current .thumb__num { color: var(--ink); font-weight: 600; }

.search {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 46px;
  border: 1px solid var(--cream-300); border-radius: 999px; background: #fff;
}
.search:focus-within { border-color: var(--gold-500); box-shadow: 0 0 0 3px rgba(200, 169, 106, .25); }
.search svg { color: var(--ink-soft); width: 20px; height: 20px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: 16px var(--sans); color: var(--ink); }
.search__status { margin: 14px 4px 6px; font-size: 14px; color: var(--ink-soft); min-height: 1.2em; }
.results { list-style: none; margin: 0; padding: 0; }
.result {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px;
  border-bottom: 1px solid var(--cream-200);
}
.result:hover { background: var(--cream-100); }
.result__page { display: block; font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 3px; }
.result__page small { font-weight: 400; color: var(--ink-soft); font-family: var(--sans); font-size: 12px; margin-left: 6px; }
.result__snippet { display: block; font-size: 14px; line-height: 1.45; color: var(--ink-soft); }
.result mark { background: rgba(200, 169, 106, .45); color: var(--ink); border-radius: 2px; padding: 0 1px; }

/* ------------------------------------------------------------------- zoom */
.zoom { position: fixed; inset: 0; z-index: 30; background: rgba(16, 10, 6, .97); animation: fade .2s ease; }
.zoom__viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.zoom__viewport.is-dragging { cursor: grabbing; }
/* No will-change here: with it Chrome keeps the layer's bitmap at 100% and just
   stretches it when zoomed, so the sharper re-render would still look blurry. */
.zoom__content { position: absolute; left: 0; top: 0; display: flex; transform-origin: 0 0; box-shadow: var(--shadow-lg); }
.zoom__content img { display: block; width: 50%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; background: var(--cream-100); }
.zoom__content.is-single img { width: 100%; }
.zoom__controls {
  position: absolute; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); translate: -50% 0;
  display: flex; align-items: center; gap: 2px; padding: 6px;
  background: var(--cream-100); color: var(--ink); border-radius: 999px; box-shadow: var(--shadow-lg);
}
.zoom__level { min-width: 64px; height: 42px; border-radius: 999px; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink); }
.zoom__level:hover { background: var(--cream-200); }

/* ----------------------------------------------------------------- loader */
.loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: var(--pattern), linear-gradient(180deg, var(--espresso-800), var(--espresso-950));
  background-color: var(--espresso-900);
  transition: opacity .6s ease, visibility .6s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader__inner { text-align: center; max-width: 520px; }
.loader__ornament { color: var(--gold-500); font-size: 22px; }
.loader__title {
  margin: 14px 0 6px; font-family: var(--serif); font-size: clamp(22px, 4.6vw, 34px); line-height: 1.2;
  letter-spacing: .14em; text-transform: uppercase; color: var(--gold-300);
}
.loader__subtitle { margin: 0 0 28px; font-family: var(--serif); font-style: italic; font-size: 17px; color: rgba(245, 237, 226, .7); }
.loader__bar { width: 200px; height: 1px; margin: 0 auto; background: rgba(200, 169, 106, .2); overflow: hidden; }
.loader__bar span { display: block; height: 100%; width: 100%; background: var(--gold-500); transform-origin: 0 50%; transform: scaleX(var(--p, .04)); transition: transform .3s ease; }
.loader__text { margin: 14px 0 0; font-size: 13px; letter-spacing: .08em; color: rgba(245, 237, 226, .5); }
.loader__text a { color: var(--gold-300); }

/* ------------------------------------------------------------------ toast */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(var(--toolbar-h) + 14px); translate: -50% 12px;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--cream-100); font-size: 14px;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: opacity .25s, translate .25s var(--ease);
}
.toast.is-visible { opacity: 1; translate: -50% 0; }

.noscript { position: fixed; inset: 0; z-index: 70; display: grid; place-content: center; text-align: center; background: var(--espresso-900); font-family: var(--serif); font-size: 18px; }
.noscript a { color: var(--gold-300); }

@keyframes fade { from { opacity: 0; } }

/* ------------------------------------------------------------- responsive */
@media (max-width: 760px) {
  :root { --topbar-h: 48px; --toolbar-h: 68px; }
  .stage { padding: 10px 8px 4px; }
  .brand__subtitle, .topbar__download { display: none; }
  .brand__title { font-size: 14px; }
  .tb--wide-only { display: none; }
  .tb--narrow-only { display: grid; }
  .tb { width: 40px; height: 40px; }
  .tb-indicator { min-width: 84px; font-size: 16px; padding: 0 8px; }
  .tb-sep { margin: 0 3px; }
  .panel {
    top: auto; left: 0; width: 100%; height: min(78dvh, 640px);
    border-radius: 20px 20px 0 0; transform: translateY(105%);
  }
  .thumbs { grid-template-columns: repeat(3, 1fr); gap: 14px 10px; }
  .thumbs li:first-child { grid-column: auto; }
}
@media (max-width: 380px) {
  .tb { width: 36px; height: 36px; }
  .tb-indicator { min-width: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
