:root {
  --desk: #222222;   /* the portfolio's BLACK */
  --ink: #ece7df;
  --ink-dim: #9a938a;
  --paper: #fbfaf7;
  --board: #e9e6df;
  --accent: #e8d36a;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  /* set from JS once the viewport is measured */
  --pw: 360px;
  --ph: 475px;
  --ov: 8px;
  --eL: 8px;
  --eR: 0px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--desk);
  color: var(--ink);
  font-family: var(--mono);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- around the book: just the turn arrows and one button below ---------- */
.stage { height: 100dvh; }
.panel {
  position: relative; height: 100%;
  display: grid; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
}
/* the button hangs just under the book, whatever size the frame is */
.foot {
  direction: ltr; position: absolute; left: 0; right: 0;
  top: calc(50% + var(--ph) / 2 + var(--ov) + 18px);
  display: flex; justify-content: center; pointer-events: none;
}
.foot > * { pointer-events: auto; }

/* the portfolio's arrow: one stroke, redrawn on hover */
.arrow {
  flex: none; width: 30.344px; height: 19.211px; display: block;
  fill: none; stroke: currentColor; stroke-width: 1.886; stroke-linecap: butt; stroke-linejoin: miter;
}
@keyframes drawArrow {
  from { stroke-dasharray: 1; stroke-dashoffset: 1; }
  to   { stroke-dasharray: 1; stroke-dashoffset: 0; }
}
.flip:hover .arrow path, .flip:focus-visible .arrow path {
  animation: drawArrow .46s cubic-bezier(.33, 0, .67, 1);
}

/* the one action, set like the portfolio's "Next project" */
.cta {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px; border-bottom: 1px solid var(--ink);
  font-family: var(--mono); font-size: 20px; line-height: 1.3;   /* Figma 2177:2605 */
  letter-spacing: .2px; text-transform: uppercase; color: var(--ink);
}
.cta[hidden] { display: none; }
/* the restart icon (Figma 2177:2611), at its drawn size, in the text colour */
.cta:not(.over) .cta-icon { display: none; }
.cta-icon { flex: none; width: 26.863px; height: 27.607px; display: block; fill: currentColor; }

.desk { position: relative; display: grid; place-items: center; min-height: 0; min-width: 0; }

/* turn arrows hug the book from outside: --half is how far the book reaches from the centre */
.flip {
  position: absolute; top: 50%; z-index: 80;
  width: 56px; height: 56px; display: grid; place-items: center;
  color: var(--ink); transform: translateY(-50%);
  transition: left .9s cubic-bezier(.42,.08,.26,1), right .9s cubic-bezier(.42,.08,.26,1), opacity .3s;
}
.flip[hidden] { display: grid; opacity: 0; pointer-events: none; }
.flip.next { right: calc(50% + var(--half) + 12px); }
.flip.next .arrow { transform: rotate(180deg); }
.flip.prev { left: calc(50% + var(--half) + 12px); }

/* ---------- the book ---------- */
.book {
  position: relative;
  width: calc(var(--pw) * 2);
  height: var(--ph);
  direction: ltr;
  transition: transform 1.1s cubic-bezier(.42,.08,.26,1), opacity .6s;
}
.book.closed { transform: translateX(calc(var(--pw) / 2)); }
.book.loading { opacity: 0; }

.board {
  position: absolute; top: calc(var(--ov) * -1); height: calc(var(--ph) + var(--ov) * 2);
  width: calc(var(--pw) + var(--ov));
  background: var(--board) center / cover no-repeat;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.7), 0 6px 18px rgba(0,0,0,.35);
}
.board::after { content: ""; position: absolute; inset: 0; background: url("paper.webp") 0 0 / 256px 256px repeat; mix-blend-mode: multiply; opacity: .7; border-radius: inherit; pointer-events: none; }
.board.left.cover::after { display: none; }
.board.left { left: calc(var(--ov) * -1); border-radius: 3px 0 0 3px; }
.board.right { left: var(--pw); border-radius: 0 3px 3px 0; }
.board.right.off { visibility: hidden; }
/* closed: the left board is the front cover, anchored to the spine side */
.board.left.cover { background-position: right center; border-radius: 2px 5px 5px 2px; }

.edges {
  position: absolute; top: 3px; bottom: 3px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.18), transparent 30%, transparent 70%, rgba(0,0,0,.12)),
    repeating-linear-gradient(90deg, #d8d3c8 0 1px, #f7f5f0 1px 2.5px);
  transition: width .6s;
}
.edges.left { left: calc(var(--eL) * -1); width: var(--eL); }
.edges.right { left: calc(var(--pw) * 2); width: var(--eR); }
.book.closed .edges { display: none; }

.page, .face {
  position: absolute; top: 0; width: var(--pw); height: var(--ph);
  background: var(--paper) center / 100% 100% no-repeat;
}
.page.left { left: 0; }
.page.right { left: var(--pw); }
.page.none { visibility: hidden; }

/* gutter shading: every page darkens toward the spine */
.page::before, .face::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
}
.page::after, .face::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: url("paper.webp") 0 0 / 256px 256px repeat;
  mix-blend-mode: multiply; opacity: .7;
}
.page.left::before, .face.l::before {
  background: linear-gradient(270deg, rgba(0,0,0,.22), rgba(0,0,0,.06) 4%, transparent 11%),
              linear-gradient(90deg, rgba(0,0,0,.05), transparent 3%);
}
.page.right::before, .face.r::before {
  background: linear-gradient(90deg, rgba(0,0,0,.24), rgba(0,0,0,.07) 4%, transparent 11%),
              linear-gradient(270deg, rgba(0,0,0,.05), transparent 3%);
}
.page.blank::before, .face.blank::before { opacity: .7; }
.spine-shade {
  position: absolute; top: 0; bottom: 0; left: calc(var(--pw) - 1px); width: 2px; z-index: 2;
  background: rgba(0,0,0,.18); pointer-events: none;
}
.book.closed .spine-shade { display: none; }


/* front matter: the whole page turns */
.page.turn { cursor: pointer; }

/* ---------- choices ----------
 * A hairline drawn under the printed option, right to left like the text.
 * --ix / --ib are the hotspot's padding, so the line sits on the words.
 */
.links { position: absolute; inset: 0; z-index: 4; }
.choice { position: absolute; outline: none; }
.choice::after {
  content: ""; position: absolute;
  left: var(--ix); right: var(--ix); bottom: calc(var(--ib) * .35);
  height: max(1px, calc(var(--ph) * .0025));
  background: var(--line, #1d1b19);
  transform: scaleX(0); transform-origin: 100% 50%;
  transition: transform .35s cubic-bezier(.4,0,.2,1);
}
.choice:hover::after, .choice:focus-visible::after { transform: scaleX(1); }
.choice:not(:hover):not(:focus-visible)::after { transform-origin: 0% 50%; }
/* an option the reader wasn't sent to: washed back into its own paper */
.choice.off { cursor: default; background: var(--paper-here, var(--paper)); opacity: .62; }
.choice.off::after { display: none; }
.book.nudge .choice::after { animation: nudge 1.6s cubic-bezier(.4,0,.2,1) .5s 2; }
@keyframes nudge {
  0% { transform: scaleX(0); transform-origin: 100% 50%; }
  45%, 55% { transform: scaleX(1); transform-origin: 100% 50%; }
  56% { transform-origin: 0% 50%; }
  100% { transform: scaleX(0); transform-origin: 0% 50%; }
}

/* ---------- turning leaves ---------- */
.leaf {
  position: absolute; top: 0; width: var(--pw); height: var(--ph);
  transform-style: preserve-3d; pointer-events: none; will-change: transform;
}
.leaf.fwd { left: 0; transform-origin: 100% 50%; }
.leaf.bwd { left: var(--pw); transform-origin: 0% 50%; }
.face { left: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face.back { transform: rotateY(180deg); }
.face .shade { position: absolute; inset: 0; z-index: 2; opacity: 0; pointer-events: none; }
.face.l .shade { background: linear-gradient(90deg, rgba(0,0,0,.45), rgba(0,0,0,.12) 55%, rgba(255,255,255,.05)); }
.face.r .shade { background: linear-gradient(270deg, rgba(0,0,0,.45), rgba(0,0,0,.12) 55%, rgba(255,255,255,.05)); }

/* the cover is a board, a touch larger than the block */
.leaf.cover {
  top: calc(var(--ov) * -1); left: calc(var(--ov) * -1);
  width: calc(var(--pw) + var(--ov)); height: calc(var(--ph) + var(--ov) * 2);
}
.leaf.cover .face { width: 100%; height: 100%; }
.leaf.cover.bwd { left: var(--pw); }
.leaf.cover .face.coverimg { background: var(--board) right center / cover no-repeat; border-radius: 2px 5px 5px 2px; }
.leaf.cover .face.boardpaste { background: var(--board); border-radius: 0 3px 3px 0; }
.leaf.cover .face.boardpaste .paste {
  position: absolute; left: 0; top: var(--ov); width: var(--pw); height: var(--ph);
  background: center / 100% 100% no-repeat;
}

/* shadow the turning leaf throws on the pages beneath it */
.cast { position: absolute; top: 0; width: var(--pw); height: var(--ph); z-index: 50; pointer-events: none; opacity: 0; }
.cast.left { left: 0; background: linear-gradient(270deg, rgba(0,0,0,.35), transparent 70%); }
.cast.right { left: var(--pw); background: linear-gradient(90deg, rgba(0,0,0,.35), transparent 70%); }

/* ---------- portrait phones ---------- */
.rotate {
  font-family: var(--mono); font-size: 14px; text-transform: uppercase; letter-spacing: .14px;
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(20,18,16,.94); text-align: center; padding: 24px; line-height: 1.5;
}
.rotate[hidden] { display: none; }
.rotate svg { width: 64px; height: 64px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rotate svg rect { animation: tilt 2.4s ease-in-out infinite; transform-origin: 24px 24px; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
.rotate button { color: var(--ink-dim); text-decoration: underline; text-underline-offset: 3px; font-family: var(--mono); font-size: 12px; text-transform: uppercase; }

/* phones on their side: a tighter foot so the book keeps its height */
@media (max-height: 520px) and (pointer: coarse) {
  .foot { top: calc(50% + var(--ph) / 2 + var(--ov) + 6px); }
  .cta { font-size: 16px; letter-spacing: .16px; }
  .cta-icon { width: 21.2px; height: 21.8px; }
  .arrow { width: 24px; height: 15.2px; }
  .flip { width: 40px; height: 40px; }
}
