/* ============================================================
   Delass 3D Gallery
   Two views live in one document: the gallery index and a single
   piece. body[data-view] decides which one is on screen — the piece
   is a real page, not a modal over the grid.
   ============================================================ */

:root {
  color-scheme: dark;

  --bg: #0a0a0b;
  --ink: #f2f0ed;
  --ink-dim: #a5a19b;
  --ink-faint: #8b867f;
  --accent: #c2a06a;
  --line: rgba(242, 240, 237, 0.11);
  --line-strong: rgba(242, 240, 237, 0.22);

  --serif: "Instrument Serif", Charter, "Bitstream Charter", Georgia,
    "Liberation Serif", "Times New Roman", serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", "Liberation Sans",
    sans-serif;

  --wrap: 1180px;
  --gutter: 28px;
}

* { box-sizing: border-box; }

/* The hidden attribute must beat any display rule set below. */
[hidden] { display: none !important; }

html {
  /* No base font-size override: 1rem stays whatever the reader has set
     in their browser or in iOS text-size settings, and every type size
     below is relative to it. */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* A title or spec value long enough to out-measure its column breaks
     rather than pushing the page sideways. Must be "anywhere", not
     "break-word": only "anywhere" is taken into account when a grid or
     flex track works out its minimum width. */
  overflow-wrap: anywhere;
}

/* Nothing here takes typed input today. If something ever does, Safari
   zooms the page when a control smaller than 16px takes focus — this
   keeps that from happening. */
input,
select,
textarea {
  font-size: max(1rem, 16px);
}

/* No double-tap-to-zoom delay on anything tappable. */
a,
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* height:auto is required alongside the width/height attributes on the
   images — without it the attribute height would be taken literally. */
img { max-width: 100%; height: auto; display: block; }

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  /* Keep clear of the notch and rounded corners in landscape. */
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.skip {
  position: absolute;
  left: -9999px;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  z-index: 100;
}
.skip:focus { left: 12px; top: 12px; }

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 4px;
}

/* small caps label, used for every piece of metadata on the site */
.kicker,
.index-label,
.piece-num,
.specs dt,
.foot {
  font-family: var(--sans);
  font-weight: 400;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

/* ============================================================
   masthead
   ============================================================ */

.masthead { padding-block: clamp(72px, 14vh, 140px) 0; }

.kicker {
  margin: 0 0 24px;
  color: var(--accent);
}

.masthead h1 {
  margin: 0;
  font: 400 clamp(3.5rem, 13vw, 9.25rem)/0.92 var(--serif);
  letter-spacing: -0.015em;
}

.lede {
  max-width: 38ch;
  margin: 32px 0 0;
  color: var(--ink-dim);
  font-size: 1.0625rem;
}

/* ============================================================
   gallery index
   ============================================================ */

#gallery { padding-block: clamp(64px, 12vh, 120px) 0; }

.index-label {
  margin: 0 0 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-faint);
}

.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: clamp(36px, 5vw, 64px) clamp(28px, 4vw, 48px);
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
}

.card { margin: 0; min-width: 0; }

.card-btn {
  display: block;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.thumb {
  position: relative;
  aspect-ratio: 3 / 4;   /* fallback; JS sets the photo's real ratio */
  max-width: 100%;
  overflow: hidden;
  background: #060607;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.7s cubic-bezier(0.2, 0.6, 0.2, 1),
    filter 0.5s ease;
}

/* a hairline that sits over the image edge, so the photo is framed
   without the card looking like a bordered box */
.thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid var(--line);
  pointer-events: none;
  transition: border-color 0.4s ease;
}

.card-btn:hover .thumb img,
.card-btn:focus-visible .thumb img { transform: scale(1.035); }

.card-btn:hover .thumb::after,
.card-btn:focus-visible .thumb::after { border-color: var(--line-strong); }

/* A lone piece would look stranded in a multi-column grid, so it gets
   laid out as a single plate with its label set beside it. */
.grid[data-count="1"] { grid-template-columns: minmax(0, 1fr); }

.grid[data-count="1"] .card-btn {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: clamp(32px, 5vw, 72px);
  align-items: end;
}

.grid[data-count="1"] .card-caption { padding-bottom: 8px; }

.grid[data-count="1"] .card-meta { margin-top: 0; }

.grid[data-count="1"] .card-title {
  font-size: clamp(1.625rem, 3.2vw, 2.375rem);
}

.card-meta {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 14px;
  margin-top: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  transition: border-color 0.4s ease;
}

.card-btn:hover .card-meta { border-color: var(--line-strong); }

.card-num {
  flex: none;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.card-title {
  margin: 0;
  min-width: 0;
  font: 400 clamp(1.3125rem, 2.3vw, 1.625rem)/1.25 var(--serif);
  letter-spacing: 0.003em;
}

.card-sub {
  margin: 12px 0 0;
  color: var(--ink-faint);
  font-size: 0.9375rem;
  font-style: italic;
  font-family: var(--serif);
}

/* ============================================================
   single piece
   ============================================================ */

.piece { padding-block: 32px clamp(56px, 9vh, 104px); }

.piece-nav {
  padding-bottom: clamp(40px, 7vh, 72px);
  border-bottom: 1px solid var(--line);
  margin-bottom: clamp(40px, 7vh, 72px);
}

.back,
.step {
  display: inline-flex;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-dim);
  font: 400 0.75rem/1 var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.3s ease;
}

.back:hover,
.step:hover,
.back:active,
.step:active { color: var(--ink); }

.card-btn:active .thumb::after { border-color: var(--line-strong); }

.back-arrow {
  display: inline-block;
  transition: transform 0.3s ease;
}

.back:hover .back-arrow { transform: translateX(-5px); }

.piece-body {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: clamp(40px, 6vw, 88px);
  align-items: start;
}

.piece-figure { margin: 0; min-width: 0; }

.piece-figure img {
  width: 100%;
  border: 1px solid var(--line);
}

.piece-num {
  margin: 0 0 20px;
  color: var(--accent);
}

.piece-title {
  margin: 0;
  font: 400 clamp(2rem, 4.4vw, 3.25rem)/1.12 var(--serif);
  letter-spacing: -0.005em;
  outline: none;
}

.piece-translit {
  margin: 18px 0 0;
  font: italic 400 clamp(1.125rem, 2vw, 1.3125rem)/1.45 var(--serif);
  color: var(--accent);
}

.piece-blurb {
  margin: 32px 0 0;
  max-width: 46ch;
  color: var(--ink-dim);
  font-size: 1rem;
}

.specs {
  margin: clamp(40px, 6vh, 60px) 0 0;
  display: grid;
  grid-template-columns: minmax(88px, auto) minmax(0, 1fr);
  gap: 0 28px;
}

.specs dt,
.specs dd {
  padding: 15px 0;
  border-top: 1px solid var(--line);
}

.specs dt { color: var(--ink-faint); padding-top: 18px; }

.specs dd {
  margin: 0;
  color: var(--ink);
  font-size: 0.9375rem;
}

.piece-steps {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-top: clamp(64px, 10vh, 112px);
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

/* ============================================================
   call to action
   ============================================================ */

.cta-band {
  margin-top: clamp(56px, 9vh, 104px);
  padding-top: 28px;
  padding-bottom: clamp(64px, 11vh, 120px);
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px clamp(20px, 4vw, 48px);
}

.cta-note {
  margin: 0;
  color: var(--ink-faint);
  font-size: 0.9375rem;
  font-style: italic;
  font-family: var(--serif);
}

.cta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  color: var(--accent);
  text-decoration: none;
  font: 400 0.75rem/1 var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  transition: color 0.3s ease;
}

.cta:hover,
.cta:active { color: var(--ink); }

.cta-arrow {
  display: inline-block;
  transition: transform 0.3s ease;
}

.cta:hover .cta-arrow { transform: translateX(5px); }

.cta-piece {
  margin-top: clamp(28px, 4vh, 44px);
  padding-top: 22px;
  border-top: 1px solid var(--line);
  width: 100%;
}

/* ============================================================
   footer
   ============================================================ */

.foot {
  padding-block: clamp(48px, 8vh, 88px)
    calc(56px + env(safe-area-inset-bottom));
  color: var(--ink-faint);
}

.foot p { margin: 0; }

body[data-view="piece"] .foot { border-top: 1px solid var(--line); }

/* ============================================================
   narrow screens
   ============================================================ */

@media (max-width: 860px) {
  :root { --gutter: 20px; }

  .grid[data-count="1"] .card-btn {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .grid[data-count="1"] .card-caption { padding-bottom: 0; }

  .grid[data-count="1"] .card-meta { margin-top: 20px; }

  .piece-body { grid-template-columns: minmax(0, 1fr); }

  .piece-text { padding-top: 4px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
}

@media (max-width: 520px) {
  .lede { font-size: 1rem; }
  .piece-steps { flex-direction: column; align-items: flex-start; gap: 4px; }
}

/* ============================================================
   motion
   Everything here is inside a no-preference query, so a reader who
   asks for less motion gets the page with none of it.
   ============================================================ */

@media (prefers-reduced-motion: no-preference) {
  /* Entrance: the masthead, then the plates, arriving in order.
     Scoped to body.intro, which JS drops once the run is over. Returning
     from a piece un-hides the gallery, and an un-hidden element restarts
     its animations — without this scope the text would blink out and
     fade back in every time the reader came back. */
  body.intro .kicker,
  body.intro .masthead h1,
  body.intro .lede,
  body.intro .index-label {
    animation: rise 800ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  }

  body.intro .masthead h1 { animation-delay: 60ms; }
  body.intro .lede { animation-delay: 140ms; }
  body.intro .index-label { animation-delay: 220ms; }

  body.intro .card {
    animation: rise 900ms cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
    animation-delay: calc(300ms + var(--i, 0) * 90ms);
  }

  @keyframes rise {
    from { opacity: 0; transform: translate3d(0, 14px, 0); }
    to { opacity: 1; transform: none; }
  }

  /* the press itself, since hover says nothing on a touch screen */
  .card-btn:active .thumb img { transform: scale(0.992); }
  .back:active .back-arrow { transform: translateX(-5px); }

  /* The photo carries across from the grid to the piece page. The name
     is applied from JS at both ends, and withheld when either end would
     be off screen — see setPhotoNames(). */
  ::view-transition-group(piece-photo) {
    animation-duration: 520ms;
    animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
  }

  ::view-transition-old(piece-photo),
  ::view-transition-new(piece-photo) {
    /* the two photos are the same picture: hold both at full opacity so
       it reads as one object moving, not one fading into another */
    animation: none;
    mix-blend-mode: normal;
    height: 100%;
    object-fit: cover;
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 380ms;
    animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
  }
}

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