:root {
  --bg: #14110f;            /* the desk the book lies on */
  --paper: #efe6d6;         /* paper tone: letterbox of the guided view, cover scrim ink */
  --dim: rgba(20, 17, 15, 0.84);
  --shadow: rgba(0, 0, 0, 0.5);
  --spine: rgba(0, 0, 0, 0.38);
  --surface: rgba(24, 20, 18, 0.88);
  --surface-solid: #1d1815;
  --text: #f1e9de;
  --text-dim: #a89d8f;
  --accent: #f0b95a;
  --on-accent: #1b140c;
  --line: rgba(241, 233, 222, 0.16);
  --radius: 10px;
  --dur: 280ms;
  --cam: 380ms;
  --ease: cubic-bezier(.22, .8, .3, 1);
}
@media (prefers-reduced-motion: reduce) { :root { --dur: 0ms; --cam: 0ms; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%; overflow: hidden; position: fixed; inset: 0;
  background: var(--bg); color: var(--text);
  font: 15px/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
}
img { -webkit-user-drag: none; -webkit-touch-callout: none; }
::-webkit-scrollbar { display: none; }
#stage {
  position: absolute; inset: 0; overflow: hidden; outline: none; touch-action: none;
  background: radial-gradient(120% 90% at 50% 40%, var(--surface-solid), var(--bg));
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#track { position: absolute; inset: 0; display: flex; will-change: transform; transition: transform var(--dur) var(--ease); --lift: 0; }
#track.dragging { transition: none; }
.view { flex: 0 0 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.zoom { position: relative; display: flex; transform-origin: 50% 50%; will-change: transform; transition: transform var(--cam) var(--ease); }
.zoom.live { transition: none; }
.zoom picture { display: block; height: 100%; flex: 0 0 auto; box-shadow: 0 8px calc(18px + 30px * var(--lift)) var(--shadow); }
.zoom img { display: block; height: 100%; width: auto; pointer-events: none; background: var(--surface-solid); }
.zoom .ph { height: 100%; background: var(--surface-solid); box-shadow: 0 8px 18px var(--shadow); }
.zoom.two::after { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 7%; transform: translateX(-50%); pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--spine) 46%, var(--spine) 54%, transparent); mix-blend-mode: multiply; }
.mask { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity 160ms linear; }
.mask path { fill: var(--dim); fill-rule: evenodd; }
.mask.on { opacity: 1; transition-duration: 320ms; }
@media (prefers-reduced-motion: reduce) {
  #track, #track.dragging { transition: none; }
  .view { opacity: 0; transition: opacity 220ms linear; }
  .view.cur { opacity: 1; }
}
.bar { position: absolute; left: 0; right: 0; background: var(--surface); color: var(--text); z-index: 5;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); display: flex; align-items: center; gap: 8px;
  padding-left: calc(10px + env(safe-area-inset-left)); padding-right: calc(10px + env(safe-area-inset-right)); }
.bar[hidden] { display: none; }
#topbar { top: 0; justify-content: space-between; padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: 8px; border-bottom: 1px solid var(--line); }
#bottombar { bottom: 0; padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
button { appearance: none; border: 1px solid var(--line); background: transparent; color: var(--text);
  min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: var(--radius); font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, #stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; padding: 0 12px; }
.seg button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg button:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
#btn-prev, #btn-next { font-size: 26px; line-height: 1; padding: 0 10px; flex: 0 0 auto; }
#pos { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; white-space: nowrap; }
#strip { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-x; padding: 2px; }
#strip button { flex: 0 0 auto; padding: 0; min-width: 0; min-height: 0; height: 64px; width: 50px; overflow: hidden; border-radius: 6px; opacity: .7; }
#strip button[aria-current="true"] { border-color: var(--accent); border-width: 2px; opacity: 1; }
#strip img, #gridinner img, #endgrid img { display: block; width: 100%; height: 100%; object-fit: cover; }
#grid { position: absolute; inset: 0; z-index: 4; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  padding: calc(72px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); }
#grid[hidden] { display: none; }
#gridinner, #endgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; max-width: 900px; margin: 0 auto; }
#gridinner button, #endgrid button { padding: 0; aspect-ratio: 1313 / 1688; overflow: hidden; position: relative; box-shadow: 0 4px 10px var(--shadow); }
#gridinner button[aria-current="true"] { border-color: var(--accent); border-width: 2px; }
#gridinner span, #endgrid span { position: absolute; left: 4px; bottom: 4px; font-size: 11px; background: var(--surface); padding: 1px 6px; border-radius: 99px; }
/* book moments */
#intro, #end { position: absolute; inset: 0; z-index: 8; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; overflow: hidden; transition: opacity 320ms var(--ease); }
#intro[hidden], #end[hidden] { display: none; }
#intro.out, #end.out { opacity: 0; pointer-events: none; }
#introimg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 36%; }
.scrim { position: relative; width: 100%; padding: 96px 20px calc(28px + env(safe-area-inset-bottom)); text-align: center;
  background: linear-gradient(to top, var(--bg) 52%, transparent); }
.scrim h1, #end h2 { margin: 0 0 14px; font: 700 clamp(26px, 7vw, 44px)/1.1 Georgia, "Iowan Old Style", serif; color: var(--paper); text-shadow: 0 2px 12px var(--shadow); }
.btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btns button { min-height: 48px; padding: 0 22px; font-weight: 600; }
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
#end { justify-content: flex-start; overflow-y: auto; touch-action: pan-y; background: radial-gradient(120% 80% at 50% 0, var(--surface-solid), var(--bg));
  padding: calc(40px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.endin { width: 100%; max-width: 760px; text-align: center; }
#end h2 { font-size: clamp(34px, 9vw, 60px); margin-bottom: 18px; }
#endgrid { margin-top: 26px; }
#a2hs { position: absolute; z-index: 9; left: 12px; right: 12px; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center;
  background: var(--surface-solid); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; box-shadow: 0 6px 20px var(--shadow); }
#a2hs[hidden] { display: none; }
#a2hs span { flex: 1; }
.nojs { padding: 2rem; }
