/*
 * Category line drawings, the category overview and subcategory tiles.
 *
 * Drawings (assets/drawings/*.svg) are monoline ink on one pale sage field
 * (--tile), with one sage accent at most; their line stays 1.5 px at any
 * size. Every category tile has the same field, so a category reads as a
 * category and a white field as a product. Tiles in one grid are equal:
 * the same square field, and
 * long words wrap instead of widening a column.
 */

/* ── The drawing field ─────────────────────────────────────────────── */

.frame--art {
  background: var(--tile);
  color: var(--sage-deep);
  transition: background-color var(--dur) var(--ease);
}

.frame--art img {
  /* The drawing brings its own margin and floor line: fill the field. */
  inset: 0;
  width: 100%;
  height: 100%;
  mix-blend-mode: normal;
  transition: transform var(--dur-slow) var(--ease-out);
}

/* Hover: the field deepens a touch and the drawing settles a little closer. */
a:hover > .frame--art,
a:focus-visible > .frame--art {
  background: var(--tile-hover);
}

@media (hover: hover) and (pointer: fine) {
  a:hover > .frame--art img {
    transform: scale(1.04);
  }
}

/* Names wrap inside their column, whatever the language. */
.tile__name,
.cat-tile__name,
.cat-tile__subs a,
.cat-tile__also a {
  overflow-wrap: break-word;
  hyphens: auto;
}

/* ── Category overview: 4 / 3 / 2 equal tiles ─────────────────────── */
.cat-tiles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-14) var(--grid-gap-x);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 768px) {
  .cat-tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .cat-tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.cat-tile {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cat-tile__main {
  display: grid;
  gap: 2px;
  text-decoration: none;
}

.cat-tile__main .frame {
  margin-bottom: var(--space-4);
}

.cat-tile__name {
  font-size: var(--text-h4);
  line-height: var(--leading-snug);
}

.cat-tile__main:hover .cat-tile__name {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.cat-tile__count {
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
}

.cat-tile__subs,
.cat-tile__also {
  margin: var(--space-4) 0 0;
  padding: var(--space-3) 0 0;
  border-top: 1px solid var(--line);
  list-style: none;
}

.cat-tile__subs a,
.cat-tile__also a {
  display: inline-block;
  padding-block: 3px;
  color: var(--text-body);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  text-decoration: none;
}

.cat-tile__subs a:hover,
.cat-tile__also a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.cat-tile__subs .cat-tile__more {
  margin-top: var(--space-1);
  color: var(--ink);
  font-weight: var(--fw-medium);
}

.cat-tile__also {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

@media (max-width: 767px) {
  .cat-tiles {
    gap: var(--space-10) var(--grid-gap-x);
  }

  .cat-tile__name {
    font-size: var(--text-lead);
  }

  .cat-tile__subs a,
  .cat-tile__also a {
    /* Comfortable touch targets without widening the column. */
    min-height: 32px;
    padding-block: var(--space-2) 0;
  }
}

/* ── Subcategory tiles on a category page ──────────────────────────── */
.subcats {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: var(--space-8) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.subcats > li {
  min-width: 0;
}

.subcats .tile .frame {
  margin-bottom: var(--space-3);
}

.subcats .tile__name {
  font-size: var(--text-sm);
}

/* Between phone and desktop: five in a row. */
@media (min-width: 768px) and (max-width: 1099px) {
  .subcats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* Phones: one row of compact tiles (small drawing beside the name) that
   scrolls sideways, so sixteen subcategories cost one line, not a screen. */
@media (max-width: 767px) {
  .subcats {
    display: flex;
    gap: var(--space-2);
    margin-inline: calc(-1 * var(--gutter));
    padding: 0 var(--gutter) var(--space-1);
    overflow-x: auto;
    scroll-padding-inline: var(--gutter);
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .subcats::-webkit-scrollbar {
    display: none;
  }

  .subcats > li {
    flex: none;
    scroll-snap-align: start;
  }

  .subcats .tile {
    grid-template-columns: 52px auto;
    grid-template-rows: 1fr auto auto 1fr;
    column-gap: var(--space-3);
    row-gap: 0;
    height: 100%;
    padding: var(--space-1) var(--space-4) var(--space-1) var(--space-1);
    background: var(--tile);
  }

  .subcats .tile .frame {
    grid-row: 1 / -1;
    width: 52px;
    margin: 0;
  }

  .subcats .tile__name {
    grid-row: 2;
    min-height: 0;
    font-size: var(--text-sm);
    white-space: nowrap;
  }

  .subcats .tile__caption {
    grid-row: 3;
    font-size: var(--text-caption);
    white-space: nowrap;
  }

  .subcats .tile:hover,
  .subcats .tile:hover .frame--art {
    background: var(--tile-hover);
  }
}
