:root {
  --wall-top: #e4e1dc;
  --wall-bottom: #c9c5be;
  --floor-a: #d9c7aa;
  --floor-b: #cdb995;
  --ink: #23221f;
  --muted: #6f6a62;
  --panel: rgba(250, 248, 244, 0.97);
  --chrome: rgba(35, 34, 31, 0.78);
  --chrome-hover: rgba(35, 34, 31, 0.92);
  --accent: #8b7444;
  --radius: 14px;
  --toolbar-h: 56px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--wall-bottom); -webkit-tap-highlight-color: transparent; }
button, input, a { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.app {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: 1fr auto; /* title floats over the stage: more room for the book */
  /* wall + floor backdrop, like a book on display */
  background:
    linear-gradient(to bottom, transparent 0 78%, rgba(0,0,0,.10) 78%, transparent 78.6%),
    repeating-linear-gradient(90deg, var(--floor-a) 0 46px, var(--floor-b) 46px 47px, var(--floor-a) 47px 92px) bottom / 100% 22% no-repeat,
    radial-gradient(120% 90% at 50% 30%, var(--wall-top), var(--wall-bottom));
}

/* ---------- top bar ---------- */
.topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 4; pointer-events: none;
  display: flex; align-items: center; padding: 14px 20px 0; min-height: 44px; }
.title { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.3; letter-spacing: .02em; color: var(--ink); opacity: .85;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- stage ---------- */
.stage { position: relative; min-height: 0; grid-row: 1; }
.book-wrap { position: absolute; inset: 10px 84px 6px; } /* absolute so the engine measures a real height */
.book { width: 100%; height: 100%; }
.book .page { background: #fbf9f5; overflow: hidden; }
.book:not(.stf__parent) > .page { display: none; } /* hide raw pages until the engine takes over */
.book .page img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; }
.book .page .ph { position: absolute; inset: 0; background: linear-gradient(110deg, #f4f1eb 30%, #ebe6dd 50%, #f4f1eb 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -150% 0; } }
.stf__parent { filter: drop-shadow(0 18px 22px rgba(30, 25, 15, .28)); }

.loader { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; justify-items: center;
  color: var(--muted); font-size: 13px; pointer-events: none; transition: opacity .3s; text-align: center; padding: 0 16px; }
.loader span { width: 28px; height: 28px; border: 2px solid rgba(0,0,0,.15); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
.loader.done { opacity: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- WebGL engine ---------- */
.curl-canvas { position: absolute; inset: 0; display: block; touch-action: none; -webkit-user-select: none; user-select: none; }
.curl-overlay { position: absolute; inset: 0; pointer-events: none; }

/* ---------- hotspots ---------- */
.hotspots { position: absolute; inset: 0; pointer-events: none; }
.hotspot { position: absolute; pointer-events: auto; border-radius: 8px; cursor: pointer;
  outline: 1.5px solid transparent; transition: background .2s, outline-color .2s; }
.hotspot:hover, .hotspot:focus-visible { background: rgba(139, 116, 68, .12); outline-color: rgba(139, 116, 68, .65); }
.hotspot::after { content: attr(data-label); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 11px; padding: 5px 8px; border-radius: 6px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s; }
.hotspot:hover::after { opacity: 1; }
.app.show-hotspots .hotspot { animation: hint .6s ease-out; } /* one brief pulse when a page arrives (was 2 x 1.6 s) */
@keyframes hint { 0%, 100% { background: transparent; } 35% { background: rgba(139, 116, 68, .14); } }

/* ---------- side navigation ---------- */
.side { position: absolute; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.side-left { left: 18px; }
.side-right { right: 18px; }
.nav-btn { width: 44px; height: 52px; display: grid; place-items: center; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--chrome); color: #fff; transition: background .15s, opacity .2s, transform .15s; }
.nav-btn.small { height: 40px; }
@media (hover: hover) { .nav-btn:hover { background: var(--chrome-hover); } } /* touch: no hover that sticks after a tap */
.nav-btn:active { transform: scale(.96); }
.nav-btn:disabled { opacity: .25; cursor: default; }
.nav-btn svg { width: 22px; height: 22px; stroke-width: 2; }

/* ---------- toolbar ---------- */
.toolbar { grid-row: 2; justify-self: center; margin: 0 12px 16px; display: flex; align-items: center; gap: 2px; padding: 6px 8px;
  background: var(--chrome); color: #fff; border-radius: 999px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.toolbar button, .toolbar a { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; cursor: pointer; text-decoration: none; transition: background .15s; }
.toolbar [hidden] { display: none !important; } /* the grid display above would otherwise override `hidden` (search / download buttons) */
.toolbar .on { background: rgba(255,255,255,.14); }
@media (hover: hover) { .toolbar button:hover, .toolbar a:hover { background: rgba(255,255,255,.14); } }
.toolbar .sep { width: 1px; height: 22px; background: rgba(255,255,255,.2); margin: 0 6px; }
.toolbar button.labelled { width: auto; display: flex; gap: 7px; padding: 0 14px 0 11px; border-radius: 20px; font: inherit; font-size: 13px; color: inherit; white-space: nowrap; }
.counter { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 0 6px; }
.counter input { width: 8ch; min-width: 42px; height: 30px; text-align: center; border: 1px solid rgba(255,255,255,.25); border-radius: 8px;
  background: rgba(255,255,255,.08); color: #fff; }
.counter input:focus { outline: none; border-color: #fff; }
.counter b { font-weight: 600; }
.mobile-only { display: none !important; }

/* previous / next collection buttons. Desktop + tablet (> 720 px): a tinted pill with swatch-tiles + arrow icon and, when
   there is room (>= 960 px), a two-line label; disabled at the first / last collection (main.js). Phones and <= 720 px
   never see any of this: they keep the plain double-chevron icon buttons (.ic-m) exactly as they were. */
.toolbar .coll .ic-d, .toolbar .coll .coll-txt { display: none; }
@media (min-width: 721px) {
  .toolbar .coll { background: rgba(255,255,255,.1); }
  .toolbar .coll .ic-m { display: none; }
  .toolbar .coll .ic-d { display: block; width: 22px; height: 22px; stroke-width: 1.8; color: #e8d5a8; flex: none; }
  .toolbar .coll:active { background: rgba(255,255,255,.26); }
  .toolbar .coll:disabled { opacity: .3; cursor: default; pointer-events: none; }
  .toolbar .coll[hidden] { display: none; } /* books without collections */
}
@media (min-width: 721px) and (hover: hover) { .toolbar .coll:hover { background: rgba(255,255,255,.2); } }
/* v7b (Nuke 2026-10-09): collection buttons are icon-only (no text pills); the toolbar has 4 nav buttons on
   desktop: previous collection, previous page, [page], next page, next collection.  Phones keep their own layout. */

/* ---------- drawers ---------- */
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(340px, 88vw); z-index: 20; background: var(--panel);
  box-shadow: 8px 0 32px rgba(0,0,0,.18); display: flex; flex-direction: column; animation: slidein .22s ease-out; }
.drawer[hidden] { display: none; }
@keyframes slidein { from { transform: translateX(-24px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px 20px; }
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.drawer-head button { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; }
.drawer-head button:hover { background: rgba(0,0,0,.06); }

.thumbs { overflow-y: auto; padding: 6px 16px 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.thumb { border: 0; padding: 0; background: none; cursor: pointer; text-align: center; font-size: 11px; color: var(--muted); }
.thumb .t-img { aspect-ratio: var(--page-ratio, 0.707); background: #eee8de; border-radius: 3px; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.12); outline: 2px solid transparent; outline-offset: 2px; transition: outline-color .15s, transform .15s; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb:hover .t-img { transform: translateY(-2px); }
.thumb.current .t-img { outline-color: var(--accent); }
.thumb span { display: block; margin-top: 6px; }

.search-form { padding: 0 16px 12px; }
.search-form input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid #d8d1c4; border-radius: 10px; background: #fff; }
.search-form input { text-overflow: ellipsis; }
.search-form input::placeholder { font-size: 13px; } /* bilingual placeholder fits the 340px drawer / 375px phones */
.search-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results { list-style: none; margin: 0; padding: 0 8px 24px; overflow-y: auto; }
.results li button { width: 100%; text-align: left; border: 0; background: none; cursor: pointer; padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.45; }
.results li button:hover { background: rgba(0,0,0,.05); }
.results .pg { display: block; font-size: 11px; font-weight: 600; color: var(--accent); letter-spacing: .06em; text-transform: uppercase; margin-bottom: 2px; }
.results mark { background: #f1e2b8; color: inherit; border-radius: 2px; }
.results .empty { padding: 12px; color: var(--muted); font-size: 13px; }

/* ---------- zoom ---------- */
.zoom { position: fixed; inset: 0; z-index: 30; background: rgba(239, 234, 226, .97); } /* warm + bright */
.zoom[hidden] { display: none; }
.zoom-canvas { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; }
.zoom-canvas.dragging { cursor: grabbing; }
.zoom-inner { position: absolute; left: 0; top: 0; display: flex; transform-origin: 0 0; }
/* GPU hint only while moving: a permanent will-change freezes the raster at the opening scale (blurry when zoomed) */
.zoom-inner.moving { will-change: transform; }
.zoom-inner img { display: block; height: 100%; user-select: none; -webkit-user-drag: none; }
.zoom-bar { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 4px;
  padding: 6px 8px; border-radius: 999px; background: rgba(37, 36, 31, .86); color: #fff; z-index: 2;
  box-shadow: 0 8px 24px rgba(80, 64, 36, .22); } /* dark pill: readable on the warm light zoom background */
.zoom-bar button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; display: grid; place-items: center; }
.zoom-bar button:hover { background: rgba(255,255,255,.14); }
.zoom-bar span { min-width: 52px; text-align: center; font-size: 13px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--toolbar-h) + 34px); transform: translate(-50%, 10px); z-index: 40;
  width: max-content; max-width: calc(100vw - 32px); text-align: center; line-height: 1.35;
  background: var(--ink); color: #fff; font-size: 13px; padding: 9px 14px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .book-wrap { inset: 6px 8px 10px; }
  .side { display: none; }
  .mobile-only { display: grid !important; }
  .toolbar { margin: 0 8px 10px; padding: 4px 6px; max-width: calc(100vw - 16px); }
  .toolbar { gap: 0; padding: 4px; }
  .toolbar button, .toolbar a { width: 29px; height: 36px; flex-shrink: 0; } /* fits 10 controls incl. collection jumps on 360px phones */
  .toolbar .sep { display: none; }
  .toolbar button.labelled { width: 29px; padding: 0; justify-content: center; }
  .toolbar .btn-label { display: none; } /* phones: icon only, the 10 controls must fit 360px */
  .counter { gap: 4px; padding: 0 2px; white-space: nowrap; }
  .counter input { width: 32px; min-width: 32px; }
  .toolbar [data-act="sound"], .toolbar [data-act="fullscreen"] { display: none; }
  .topbar { padding: 10px 14px 0; min-height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---- swatch card overlay (warm, bright) ---- */
.swatch-card { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px;
  background: rgba(239, 234, 226, .94); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.swatch-card[hidden] { display: none; }
.sc-panel { position: relative; display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: min(560px, 100%); max-height: 100%; }
.sc-img { display: block; max-width: 100%; max-height: calc(100vh - 150px); width: auto; height: auto;
  border-radius: 8px; background: #fff; box-shadow: 0 18px 50px rgba(80, 64, 36, .22); }
.sc-close { position: absolute; top: -6px; right: -6px; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid #d9d2c5; background: #fff; color: #25241f; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(80, 64, 36, .18); }
.sc-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.sc-close:hover { background: #f6f2ea; }
.sc-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.sc-btn { padding: 11px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; text-decoration: none; text-align: center; max-width: 100%;
  border: 1px solid #d9d2c5; background: #fff; color: #25241f; }
.sc-btn.sc-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.sc-hint { margin: 0; font-size: 12px; color: #7a746c; text-align: center; }

/* zoom close button: always visible, top right */
.zoom-x { position: absolute; top: 16px; right: 16px; z-index: 2; width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid #d9d2c5; background: #fff; color: #25241f; cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(80, 64, 36, .18); }
.zoom-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.zoom-x:hover { background: #f6f2ea; }
.zoom-inner img { box-shadow: 0 10px 40px rgba(80, 64, 36, .18); background: #fff; }

/* the bigger book reaches the top edge: keep the title for screen readers only (cover + tab already show it) */
.topbar .title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.loader em { font-style: normal; }

/* ================= phone layout (.app.phone) =================
   Set by main.js only for touch devices (pointer: coarse) in the one-page layout, when there is room.
   The page fills the screen width; the space below it holds a nav bar: big prev/next on both sides,
   the current collection in the middle with its own prev/next-collection jumps. The bottom toolbar
   keeps pages / search / page number / zoom / share / download. Desktop CSS above is untouched. */
.phone-nav { display: none; }
.app.phone .stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.app.phone .book-wrap { position: relative; inset: auto; flex: none; width: var(--pw); height: var(--ph); }
.app.phone .side { display: none; }

.app.phone .phone-nav {
  display: grid; flex: none; z-index: 5;
  grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  width: calc(100% - 16px); max-width: 560px; height: var(--pn-h, 60px); padding: 6px;
  background: rgba(251, 249, 245, .97); border: 1px solid #d9d2c5; border-radius: 20px;
  box-shadow: 0 8px 22px rgba(80, 64, 36, .16);
}
.pn-arrow { width: 56px; height: 100%; max-height: 76px; display: grid; place-items: center; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer; touch-action: manipulation; transition: transform .12s, opacity .2s; }
.pn-arrow svg { width: 30px; height: 30px; stroke-width: 2.5; }
.pn-arrow:active { transform: scale(.94); }
.pn-arrow:disabled { opacity: .28; cursor: default; }
.pn-mid { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.pn-kicker { display: none; max-width: 100%; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pn-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; width: 100%; }
.pn-jump { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px; background: #f0eadc; color: var(--ink);
  cursor: pointer; touch-action: manipulation; transition: transform .12s, opacity .2s; }
.pn-jump svg { width: 22px; height: 22px; stroke-width: 2.2; }
.pn-jump:active { transform: scale(.92); }
.pn-jump:disabled { opacity: .3; cursor: default; }
.pn-title { text-align: center; font-size: 17px; line-height: 1.15; font-weight: 700; letter-spacing: .01em; color: var(--ink);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.phone-nav.roomy .pn-kicker { display: block; }
.phone-nav.roomy .pn-arrow { width: 64px; }
.phone-nav.roomy .pn-title { font-size: 22px; }
.phone-nav.no-sections .pn-kicker, .phone-nav.no-sections .pn-jump { display: none; }
.phone-nav.no-sections .pn-row { grid-template-columns: minmax(0, 1fr); }

/* toolbar on phones: the nav bar already has prev/next + collection jumps, so the toolbar keeps the rest (bigger targets) */
.app.phone .toolbar .mobile-only,
.app.phone .toolbar .tb-page,
.app.phone .toolbar [data-act="prevColl"],
.app.phone .toolbar [data-act="nextColl"] { display: none !important; }
.app.phone .toolbar { gap: 2px; padding: 4px 6px; }
.app.phone .toolbar button, .app.phone .toolbar a { width: clamp(34px, 11.5vw, 46px); height: 42px; }
.app.phone .toolbar button.labelled { width: clamp(34px, 11.5vw, 46px); }
.app.phone .toolbar .btn-label { display: none; }
.app.phone .toolbar .counter { padding: 0 6px; gap: 6px; }
.app.phone .toolbar .counter input { width: 46px; min-width: 46px; height: 32px; }
