:root {
  --bg: #ffffff;
  --ink: #161616;
  --muted: #8a8780;
}

/* The frame's width, animatable so a frame can grow in around a picture. */
@property --fw {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Drift: the row along the bottom ---------------------------------------- */
#strip {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
#strip.dragging { cursor: grabbing; }
#strip.gone { visibility: hidden; }

/* An invisible marker for the line the row stands on. */
.baseline {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(5vh + env(safe-area-inset-bottom, 0px));
  height: 0;
  pointer-events: none;
}

.piece {
  position: absolute;
  left: 0;
  bottom: calc(5vh + env(safe-area-inset-bottom, 0px));
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  will-change: transform;
}
.piece img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .35s cubic-bezier(.2, .7, .2, 1), opacity .4s ease;
  opacity: 0;
  pointer-events: none;
  -webkit-user-drag: none;
}
.piece img.loaded { opacity: 1; }
.piece:hover img, .piece:focus-visible img { transform: translateY(-6px); }
.piece:focus-visible { outline: none; }
.piece:focus-visible img { outline: 2px solid var(--ink); outline-offset: 3px; }
.piece.away img { visibility: hidden; }

/* ---- Wall: framed portraits hung around the text -------------------------- */
.wallview {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.wallview[hidden] { visibility: hidden; pointer-events: none; }  /* kept laid out, so switching is quick */
.wallview.dragging { cursor: grabbing; }
.wall {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

/* One framed portrait. --x, --y and --s place and size the picture; the frame
   (--fw wide) is built outward from it, so it can grow in around it. */
.hang {
  position: absolute;
  left: calc(var(--x) - var(--fw));
  top: calc(var(--y) - var(--fw));
  width: calc(var(--s) + var(--fw) * 2);
  height: calc(var(--s) + var(--fw) * 2);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: 0 0;
}
/* The frame and its shadow, in their own layer so they can grow in and fade
   on the compositor while a portrait flies (--fw itself never animates). */
.hang .fr {
  position: absolute;
  inset: 0;
  box-shadow: 0 2px 3px rgba(40, 28, 18, .14), 0 10px 18px rgba(40, 28, 18, .1);
  pointer-events: none;
}
.hang img {
  position: absolute;
  inset: var(--fw);
  width: calc(100% - var(--fw) * 2);
  height: calc(100% - var(--fw) * 2);
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}
.hang.away { visibility: hidden; }
.hang:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

/* ---- The wooden frame (the big one, and every frame on the wall) ---------- */
/* A thin, flat moulding of four mitred rails. Each rail is the wood colour
   multiplied by a grain texture; each side is one even, matte face, lit from
   the top left so the top is a touch lighter and the bottom a touch darker. */
.rail {
  position: absolute;
  background-color: var(--wood, #a87a4f);
  background-blend-mode: multiply;
}
.rail::after { content: ""; position: absolute; inset: 0; }
.rail.top, .rail.bottom { left: 0; right: 0; height: var(--fw); background-size: auto 100%; }
.rail.left, .rail.right { top: 0; bottom: 0; width: var(--fw); background-size: 100% auto; }
.rail.top { top: 0; clip-path: polygon(0 0, 100% 0, calc(100% - var(--fw)) 100%, var(--fw) 100%); }
.rail.bottom { bottom: 0; clip-path: polygon(var(--fw) 0, calc(100% - var(--fw)) 0, 100% 100%, 0 100%); }
.rail.left { left: 0; clip-path: polygon(0 0, 100% var(--fw), 100% calc(100% - var(--fw)), 0 100%); }
.rail.right { right: 0; clip-path: polygon(0 var(--fw), 100% 0, 100% 100%, 0 calc(100% - var(--fw))); }
.rail.top::after    { background: rgba(255, 255, 255, .1); }
.rail.left::after   { background: rgba(255, 255, 255, .04); }
.rail.right::after  { background: rgba(0, 0, 0, .08); }
.rail.bottom::after { background: rgba(0, 0, 0, .14); }

/* A round frame, for a portrait drawn as a circle (`"shape": "circle"` in
   illustrations.json). The drawn circle fills 94% of its square, so the
   picture is cut to that circle and a white ring hugs its edge, in place of
   the four rails. --s is the picture's size. */
.ring { display: none; }
.round .rail { display: none; }
.round .ring {
  display: block;
  position: absolute;
  inset: 0;
  background: #f7f6f3 none !important;    /* a white painted ring, not wood */
  --r: calc(var(--s) * .47);
  -webkit-mask: radial-gradient(circle at center, transparent calc(var(--r) - .5px), #000 var(--r), #000 calc(var(--r) + var(--fw)), transparent calc(var(--r) + var(--fw) + .5px));
          mask: radial-gradient(circle at center, transparent calc(var(--r) - .5px), #000 var(--r), #000 calc(var(--r) + var(--fw)), transparent calc(var(--r) + var(--fw) + .5px));
}
/* Lit from the top left, like the straight rails. */
.round .ring::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(150deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, .16));
}
.hang.round img, .lifted.round { clip-path: circle(47%); }
/* The shadow follows the ring, not the square. */
.hang.round .fr { box-shadow: none; filter: drop-shadow(0 2px 2px rgba(40, 28, 18, .16)) drop-shadow(0 8px 10px rgba(40, 28, 18, .12)); }
.round.frame::after, .hang.round .fr::after { inset: calc(var(--fw) + var(--s) * .03); border-radius: 50%; }

/* A fine line where the frame meets the picture. */
.frame::after, .hang .fr::after {
  content: "";
  position: absolute;
  inset: var(--fw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .3);
  pointer-events: none;
}

/* ---- Text and logo ---------------------------------------------------------- */
.intro {
  position: fixed;
  left: 50%;
  top: 38%;
  z-index: 2;
  width: min(40ch, calc(100vw - 48px));
  margin: 0;
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity .5s ease;
}
.intro .logo, .about .logo { display: block; width: 104px; height: auto; margin: 0 auto 34px; color: var(--ink); }
.intro .title { margin: 0 0 10px; font-size: 17px; font-weight: 700; line-height: 1.35; letter-spacing: -.005em; text-wrap: balance; }
.intro p { margin: 0; font-size: 15px; line-height: 1.55; text-wrap: balance; }
/* "Read more", a small grey link on its own line under the text. */
.more {
  display: block;
  margin: 10px auto 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: 400 13px/1.4 "DM Sans", system-ui, sans-serif;
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, .18);
  text-underline-offset: 3px;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
  transition: color .45s ease, text-decoration-color .45s ease;
}
.more:hover { color: var(--ink); text-decoration-color: currentColor; }
.more:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
/* While a portrait is framed the text steps aside. */
body.framing .intro { opacity: 0; }
body.framing .more { pointer-events: none; }

/* On load the logo, title, text and Read more come in one after another, then
   the view toggle. */
@keyframes enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
body.entering .intro .logo,
body.entering .intro .title,
body.entering .intro p,
body.entering .intro .more,
body.entering .modes { animation: enter .9s cubic-bezier(.2, .7, .2, 1) both; }
body.entering .intro .logo  { animation-delay: .1s; }
body.entering .intro .title { animation-delay: .25s; }
body.entering .intro p      { animation-delay: .4s; }
body.entering .intro .more  { animation-delay: .65s; }
body.entering .modes        { animation-delay: .8s; }

/* ---- View toggle ------------------------------------------------------------ */
.modes {
  position: fixed;
  z-index: 3;
  right: max(16px, env(safe-area-inset-right, 0px));
  top: max(16px, env(safe-area-inset-top, 0px));
  display: inline-flex;
  padding: 3px;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: 999px;
  background: var(--bg);
  transition: opacity .4s ease;
}
/* The dark pill behind the chosen view; it slides (and stretches to fit)
   from one label to the other. Placed by drift.js. */
.modes .thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  width: 0;
  border-radius: 999px;
  background: var(--ink);
  transition: transform .55s cubic-bezier(.65, 0, .25, 1), width .55s cubic-bezier(.65, 0, .25, 1);
}
.modes button {
  position: relative;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 500 13px/1 "DM Sans", system-ui, sans-serif;
  cursor: pointer;
  transition: color .35s ease .1s;
}
.modes button[aria-pressed="true"] { color: var(--bg); }
.modes:not(.ready) button[aria-pressed="true"] { background: var(--ink); }   /* until the pill is placed */
.modes button:not([aria-pressed="true"]):hover { color: var(--ink); }
.modes button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
body.framing .modes { opacity: 0; pointer-events: none; }

/* ---- Close buttons: a pill the same height as the view toggle, in its place -- */
.close, .about-close {
  height: 33px;
  display: inline-flex;
  align-items: center;
  padding: 0 15px;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font: 500 13px/1 "DM Sans", system-ui, sans-serif;
  cursor: pointer;
  transition: border-color .45s ease;
}
.close:hover, .about-close:hover { border-color: var(--ink); }
.close:focus-visible, .about-close:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- Framed view --------------------------------------------------------- */
.stage {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0);
  transition: background .5s ease;
}
.stage.open { background: rgba(255, 255, 255, .92); }
.stage[hidden] { display: none; }

.lifted {
  position: fixed;
  left: 0;
  top: 0;
  display: block;
  object-fit: cover;
  transform-origin: 0 0;
  will-change: transform;
}

.frame {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  transform-origin: 0 0;
  will-change: transform;
  filter: drop-shadow(0 22px 26px rgba(40, 28, 18, .22)) drop-shadow(0 4px 6px rgba(40, 28, 18, .2));
}

.caption {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 15px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .4s ease, transform .4s ease;
}
.stage.framed .caption { opacity: 1; transform: none; }
.caption a { color: var(--ink); text-decoration: none; }
.caption a[href] { text-decoration: underline; text-decoration-color: rgba(0, 0, 0, .25); text-underline-offset: 3px; transition: text-decoration-color .45s ease; }
.caption a[href]:hover { text-decoration-color: currentColor; }

.close {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  top: max(16px, env(safe-area-inset-top, 0px));
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease, border-color .45s ease;
}
/* Only while a portrait is fully framed, so it never sits over the toggle. */
.stage.framed .close { opacity: 1; pointer-events: auto; }
.close:focus-visible, .caption a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ---- About: the longer story, over the whole screen ------------------------- */
.about {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  opacity: 0;
  transition: opacity .4s ease;
}
.about[hidden] { display: none; }
.about.open { opacity: 1; }
/* The text starts under the logo, which sits exactly where the intro's logo
   does: --logo-top is measured from the intro when the story opens. */
.about-body {
  width: min(52ch, calc(100vw - 48px));
  margin: 0 auto;
  padding: var(--logo-top, 120px) 0 80px;
  text-align: center;
}
/* The logo stays still; only the text drifts up into place. */
.about-body p { transform: translateY(12px); transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
.about.open .about-body p { transform: none; }
.about p { margin: 0 0 1em; font-size: 15px; line-height: 1.55; text-wrap: pretty; }                            /* as the intro's text */
.about a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(0, 0, 0, .25);
  text-underline-offset: 3px;
  transition: text-decoration-color .45s ease;
}
.about a:hover { text-decoration-color: currentColor; }
.about a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
.about-close {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  top: max(16px, env(safe-area-inset-top, 0px));
}

@media (max-width: 640px) {
  .about p { font-size: 14px; }
  .intro .logo, .about .logo { width: 86px; margin-bottom: 26px; }
  .intro .title { font-size: 16px; }
  .intro p { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  body.entering .intro .logo, body.entering .intro .title, body.entering .intro p,
  body.entering .intro .more, body.entering .modes { animation: none; }
  .piece img, .caption, .stage, .intro, .modes, .modes .thumb, .modes button, .about, .about-body p, .more, .about a, .caption a { transition: none; }
}
