/* ========================================
   SKETCHBOOK — one open spread per web page
   Almost no colour in here: black, white and greys. The pages bring the colour.
   ======================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --strip-height: 0px;     /* room taken by the strip along the bottom (none while the switch is down) */
  --edge: 1.5rem;          /* how far the exit sign and switch sit from the edge of the window */
  --plane: clamp(4rem, 6.4vw, 6.75rem);   /* how wide the two paper planes are: they grow with the window, within limits */
  --plane-in: 2.25rem;     /* how far in from the side of the window each plane sits */
  /* The little pages in the strip shrink until every spread fits across the window without scrolling,
     and the gaps between them close up first. They never go below --thumb-min: on a window too
     narrow even for that, the strip scrolls sideways instead.
     (--spreads and --strip-width are written into each page by sketchbook.njk.) */
  --thumb-max: 3.75rem;    /* how tall the little pages are when there is room to spare */
  --thumb-min: 1.5rem;     /* the smallest they are allowed to get */
  --gap-max: 1rem;         /* the space between spreads when there is room to spare */
  --gap-min: 0.3rem;       /* ...and when there isn't */
  --strip-room: calc(100vw - var(--edge) - var(--switch) - 0.5rem - 2rem);   /* the window, less the switch and the strip's own margins */
  --gaps: max(var(--spreads, 1) - 1, 1);
  --thumb: clamp(var(--thumb-min), (var(--strip-room) - var(--gaps) * var(--gap-min)) / var(--strip-width, 30), var(--thumb-max));
  --gap: clamp(var(--gap-min), (var(--strip-room) - var(--strip-width, 30) * var(--thumb-max)) / var(--gaps), var(--gap-max));
  --switch: 2.75rem;       /* how wide the light switch is (its height follows from the picture) */
  --switch-height: calc(var(--switch) * 160 / 99);
  /* how far the switch sits above the bottom of the window: level with the row of little pages when
     they are tall, and never closer than half a rem to the bottom when they are short */
  --switch-bottom: max(0.5rem, calc((var(--thumb) + 2rem - var(--switch-height)) / 2));
  --strip-lift: 0px;       /* raises the row of little pages above the middle of the switch (minus lowers it) */
  --book-size: 1.08;       /* how big the open book is: 1 is the plain size, 1.08 is 8% bigger */
  --faded: 0.3;            /* how much colour the exit sign keeps until the cursor is on it: 0 is grey, 1 is full colour */
  --switch-faded: 0.5;     /* the same, for the on/off switch */
  --switch-dim: 0.85;      /* how bright the switch is until the cursor is on it: 1 is untouched, 0.85 is 15% darker */
}
html.strip-on { --strip-height: calc(var(--thumb) + 2rem); }

html { background: #000; }

/* The spread fills the window; nothing scrolls. The background tile comes from the page itself
   (bg_default, or a spread's own bg_005 and so on). */
body {
  height: 100vh;
  overflow: hidden;
  /* --bg-dim (the "dim" setting) lays a see-through colour over the background */
  --dim: linear-gradient(var(--bg-dim, transparent), var(--bg-dim, transparent));
  background: var(--dim), var(--bg, none) repeat #000;
  color: #fff;
}
/* the "once" setting: one copy of the picture, covering the window, centred */
body.bg-once { background-position: 0 0, center; background-size: auto, cover; background-repeat: no-repeat; }

/* --- The book --- */
.book {
  /* room kept clear at each side: enough for a paper plane and its trail (the trail is 0.6 of a
     plane long), or for the exit sign in its corner (7rem wide), whichever needs more */
  --side: max(var(--plane-in) + var(--plane) * 1.6 + 1rem, 7rem + var(--edge) + 0.75rem);
  /* how tall the open book is: as tall as the window allows (times --book-size), or shorter if it
     would be too wide to fit between the paper planes. (--side has a rem to spare at each side;
     the 1.5rem lets the book grow into most of it. The middle term keeps a rem clear above and
     below however big --book-size is.) */
  --book-height: min((100vh - var(--strip-height) - 8.5rem) * var(--book-size), 100vh - var(--strip-height) - 2rem, (100vw - 2 * var(--side) + 1.5rem) / var(--ratio));
  position: fixed;
  inset: 0 0 var(--strip-height) 0;
  display: grid;
  place-items: center;
}

/* Both halves get the same room, so the fold always sits dead centre of the window.
   The book is as tall as the window allows, or shorter if it would be too wide to fit
   between the paper planes. --ratio (width over height of the open book) is set on each page. */
.spread {
  /* room kept clear at each side: enough for a paper plane and its trail (the trail is 0.6 of a
     plane long), or for the exit sign in its corner (7rem wide), whichever needs more */
  grid-area: 1 / 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  /* a black glow round the open book, following the outline of the pages: it blots out the stars
     close to the book and dims them further off, so the pages sit in a pool of dark.
     The glows themselves are the three filters at the top of sketchbook.njk (their reach and
     strength are set there). Its colour is black unless the spread is given one in the "glow"
     list in _data/sketchbookSettings.js. */
  filter: url(#glow);
  height: var(--book-height);
}
/* a spread with a background of its own (bg_023.jpg and the like) gets the small glow,
   so the background shows right up close to the book */
.own-bg .spread { filter: url(#glow-small); }
/* a glow given two colours (glow: { "037": ["black", "red"] }) changes colour as it spreads */
.glow-turns .spread { filter: url(#glow-turns); }
.glows { position: absolute; }

/* Sparks: a layer exactly over the book, with little white sparks that flash, fly a short way
   outwards and go out, each at its own pace. Positions are in % of the picture; lengths and
   distances in % of its width (cqw). */
.sparks {
  grid-area: 1 / 1;
  position: relative;
  z-index: 1;
  height: var(--book-height);
  aspect-ratio: var(--ratio);
  container-type: size;
  pointer-events: none;
}
.spark {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: 3px;
  height: calc(var(--l) * 1cqw);
  margin-left: -1.5px;
  border-radius: 2px;
  background: linear-gradient(to top, rgba(255, 255, 255, 0), #fff 55%);
  box-shadow: 0 0 3px 1px rgba(255, 255, 255, 0.9), 0 0 9px 1px rgba(255, 255, 255, 0.4);
  opacity: 0;
  transform-origin: 50% 100%;
  will-change: transform, opacity;
  animation: spark var(--t) linear var(--w) infinite;
}
@keyframes spark {
  0%   { opacity: 0; transform: rotate(var(--a)) translateY(0) scaleY(0.4); }
  3%   { opacity: 1; }
  6%   { opacity: 0.45; }
  9%   { opacity: 1; }
  22%  { opacity: 0; transform: rotate(var(--a)) translateY(calc(var(--d) * -1cqw)) scaleY(1); }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(var(--d) * -1cqw)) scaleY(1); }
}

/* Trails: little pencil lines streaming away behind something on the page, over and over, so it
   looks as if it is falling (the "trails" list in _data/sketchbookSettings.js). They live in the
   same layer as the sparks. Each line starts at its foot, just behind the thing, and slides away
   along its own length as it fades. */
.trail {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: max(1.5px, 0.22cqw);
  height: calc(var(--l) * 1cqw);
  margin-left: calc(max(1.5px, 0.22cqw) / -2);
  margin-top: calc(var(--l) * -1cqw);          /* the line stands on its point, reaching away from it */
  border-radius: 2px;
  background: linear-gradient(to top, var(--trail, #4f5362), transparent);
  opacity: 0;
  transform-origin: 50% 100%;
  will-change: transform, opacity;
  animation: trail var(--t) linear var(--w) infinite;
}
@keyframes trail {
  0%   { opacity: 0; transform: rotate(var(--a)) translateY(0) scaleY(0.35); }
  18%  { opacity: 0.85; }
  75%  { opacity: 0; transform: rotate(var(--a)) translateY(calc(var(--d) * -1cqw)) scaleY(1); }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(var(--d) * -1cqw)) scaleY(1); }
}

/* Pixelly sparks and trails ( pixelly: true  on their line in _data/sketchbookSettings.js; take it
   off and they are the smooth ones above again). Each is one square block (--u across) with the
   rest of its row drawn as hard-edged shadows of it, worked out in _includes/sketchbook-pages.js.
   Nothing turns or stretches: it moves a whole block at a time, --mx across and --my down. */
.spark--px,
.trail--px {
  --u: max(2px, calc(var(--p, 0.22) * 1cqw));
  width: var(--u);
  height: var(--u);
  margin: calc(var(--u) / -2) 0 0 calc(var(--u) / -2);
  border-radius: 0;
  background: var(--c0);
  transform: none;
  will-change: translate, opacity;
  animation-timing-function: step-end;
}
/* (a whole number of screen pixels per block where the browser can round, so the edges stay crisp) */
@supports (width: round(1cqw, 1px)) {
  .spark--px,
  .trail--px { --u: max(2px, round(calc(var(--p, 0.22) * 1cqw), 1px)); }
}
.spark--px {
  top: calc(var(--y) * 1% + var(--l) * 1cqw);    /* the foot of the smooth spark: the point it flies out from */
  animation-name: spark-px;
}
/* (a trail hops once for every block it travels; with  soft  its blocks have blurred edges, so they
   run together into a gentler line) */
.trail--px { animation-name: trail-px; animation-timing-function: steps(var(--hops, 4)); }
.trail--soft { width: 0; height: 0; margin: 0; }   /* a point: its blocks are all shadows spread out from it */
/* a flash, a flicker, then three hops outwards as it goes out */
@keyframes spark-px {
  0%   { opacity: 0; translate: 0 0; }
  4%   { opacity: 1; translate: 0 0; }
  8%   { opacity: 0.4; translate: 0 0; }
  12%  { opacity: 1; translate: 0 0; animation-timing-function: steps(3); }
  24%  { opacity: 0; translate: calc(var(--u) * var(--mx)) calc(var(--u) * var(--my)); }
  100% { opacity: 0; translate: calc(var(--u) * var(--mx)) calc(var(--u) * var(--my)); }
}
/* hop by hop away from the thing, fainter each time */
@keyframes trail-px {
  0%   { opacity: 0.9; translate: 0 0; }
  70%  { opacity: 0; translate: calc(var(--u) * var(--mx)) calc(var(--u) * var(--my)); }
  100% { opacity: 0; translate: calc(var(--u) * var(--mx)) calc(var(--u) * var(--my)); }
}

/* A spread made bigger than the rest (the "bigger" list in _data/sketchbookSettings.js): its top stays
   where every other book's top is, and it grows downwards, under the strip if need be. */
.spread--bigger .page {
  align-self: start;
  height: calc(100% * var(--size, 1) * var(--grow));
}
.spread--bigger .count { top: calc(100% * var(--grow)); }

/* The file number of each page, just under it: left page's on the left of the fold, right page's
   on the right. A two-page picture has one, in the middle. */
.spread { position: relative; }
.count {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.7rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 1.5rem;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9rem;
  line-height: 1;
  color: #b9b9b9;
}
.count span:first-child { text-align: right; }
.count span.count-whole { grid-column: 1 / -1; text-align: center; }

.page {
  display: block;
  /* a page can be made a touch smaller or bigger than its neighbour (the "size" list in
     _data/sketchbookSettings.js); it stays against the fold, centred top to bottom */
  height: calc(100% * var(--size, 1));
  width: auto;
  align-self: center;
}
.page--left { justify-self: end; }
.page--right { justify-self: start; }
/* two facing pages in one picture: it lies across both halves, centred on the fold */
.page--whole {
  grid-column: 1 / -1;
  justify-self: center;
}
/* A picture with an empty see-through border round it is shown through a window that crops the
   border off. --w and --h are the size of the real picture, --W is the width of the whole file,
   and --x and --y are how far in and down the real picture starts (all in the file's own pixels). */
.crop {
  display: block;
  overflow: hidden;
  aspect-ratio: var(--w) / var(--h);
}
.crop > img {
  display: block;
  max-width: none;
  width: calc(100% * var(--W) / var(--w)) !important;
  height: auto !important;
  margin-left: calc(-100% * var(--x) / var(--w));
  margin-top: calc(-100% * var(--y) / var(--w));
}
.is-turned { transform: rotate(180deg); }

/* --- Turning the page: a paper plane at each side of the window --- */
/* They stay in exactly the same spot from spread to spread, so you can keep clicking.
   Each link holds the plane (in a window cropped to just the plane) and its trail, side by side. */
.turn {
  position: absolute;
  top: 50%;
  z-index: 2;                /* above the book: its glow would otherwise lie over the left-hand plane and swallow clicks */
  display: flex;
  align-items: center;
  gap: 0.2rem;
  line-height: 0;
  transform: translateY(-50%);
}
/* on a spread with a background of its own, a slight shadow under each plane lifts it off the page */
.own-bg .turn-plane { filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.4)); }
.turn--prev { left: var(--plane-in); }
.turn--next { right: var(--plane-in); }
.turn-plane {
  display: block;
  flex: none;
  width: var(--plane);
  overflow: hidden;
}
.turn-plane img {
  display: block;
  max-width: none;
  height: auto;
  transition: transform 0.2s, filter 0.2s;
}
/* The numbers are measured from the two picture files, in their own pixels.
   plane-left.webp is 612 by 408; the plane is 580 wide and 226 tall, starting 24 in and 108 down */
.turn--prev .turn-plane { height: calc(var(--plane) * 226 / 580); }
.turn--prev .turn-plane img {
  width: calc(var(--plane) * 612 / 580);
  margin-left: calc(var(--plane) * -24 / 580);
  margin-top: calc(var(--plane) * -108 / 580);
}
/* plane-right.webp is 780 by 487; the plane is 665 wide and 281 tall, starting 59 in and 78 down */
.turn--next .turn-plane { height: calc(var(--plane) * 281 / 665); }
.turn--next .turn-plane img {
  width: calc(var(--plane) * 780 / 665);
  margin-left: calc(var(--plane) * -59 / 665);
  margin-top: calc(var(--plane) * -78 / 665);
}

/* The trails: gusts of wind behind each plane, drawn as calligraphy-pen strokes. Each one has
   its own strength (--o) and, over and over, appears close behind the plane, streams away from
   it and fades out, each at its own pace so they never fall into step. */
.turn-trail {
  flex: none;
  width: calc(var(--plane) * 0.6);
  height: auto;
  overflow: visible;
  opacity: 0.9;
  /* a light black glow round the strokes, which dims the stars just behind them */
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 6px rgba(0, 0, 0, 0.6));
  transition: opacity 0.2s;
}
.turn--next .turn-trail { transform: scaleX(-1); }      /* behind the right-hand plane they stream the other way */
.swoosh {
  opacity: var(--o);
  animation: whoosh var(--t) cubic-bezier(0.3, 0.1, 0.5, 1) infinite both;
}
.swoosh--long { --o: 0.9;  --t: 5.5s; }
.swoosh--a    { --o: 0.68; --t: 6.5s; animation-delay: -2.2s; }
.swoosh--b    { --o: 0.82; --t: 4.75s; animation-delay: -3.4s; }
.swoosh--c    { --o: 0.75; --t: 7.25s; animation-delay: -1.1s; }
@keyframes whoosh {
  0%   { transform: translateX(-5px); opacity: 0; }
  22%  { opacity: var(--o); }
  65%  { opacity: calc(var(--o) * 0.85); }
  100% { transform: translateX(7px); opacity: 0; }
}

/* under the cursor each plane edges forward the way it is flying and brightens, and its trail shows up more */
.turn--prev:hover img,
.turn--prev:focus-visible img { transform: translateX(-0.3rem); filter: brightness(1.2); }
.turn--next:hover img,
.turn--next:focus-visible img { transform: translateX(0.3rem); filter: brightness(1.2); }
.turn:hover .turn-trail,
.turn:focus-visible .turn-trail { opacity: 1; }

/* --- Back: a lit exit sign in the top left corner, with its own green light glowing round it --- */
.back {
  position: fixed;
  top: var(--edge);
  left: var(--edge);
  z-index: 3;
  display: block;
  line-height: 0;
}
.back img {
  display: block;
  width: 7rem;
  height: auto;
  /* Until the cursor is on it, the sign itself keeps only --faded of its colour, while the glow
     round it (which follows the sign's outline) is the sign's green with 60% of its colour kept. */
  filter:
    brightness(1)
    saturate(var(--faded))
    drop-shadow(0 0 5px rgba(129, 234, 99, 0.75))
    drop-shadow(0 0 18px rgba(129, 234, 99, 0.45));
  transition: filter 0.25s;
}
/* under the cursor the sign and its glow get brighter, in full colour */
.back:hover img,
.back:focus-visible img {
  filter:
    brightness(1.2)
    saturate(1)
    drop-shadow(0 0 7px rgba(80, 255, 30, 0.95))
    drop-shadow(0 0 26px rgba(80, 255, 30, 0.65));
}

/* --- The light switch, in the bottom left corner: on (up) shows every page along the bottom --- */
/* It never moves, so you can flick it on and off without chasing it. Two pictures of the same
   switch plate, switch-off.jpg (down) and switch-on.jpg (up); only the one that matches is shown.
   (Made from switch_down.jpg and switch_on.jpg in the Sketchbook folder, at 160px tall.) */
.switch {
  position: fixed;
  left: var(--edge);
  bottom: var(--switch-bottom);
  z-index: 3;
  width: var(--switch);
  height: var(--switch-height);
  padding: 0;
  border: 0;
  background: none;
  line-height: 0;
  cursor: pointer;
  /* off: a glow a tenth weaker than when it is on */
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.72)) drop-shadow(0 0 12px rgba(255, 255, 255, 0.61)) drop-shadow(0 0 28px rgba(255, 255, 255, 0.36));
  transition: filter 0.25s;
}
.switch img {
  display: block;
  width: 100%;
  height: 100%;
  /* half its colour, and 15% darker, until the cursor is on it
     (the little pages you aren't on are darkened by half, so this is much gentler) */
  filter: saturate(var(--switch-faded)) brightness(var(--switch-dim));
  transition: filter 0.25s;
}
.switch .switch-on,
html.strip-on .switch .switch-off { display: none; }
html.strip-on .switch .switch-on { display: block; }
/* on: the full glow */
html.strip-on .switch {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.8)) drop-shadow(0 0 12px rgba(255, 255, 255, 0.68)) drop-shadow(0 0 28px rgba(255, 255, 255, 0.4));
}
/* under the cursor its colour and full brightness come back, whichever way it is set */
.switch:hover img,
.switch:focus-visible img { filter: saturate(1) brightness(1); }

/* --- The strip: every page, small, along the bottom --- */
/* Nothing behind it and no line above it: just the little pages on the stars.
   It starts to the right of the light switch. */
.strip {
  position: fixed;
  left: calc(var(--edge) + var(--switch) + 0.5rem);
  right: 0;
  /* the row of little pages is centred on the middle of the light switch, however small they get
     (when they are tall this comes to 0: the strip sits on the bottom of the window) */
  bottom: calc(var(--switch-bottom) + var(--switch-height) / 2 - var(--strip-height) / 2 + var(--strip-lift));
  z-index: 2;
  display: none;
  height: var(--strip-height);
}
html.strip-on .strip { display: block; }
.strip ol {
  position: relative;      /* so each spread's place can be measured from the row's left edge */
  display: flex;
  align-items: center;
  gap: var(--gap);
  height: 100%;
  padding: 0 1rem;
  overflow-x: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: #777 transparent;
}
/* When the window is too narrow for every spread and the strip scrolls, the last few little pages
   at an end fade away if there are more beyond that end, and come back once you've scrolled all
   the way there. (The script in sketchbook.njk sets more-before and more-after as the strip moves.) */
.strip ol { --fade: calc(var(--thumb) * 5); --faint: rgba(0, 0, 0, 0.06); }
.strip ol.more-after {
  -webkit-mask-image: linear-gradient(to left, var(--faint), #000 var(--fade));
  mask-image: linear-gradient(to left, var(--faint), #000 var(--fade));
}
.strip ol.more-before {
  -webkit-mask-image: linear-gradient(to right, var(--faint), #000 var(--fade));
  mask-image: linear-gradient(to right, var(--faint), #000 var(--fade));
}
.strip ol.more-before.more-after {
  -webkit-mask-image: linear-gradient(to right, var(--faint), #000 var(--fade), #000 calc(100% - var(--fade)), var(--faint));
  mask-image: linear-gradient(to right, var(--faint), #000 var(--fade), #000 calc(100% - var(--fade)), var(--faint));
}
.strip li { flex: none; }
.strip a { display: flex; }
.strip img {
  display: block;
  height: var(--thumb);
  width: auto;
  /* the other spreads sit back in the dark; every little page has a slight shadow that follows its outline */
  filter: brightness(0.5) drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9));
}
.strip .crop { height: var(--thumb); }
.strip a:hover img,
.strip a:focus-visible img { filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9)); }
/* the spread you're on: full brightness, with a little glow */
.strip a[aria-current] {
  box-shadow:
    0 0 7px 2px rgba(255, 255, 255, 0.8),
    0 0 18px 5px rgba(255, 255, 255, 0.35);
}
.strip a[aria-current] img { filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.9)); }

/* --- Keyboard focus --- */
.back:focus-visible,
.switch:focus-visible,
.turn:focus-visible,
.strip a:focus-visible {
  outline: 2px dashed #fff;
  outline-offset: 4px;
}

/* --- Phones and other narrow windows --- */
/* There is no room for a plane at each side of the book, so the book takes the whole width of the
   window and the two planes sit just under it, one at each corner. */
@media (max-width: 760px) {
  :root {
    --plane: 5.25rem;      /* a little bigger than they would be here, to be easy to tap */
    --plane-in: 1rem;
  }
  .book {
    --side: 0.5rem;        /* the margin at each side of the book */
    --under: calc(var(--plane) * 281 / 665 + 2.75rem);   /* room kept under the book: the taller plane, and the space above and below it */
    --over: 6.5rem;        /* room kept above it, for the exit sign */
    /* as wide as the window allows; on a very short window, as tall as fits between the two rooms */
    --book-height: min(100vh - var(--strip-height) - var(--under) - 2 * var(--over), (100vw - 2 * var(--side)) / var(--ratio));
    padding-bottom: var(--under);     /* the book sits in the middle of what is left above the planes' room */
  }
  .turn {
    top: calc((100% - var(--under)) / 2 + var(--book-height) / 2 + 0.75rem);   /* just under the book */
    transform: none;
    padding: 0.5rem 0;     /* a taller place to tap */
  }
  /* a spread set to be "bigger" would run off both sides here, so it is the usual size */
  .spread--bigger .page {
    align-self: center;
    height: calc(100% * var(--size, 1));
  }
  /* the small book gets the glows with the shorter reach (the -phone filters in sketchbook.njk) */
  .spread { filter: url(#glow-phone); }
  .own-bg .spread { filter: url(#glow-small-phone); }
  .glow-turns .spread { filter: url(#glow-turns-phone); }
}

/* (There used to be a quick cross-fade between spreads here. It made the page ignore clicks for
   about half a second after every turn, so clicking a plane several times in a row skipped
   pages. Spreads now simply swap, and every click counts.) */

/* People who ask their device for less motion get a still background and nothing moving */
@media (prefers-reduced-motion: reduce) {
  body { background-image: var(--dim), var(--bg-still, none); }
  .back img,
  .turn img,
  .turn-trail,
  .switch,
  .switch img { transition: none; }
  .swoosh { animation: none; }
  .sparks { display: none; }
}


/* ========================================
   THE COVER — /sketchbook/, the way in (sketchbook-cover.njk)
   The closed book in the middle with the question under it, and writing either side in the
   gallery's style: PixelWarden, with the gallery heading's near-white, violet shadow and purple glow.
   ======================================== */
@font-face { font-family: "PixelWarden"; src: url("/fonts/PixelWarden.ttf") format("truetype"); font-display: swap; }

.cover-stage {
  --pink: #f3bcd3;
  --violet: #4a00d6;
  /* how tall the closed book is: well over half the window */
  --pad: 7vw;              /* the margin at the left and right of the window */
  --cover-h: min(58vh, 100vh - 17rem, (50vw - var(--pad) - 1.5rem) * 1262 / 951);
  --squish: 1in;           /* how much narrower the writing is squeezed, from its left-hand side */
  /* the size of the big writing: 3rem when there is room, otherwise as big as lets the block fit
     its half of the window (across, then up and down); then made a little smaller still, so the
     block comes out --squish narrower (0.06 is the letter size for each unit of the block's width).
     The block is always the same number of letters wide, so the lines break in the same places
     whatever the size, and it always ends at the middle of the window. */
  --side-text: max(0.75rem, min(3rem, (50vw - var(--pad)) * 0.06, (100vh - 9rem) * 0.08) - var(--squish) * 0.06);
  --ask-glow: 0 0 0.5rem rgba(255, 130, 190, 0.9), 0 0 1.4rem rgba(255, 80, 170, 0.6), 0 0 3rem rgba(255, 80, 170, 0.35);   /* the pink glow round the question */
  position: fixed;
  inset: 0;
  display: grid;
  /* two halves: the writing in the left one, ending at the middle of the window, and the book
     in the middle of the right one */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 0;
  padding: 6rem var(--pad) 2rem;
  font-family: "PixelWarden", "Courier New", monospace;
  color: var(--pink);
}
.cover-middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.75rem;            /* between the book and the question under it */
  text-align: center;
  justify-self: center;
}
/* the writing either side: like the gallery's big heading */
.cover-left {
  width: calc(50em / 3);   /* 50rem when the writing is at its full 3rem */
  font-size: var(--side-text);
  line-height: 1.25;
  color: #fff3f8;
  text-shadow: calc(var(--side-text) / 16) calc(var(--side-text) / 16) 0 var(--violet), 0 0 22px rgba(110, 90, 255, 0.75), 0 0 60px rgba(74, 0, 214, 0.45);
}
.cover-left { justify-self: end; }
/* the small line under it */
.cover-left .cover-note {
  margin-top: 0.75em;
  font-size: max(1rem, 2em / 3);   /* two thirds of the big writing: 2rem at full size */
  line-height: 1.2;
  color: var(--pink);
  text-shadow: calc(var(--side-text) / 24) calc(var(--side-text) / 24) 0 var(--violet), 0 0 12px rgba(110, 90, 255, 0.6);
}
.cover-left p + p { margin-top: 1em; }
/* on the cover the exit sign keeps most of its colour (elsewhere it keeps --faded: 0.3) */
.cover-page { --faded: 0.8; }
.closed-book {
  display: block;
  height: var(--cover-h);
  width: auto;
  rotate: -1.2deg;
  filter: drop-shadow(0 0 0.6rem rgba(255, 255, 255, 0.5)) drop-shadow(0 0 2.5rem rgba(255, 255, 255, 0.3));   /* a white glow */
}

/* PixelWarden is drawn on a 16-pixel grid, so its sizes are whole rems (it is sharpest that way) */
.cover-ask {
  translate: 0 0.3em;      /* a quarter of a line lower than it would sit */
  font-size: 2rem;
  line-height: 1.2;
  text-shadow: 2px 2px 0 var(--violet), var(--ask-glow);
}
.answers {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin-top: 1.25rem;
}
/* the yes and no buttons: pictures, each glowing its own colour */
.answer { display: block; line-height: 0; border-radius: 50%; --glow: 255, 255, 255; }
.answer--yes { --glow: 40, 255, 90; }
.answer--no { --glow: 255, 40, 40; }
.answer img {
  display: block;
  width: 5.5rem;
  height: auto;
  filter: drop-shadow(0 0 0.4rem rgba(var(--glow), 0.6)) drop-shadow(0 0 1.2rem rgba(var(--glow), 0.35));
  transition: filter 0.2s, scale 0.1s;
}
.answer:hover img,
.answer:focus-visible img { filter: drop-shadow(0 0 0.5rem rgba(var(--glow), 0.85)) drop-shadow(0 0 1.6rem rgba(var(--glow), 0.5)); }
.answer:hover { animation: jiggle 0.3s steps(3) infinite; }
.answer:active img { scale: 0.92; }          /* pressed in */
/* the yes button gently swells and shrinks, all the time */
.answer--yes { animation: breathe 1.6s ease-in-out infinite; }
.answer--yes:hover { animation: breathe 1.6s ease-in-out infinite, jiggle 0.3s steps(3) infinite; }
@keyframes breathe { 0%, 100% { scale: 0.97; } 50% { scale: 1.03; } }
.answer:focus-visible { outline: 2px dashed var(--pink); outline-offset: 6px; }
@keyframes jiggle {
  0% { translate: 0 0; } 33% { translate: -2px 2px; } 66% { translate: 2px -2px; } 100% { translate: 0 0; }
}

/* wavy lettering, as in the gallery: each letter nudged up or down a whole number of font-pixels */
.wavy-word { display: inline-block; white-space: nowrap; }
.wavy-word > span { display: inline-block; transform: translateY(calc(var(--y) * 0.0625em)); }

/* smaller windows: narrower margins and the question a size down, then smaller again */
@media (max-width: 1300px), (max-height: 820px) {
  .cover-stage { --pad: 3rem; }
  .cover-ask { font-size: 1.5rem; }
}
@media (max-width: 1050px), (max-height: 680px) {
  .cover-ask { font-size: 1rem; text-shadow: 1px 1px 0 var(--violet), var(--ask-glow); }
}
/* a narrow window: everything in one column, and the page scrolls */
@media (max-width: 760px) {
  body.cover-page { height: auto; min-height: 100vh; overflow: auto; }
  .cover-stage {
    --cover-h: min(48vh, (100vw - 3rem) * 1262 / 951);
    --side-text: 1rem;
    position: static;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 2rem;
    padding: 6rem 1.5rem 3rem;
  }
  .cover-left { justify-self: center; width: auto; }
  .cover-ask { font-size: 1rem; text-shadow: 1px 1px 0 var(--violet), var(--ask-glow); }
  .answer img { width: 4.25rem; }
  .answers { margin-top: 0.5rem; gap: 2rem; }
}

/* "yes": the cover whooshes off to the left (a little pull back first); the writing flies off
   up and down */
.leaving .closed-book { animation: cover-off 0.55s cubic-bezier(0.55, -0.35, 0.85, 0.4) forwards; }
.leaving .cover-left { animation: words-left 0.4s cubic-bezier(0.5, 0, 0.9, 0.5) forwards; }
.leaving .cover-below { animation: words-down 0.4s cubic-bezier(0.5, 0, 0.9, 0.5) forwards; }
@keyframes cover-off { to { translate: -115vw -4vh; rotate: -14deg; } }
@keyframes words-left { to { translate: -60vw 0; opacity: 0; } }

@keyframes words-down { to { translate: 0 60vh; opacity: 0; } }

/* --- ...and the first spread whooshing in where the cover was (sketchbook.njk adds .entering) --- */
/* The book swoops in from the right, overshoots a little and settles; the plane and the switch
   jerk in after it, a few frames at a time, like stop-motion. The exit sign never moves. */
html.entering .spread,
html.entering .sparks { animation: book-in 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.15) both; }
html.entering .turn--next { animation: plane-in 0.45s steps(5) 0.3s both; }
html.entering .switch { animation: switch-in 0.4s steps(4) 0.45s both; }
html.entering .strip { animation: strip-in 0.45s steps(5) 0.5s both; }
@keyframes book-in {
  from { translate: 75vw 3vh; rotate: 9deg; }
  70% { translate: -1.5vw 0; rotate: -0.8deg; }
  to { translate: 0 0; rotate: 0deg; }
}
@keyframes plane-in { from { translate: 40vw -10vh; rotate: 20deg; } to { translate: 0 0; rotate: 0deg; } }
@keyframes switch-in { from { translate: 0 calc(100% + 2rem); } to { translate: 0 0; } }
@keyframes strip-in { from { translate: 0 100%; opacity: 0; } to { translate: 0 0; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .leaving .closed-book,
  .leaving .cover-left,
  .leaving .cover-below,
  html.entering .spread,
  html.entering .sparks,
  html.entering .turn--next,
  html.entering .switch,
  html.entering .strip,
  .answer,
  .answer:hover,
  .answer--yes:hover,
  .answer:focus-visible { animation: none; }
}

/* pages can be clicked for their full-size picture */
.spread [data-full] { cursor: zoom-in; }
