/* Zach Lewis — base styles
   ------------------------------------------------------------------ */

@font-face {
  font-family: "Special Elite";
  src: url("../fonts/special-elite.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper:   #faf9f6;   /* near-white with a trace of warmth */
  --paper-2: #ebe8e1;   /* deeper paper tone for image stand-ins */
  --ink:     #1b1a17;   /* warm off-black */
  --ink-soft: rgba(27, 26, 23, 0.62);

  /* Typewriter stack: self-hosted Special Elite, then Apple's American
     Typewriter, then Courier. */
  --font: "Special Elite", "American Typewriter", "Courier Prime", "Courier New", Courier, monospace;

  --gutter: clamp(20px, 5vw, 64px);
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* One painting per screen. A picture keeps its own proportions inside
     this box; a placeholder tile is 4:5 at the box height. */
  --art-max-w: min(72vw, 1100px);
  --art-max-h: 62vh;
  --tile-w: calc(var(--art-max-h) * 0.8);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  /* Settle on one painting at a time. Change to "y proximity" for a looser feel. */
  scroll-snap-type: y mandatory;
}

body {
  min-height: 100vh;
}

/* Keep the page still while the viewer is open. */
body:has(.viewer[open]) {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ==================================================================
   Gallery: tall section, pinned stage, sideways track
   ================================================================== */

.gallery {
  --slides: 1;          /* set by JS from the tile count */
  --slide-w: 100vw;     /* set by JS to the stage width in px */
  position: relative;
  height: calc(100vh + (var(--slides) - 1) * var(--slide-w));
}

/* The stage: pinned for the whole scroll, carrying the painted ZL.
   The mark is a photograph of the real brushwork (1560 x 692, whites
   toned to --paper so its edges dissolve into the page). */
.gallery__sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: clip;       /* clip, not hidden: focus must never scroll this box */
  background-color: var(--paper);
  background-image: url("../img/hero-mark.jpg");
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: cover;
}

/* Mark sizing
   Landscape, up to the photo's own ratio: the whole mark at full width,
   centred, with paper above and below. Wider than the photo (ultrawide):
   cover, which trims a little from top and bottom.
   Portrait: the whole mark at full width near the top, and the painting
   sits in the space below it rather than hiding it. */

@media (min-aspect-ratio: 1/1) and (max-aspect-ratio: 1560/692) {
  .gallery__sticky {
    background-size: 100% auto;
  }
}

@media (max-aspect-ratio: 1/1) {
  .gallery__sticky {
    background-size: 100% auto;
    background-position: 50% 10%;
  }
}

/* Snap stops: invisible, one per slide, positioned by JS. */
.snap {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.snap > i {
  position: absolute;
  left: 0;
  display: block;
  width: 1px;
  height: 100vh;
  scroll-snap-align: start;
}

/* The track of paintings, moved sideways by JS. */
.track {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  height: 100%;
  width: calc(var(--slides) * var(--slide-w));
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  will-change: transform;
  pointer-events: none;           /* let the mark show through */
}

.slide {
  flex: 0 0 var(--slide-w);
  width: var(--slide-w);
  height: 100%;
  display: grid;
  place-items: center;
}

.slide > * {
  pointer-events: auto;
}

@media (max-aspect-ratio: 1/1) {
  :root {
    --art-max-w: 84vw;
    --art-max-h: 50vh;
  }

  .slide {
    padding-top: 24vh;            /* below the mark */
  }
}

/* Slide counter, bottom centre. Difference blend keeps it legible
   whether it lands on paper or on a stroke of the mark. */
.counter {
  position: absolute;
  left: 50%;
  bottom: clamp(16px, 3vh, 32px);
  z-index: 2;
  margin: 0;
  transform: translateX(-50%);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: #fff;
  mix-blend-mode: difference;
  pointer-events: none;
  white-space: nowrap;
}

.counter__sep {
  margin: 0 0.5em;
  opacity: 0.6;
}

/* ==================================================================
   Tiles (one per slide)
   ================================================================== */

.tile {
  position: relative;
}

.tile__button {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  display: block;
  width: fit-content;
  cursor: pointer;
  text-align: inherit;
  transform: translateZ(0);
  box-shadow: 0 16px 40px -18px rgba(27, 26, 23, 0.4);
  transition:
    transform 0.45s var(--ease-out),
    box-shadow 0.45s var(--ease-out);
}

.tile__button:hover,
.tile__button:focus-visible {
  transform: scale(1.03);
  box-shadow: 0 32px 64px -28px rgba(27, 26, 23, 0.5);
}

.tile__button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 6px;
}

.tile__media {
  position: relative;
  display: block;
  background: var(--paper-2);
  overflow: hidden;
}

/* A placeholder tile (no picture yet) is 4:5. */
.tile__media:not(:has(img)) {
  width: var(--tile-w);
  aspect-ratio: 4 / 5;
}

/* A tile with an artwork takes the picture's own proportions, which the
   <img> width and height attributes declare before the file loads. */
.tile__media img {
  display: block;
  width: auto;
  height: auto;
  max-width: var(--art-max-w);
  max-height: var(--art-max-h);
}

.tile__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ==================================================================
   Viewer: full-screen artwork + statement + price
   ================================================================== */

.viewer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  overflow: auto;
  overscroll-behavior: contain;
}

.viewer::backdrop {
  background: rgba(27, 26, 23, 0.35);
}

.viewer__close {
  position: fixed;
  top: clamp(12px, 2vw, 24px);
  right: clamp(12px, 2vw, 24px);
  z-index: 2;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  appearance: none;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.3s var(--ease-out), transform 0.3s var(--ease-out);
}

.viewer__close:hover {
  background: var(--paper-2);
  transform: scale(1.06);
}

.viewer__close:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.viewer__inner {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.6fr);
  gap: clamp(32px, 5vw, 80px);
  align-items: center;
  padding: clamp(72px, 10vh, 96px) var(--gutter) clamp(40px, 8vh, 80px);
}

.viewer__figure {
  margin: 0;
  min-width: 0;
  display: grid;
  place-items: center;
}

.viewer__media {
  display: grid;
  place-items: center;
  width: 100%;
}

.viewer__media img {
  display: block;
  max-width: 100%;
  max-height: 78dvh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.viewer__placeholder {
  height: 78dvh;
  aspect-ratio: 4 / 5;
  max-width: 100%;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.viewer__text {
  max-height: 78dvh;
  overflow: auto;
  padding-right: 4px;
}

.viewer__title {
  margin: 0 0 8px;
  font-size: clamp(24px, 2.6vw, 34px);
  font-weight: 400;
  line-height: 1.15;
}

.viewer__meta {
  margin: 0 0 clamp(20px, 3vw, 32px);
  font-size: 13px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.viewer__meta:empty {
  display: none;
}

.viewer__statement {
  font-size: clamp(15px, 1.2vw, 17px);
  line-height: 1.65;
}

.viewer__statement p {
  margin: 0 0 1em;
}

.viewer__statement p:last-child {
  margin-bottom: 0;
}

/* Price + Buy */
.viewer__purchase {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px 24px;
  margin-top: clamp(24px, 3vw, 36px);
  padding-top: clamp(20px, 2.5vw, 28px);
  border-top: 1px solid rgba(27, 26, 23, 0.14);
}

.viewer__pricing {
  display: grid;
  gap: 6px;
}

.viewer__price-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.viewer__price {
  font-size: clamp(20px, 1.8vw, 24px);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.viewer__buy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 128px;
  padding: 14px 28px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 999px;
  transition: transform 0.3s var(--ease-out), background 0.3s var(--ease-out);
}

.viewer__buy:hover {
  background: #000;
  transform: translateY(-1px);
}

.viewer__buy:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.viewer__note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Stack the viewer on narrow screens. */
@media (max-width: 820px) {
  .viewer__inner {
    grid-template-columns: 1fr;
    align-items: start;
    align-content: start;
    gap: 28px;
    padding-top: 80px;
  }

  .viewer__media img {
    max-height: 70dvh;
  }

  .viewer__placeholder {
    width: 100%;
    height: auto;
    max-height: 70dvh;
  }

  .viewer__text {
    max-height: none;
    overflow: visible;
  }
}

/* Open / close fade for browsers that support @starting-style. */
.viewer[open] {
  opacity: 1;
  transition: opacity 0.35s var(--ease-out), overlay 0.35s allow-discrete, display 0.35s allow-discrete;
}

@starting-style {
  .viewer[open] {
    opacity: 0;
  }
}

/* ==================================================================
   Motion preferences
   ================================================================== */

@media (prefers-reduced-motion: reduce) {
  .tile__button,
  .viewer__close,
  .viewer__buy,
  .viewer[open] {
    transition: none;
  }

  .tile__button:hover,
  .tile__button:focus-visible,
  .viewer__buy:hover {
    transform: none;
  }
}
