/* Research diary — white space, one object, a scan you can turn */

:root {
  --ph: min(59vh, 44vw);            /* page height */
  --pw: calc(var(--ph) * .656);     /* page width (scan ratio 900 x 1372) */
  --r: calc(var(--pw) * .065);      /* rounded outer corner of the notebook */
  --paper: #f2edde;
  --bg: #fdfcfb;
  --ink: #1d1d1b;
  --flip: .95s;
  --ease: cubic-bezier(.45, .05, .25, 1);
  --pad: clamp(18px, 2vw, 34px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 300 clamp(14px, 1.07vw, 18px)/1.3 "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* a whisper of paper grain over everything, so the white is paper and not a screen */
.grain {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  opacity: .055; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='n' x='0' y='0' width='100%' height='100%'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .1  0 0 0 0 .08  0 0 0 0 .05  0 0 0 1.1 -.25'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 320px 320px;
}

/* ---------- header ---------- */
.top {
  position: fixed; z-index: 45; top: var(--pad); left: var(--pad); right: var(--pad);
  display: flex; justify-content: space-between; align-items: baseline;
}
.title {
  appearance: none; border: 0; background: none; padding: 0; margin: 0; cursor: pointer;
  font: inherit; color: inherit;
}
.title:hover { opacity: .55; }
.title:focus-visible, .arrow:focus-visible { outline: 1px solid var(--ink); outline-offset: 6px; }

/* ---------- stage / zoom ---------- */
.stage {
  position: fixed; inset: 0; z-index: 5;
  display: grid; place-items: center;
  padding-bottom: 11vh;             /* sits a little above the middle, like the mockup */
}
.zoomer {
  transform-origin: var(--zx, 50%) var(--zy, 50%);
  transition: transform .6s var(--ease);
  will-change: transform;
}
body.zoomed .zoomer { transform: scale(2.15); }
body.zoomed .stage { cursor: zoom-out; }

/* ---------- the book ---------- */
.book {
  position: relative;
  width: calc(var(--pw) * 2);
  height: var(--ph);
  transition: transform 1s var(--ease), opacity .2s ease;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  cursor: grab;
}
.book.dragging { cursor: grabbing; }
.book[data-state="end"] { transform: translateX(calc(var(--pw) / 2)); }
.book.jumping { opacity: 0; }
.notrans, .notrans * { transition: none !important; animation: none !important; }

/* soft shadow on the white */
.shadow {
  position: absolute; top: 0; height: 100%; left: 0; width: 100%;
  border-radius: var(--r);
  box-shadow:
    0 1px 2px rgba(40, 30, 20, .28),
    0 14px 18px -10px rgba(40, 30, 20, .38),
    0 34px 44px -26px rgba(40, 30, 20, .30);
  transition: left 1s var(--ease), width 1s var(--ease);
}
.book[data-state="end"] .shadow { left: 0; width: 50%; }

/* the real ribbon, cut out of a scan, hanging from the spine */
.ribbon {
  position: absolute; z-index: 1;
  left: calc(50% + var(--ph) * .126); top: calc(100% - 3px);
  height: calc(var(--ph) * .25); width: auto;
  pointer-events: none; user-select: none;
  filter: drop-shadow(0 3px 3px rgba(40, 30, 20, .28));
  transition: opacity .5s ease;
}
.book[data-state="end"] .ribbon { opacity: 0; }

.sheets { position: absolute; inset: 0; z-index: 2; perspective: 2800px; perspective-origin: 50% 40%; }

.sheet {
  position: absolute; top: 0; left: 50%; width: 50%; height: 100%;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--flip) var(--ease);
}
.sheet.flipped { transform: rotateY(-180deg); }

.face {
  position: absolute; inset: 0; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  background: var(--paper);
}
.face.front { border-radius: 0 var(--r) var(--r) 0; }
.face.back  { border-radius: var(--r) 0 0 var(--r); transform: rotateY(180deg); }
.face img { display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; -webkit-user-drag: none; pointer-events: none; }

/* gutter: pages darken where they dive into the spine */
.face.front::after, .face.back::after { content: ""; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: multiply; }
.face.front::after { background: linear-gradient(90deg,  rgba(70, 52, 28, .34) 0, rgba(70, 52, 28, .09) 3.5%, transparent 10%); }
.face.back::after  { background: linear-gradient(270deg, rgba(70, 52, 28, .34) 0, rgba(70, 52, 28, .09) 3.5%, transparent 10%); }

/* shadow that sweeps over a page while it turns */
.face::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, rgba(40, 28, 12, 0), rgba(40, 28, 12, .40));
}
.sheet.turning .face::before { animation: turn var(--flip) ease-in-out; }
@keyframes turn { 0% { opacity: 0; } 45% { opacity: 1; } 100% { opacity: 0; } }

.face.blank { background: var(--paper); }
.face.inside { background: #0f0f0f; }
.face.inside::after { background: linear-gradient(270deg, rgba(0,0,0,.6), transparent 12%); }

/* ---------- arrows + caption ---------- */
.arrow {
  position: fixed; z-index: 20; top: 50%; translate: 0 -50%;
  appearance: none; border: 0; background: none; padding: 14px; cursor: pointer; color: var(--ink);
  transition: transform .25s ease, opacity .3s ease;
}
.arrow svg { display: block; width: clamp(22px, 1.8vw, 30px); height: auto; }
.arrow-l { left: calc(var(--pad) + 1.2vw - 14px); }
.arrow-r { right: calc(var(--pad) + 1.2vw - 14px); }
.arrow-l:hover { transform: translateX(-4px); }
.arrow-r:hover { transform: translateX(4px); }
.arrow:disabled { opacity: .38; cursor: default; pointer-events: none; }

/* ---------- index: all spreads on white ---------- */
.index {
  position: fixed; inset: 0; z-index: 40; overflow: auto; background: var(--bg);
  padding: calc(var(--pad) + 64px) var(--pad) 80px;
  animation: fade .35s ease;
}
.index[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.index-grid {
  display: grid; gap: clamp(22px, 3vw, 48px);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  max-width: 1500px; margin: 0 auto;
}
.thumb { appearance: none; border: 0; padding: 0; background: none; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.thumb img {
  display: block; width: 100%; height: auto; aspect-ratio: 600 / 457; background: var(--paper);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(40,30,20,.28), 0 10px 14px -8px rgba(40,30,20,.35);
  transition: transform .3s var(--ease);
}
.thumb span { display: block; margin-top: 10px; font-size: .8em; color: #6a6863; }
.thumb:hover img, .thumb:focus-visible img { transform: translateY(-3px); }
.thumb:focus-visible { outline: none; }

@media (max-width: 700px) { :root { --ph: min(52vh, 62vw); } }
@media (prefers-reduced-motion: reduce) { :root { --flip: .01s; } .zoomer, .book, .shadow { transition-duration: .01s; } }
