/* =========================================================
   PANTRY work section
   Projects on the page's own grid: the vertical page lines run straight
   through, and the horizontal lines are the section-edge hairline with
   its plus marks, one per row. Rectangles span whole cells.
   Motion lives in scripts/work.js. Values come from tokens.css; the ones
   below only apply to this section.
   ========================================================= */

.work {
  /* Space above the label and after the section. */
  --work-pad-top: 25svh;
  --work-pad-bottom: 30svh;
  /* One grid row, as a share of one bay's width. Rows grow if a caption
     needs more. */
  --work-row-ratio: 0.7;
  /* One bay, a satellite on mobile: share of the bay it takes, hung
     from one line. */
  --work-sat-share: 62%;
  /* Placeholder hatch: line spacing. */
  --work-hatch-gap: var(--space-8);
  /* Reveal: image scale at the start (read by JS). */
  --work-reveal-scale: 1.15;
  /* Caption lines rise from below their mask; the mask leaves this much
     room around a line so nothing (the button border, a focus ring) is cut. */
  --work-line-slack: var(--space-8);
  /* Hover: cover to video. */
  --work-hover-duration: var(--duration);
  --work-hover-scale: 1.04;
  --work-progress-duration: calc(var(--duration) * 12);
  /* Red marker: twice the stroke of a hairline, the page plus size. */
  --work-marker-stroke: calc(var(--line-width) * 2);
  --work-stamp-duration: calc(var(--duration) * 1.5);
  --work-stamp-scale: 1.8;
  /* Reduced motion fade. */
  --work-fade: calc(var(--duration) * 2);

  padding: var(--work-pad-top) 0 var(--work-pad-bottom);
  overflow-x: clip;
}

/* ---------- Grid ----------
   One column per bay, no gaps: cell edges are the page lines. The body is
   a size container, so a row can be measured from the bay width. Rows are
   set by JS (count) and close with a zero-height row for the last line. */

.work-body {
  container-type: inline-size;
  margin-top: var(--space-96);
}

.work-grid {
  --work-row: calc(100cqi / var(--bays) * var(--work-row-ratio));
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--bays), minmax(0, 1fr));
  gap: 0;
}

/* Projects lay their parts straight onto the grid. */
.work-project {
  display: contents;
}

/* Horizontal line at the top of a row: the same hairline as a section
   edge (.has-lines), across the whole page, with the same plus marks. */
.work-rule {
  position: relative;
  grid-column: 1 / -1;
  align-self: start;
  height: 0;
  pointer-events: none;
}

.work-rule::before {
  content: "";
  position: absolute;
  z-index: -2;
  top: 0;
  left: calc(50% - 50vw);
  width: 100vw;
  height: var(--line-width);
  background: var(--color-guide);
}

/* ---------- Rectangles ----------
   Each spans whole cells. Its border sits on the lines: the right and
   bottom edges reach one line width over, onto the next line, except in
   the last column, whose line sits inside the container edge. */

.work-rect {
  position: relative;
  display: block;
  margin-right: calc(var(--line-width) * -1);
  margin-bottom: calc(var(--line-width) * -1);
  will-change: transform;
}

.work-rect.is-last-col {
  margin-right: 0;
}

/* One bay: the satellite hangs from the left or right line. */
.work-rect.is-start,
.work-rect.is-end {
  width: var(--work-sat-share);
}

.work-rect.is-start {
  justify-self: start;
}

.work-rect.is-end {
  justify-self: end;
}

.work-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  clip-path: inset(0 0 100% 0);
}

.work-media {
  position: absolute;
  inset: 0;
  display: block;
  transform: scale(var(--work-reveal-scale));
}

.work-cover,
.work-video {
  position: absolute;
  inset: 0;
  display: block;
}

.work-img,
.work-video-el {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

/* Placeholders: the site placeholder with a fine diagonal hatch and a
   mono label. Hidden once the real file has loaded. */
.work-ph.placeholder {
  position: absolute;
  inset: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    repeating-linear-gradient(135deg, var(--hatch) 0 var(--line-width), transparent var(--line-width) var(--work-hatch-gap)),
    var(--hatch-ground);
}

.work-ph--cover {
  --hatch: var(--color-rule);
  --hatch-ground: var(--color-surface-subtle);
}

.work-ph--video {
  --hatch: var(--color-guide-on-ink);
  --hatch-ground: var(--color-ink);
  border-color: var(--color-ink);
}

.work-ph-label {
  padding: var(--space-4) var(--space-8);
  background: var(--hatch-ground);
}

.work-ph--video .work-ph-label {
  color: var(--color-text-on-ink-secondary);
}

.has-image > .work-ph,
.has-video .work-ph--video {
  visibility: hidden;
}

/* ---------- Lead: cover, then video on hover ---------- */

.work-lead {
  color: inherit;
}

@media (hover: hover) and (pointer: fine) {
  .work-lead {
    cursor: none;
  }
}

.work-video {
  clip-path: inset(0 100% 0 0);
  transform: scale(var(--work-hover-scale));
  transition:
    clip-path var(--work-hover-duration) var(--ease),
    transform var(--work-hover-duration) var(--ease);
}

.work-lead.is-playing .work-video {
  clip-path: inset(0);
  transform: none;
}

/* Thin progress bar so the placeholder shows it is "playing". */
.work-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--work-marker-stroke);
  background: var(--color-red-signal);
  transform: scaleX(0);
  transform-origin: left center;
}

.work-lead.is-playing .work-progress {
  animation: work-progress var(--work-progress-duration) linear infinite;
}

.has-video .work-progress {
  display: none;
}

@keyframes work-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* ---------- Caption ----------
   In its own cell, clear of the lines by the text cell padding. */

.work-caption {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-8);
  min-width: 0;
  padding: var(--cell-pad);
}

.work-caption .item-title {
  margin-top: var(--space-4);
}

/* .btn .btn--secondary .btn--small from components.css. */
.work-caption .btn {
  margin-top: var(--space-16);
}

/* Each line rises out of a mask. The mask is a clip with slack on every
   side, so a line is hidden only while it sits below, and once the
   caption is shown the clip is gone. */
.work-line {
  display: block;
  max-width: 100%;
  clip-path: inset(calc(var(--work-line-slack) * -1));
}

.work-caption.is-shown .work-line {
  clip-path: none;
}

.work-line-inner {
  display: block;
  transform: translate3d(0, calc(100% + var(--work-line-slack)), 0);
  will-change: transform;
}

/* ---------- Red marker ----------
   The page plus mark in signal red, a little heavier. It sits on a line
   crossing; the counter rests beside it in the space above the line. */

.work-marker {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  pointer-events: none;
  will-change: transform;
}

.work-marker-plus {
  position: relative;
  display: block;
  width: var(--plus-size);
  height: var(--plus-size);
  background:
    linear-gradient(var(--color-red-signal), var(--color-red-signal)) center / 100% var(--work-marker-stroke) no-repeat,
    linear-gradient(var(--color-red-signal), var(--color-red-signal)) center / var(--work-marker-stroke) 100% no-repeat;
}

.work-marker-plus::after {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--line-width) solid var(--color-red-signal);
  opacity: 0;
}

.work-marker.is-stamped .work-marker-plus {
  animation: work-stamp-press var(--work-stamp-duration) var(--ease);
}

.work-marker.is-stamped .work-marker-plus::after {
  animation: work-stamp-ring var(--work-stamp-duration) var(--ease);
}

@keyframes work-stamp-press {
  0% { transform: scale(1); }
  30% { transform: scale(0.6); }
  100% { transform: scale(1); }
}

@keyframes work-stamp-ring {
  0% { opacity: 1; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(var(--work-stamp-scale)); }
}

/* Counter: the mono label, right of the column line and above the row
   line, clear of both by the cell padding. Shown while the marker rests. */
.work-counter {
  position: absolute;
  bottom: calc(var(--plus-size) / 2 + var(--cell-pad) / 2);
  left: calc(var(--plus-size) / 2 + var(--cell-pad));
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

.work-marker.is-resting .work-counter {
  opacity: 1;
}

/* ---------- Cursor tag ---------- */

.work-cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  will-change: transform;
}

.work-cursor-text {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-4) var(--space-8);
  background: var(--color-ink);
  color: var(--color-canvas);
  white-space: nowrap;
  opacity: 0;
  transform: translate(var(--space-12), var(--space-24));
  transition:
    opacity var(--shape-label-duration) var(--ease),
    transform var(--shape-label-duration) var(--ease);
}

.work-cursor.is-visible .work-cursor-text {
  opacity: 1;
  transform: translate(var(--space-12), var(--space-12));
}

/* The only blue on the page. */
.work-cursor-dot {
  width: calc(var(--space-4) + var(--line-width) * 2);
  height: calc(var(--space-4) + var(--line-width) * 2);
  background: var(--color-accent-signal);
}

@media (hover: none), (pointer: coarse) {
  .work-cursor {
    display: none;
  }
}

/* ---------- Reduced motion ----------
   Same grid, nothing scrubbed: rectangles and captions fade in. */

.work.is-reduced .work-clip,
.work.is-reduced .work-line {
  clip-path: none;
}

.work.is-reduced .work-media,
.work.is-reduced .work-line-inner {
  transform: none;
}

.work.is-reduced .work-rect,
.work.is-reduced .work-caption {
  opacity: 0;
  transition: opacity var(--work-fade) var(--ease);
}

.work.is-reduced .is-in {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .work-video,
  .work-cursor-text,
  .work-counter {
    transition: none;
  }

  .work-marker.is-stamped .work-marker-plus,
  .work-marker.is-stamped .work-marker-plus::after {
    animation: none;
  }
}
