/* ============================================================
   Pasture — Project Detail Page
   ============================================================ */

:root {
  --color-primary: #333A3E;
  --color-secondary: #88959D;
  --color-tertiary: #dadfe2;
  --color-bg-lightest: #FCFDFD;

  --pasture-badge-width: 24px;

  /* Typography — sizes/weights from tokens.css; page-specific overrides here */
  --tracking-lg: -0.152px;
  --tracking-sm: 0px;

  /* Grid */
  --margin: 20px;
  --gutter: 20px;
  --top-offset: max(40px, 20svh);

  /* Range label typewriter */
  --typein-duration: 150ms;
  --typein-stagger: 12ms;
  --typeout-duration: 30ms;
  --typeout-stagger: 6ms;
  --type-spacing-wide: 0.22em;
}

/* ── Reset ─────────────────────────────────────────────────── */

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

/* ── Page ──────────────────────────────────────────────────── */

body {
  background: var(--color-bg-lightest);
  font-family: var(--font-family);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ── Page Transitions (MPA View Transitions API) ───────────
     Mirrors style.css. Old page dissolves, new page's .enter
     animations handle the content entrance.
   ─────────────────────────────────────────────────────────── */

@view-transition {
  navigation: auto;
}

@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

::view-transition-old(root) {
  animation: vt-fade-out 400ms ease forwards;
}

::view-transition-new(root) {
  animation: vt-fade-in 400ms ease forwards;
}

/* ── Entrance animation ─────────────────────────────────────
     Identical keyframe values to style.css. These files are
     never loaded together so there is no naming conflict.
   ─────────────────────────────────────────────────────────── */

@keyframes enter {
  from {
    opacity: 0;
    filter: blur(6px);
    -webkit-filter: blur(6px);
  }

  to {
    opacity: 1;
    filter: blur(0px);
    -webkit-filter: blur(0px);
  }
}

.enter {
  animation: enter 350ms ease-out both;
  -webkit-animation: enter 350ms ease-out both;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: opacity, filter;
}

/* ── 6-column grid ─────────────────────────────────────────── */
/* Identical column count, gap, and margin to the homepage grid
   (.page in style.css) so columns align on page navigation.  */

.p-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  column-gap: var(--gutter);
  padding: 0 var(--margin);
  padding-top: var(--top-offset);
  /* mirrors homepage minmax(40px, 20svh) */
  padding-bottom: 120px;
  align-items: start;

  /* Base typography — cascades to all children */
  font-family: var(--font-family);
  font-size: var(--font-size-lg);
  font-weight: var(--font-regular);
  line-height: var(--line-height-lg);
  letter-spacing: var(--tracking-lg);
  color: var(--color-primary);
}

/* ── Col 1: logo (back) + year ─────────────────────────────── */

.p-meta {
  grid-column: 1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: sticky;
  top: var(--top-offset);
  align-self: start;
}

/* The homepage logo PNG is white on transparent — designed for
   the dark homepage bg. Convert to a readable gray here.     */
.p-back {
  display: block;
  line-height: 0;
  color: var(--color-tertiary);
  transition: color 501ms ease;
}

.p-back:hover {
  color: var(--color-primary);
}

.p-year {
  color: var(--color-secondary);
  white-space: nowrap;
}

/* ── Cols 2–3: project info ────────────────────────────────── */

.p-info {
  grid-column: 2 / 4;
  display: flex;
  flex-direction: column;
  gap: 80px;
  align-self: start;
}

.p-info.is-sticky {
  position: sticky;
  top: var(--top-offset);
}

.p-title {
  font-family: var(--font-family);
  font-size: var(--font-size-lg);
  font-weight: var(--font-medium);
  line-height: var(--line-height-lg);
  letter-spacing: var(--tracking-lg);
}

.p-title-group {
  display: contents;
  /* transparent to the flex layout on desktop */
}

.p-year-mobile {
  display: none;
}

.p-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.p-label {
  color: var(--color-secondary);
}

.p-services {
  display: flex;
  flex-direction: column;
}

.p-services p {
  margin: 0;
}

.p-credits {
  display: flex;
  flex-direction: column;
}

.p-credit-row {
  display: flex;
  gap: 2px;
  align-items: center;
  position: relative;
}

.p-credit-role {
  color: var(--color-secondary);
}

.p-pasture-badge {
  display: inline-flex;
  align-items: center;
  color: var(--color-tertiary);
  width: var(--pasture-badge-width);
  position: absolute;
  height: 100%;
  left: calc((var(--pasture-badge-width) * -1) - 4px);
  top: 53%;
  transform: translateY(-50%);
}

.p-pasture-badge svg {
  width: var(20px);
  height: auto;
}

@media (max-width: 768px) {
  .p-pasture-badge {
    position: static;
    transform: none;
  }
}

.p-description {
  line-height: 1.24;
}

.p-description p,
.p-description h1,
.p-description h2,
.p-description figure {
  margin: 0;
}

/* ── Link row ──────────────────────────────────────────────── */

.p-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.p-live-dot {
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #0cbe4a;
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

.p-link,
.p-link:visited {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: solid;
  text-decoration-color: var(--color-tertiary);
  text-underline-offset: 6px;
  text-decoration-thickness: 2px;
  transition: text-decoration-color 501ms;
}

.p-link:hover {
  text-decoration-color: #8a9095;
}

.p-list {
  gap: 4px;
}

.p-link-arrow {
  display: inline-block;
  text-decoration: none;
  color: var(--color-secondary);
  margin-left: 0.3em;
}

/* ── Range credit line ──────────────────────────────────────── */

.p-range-credit {
  font-size: var(--font-size-sm);
  line-height: normal;
  letter-spacing: var(--tracking-sm);
  color: var(--color-secondary);
  max-width: 430px;
}

.p-range-credit strong {
  font-weight: var(--font-medium);
}

.p-range-insignia {
  display: inline-block;
  height: 13px;
  width: auto;
  vertical-align: middle;
  position: relative;
  top: -1px;
  margin: 0 2px;
}

/* ── Cols 4–6: media gallery ─────────────────────────────── */

.p-media {
  grid-column: 4 / 7;
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-self: start;
}

.p-media-item {
  position: relative;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0px 2px 36px 0px rgba(0, 0, 0, 0.07);
  overflow: hidden;
  line-height: 0;
}

.p-media-item img,
.p-media-item video {
  display: block;
  width: 100%;
  height: auto;
}

/* ── iPhone Frame mockup ─────────────────────────────────────
   Tweak these CSS variables until the content lines up with
   your PNG frame exactly.
   ──────────────────────────────────────────────────────────── */

:root {
  /* Aspect ratio of the iPhone-Frame.png (width ÷ height).
     Measure your PNG and update: e.g. 390/844 for a standard iPhone */
  --iphone-frame-aspect: 393 / 852;

  /* How far the screen window sits from each edge of the frame PNG.
     Store as plain NUMBERS (no unit) — both the gallery and lightbox
     read these and apply them as % of the frame WIDTH, which is the
     consistent reference dimension in both contexts. */
  --iphone-screen-top: 3.9;
  --iphone-screen-bottom: 13;
  --iphone-screen-left: 8.4;
  --iphone-screen-right: 8.3;

  /* Corner radius of the screen window, as % of the frame's WIDTH.
     Uses container query units (cqi) so it scales correctly at any size —
     unlike plain %, which is relative to the element's own dimensions and
     creates oval corners on a portrait rectangle. */
  --iphone-screen-radius: 6.5cqi;
}

.p-media-item--iphone {
  /* Adjust these to shrink/grow the phone in the gallery column */
  --iphone-gallery-width: 55%;
  --iphone-gallery-width-mobile: 90%;

  border: none;
  box-shadow: none;
  overflow: visible;
  background: transparent;
  width: var(--iphone-gallery-width);
  margin: 0 auto;
  /* Container context lives here so cqi units in .iphone-screen resolve
     correctly, while .iphone-wrap is free to establish its height via
     aspect-ratio without containment interference. */
  container-type: inline-size;
}

.iphone-wrap {
  position: relative;
  aspect-ratio: var(--iphone-frame-aspect);
  width: 100%;
}

.iphone-screen {
  position: absolute;
  /* Gallery: containing block has height:auto (from aspect-ratio), so CSS resolves
     top/bottom % relative to the WIDTH — hence calc(n * 1%) = n% of width. */
  top: calc(var(--iphone-screen-top) * 1%);
  bottom: calc(var(--iphone-screen-bottom) * 1%);
  left: calc(var(--iphone-screen-left) * 1%);
  right: calc(var(--iphone-screen-right) * 1%);
  overflow: hidden;
  border-radius: var(--iphone-screen-radius);
  background: #000;
}

.iphone-screen .iphone-content {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.iphone-bezel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  z-index: 2;
  display: block;
}

/* Cursor on framed items */
.p-media-item--iphone {
  cursor: zoom-in;
}

/* ── Gallery loading spinners ─────────────────────────────── */

/* Regular media items: reserve height and show a centered spinner */
.p-media-item.is-loading {
  min-height: 220px;
}

.p-media-item.is-loading::after,
.iphone-screen.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  animation: media-spin 0.65s linear infinite;
  z-index: 1;
  pointer-events: none;
}

/* Light spinner on the white card background */
.p-media-item.is-loading::after {
  border: 2px solid rgba(51, 58, 62, 0.10);
  border-top-color: rgba(51, 58, 62, 0.40);
}

/* Dark spinner on the black iPhone screen background */
.iphone-screen.is-loading::after {
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: rgba(255, 255, 255, 0.65);
}

/* Hide media while loading so alt-text placeholder text doesn't appear */
.p-media-item.is-loading img:not(.iphone-bezel),
.p-media-item.is-loading video,
.iphone-screen.is-loading .iphone-content {
  opacity: 0;
}

@keyframes media-spin {
  to { transform: rotate(360deg); }
}

/* ── Wide screens (≥1800px) ────────────────────────────────── */

@media (min-width: 1800px) {
  .p-media {
    grid-column: 4 / 6;
  }
}

/* ── Mobile (≤768px) ───────────────────────────────────────── */

@media (max-width: 768px) {

  .p-year {
    display: none;
  }

  /* align-self: start on the desktop grid makes the media column
     shrink-wrap its width. In the mobile flex layout this creates a
     circular dependency for children with percentage widths (iPhone
     frames) — resolved to 0. Override to stretch like the other columns. */
  .p-media {
    align-self: stretch;
  }

  .p-media-item--iphone {
    width: var(--iphone-gallery-width-mobile);
  }

  .p-title {
    font-size: var(--font-size-lg);
  }

  .p-section {
    gap: 8px;
  }

  .p-list {
    gap: 2px;
  }

  .p-grid {
    display: flex;
    flex-direction: column;
    padding: 80px 24px 80px;
    gap: 40px;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-sm);
    letter-spacing: var(--tracking-sm);
  }

  .p-meta {
    position: static;
  }

  .p-info {
    gap: 40px;
    position: static !important;
  }

  .p-title-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .p-year-mobile {
    display: block;
    color: var(--color-secondary);
  }
}