.project-main {
  padding-block: var(--space-3) var(--space-8);
}

/* Back link */
.back-link {
  display: inline-block;
  margin-bottom: var(--space-3);
  font-size: var(--font-caption);
  color: var(--color-fg);
  text-decoration: none;
}

.back-link:hover,
.back-link:focus-visible {
  text-decoration: underline;
}

/* Carousel — breaks out of the constrained .wrapper column to go full
   viewport width, while staying structurally inside <main>. */
.carousel-breakout {
  width: 100vw;
  position: relative;
  left: 50%;
  margin-left: -50vw;
}

.carousel {
  position: relative;
  height: 60vh;
  overflow: hidden;
  background: #111111;
}

@media (max-width: 599px) {
  .carousel {
    height: 45vh;
  }
}

.carousel-viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.carousel-track {
  display: flex;
  height: 100%;
  transition: transform 0.35s ease;
  will-change: transform;
}

.carousel-slide {
  flex: 0 0 100%;
  height: 100%;
}

.carousel-slide img,
.carousel-slide video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border: none;
  outline: none;
  box-shadow: none;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-fg);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-fg);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.carousel-arrow-prev {
  left: var(--space-2);
}

.carousel-arrow-next {
  right: var(--space-2);
}

.carousel-dots {
  position: absolute;
  bottom: var(--space-2);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--space-1);
}

.carousel-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 1px solid var(--color-fg);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.carousel-dot.is-active {
  background: var(--color-fg);
}

/* Single-image projects: no arrows, no dots */
.carousel.single-image .carousel-arrow,
.carousel.single-image .carousel-dots {
  display: none;
}

/* Horizontal label block — same spec-sheet language as the index cards,
   laid out as one row of 6 cells instead of a stacked card. Rounded
   corners + overflow:hidden on the container clip the grid's corners
   cleanly; dividers are border-right on every cell but the last, so the
   container's own border isn't doubled up against a cell's own edge. */
.project-label {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  margin-top: var(--space-4);
  border: 1px solid var(--color-fg);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.project-label-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  border-right: 2px solid var(--color-fg);
}

.project-label-cell:last-child {
  border-right: none;
}

.project-label-cell-icon-left {
  padding-left: 28px;
}

.project-label-cell-icon-right {
  padding-right: 28px;
}

.label-icon {
  position: absolute;
  top: var(--space-1);
  display: block;
  width: 14px;
  height: 11px;
}

.project-label-cell-icon-left .label-icon {
  left: var(--space-1);
}

.project-label-cell-icon-right .label-icon {
  right: var(--space-1);
}

/* Key row and value row are separated by their own hairline — the same
   two-tier label/value split as the index card's header bar. Drawn as a
   pseudo-element rather than a border: since this element already fills
   100% of the cell's own width (padding only insets its text, not its
   box), an absolutely-positioned ::after reaches both edges cleanly with
   no margin/width tricks needed. */
.project-label-key {
  position: relative;
  overflow: visible;
  display: block;
  padding: var(--space-2) var(--space-2) var(--space-1);
  font-size: calc(var(--font-caption) * 0.8);
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.project-label-key::after {
  content: '';
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: var(--color-fg);
}

/* Icon cells inset their content (28px reserved for the globe), which
   would leave the key's hairline stopping short of the cell edge —
   stretch it back out so the line always runs wall to wall. */
.project-label-cell-icon-left .project-label-key::after {
  left: -28px;
}

.project-label-cell-icon-right .project-label-key::after {
  right: -28px;
}

.project-label-value {
  font-size: var(--font-caption);
  font-weight: 700;
  overflow-wrap: break-word;
  padding: var(--space-1) var(--space-2) var(--space-2);
}

@media (max-width: 599px) {
  .project-label {
    grid-template-columns: repeat(2, 1fr);
  }

  .project-label-cell:nth-child(2n) {
    border-right: none;
  }

  .project-label-cell:nth-child(n+3) {
    border-top: 2px solid var(--color-fg);
  }
}

/* Description block */
.project-description {
  max-width: 720px;
  margin-inline: auto;
  padding-top: var(--space-5);
  font-size: var(--font-body);
  line-height: 1.6;
}

/* Section title — only rendered when the gallery has content. Border
   matches the card/label-bar border weight (2px) established elsewhere. */
.project-section-title {
  display: block;
  width: 100%;
  margin-top: var(--space-5);
  margin-bottom: var(--space-3);
  padding-top: var(--space-3);
  border-top: 2px solid var(--color-fg);
  text-align: left;
  text-transform: uppercase;
  font-family: var(--font-mono);
  font-size: var(--font-caption);
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* Reveal animation only runs when motion is allowed — under
   prefers-reduced-motion: reduce, the title just shows normally with no
   opacity/transform state to fight against. */
@media (prefers-reduced-motion: no-preference) {
  .project-section-title {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.6s ease, transform 0.6s ease;
  }

  .project-section-title.is-visible {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Gallery — justified rows. Each row is a flex container and each cell's
   flex-grow equals the media's aspect ratio (set by JS as --cell-ratio),
   so widths are distributed proportionally to ratio and every item in a
   row renders at exactly the same height: h = (rowWidth - gap) / Σratios.
   No holes, no stretching, no per-case filler guessing.
   aspect-ratio on the cell reserves the correct box height before the
   media loads, so nothing shifts as images/videos arrive. */
.project-gallery {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.project-gallery-row {
  display: flex;
  gap: var(--space-3);
  align-items: stretch;
}

.project-gallery-cell {
  flex: var(--cell-ratio, 1) 1 0%;
  aspect-ratio: var(--cell-ratio, auto);
  min-width: 0;
}

.project-gallery-cell img,
.project-gallery-cell video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border: none;
  outline: none;
  box-shadow: none;
}

/* Reduced in-cell rendering (project.json "display_scale"). The cell
   keeps its full layout box; only the media inside shrinks and centers,
   so lower-res assets can sit below their native pixel size and stay
   sharp on retina screens. */
.project-gallery-cell.media-scaled {
  display: flex;
  align-items: center;
  justify-content: center;
}

.project-gallery-cell.media-scaled img,
.project-gallery-cell.media-scaled video {
  width: calc(var(--media-scale, 1) * 100%);
  height: calc(var(--media-scale, 1) * 100%);
  object-fit: contain;
}

/* Scroll-linked rotation (project.json "scroll_rotate"). contain instead
   of cover so nothing crops while tilted; corners may swing slightly
   outside the cell, which is the intended loose, physical feel — export
   these images with a transparent background so the overlap stays clean. */
.project-gallery-cell img.scroll-rotate,
.project-gallery-cell video.scroll-rotate {
  object-fit: contain;
  will-change: transform;
}

/* Animated catalog-ID tile — shares a row with a lone trailing item,
   sized by the same ratio math as any image cell. Borderless, same
   treatment as the footer name. */
.project-gallery-filler {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-align: center;
  padding: 0;
  /* Size container so the text below can scale with the cell width */
  container-type: inline-size;
}

/* Mobile keeps the exact same justified 2-per-row layout as desktop —
   the equal-height math is width-independent, so rows simply render
   smaller. Only the gap tightens to match the mobile grid gutter. */
@media (max-width: 599px) {
  .project-gallery,
  .project-gallery-row {
    gap: var(--space-2);
  }
}

/* Same font treatment as the footer's giant MATIAS CAROCA name — sized
   large enough to nearly fill the column width. */
.project-gallery-filler-text {
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  /* Fallback for browsers without container query units */
  font-size: clamp(2.5rem, 10vw, 6.5rem);
  /* Fill the cell edge-to-edge, same treatment as the footer name.
     Catalog IDs are always 8 monospace chars (MCDU + 4 digits):
     8 chars x 0.6em advance minus the negative letter-spacing ≈ 4.64em,
     so exact fill is 100cqw / 4.64 ≈ 21.5cqw — held a touch under so
     rendering differences never clip the outer glyphs. */
  font-size: 21.2cqw;
  line-height: 1;
  color: var(--color-fg);
  -webkit-text-stroke: 0px var(--color-fg);
}

/* Solid/outline pulse: the label cycles between filled and stroke-only,
   like the mockup's alternating solid/hollow repeats. */
@keyframes gallery-filler-pulse {
  0%, 45%   { color: var(--color-fg); -webkit-text-stroke: 0px var(--color-fg); }
  55%, 100% { color: transparent; -webkit-text-stroke: 1.5px var(--color-fg); }
}

@media (prefers-reduced-motion: no-preference) {
  .project-gallery-filler-text {
    animation: gallery-filler-pulse 3s ease-in-out infinite;
  }
}

/* Prev/next project pager */
.project-pager {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-fg);
}

/* Keeps → pinned right even when there's no ← (first project) —
   space-between alone would let a lone next-arrow sit at the left. */
.project-pager-next {
  margin-left: auto;
}

.project-pager-prev,
.project-pager-next {
  font-family: var(--font-mono);
  font-size: var(--font-heading);
  color: var(--color-fg);
  text-decoration: none;
  background: none;
  border: none;
  line-height: 1;
  transition: opacity 0.2s ease;
}

.project-pager-prev:hover,
.project-pager-next:hover,
.project-pager-prev:focus-visible,
.project-pager-next:focus-visible {
  opacity: 0.5;
}

