/* Shared base for the three journal builds: pastel tokens, the book and its
   turning leaves, the lamp with its smoke, and the stacked layout for phones. */

:root {
  --cream: #FCF8F1;
  --sand: #F5ECDF;
  --oat: #EADFCE;
  --butter: #F8EBC2;
  --glow: #FCF6E1;
  --latte: #D6C1AC;
  --mocha: #867060;
  --cocoa: #6E574B;
  --blush: #FAEBEC;
  --rose: #F4D3D9;
  --pop: #EBB3C1;
  --ink: #A85C7B;
  --smoke: #C9C4BF;
  --smoke-dark: #A8A29C;
  --paper: #FFFEFB;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --inset: 0px;
  --g: 0px;   /* half the gap between the page stacks, where the wire binding sits */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--cocoa);
  background: var(--cream);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(44vw 44vw at 90% 10%, rgba(244, 211, 217, 0.6), transparent 70%),
    radial-gradient(40vw 40vw at 6% 36%, rgba(248, 235, 194, 0.6), transparent 70%),
    radial-gradient(46vw 46vw at 94% 80%, rgba(250, 235, 236, 0.75), transparent 70%),
    radial-gradient(38vw 38vw at 10% 98%, rgba(252, 246, 225, 0.75), transparent 70%),
    linear-gradient(var(--cream), #F8E6DC);
}

a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 4px; }

.hand { font-family: var(--font-hand); color: var(--ink); }

/* ---------- the book, flip mode ---------- */

.track { position: relative; }

.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  overflow: clip;
}

.artboard {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1320px;
  height: 880px;
  transform-origin: 50% 50%;
}

.book {
  position: absolute;
  left: var(--bx, 36px);
  top: var(--by, 60px);
  width: calc((var(--pw) + var(--inset) + var(--g)) * 2);
  height: calc(var(--ph) + var(--inset) * 2);
}

.page {
  position: absolute;
  width: var(--pw);
  height: var(--ph);
  background-color: var(--paper);
  overflow: hidden;
  padding: var(--pad);
}

.base-left { left: var(--inset); top: var(--inset); z-index: 0; }
.base-right { left: calc(50% + var(--g)); top: var(--inset); z-index: 0; }

.leaf {
  position: absolute;
  left: calc(50% + var(--g));
  top: var(--inset);
  width: var(--pw);
  height: var(--ph);
}
.leaf .face { position: absolute; left: 0; top: 0; }

/* covers are board: they swing round the wire in one stiff piece */
.leaf.cover {
  top: 0;
  width: calc(var(--pw) + var(--inset));
  height: 100%;
  transform-origin: calc(var(--g) * -1) 50%;
  transform-style: preserve-3d;
}
.is-moving .leaf.cover { will-change: transform; }
.leaf.cover .face { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.leaf.cover .face.back { transform: rotateY(180deg); }
.leaf .coverface { width: 100%; height: 100%; }
/* a page pasted down inside a cover (see "endpapers" in js/book.js): it lies where a loose page would */
.leaf .coverface > .page.endpaper { top: var(--inset); }
.leaf .coverface > .page.left.endpaper { left: var(--inset); }
.leaf .coverface > .page.right.endpaper { left: 0; }

/* pages are paper and bend (js/book.js, "a page as bending paper"). Under each page lies a copy
   of it cut into upright strips. At rest the page hides them; while it turns it is hidden and the
   strips, each at its own angle, show the sheet curving. */
.leaf.soft .lift { z-index: 0; }
.leaf.soft .curl { display: none; position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 1; }
.leaf.soft.ready .curl, .leaf.soft.turning .curl { display: block; }
.leaf.soft .face { z-index: 2; will-change: transform; }
.curl .strip {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  overflow: hidden;
  transform-origin: 0 0;
  /* a strip's hidden side is switched off with opacity (js/book.js, pose) and stays painted, ready to show */
  will-change: transform, opacity;
}
.curl .strip *, .curl .strip *::before, .curl .strip *::after { animation: none !important; transition: none !important; }
/* a strip darkens as it tilts away from the light */
.curl .dim { position: absolute; inset: 0; z-index: 9; background: rgb(84, 62, 52); opacity: 0; will-change: opacity; }

/* gutter shading on the inner edge of every page */
.page.left::after,
.page.right::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 72px;
  pointer-events: none;
}
.page.left::after { right: 0; background: linear-gradient(to left, rgba(110, 87, 75, 0.13), rgba(110, 87, 75, 0)); }
.page.right::after { left: 0; background: linear-gradient(to right, rgba(110, 87, 75, 0.13), rgba(110, 87, 75, 0)); }

/* a turning cover darkens a little towards the spine */
.shade { display: none; position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: 0; }
.leaf.cover.turning .shade { display: block; will-change: opacity; }
.leaf.cover .face.front .shade { background: linear-gradient(to right, rgba(90, 68, 58, 0.34), rgba(90, 68, 58, 0.06) 68%, rgba(90, 68, 58, 0)); }
.leaf.cover .face.back .shade { background: linear-gradient(to left, rgba(90, 68, 58, 0.34), rgba(90, 68, 58, 0.06) 68%, rgba(90, 68, 58, 0)); }

.lift { display: none; position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; opacity: 0; }
.leaf.soft.turning .lift, .leaf.soft.ready .lift { display: block; }
/* a lifted page throws a soft shadow on the pages under it: a band that fades out at both sides,
   stretched to the page's width as it is seen (js/book.js, pose) */
.lift > span {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
  will-change: transform;
  background: linear-gradient(to right, rgba(70, 50, 42, 0), rgba(70, 50, 42, 0.2) 30%, rgba(70, 50, 42, 0.2) 70%, rgba(70, 50, 42, 0));
}

/* a turning cover throws a soft shadow on what lies under it */
.cast {
  position: absolute;
  top: var(--inset);
  width: var(--pw);
  height: var(--ph);
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  will-change: transform, opacity;
}
.cast.r { left: calc(50% + var(--g)); transform-origin: 0 50%; background: linear-gradient(to right, rgba(70, 50, 42, 0.36), rgba(70, 50, 42, 0.14) 72%, rgba(70, 50, 42, 0)); }
.cast.l { right: calc(50% + var(--g)); transform-origin: 100% 50%; background: linear-gradient(to left, rgba(70, 50, 42, 0.36), rgba(70, 50, 42, 0.14) 72%, rgba(70, 50, 42, 0)); }

/* ---------- wire binding ----------
   Each ring is drawn in three pieces: the arc that shows in the gap between the page stacks,
   and a short length on every page that runs from the page edge into its punched hole.
   A turning page sits above the arc and carries its own length of wire with it,
   so the ring passes through the page instead of lying on top of it. */
.ringbound {
  --g: 7px;
  --ring-h: 7px;
  --ring-pitch: 36px;
  --ring-top: 36px;
  --ring-n: 21;
  --ring-a: #EFE2D2;
  --ring-b: #D6C1AC;
  --ring-c: #B39A82;
  --ring-rows: linear-gradient(to bottom, #000 0, #000 var(--ring-h), transparent var(--ring-h)) 0 0 / 100% var(--ring-pitch) repeat-y;
  --ring-metal: linear-gradient(to bottom, var(--ring-a) 0, var(--ring-b) 3px, var(--ring-c) var(--ring-h), transparent var(--ring-h));
}
.rings {
  position: absolute;
  z-index: 0;
  pointer-events: none;
  left: calc(50% - var(--g) - 1px);
  width: calc(var(--g) * 2 + 2px);
  top: calc(var(--inset) + var(--ring-top));
  height: calc(var(--ring-pitch) * var(--ring-n));
  background:
    linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.5) 50%, rgba(255, 255, 255, 0)),
    var(--ring-metal) 0 0 / 100% var(--ring-pitch) repeat-y;
  -webkit-mask: var(--ring-rows);
  mask: var(--ring-rows);
}
.ringbound .flip .page::before,
.ringbound .flip .coverface::before {
  content: "";
  position: absolute;
  z-index: 5;
  pointer-events: none;
  left: 0;
  top: var(--ring-top);
  width: 18px;
  height: calc(var(--ring-pitch) * var(--ring-n));
  background:
    linear-gradient(to right, rgba(60, 40, 32, 0) 3px, rgba(60, 40, 32, 0.34) 9px, rgba(60, 40, 32, 0) 9px) 0 0 / 18px var(--ring-pitch) repeat-y,
    var(--ring-metal) 0 0 / 9px var(--ring-pitch) repeat-y,
    radial-gradient(circle at 9.5px calc(var(--ring-h) / 2), rgba(74, 56, 48, 0.62) 0, rgba(74, 56, 48, 0.62) 3.3px, rgba(74, 56, 48, 0) 3.6px) 0 0 / 18px var(--ring-pitch) repeat-y;
  -webkit-mask: var(--ring-rows);
  mask: var(--ring-rows);
}
.ringbound .flip .coverface::before { top: calc(var(--ring-top) + var(--inset)); }
.ringbound .flip .page.left::before,
.ringbound .flip .coverface.back::before { left: auto; right: 0; transform: scaleX(-1); }

/* only the two pages on top take the pointer. A page's own box stays on the right even after the
   page has turned, so it must never catch a press meant for the page lying there now. */
.flip .leaf,
.flip .face,
.flip .base-left,
.flip .base-right { pointer-events: none; }
.flip .is-active { pointer-events: auto; }
/* a page in the air can be caught again by any part of it */
.flip .leaf.turning .curl .strip { pointer-events: auto; }

/* pages and covers can be taken hold of and turned by hand */
.flip .page,
.flip .coverface { touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.flip .page a, .flip .coverface a { -webkit-user-select: text; user-select: text; }
.flip img { -webkit-user-drag: none; }
.flip .leaf.cover .face.is-active,
.artboard.can-grab,
.artboard.can-grab .page { cursor: grab; }
.artboard.is-grabbing,
.artboard.is-grabbing * { cursor: grabbing !important; }

/* ---------- the phone notepad ----------
   The same book, turned a quarter so its wire runs along the top and a page hangs down from it
   (js/book.js, "the notepad"). .padpos is the middle of the wire on the phone artboard; the book
   is centred on that point and turned, and everything printed on a page or a cover sits in a
   .pad-in box that is turned back upright. */
.artboard.pad { width: 390px; height: 844px; touch-action: pinch-zoom; }
.pad .padpos { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; will-change: transform; }
.pad .book {
  left: calc((var(--pw) + var(--inset) + var(--g)) * -1);
  top: calc((var(--ph) + var(--inset) * 2) / -2);
  transform: rotate(90deg);
  transform-origin: 50% 50%;
}
.pad .page { padding: 0; }
.pad .pad-in {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--ph);
  height: var(--pw);
  padding: var(--pad);
  transform-origin: 0 0;
  transform: translateY(var(--ph)) rotate(-90deg);
}
.pad .coverface > .pad-in {
  width: calc(var(--ph) + var(--inset) * 2);
  height: calc(var(--pw) + var(--inset));
  padding: 0;
  transform: translateY(calc(var(--ph) + var(--inset) * 2)) rotate(-90deg);
}
/* a finger turns the pages here; the screen itself does not scroll under it */
.pad .page, .pad .coverface, .pad .lamp { touch-action: pinch-zoom; }
/* nothing lies beyond the wire: a turned page hangs behind the pad */
.pad .cast.l { display: none; }
.pad .pn { right: 20px; left: auto; bottom: 16px; }

/* what sits beside the journal once it is closed at the back */
.flip .outro { visibility: hidden; will-change: transform; }

.pn {
  position: absolute;
  bottom: 22px;
  font-size: 13px;
  color: var(--mocha);
  font-variant-numeric: tabular-nums;
}
.page.left .pn { left: 34px; }
.page.right .pn { right: 34px; }

/* ---------- shared page furniture ---------- */

.page p { margin: 0 0 0.85em; }
.page p:last-child { margin-bottom: 0; }
.page h1, .page h2, .page h3 { margin: 0; font-weight: 400; }

.mail { text-decoration-color: var(--pop); text-decoration-thickness: 2px; text-underline-offset: 5px; }

.pen {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--ink) 62%, transparent);
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}

.print {
  position: relative;
  margin: 0;
  width: var(--w, 340px);
  max-width: 100%;
  padding: 14px 14px 8px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(110, 87, 75, 0.16);
}
.print .crop { display: block; aspect-ratio: var(--ar, 5 / 6); overflow: hidden; background: var(--sand); }
.print img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--pos, 50% 20%);
  transform: scale(var(--z, 1));
  transform-origin: var(--zo, 50% 30%);
}
.print figcaption { text-align: center; line-height: 1; padding-top: 8px; }
.tape {
  position: absolute;
  z-index: 2;
  top: -15px;
  left: 50%;
  width: 112px;
  height: 30px;
  margin-left: -56px;
  background: color-mix(in srgb, var(--pop) 72%, transparent);
  transform: rotate(-4deg);
}

.creds, .training { list-style: none; margin: 0; padding: 0; }
.creds li { margin-bottom: 18px; }
.creds strong, .creds span, .creds em { display: block; }
.creds strong { font-weight: 400; }

.turn-hint { position: absolute; margin: 0; line-height: 1; }

/* ---------- the lamp ---------- */

.lampwrap { position: relative; width: var(--lamp-w, 360px); max-width: 82%; }
.lamp {
  position: relative;
  display: block;
  width: 100%;
  margin-top: 62%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: pan-y;
  -webkit-tap-highlight-color: transparent;
}
.lamp img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
.lamp.is-puffing img { animation: rubbed 0.9s var(--ease); }

.smoke {
  position: absolute;
  left: 94.3%;
  top: 45.3%;
  width: 72%;
  transform: translate(-50%, -99%);
  overflow: visible;
  pointer-events: none;
  filter: blur(0.7px);
}
.ribbon { opacity: 0; fill: var(--smoke-dark); transform-box: view-box; transform-origin: 150px 416px; }
.ribbon.pale { fill: var(--smoke); }
.cough { opacity: 0; fill: var(--smoke-dark); transform-box: fill-box; transform-origin: 50% 50%; }

/* rubbed: the smoke rises, thins and leaves nothing behind */
.lamp.is-puffing .ribbon { animation: puff 3s var(--ease) both; animation-delay: calc(var(--i) * 110ms); }
.lamp.is-puffing .cough { animation: cough-once 1.1s ease-out both; animation-delay: calc(2s + var(--i) * 0.36s); }
/* waiting: it coughs up a little smoke now and then */
.is-live .lamp:not(.is-puffing) .cough { animation: cough 4.4s ease-out infinite; animation-delay: calc(var(--i) * 0.5s); }

@keyframes puff {
  0% { opacity: 0; transform: scale(0.2, 0.05); }
  22% { opacity: var(--o, 0.8); transform: scale(0.85, 0.8); }
  48% { opacity: var(--o, 0.8); transform: scale(1, 1); }
  72% { opacity: calc(var(--o, 0.8) * 0.45); transform: translate(6px, -14px) scale(0.96, 1.05); }
  100% { opacity: 0; transform: translate(-4px, -36px) scale(0.9, 1.12); }
}
@keyframes cough {
  0%, 60% { opacity: 0; transform: translate(0, 0) scale(0.3); }
  67% { opacity: 0.7; transform: translate(0, -8px) scale(0.8); }
  100% { opacity: 0; transform: translate(var(--dx, 8px), -66px) scale(1.5); }
}
@keyframes cough-once {
  0% { opacity: 0; transform: translate(0, 0) scale(0.3); }
  22% { opacity: 0.7; transform: translate(0, -8px) scale(0.8); }
  100% { opacity: 0; transform: translate(var(--dx, 8px), -60px) scale(1.5); }
}
@keyframes rubbed {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-1.6deg); }
  60% { transform: rotate(1.2deg); }
}

.lamp-hint { margin: 0; line-height: 1; transition: opacity 0.6s var(--ease); }
.lamp-hint.is-used { opacity: 0.45; }

/* ---------- the words that get written, struck out and rewritten ---------- */

.words { position: relative; }
.word { position: relative; display: inline-block; }
.word .ink {
  display: inline-block;
  clip-path: inset(-25% 106% -25% -6%);
  transition: clip-path 0.75s var(--ease), opacity 0.6s var(--ease);
}
.word.on .ink { clip-path: inset(-25% -8% -25% -6%); }
.word.done:not(.keep) .ink { opacity: 0.55; }
.word svg { position: absolute; overflow: visible; pointer-events: none; opacity: 0; transition: opacity 0.25s linear; }
.word.done svg { opacity: 1; }
.word svg path {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.6s var(--ease);
}
.word.done svg path { stroke-dashoffset: 0; }
.strike { left: -6%; width: 112%; top: 50%; height: 12px; margin-top: -3px; }
.ring { left: -9%; width: 118%; top: -16%; height: 132%; }
.word .ring path { stroke-width: 1.8; }

/* ---------- stacked pages: phones and small windows ---------- */

.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 14px 12px 64px;
}
.stack .page {
  position: relative;
  left: auto;
  top: auto;
  width: 100%;
  max-width: 560px;
  height: auto;
  padding: 34px 26px 46px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(110, 87, 75, 0.1);
  scroll-margin-top: 12px;
}
.stack .page::after { display: none; }
.stack .pn { bottom: 16px; }
.stack .page.left .pn { left: 26px; }
.stack .page.right .pn { right: 26px; }
.stack .turn-hint { display: none; }
.stack .tabs {
  position: relative;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 560px;
  padding: 8px 0;
}

.review-link {
  position: fixed;
  left: 14px;
  bottom: 12px;
  z-index: 40;
  font: 600 12px/1 system-ui, sans-serif;
  color: var(--mocha);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255, 254, 251, 0.8);
}
.review-link:hover { color: var(--cocoa); }

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