/* ================================================================
   HOME — CATEGORY-DRIVEN LAYOUT
   Implements the homepage half of DESIGN.md: a category index rail plus
   one masthead-led row per category. Editorial rules borrowed from the
   WIRED DESIGN.md — hairlines instead of shadows, square geometry,
   serif display over sans metadata, no decorative chrome.

   Every accent here comes from --cat-accent, set inline per section from
   the admin-managed category colour. Nothing in this file hardcodes a
   category name, slug, or colour.
   ================================================================ */

.cat-index,
.cat-row {
  /* Fallback when a category has no colour set in admin. */
  --cat-accent: var(--silver);
}

/* Dark accents (Travel #5A3D35, Automobiles #3a3a3a) fail contrast as text
   on the near-black canvas, so eyebrow text uses a lightened derivative
   while the 2px rule keeps the true brand colour. The plain declaration
   is the fallback for browsers without color-mix(). */
.cat-index__cell,
.cat-row {
  --cat-accent-text: var(--silver);
}
@supports (color: color-mix(in srgb, red, blue)) {
  .cat-index__cell,
  .cat-row {
    --cat-accent-text: color-mix(in srgb, var(--cat-accent) 60%, #fafafa);
  }
}

/* ─────────────────────────────────────────────────────────────
   CATEGORY INDEX RAIL — the directory, directly under the hero
   ───────────────────────────────────────────────────────────── */
/* ─────────────────────────────────────────────────────────────
   HERO MOSAIC — five stories, lead spanning both rows
   Structure follows the brief's reference (full-bleed tiles, scrim, chip and
   headline overlaid), but rendered in our own language: near-black canvas,
   Playfair for the lead headline, Archivo Narrow for the secondaries, square
   corners, hairline gutters, and each chip in its own category accent rather
   than one universal red.
   ───────────────────────────────────────────────────────────── */
.hero-mosaic {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  grid-template-rows: repeat(2, minmax(0, 1fr));
  /* 1px gutter showing the rule colour, same as every other grid on the page. */
  gap: 1px;
  background: var(--dark-gray);
  height: clamp(460px, 64vh, 660px);
}

.hero-tile {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--charcoal);
  text-decoration: none;
  cursor: none;
  min-width: 0;
  min-height: 0;
}
.hero-tile--lead { grid-row: span 2; }

.hero-tile:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: -2px;
}

/* .cover-img is absolutely positioned, so its container must be relative. */
.hero-tile__media {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.25);
}
.hero-tile__media .cover-img {
  transition: transform var(--speed-slow) cubic-bezier(.22,1,.36,1);
}
.hero-tile:hover .cover-img { transform: scale(1.05); }

/* Legibility scrim. Text sits on photography here — the only place in the
   system where it does — so the bottom of every tile is darkened. */
.hero-tile__scrim {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(
    to top,
    rgba(10,10,10,0.92) 0%,
    rgba(10,10,10,0.72) 28%,
    rgba(10,10,10,0.20) 58%,
    rgba(10,10,10,0.05) 100%
  );
}

.hero-tile__body {
  position: absolute;
  z-index: 3;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 22px 24px 24px;
}

.hero-tile__chip {
  display: inline-block;
  font-family: var(--ff-ui);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 5px 10px;
  margin-bottom: 12px;
  /* Square, like every other interactive shape in the system. */
  border-radius: 0;
  /* Fallback if a category has no colour set in admin. */
  background: var(--silver);
  color: var(--black);
}

.hero-tile__title {
  /* Secondary tiles: sans, per the serif-lead / sans-secondary rule. */
  font-family: var(--ff-ui);
  font-size: clamp(15px, 1.15vw, 18px);
  font-weight: 700;
  line-height: 1.24;
  letter-spacing: -0.01em;
  color: var(--pure-white);
  /* Never let a headline stack into a paragraph over a photo. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hero-tile--lead .hero-tile__body { padding: 30px 36px 34px; }
.hero-tile--lead .hero-tile__chip { font-size: 11px; padding: 6px 12px; margin-bottom: 16px; }
.hero-tile--lead .hero-tile__title {
  /* Lead: serif display at weight 400 — elegance by proportion, not weight. */
  font-family: var(--ff-display);
  font-size: clamp(26px, 2.6vw, 40px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.02em;
  max-width: 16ch;
  -webkit-line-clamp: 4;
}

/* ── SECTION LEAD TILE ──
   The lead is the most-visited category rather than a story, so it carries
   the section name over its poster and nothing else — no headline, no
   description, no count. It links to the category page. */
.hero-tile--section .hero-tile__rule {
  display: block;
  width: 40px;
  height: 2px;
  background: var(--cat-accent, var(--silver));
  margin-bottom: 18px;
  transition: width var(--speed-med) cubic-bezier(.22,1,.36,1);
}
.hero-tile--section:hover .hero-tile__rule { width: 84px; }

.hero-tile--section .hero-tile__section {
  display: block;
  font-family: var(--ff-display);
  font-size: clamp(34px, 4vw, 62px);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--pure-white);
}

/* The rail now sits under the mosaic, so it regains its dividing top border. */
.cat-index {
  background: var(--off-black);
  padding: 60px var(--page-gutter) 64px;
  border-top: var(--border);
  border-bottom: var(--border);
}

.cat-index__empty {
  font-family: var(--ff-ui);
  font-size: 15px;
  color: var(--gray);
  padding: 8px 0 24px;
}

.cat-index__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.cat-index__h {
  font-family: var(--ff-display);
  /* Display weight 400 — the serif carries elegance by proportion, not weight. */
  font-size: clamp(26px, 3vw, 40px);
  font-weight: 400;
  line-height: 1.06;
  letter-spacing: -0.02em;
  color: var(--white);
}
.cat-index__h em { font-style: italic; }

.cat-index__meta {
  font-family: var(--ff-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gray);
  white-space: nowrap;
  padding-bottom: 4px;
}

.cat-index__grid {
  /* Defensive: nav.css styles the bare `nav` element as the sticky site header,
     so this grid is a <div role="navigation">. These resets make sure no future
     bare-element rule can take it out of flow and float it over the first
     category row (which is exactly what happened when it was a <nav>). */
  position: static;
  top: auto;
  z-index: auto;
  height: auto;
  padding: 0;
  border: 0;
  background: var(--dark-gray);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;

  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* 1px gutter showing the rule colour — a ruled table, not floating tiles. */
  gap: 1px;
  align-items: stretch;
}

.cat-index__cell {
  position: relative;
  /* Thumb left, text right — reads as a printed index rather than a tile grid,
     and keeps the rail short enough that all nine sections stay above the fold
     on a desktop viewport. */
  display: flex;
  align-items: stretch;
  gap: 18px;
  background: var(--off-black);
  padding: 18px 24px 18px 18px;
  text-decoration: none;
  cursor: none;
  transition: background var(--speed-fast);
}
.cat-index__cell:hover,
.cat-index__cell:focus-visible {
  background: var(--charcoal);
}
.cat-index__cell:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: -2px;
}

.cat-index__text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

/* ── CATEGORY THUMBNAIL ──
   The image is the category's lead story cover (see _categoryThumb) — real
   editorial photography, not an icon set. Nine different photos side by side
   would fight each other and break the near-monochrome theme, so they're
   desaturated and dimmed at rest and only resolve to full colour on hover.
   A hairline in the category accent ties each thumb to its section. */
.cat-index__thumb {
  position: relative;
  flex: 0 0 auto;
  width: 76px;
  align-self: center;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--charcoal);
  /* Square, per the system's zero-radius geometry. */
  border-radius: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.cat-index__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(1) contrast(1.05) brightness(0.78);
  transform: scale(1.02);
  transition: filter var(--speed-med) ease,
              transform var(--speed-slow) cubic-bezier(.22,1,.36,1);
}
.cat-index__cell:hover .cat-index__img,
.cat-index__cell:focus-visible .cat-index__img {
  filter: grayscale(0) contrast(1) brightness(1);
  transform: scale(1.08);
}

/* Accent hairline along the inner edge of the thumb, in the category colour. */
.cat-index__thumb::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
  background: var(--cat-accent);
  opacity: 0.85;
}

/* The 2px accent bar — the only ornament in the system. */
.cat-index__rule {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--cat-accent);
  margin-bottom: 10px;
  transition: width var(--speed-med) cubic-bezier(.22,1,.36,1);
}
.cat-index__cell:hover .cat-index__rule { width: 48px; }

.cat-index__name {
  display: block;
  font-family: var(--ff-ui);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--white);
  margin-bottom: 8px;
}

.cat-index__count {
  display: block;
  font-family: var(--ff-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  /* Counts are metadata, not badges — no pill, no fill. */
  color: var(--gray);
}

/* ─────────────────────────────────────────────────────────────
   CATEGORY ROW — accent rule → masthead → card grid → story rows
   ───────────────────────────────────────────────────────────── */
.cat-row {
  position: relative;
  /* scroll-margin so the index rail's anchor links don't hide the masthead
     behind the fixed nav. */
  scroll-margin-top: calc(var(--nav-height) + 16px);
}

.cat-row__rule {
  position: absolute;
  top: 0;
  left: var(--page-gutter);
  right: var(--page-gutter);
  height: 2px;
  background: var(--cat-accent);
}

.cat-row__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 40px;
}

.cat-row__headtext { max-width: 62ch; }

.cat-row__eyebrow {
  font-family: var(--ff-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cat-accent-text);
  margin-bottom: 14px;
}

.cat-row__title {
  font-family: var(--ff-display);
  font-size: clamp(26px, 3.2vw, 40px);
  font-weight: 400;
  /* Not uppercase — this is the reading line of the masthead. */
  text-transform: none;
  letter-spacing: -0.02em;
  line-height: 1.08;
  color: var(--white);
}

.cat-row__count {
  font-family: var(--ff-ui);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gray);
  margin-top: 14px;
}

.cat-row__all { align-self: flex-end; margin-bottom: 6px; }
.cat-row__all:hover { border-color: var(--cat-accent); }

/* Card geometry inside a row: lead card gets the 16:9 cover, secondaries 4:3
   (the shared .look-thumb default is a 3/4 portrait, which reads far too tall
   in the wide 2fr column). */
.cat-row .look-thumb { aspect-ratio: 4/3; }
.cat-row .grid-asymm > *:first-child .look-thumb { aspect-ratio: 16/9; }
.cat-row .grid-asymm > *:first-child .look-title {
  font-size: clamp(22px, 2.2vw, 30px);
  line-height: 1.1;
}
.cat-row .grid-asymm > *:first-child .look-body { padding: 26px 28px 30px; }
.cat-row .guide-img { height: auto; aspect-ratio: 4/3; }

/* ─────────────────────────────────────────────────────────────
   STORY ROWS — text-only overflow beyond the card grid
   ───────────────────────────────────────────────────────────── */
.story-rows {
  list-style: none;
  margin: 40px 0 0;
  padding: 0;
  border-top: var(--border);
}

.story-row { border-bottom: var(--border); }

.story-row__link {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  padding: 16px 4px;
  text-decoration: none;
  cursor: none;
  transition: padding-left var(--speed-fast);
}
.story-row__link:hover { padding-left: 12px; }
.story-row__link:hover .story-row__title { color: var(--white); }
.story-row__link:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: -2px;
}

.story-row__title {
  font-family: var(--ff-display);
  font-size: 18px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--light-gray);
  transition: color var(--speed-fast);
}

.story-row__meta {
  font-family: var(--ff-ui);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--mid-gray);
  white-space: nowrap;
}

/* ─────────────────────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .cat-index__grid { grid-template-columns: repeat(2, 1fr); }

  /* Tablet: lead goes full-width on top, the four secondaries sit 2×2 below.
     Auto rows + explicit tile heights, because a fixed grid height would
     squash five tiles into one viewport. */
  .hero-mosaic {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto auto auto;
    height: auto;
  }
  .hero-tile--lead { grid-column: span 2; grid-row: auto; }
  .hero-tile { aspect-ratio: 4 / 3; }
  .hero-tile--lead { aspect-ratio: 16 / 9; }
}

@media (max-width: 768px) {
  /* Mobile: single column, every tile the same 16:9 so the stack reads evenly. */
  .hero-mosaic { grid-template-columns: 1fr; grid-template-rows: none; }
  .hero-tile,
  .hero-tile--lead { grid-column: auto; aspect-ratio: 16 / 9; }
  .hero-tile__body { padding: 16px 20px 18px; }
  .hero-tile--lead .hero-tile__body { padding: 18px 20px 20px; }
  .hero-tile__title { font-size: 16px; -webkit-line-clamp: 2; }
  .hero-tile--lead .hero-tile__title { font-size: 24px; max-width: none; -webkit-line-clamp: 3; }
  .hero-tile--section .hero-tile__section { font-size: 30px; }
  .hero-tile--section .hero-tile__rule { width: 32px; margin-bottom: 12px; }

  .cat-index { padding: 44px var(--page-gutter) 44px; }
  .cat-index__head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .cat-index__meta { padding-bottom: 0; }
  .cat-index__grid { grid-template-columns: 1fr; }
  .cat-index__cell { padding: 14px 20px 14px 14px; gap: 14px; }
  .cat-index__thumb { width: 60px; }

  .cat-row__head { flex-direction: column; align-items: flex-start; gap: 16px; margin-bottom: 28px; }
  .cat-row__all { align-self: flex-start; margin-bottom: 0; }

  /* Both grids are 1-up at mobile, so every cover shares one aspect. */
  .cat-row .look-thumb,
  .cat-row .grid-asymm > *:first-child .look-thumb { aspect-ratio: 16/9; }

  .story-row__link { flex-direction: column; align-items: flex-start; gap: 6px; }
  .story-row__meta { white-space: normal; }
}

/* Touch and reduced-motion: the custom cursor is desktop-only, and the
   hover-grow rule shouldn't animate for users who opt out. */
@media (hover: none) {
  .cat-index__cell,
  .hero-tile,
  .story-row__link { cursor: pointer; }
}

@media (prefers-reduced-motion: reduce) {
  .cat-index__rule,
  .cat-index__img,
  .hero-tile__media .cover-img,
  .hero-tile__rule,
  .story-row__link,
  .cat-index__cell { transition: none; }
  .hero-tile:hover .cover-img { transform: none; }
  .hero-tile--section:hover .hero-tile__rule { width: 40px; }
  .cat-index__cell:hover .cat-index__rule { width: 24px; }
  .cat-index__cell:hover .cat-index__img { transform: scale(1.02); }
  .story-row__link:hover { padding-left: 4px; }
}
