:root {
  --ink: #1d1a16;
  --paper: #efe6d6;
  --paper-2: #f7f1e6;
  --line: #b9a98e;
  --f-read: "Bellota Text", "Palatino Linotype", Palatino, Georgia, serif;
  --f-about: "Literata", Georgia, serif;
  --f-ui: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; background: #efe6d6; color: var(--ink); }

body {
  font: 16px/1.65 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  /* sampled from the painting's own paper so letterboxing never shows a hard band */
  background: linear-gradient(#f2ece0 0%, #cdbfa6 100%) fixed;
  min-height: 100dvh;
}

/* ---------- chrome ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 56px;
  padding: 0 clamp(12px, 3vw, 28px);
  background: rgba(242, 236, 224, 0.82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(185, 169, 142, 0.6);
}

.bar .spacer { flex: 1; }

.lang {
  border: 1px solid var(--ink);
  background: transparent;
  color: inherit;
  font: 600 0.72rem/1 var(--f-ui);
  letter-spacing: 0.12em;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 2px;
}
.lang:hover, .lang:focus-visible { background: var(--ink); color: var(--paper-2); }

/* top-right nav: icon until hovered, then its label unfolds */
.nav { display: flex; align-items: center; gap: 4px; }

.nav-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: inherit;
  text-decoration: none;
  font: 500 0.74rem/1 var(--f-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 2px;
  white-space: nowrap;
}
.nav-item svg {
  width: 15px;
  height: 15px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
}
.nav-item:hover, .nav-item:focus-visible { background: rgba(29, 26, 22, 0.07); }
.nav-item:hover svg, .nav-item:focus-visible svg { fill: currentColor; fill-opacity: 0.12; }
.nav-item[aria-current="page"] { text-decoration: underline; text-underline-offset: 5px; }

@media (min-width: 721px) {
  .nav-item .nav-label { display: none; }
  .nav-item:hover .nav-label, .nav-item:focus-visible .nav-label { display: inline; }
}

/* ---------- scene ---------- */

.scene-wrap {
  /* The stage is sized to fit the viewport, so nothing should ever pan. Leaving this
     scrollable let the oversized stage drift under the cursor, which read as the
     gallery being draggable inside its frame. `clip` rather than `hidden` because
     hidden still creates a scroll container that can be nudged; clip cannot. */
  display: grid;
  place-items: center;
  overflow: clip;
  height: calc(100dvh - 56px);
  overscroll-behavior: none;
}

#stage {
  position: relative;
  /* Size by height and let the aspect ratio derive the width. Setting a width and
     clamping max-height instead would squash the painting, because the ratio breaks
     as soon as one axis is clamped. min() keeps it inside both viewport axes: on a
     large monitor it fills the height, on a narrow window the width wins. */
  height: min(calc(100dvh - 56px), calc(100vw / var(--ar, 1.7773)));
  aspect-ratio: var(--ar, 1.7773);
  max-width: 100%;
  margin: 0 auto;
  /* A 64x36 copy of the background, inlined at build time and scaled up. It arrives
     with the HTML, so on a slow link the visitor sees the painting's blue wash
     immediately instead of a blank paper, the objects. This is only a stand-in: the
     real background paints over it as soon as it decodes. */
  background: var(--bg-lqip, none) center / 100% 100% no-repeat;
}

/* The objects wait for the background. On a slow connection the plates are small and
   arrive long before the painting does; without this the collage appeared scattered on
   empty paper, the background. visibility rather than opacity: opacity is in .obj's
   transition list, and a transition that begins before the element has been laid out
   can sit stuck at 0. visibility is not transitioned here, so the swap is instant and
   cannot get caught half-way. */
#stage[data-bg="pending"] .obj { visibility: hidden; }
#stage[data-bg="ready"] .obj { visibility: visible; }

#stage > img.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
  /* Sit above the inline wash so the sharp background covers it the moment it paints. */
  z-index: 0;
}

/* Objects rest blended into the painting and come back to true colour on hover, as the
   handoff note asks. mix-blend-mode: multiply is what makes that honest: the plates
   were painted on white paper, so at rest their paper edges fall away into the
   watercolour underneath instead of reading as pasted-on stickers. Hover switches to
   normal blending, so the object sits on the painting as its own painted thing. */
.obj {
  position: absolute;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform: rotate(var(--rot)) scale(1);
  transform-origin: center;
  transition: transform 180ms ease, filter 220ms ease, opacity 220ms ease;
  /* The plates are opaque watercolour on white paper, and the artist composites them
     MULTIPLY, so the paper falls away into the painting. At rest they take the colour
     of what is underneath; hover switches to normal blending, which is the colour
     restore the handoff asks for. No artificial filter: the file has none. */
  mix-blend-mode: multiply;
  -webkit-tap-highlight-color: transparent;
}
.obj img { display: block; width: 100%; height: 100%; pointer-events: none; }

/* The stand-in art for an object whose own plate recovered blank: invisible at rest,
   switched on with hover, over the top of whatever the object in front is drawing. */
.obj .hover-art {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 180ms ease;
  /* multiply, not normal: the node export arrives on its own white paper, and white is
     the identity under multiply, so the paper disappears into the painting instead of
     showing as a rectangle around the object. */
  mix-blend-mode: multiply;
}
.obj:hover .hover-art, .obj:focus-visible .hover-art { opacity: 1; }
/* These objects sit beneath one that overlaps them, so the hover lift's z-index bump
   is not enough on its own: the overlaying object is a sibling with a higher z. Raise
   the whole stage's stacking for a hovered object that has stand-in art. */
.obj:has(.hover-art):hover, .obj:has(.hover-art):focus-visible { z-index: 1000 !important; }
.obj { overflow: visible; }
/* The plates are <img> elements, which the browser makes draggable by default. Without
   this, pressing and moving dragged a ghost of the artwork out of the painting. The
   stage is a fixed composition, so nothing in it should ever be draggable. */
.obj, .obj img, #stage, #stage img { -webkit-user-drag: none; user-select: none; }

.obj:hover, .obj:focus-visible {
  transform: rotate(var(--rot)) scale(1.09);
  filter: drop-shadow(0 8px 14px rgba(60, 40, 20, 0.35));
  opacity: 1;
  outline: none;
  z-index: 999 !important;
}
.obj:focus-visible { outline: 1px dashed var(--ink); outline-offset: 4px; }

body:has(dialog[open]) { overflow: hidden; }
body:has(dialog[open]) #stage { filter: saturate(0.7) brightness(0.82); transition: filter 300ms; }

/* ---------- reader ---------- */

dialog {
  border: 0;
  padding: 0;
  width: min(660px, 94vw);
  max-height: 88dvh;
  background: var(--paper-2);
  color: var(--ink);
  font-family: var(--f-read);
  box-shadow: 0 30px 80px rgba(20, 14, 8, 0.5);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog::backdrop {
  background: rgba(26, 22, 19, 0.42);
  backdrop-filter: blur(2px);
}

.dlg-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 22px 26px 14px;
  background: var(--paper-2);
  border-bottom: 1px solid rgba(185, 169, 142, 0.55);
}
.dlg-titles { min-width: 0; }
.dlg-head h2 {
  margin: 0;
  font: 400 clamp(1.25rem, 3vw, 1.7rem)/1.2 var(--f-read);
  letter-spacing: -0.01em;
}
.dlg-head .id {
  display: block;
  font: 600 0.66rem/1 var(--f-ui);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #8a7b66;
  margin-bottom: 8px;
}
.close {
  margin-left: 4px;
  border: 0;
  background: none;
  font: 400 1.5rem/1 var(--f-ui);
  cursor: pointer;
  color: #6b5f50;
  padding: 2px 6px;
}
.dlg-head .lang { margin-left: auto; font-family: var(--f-ui); }
.dlg-head .by {
  display: block;
  margin-top: 6px;
  font: 400 0.82rem/1.3 var(--f-ui);
  color: #8a7b66;
}
.tl-note {
  margin: 0 0 1em;
  font: 400 0.86rem/1.45 var(--f-ui);
  color: #8a7b66;
  border-left: 2px solid rgba(185, 169, 142, 0.7);
  padding-left: 0.8em;
}
.close:hover, .close:focus-visible { color: var(--ink); }

.dlg-body { padding: 8px 26px 34px; }
.dlg-body > :first-child { margin-top: 1.1em; }
.dlg-body p { margin: 0 0 1em; }
.dlg-body img { max-width: 100%; height: auto; margin: 1.2em 0; }
.dlg-body blockquote {
  margin: 1.5em 0;
  padding: 0.2em 0 0.2em 1.1em;
  border-left: 2px solid var(--line);
  color: #6b5f50;
  font-style: italic;
}
.dlg-body a { color: inherit; text-underline-offset: 3px; }

.hint {
  position: fixed;
  left: 50%;
  bottom: 16px;
  width: max-content;
  z-index: 5;
  pointer-events: none;
  transform: translateX(-50%);
  font: 500 0.7rem/1 var(--f-ui);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #5d5247;
  background: rgba(247, 241, 230, 0.82);
  padding: 8px 14px;
  border-radius: 20px;
  pointer-events: none;
  transition: opacity 600ms;
}
.hint.gone { opacity: 0; }

/* ---------- about ---------- */

/* Two columns, as the ABOUT-TRANG3 frame lays it out: TEAM at 24.6% of the width and the
   essay running from 42.7% to 98.6%, both under small uppercase kickers. The left ~24%
   stays empty because that is where the botanicals sit in the background. */
.about {
  position: relative;
  min-height: calc(100dvh - 56px);
  margin: 0;
  padding: clamp(36px, 6.2vw, 61px) 1.4% clamp(60px, 8vw, 96px) 0;
  font-family: var(--f-about);
  font-size: clamp(0.86rem, 0.62vw + 0.62rem, 1.02rem);
  line-height: 1.62;
  display: grid;
  grid-template-columns: 42.7% 1fr;
  gap: 0;
  align-items: start;
  color: #247307;
}
/* TEAM sits at 24.6% of the page width, which is 57.6% in from the grid cell's edge. */
.about .ab-team { padding-left: 57.6%; }
.about .kicker {
  display: block;
  font: 600 0.72rem/1 var(--f-ui);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ebe45a;
  margin: 0 0 0.9em;
}
.about h1, .about h2 { display: none; }          /* the kickers carry the headings */
.about p { margin: 0 0 1.05em; }
.about .ab-team, .about .ab-about { min-width: 0; }
.about ul.team { list-style: none; margin: 0; padding: 0; }
.about ul.team li {
  font: 400 clamp(1.05rem, 1.5vw, 1.35rem)/1.9 var(--f-about);
  letter-spacing: 0.01em;
}
.about hr { display: none; }
.about a { color: inherit; text-underline-offset: 3px; }

/* The About page sits on its own scan: blue-grey paper, a cream graph-paper layer and
   scattered botanicals, multiplied in the same way the home scene multiplies its plates.
   Painted on the body because about.js swaps out #about's contents on every language
   change, which would take a child element with it. */
body.about-page {
  background: #a2b3b6 url("/assets/about-bg.webp") center top / cover no-repeat fixed;
}

@media (max-width: 720px) {
  .about {
    grid-template-columns: 1fr;
    gap: 26px;
    padding: 32px 22px 64px;
    font-size: 0.92rem;
  }
  .about .ab-team { padding-left: 0; }
}

@media (max-width: 720px) {
  /* Show the whole composition. Sizing by viewport height made the stage 3.5x the
     screen width on a phone, so the artwork read as a zoomed fragment rather than the
     picture. Fit the width instead; the scene keeps its own aspect and stays whole. */
  #stage {
    height: auto;
    width: 100%;
  }
  .bar .lang { min-height: 44px; padding: 0 14px; }
  .nav-item { padding: 10px; }
  .nav-item .nav-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .obj, .hint, body #stage { transition: none; }
  .obj:hover, .obj:focus-visible { transform: rotate(var(--rot)) scale(1.04); }
}
