/* ===== HOME — numbered index, hover reveal, list/grid views ===== */

.home-main {
  min-height: 100vh;
  padding: 76px var(--pad) 64px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Intro line above the index */
.home-intro {
  max-width: 52ch;
  margin-bottom: 40px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.5;
}
.home-intro strong { color: var(--fg); font-weight: 500; }

/* ---------- View switch + grid density ---------- */
.view-switch {
  position: fixed;
  top: var(--pad);
  left: 50%;
  transform: translateX(-50%);
  z-index: 61;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: var(--ui);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  mix-blend-mode: difference;
}
.view-switch button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  letter-spacing: inherit;
  color: #fff;
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.2s;
}
.view-switch button:hover { opacity: 0.75; }
.view-switch button.is-active {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.density {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding-left: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.35);
}
.density[hidden] { display: none; }

@media (max-width: 640px) {
  .view-switch { display: none; }
}

/* ---------- LIST VIEW ---------- */
.index-list { width: 100%; }

.index-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: opacity 0.35s var(--ease), padding-left 0.35s var(--ease);
}
.index-row:first-child { border-top: 1px solid var(--line); }

.index-list:hover .index-row { opacity: 0.32; }
.index-list .index-row:hover { opacity: 1; padding-left: 12px; }

.idx-num { color: var(--muted); }
.idx-title { font-weight: 500; }
.idx-role { color: var(--muted); text-align: right; }

@media (max-width: 720px) {
  .index-row {
    grid-template-columns: 30px 1fr;
    gap: 8px;
    padding: 14px 0;
  }
  .idx-role { display: none; }
}

/* Floating image that follows the cursor on row hover */
.hover-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: clamp(240px, 26vw, 400px);
  aspect-ratio: 4/3;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.94);
  transition: opacity 0.35s var(--ease), transform 0.5s var(--ease);
  background: #141414;
}
.hover-preview.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.hover-preview img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 899px), (hover: none) {
  .hover-preview { display: none; }
}

/* ---------- GRID VIEW ----------
   A stable grid of cells, but images are object-fit:contain so every GIF keeps
   its native ratio uncropped. The varying letterboxing is what creates the
   rhythm, and it holds at any column count. Cells are 4/3 rather than square
   because the set is mostly 16:9 — a square cell wasted ~44% of its height. */
.index-grid {
  --cols: 3;
  --colgap: 2px;
  --colw: calc((100% - (var(--cols) - 1) * var(--colgap)) / var(--cols));
  display: flex;               /* flex, not grid: only flex centres a partial row */
  flex-wrap: wrap;
  justify-content: center;     /* every row centred, including the last */
  align-items: center;         /* smaller images centre against the row's tallest */
  align-content: flex-start;
  column-gap: var(--colgap);
  row-gap: 0;                  /* the 10px lives on each item instead */
  width: 100%;
  line-height: 0;
}

.grid-item {
  position: relative;
  display: block;
  flex: 0 0 var(--colw);
  max-width: var(--colw);
  aspect-ratio: 4 / 3;
  margin: 10px 0;              /* 10px above and below every row */
  transition: opacity 0.35s var(--ease);
}

.grid-media {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: transparent;
}
.grid-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;   /* centred horizontally in its cell */
  filter: grayscale(100%) brightness(0.85);
  transition: filter 0.45s var(--ease);
}

/* Hovering one item dims the rest */
.index-grid:hover .grid-item { opacity: 0.35; }
.index-grid .grid-item:hover { opacity: 1; }
.grid-item:hover .grid-media img { filter: grayscale(0%) brightness(1); }

/* Caption centred over the cell, revealed on hover */
.grid-caption {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  opacity: 0;
  line-height: 1.35;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: opacity 0.3s var(--ease);
  pointer-events: none;
}
.grid-caption span {
  background: rgba(10, 10, 10, 0.72);
  padding: 6px 10px;
}
.grid-item:hover .grid-caption { opacity: 1; }

@media (max-width: 1100px) {
  .index-grid { --cols: 2; --colgap: 4px; row-gap: 12px; }
}

@media (max-width: 640px) {
  /* Generous side margins, as on the reference */
  .home-main {
    padding-left: 9vw;
    padding-right: 9vw;
  }

  /* Single column. Cells are square and images are contained, so every format
     is normalised into the same slot — wide films sit letterboxed, portraits
     sit pillarboxed. Uniform slots, varying pictures. */
  .index-grid { --cols: 1; gap: 30px; }

  /* Item flows naturally; the square slot is the media, caption sits under it */
  .grid-item {
    aspect-ratio: auto;
    opacity: 1 !important;
  }

  .grid-media {
    position: relative;
    inset: auto;
    aspect-ratio: 1 / 1;
  }
  .grid-media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: grayscale(0%) brightness(1);
  }

  /* No hover on touch: captions always visible, dimming off */
  .grid-caption {
    position: static;
    inset: auto;
    opacity: 1;
    padding: 10px 0 0;
    justify-content: flex-start;
    text-align: left;
    pointer-events: auto;
  }
  .grid-caption span { background: none; padding: 0; }
  .index-grid:hover .grid-item { opacity: 1; }
}

/* ---------- View toggling ---------- */
.view-panel { display: none; }
.view-panel.is-active { display: block; }

/* Unlinked mood images: they join the rhythm but aren't clickable */
.grid-item.is-mood { cursor: default; }
.grid-item.is-mood .grid-media img { filter: grayscale(100%) brightness(0.7); }
.grid-item.is-mood:hover .grid-media img { filter: grayscale(0%) brightness(0.95); }
@media (max-width: 640px) {
  .grid-item.is-mood .grid-media img { filter: grayscale(0%) brightness(0.95); }
}

/* ADIDAS is the one wide tile. Portrait tiles keep their upright format.
   Mood tiles sit between the three new projects so they never touch. */
.grid-item.is-feature {
  flex: 0 0 calc(var(--colw) * 2 + var(--colgap));
  max-width: calc(var(--colw) * 2 + var(--colgap));
  aspect-ratio: 16 / 9;
}
.grid-item.is-portrait {
  aspect-ratio: 3 / 4;
}

@media (max-width: 1100px) {
  .grid-item.is-feature { aspect-ratio: 16 / 10; }
}
@media (max-width: 640px) {
  /* single column: a 2-column span would invent a phantom column */
  .index-grid { --cols: 1; --colgap: 0px; }
  .grid-item,
  .grid-item.is-feature {
    flex: 0 0 100%;
    max-width: 100%;
    aspect-ratio: auto;
  }
  .grid-item.is-portrait { aspect-ratio: auto; }
}

/* A smaller tile: same grid footprint (so the columns stay aligned and no gap
   opens up), but the image is inset so it reads as a quieter, smaller item. */
.grid-item.is-small .grid-media { padding: 12% 20%; }
.grid-item.is-small .grid-caption { padding: 8px 12%; }
@media (max-width: 640px) {
  .grid-item.is-small .grid-media { padding: 0 14%; }
  .grid-item.is-small .grid-caption { padding: 10px 0 0; }
}

/* ===== Tiles settle in as their image finishes loading =====
   The motion is on .grid-media, not .grid-item, so it never fights the
   hover-dimming opacity rules above. Gated on .has-motion so the grid is
   still visible if JS never runs. */
.has-motion .grid-media {
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}
.has-motion .grid-item.is-in .grid-media {
  opacity: 1;
  transform: none;
}

/* the intro line leads, just ahead of the first tiles */
.has-motion .home-intro {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.7s var(--ease) 0.05s, transform 0.7s var(--ease) 0.05s;
}
.has-motion.is-loaded .home-intro { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .has-motion .grid-media,
  .has-motion .home-intro {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ===== Cursor-reactive tiles =====
   The image drifts against the pointer inside its frame, the tile lifts, and
   it presses in on click. Transform lives on the <img>, while the load-in
   motion lives on .grid-media — separate elements, so they never collide. */
.grid-item { --px: 0; --py: 0; }

.grid-media img {
  transform: translate3d(calc(var(--px) * 7px), calc(var(--py) * 7px), 0) scale(var(--z, 1));
  transition: transform 0.35s var(--ease), filter 0.45s var(--ease);
  will-change: transform;
}

/* lift + push in, so the whole tile acknowledges the pointer */
.grid-item {
  transition: opacity 0.35s var(--ease), transform 0.3s var(--ease);
}
.index-grid .grid-item:hover {
  transform: translateY(-5px);
  z-index: 2;
}
.index-grid .grid-item:hover .grid-media img { --z: 1.07; }
.index-grid .grid-item:active { transform: translateY(-1px) scale(0.988); }
.index-grid .grid-item:active .grid-media img { --z: 1.03; }

/* caption rises rather than just fading */
.grid-caption span {
  transform: translateY(6px);
  transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}
.grid-item:hover .grid-caption span { transform: none; }

/* mood tiles react too, just more quietly */
.grid-item.is-mood:hover { transform: translateY(-3px); }
.grid-item.is-mood:hover .grid-media img { --z: 1.04; }

@media (prefers-reduced-motion: reduce) {
  .grid-media img { transform: none !important; }
  .index-grid .grid-item:hover,
  .index-grid .grid-item:active { transform: none !important; }
}
@media (hover: none) {
  .grid-media img { transform: none; }
}
