/* =============================================================================
   /fun index — the collection page.

   One calm outer frame for everything in /fun: an introduction, a sticky row
   of category links, then one section per kind of thing (work tools, privacy,
   books, games, the playful rest). The products keep their own personalities
   on their own pages; here each category only lends its cards one accent
   colour (`--cat`), so the page reads as a collection, not as a wall of
   identical tiles.

   The markup is also data: fun-catalog.js reads this page for the terminals
   and the navigation wheel. `[data-fun-section]` and `[data-fun-item]` are the
   hooks it reads; the classes below are only for looks.
   ========================================================================== */

.fun-lab {
  --fun-nav-h: 3.5rem;
  --cat: var(--brand-300);

  /* The header is fixed, so the page has to start below it. */
  padding-block: calc(var(--header-h) + var(--space-10)) var(--space-16);
}

/* --- Introduction --------------------------------------------------------- */
.fun-intro {
  padding-block-end: var(--space-8);
  scroll-margin-block-start: calc(var(--header-h) + var(--space-10));
}

.fun-intro__eyebrow { margin-block-end: var(--space-3); }

.fun-intro__title {
  color: var(--text);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.fun-intro__lede { margin-block-start: var(--space-4); max-inline-size: 62ch; }

/* --- Category navigation -------------------------------------------------- */
/*
  Sticks under the fixed header. Plain in-page anchors; fun-nav.js only marks
  the section being read. On narrow screens the row scrolls sideways instead
  of wrapping into several lines.
*/
.fun-nav {
  position: sticky;
  inset-block-start: var(--header-h);
  z-index: 40;
  margin-block-end: var(--space-4);
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-block: 1px solid var(--line);
}

.fun-nav__inner { display: flex; align-items: center; min-block-size: var(--fun-nav-h); }

.fun-nav__list {
  display: flex;
  gap: var(--space-1);
  margin: 0;
  padding: var(--space-2) 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  scroll-padding-inline: var(--space-4);
}

.fun-nav__list::-webkit-scrollbar { display: none; }

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

.fun-nav__link {
  display: inline-flex;
  align-items: center;
  min-block-size: 2.5rem;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--r-full);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--dur-base) var(--ease-out), background-color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}

.fun-nav__link:hover { color: var(--text); background: rgb(255 255 255 / 4%); }

.fun-nav__link[aria-current='true'] {
  color: var(--text);
  background: rgb(30 133 230 / 12%);
  border-color: var(--line-brand);
}

.fun-nav__link:focus-visible { outline-offset: -2px; border-radius: var(--r-full); }

/* --- Category sections ---------------------------------------------------- */
.fun-cat {
  padding-block-start: var(--space-12);
  /* html already pads anchors by the header. This adds the sticky row, less
     the section's own top padding, so the heading lands just under the row. */
  scroll-margin-block-start: calc(var(--fun-nav-h) - var(--space-6));
}

.fun-cat--tools { --cat: var(--brand-300); }
.fun-cat--privacy { --cat: var(--accent-300); }
.fun-cat--books { --cat: #e7c48f; }
.fun-cat--games { --cat: #f5b833; }
.fun-cat--playful { --cat: var(--violet-400); }

.fun-cat__head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: var(--space-1) var(--space-4);
  margin-block-end: var(--space-6);
  padding-block-end: var(--space-4);
  border-block-end: 1px solid var(--line);
}

.fun-cat__index {
  grid-row: span 2;
  color: var(--cat);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.fun-cat__title {
  color: var(--text);
  font-size: var(--text-3xl);
  font-weight: 800;
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.fun-cat__note { color: var(--text-muted); font-size: var(--text-base); line-height: var(--leading-normal); }

/* --- Grids ------------------------------------------------------------------ */
.fun-grid { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr); }

@media (min-width: 36rem) {
  .fun-grid--two,
  .fun-grid--three,
  .fun-grid--four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 64rem) {
  .fun-grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fun-grid--four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* A lone card in a two-up grid should not stretch into a banner. */
.fun-grid--four > .fun-card:only-child { max-inline-size: 22rem; }

.fun-grid--one { margin-block-start: var(--space-5); }

/* --- Cards ------------------------------------------------------------------ */
/*
  The title is the link and stretches over the whole card, so the card is one
  target with one meaningful name. The "open" line is decoration
  (aria-hidden); it only repeats what clicking the card does.
*/
.fun-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  overflow: hidden;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  transition: border-color var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out), background-color var(--dur-base) var(--ease-out);
}

.fun-card:hover {
  border-color: color-mix(in srgb, var(--cat) 38%, transparent);
  background: var(--surface-2);
  transform: translateY(-2px);
}

.fun-card__art {
  display: block;
  inline-size: 100%;
  block-size: auto;
  aspect-ratio: 720 / 440;
  object-fit: cover;
  background: var(--surface-2);
  border-block-end: 1px solid var(--line);
}

.fun-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-6) var(--space-6);
}

.fun-card__kicker {
  color: var(--cat);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  line-height: var(--leading-snug);
}

.fun-card__title {
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: 800;
  line-height: var(--leading-snug);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.fun-card__link { color: inherit; text-decoration: none; }

.fun-card__link::after { content: ''; position: absolute; inset: 0; z-index: 1; }

.fun-card__note {
  flex: 1;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-loose);
}

.fun-card__go {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-block-start: var(--space-2);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: 700;
}

.fun-card__arrow { color: var(--cat); transition: transform var(--dur-base) var(--ease-out); }

.fun-card:hover .fun-card__arrow { transform: translateX(0.25rem); }
html[dir='rtl'] .fun-card:hover .fun-card__arrow { transform: translateX(-0.25rem); }

/* One focus ring around the whole card rather than around the title text. */
.fun-card__link:focus-visible { outline: none; }
.fun-card__link:focus-visible::after { outline: 2px solid var(--accent-400); outline-offset: -2px; border-radius: inherit; }
.fun-card:has(.fun-card__link:focus-visible) { border-color: var(--accent-400); }

/* Sideways card: art on one side, text on the other. */
@media (min-width: 48rem) {
  .fun-card--row { flex-direction: row; }
  .fun-card--row .fun-card__art { inline-size: 40%; flex: none; aspect-ratio: auto; border-block-end: 0; border-inline-end: 1px solid var(--line); }
  .fun-card--row .fun-card__body { justify-content: center; padding: var(--space-8) var(--space-10); }
  .fun-card--row .fun-card__note { flex: 0 1 auto; max-inline-size: 60ch; }
}

/* Books: a touch quieter, so four of them sit in one row. */
.fun-cat--books .fun-card__body { padding: var(--space-4) var(--space-5) var(--space-5); }
.fun-cat--books .fun-card__title { font-size: var(--text-2xl); }

/* --- The game-night collection ------------------------------------------- */
/*
  A collection is not one more game: it gets one wide panel, with the games it
  holds listed inside it. Only the upper half links to the collection page;
  each game below is its own link.
*/
.fun-collection {
  overflow: hidden;
  background: var(--surface-1);
  border: 1px solid color-mix(in srgb, var(--cat) 24%, var(--line));
  border-radius: var(--r-2xl);
}

.fun-collection__head { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); }

.fun-collection__head:hover .fun-card__arrow { transform: translateX(0.25rem); }
html[dir='rtl'] .fun-collection__head:hover .fun-card__arrow { transform: translateX(-0.25rem); }

.fun-collection__art {
  display: block;
  inline-size: 100%;
  block-size: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: var(--surface-2);
}

.fun-collection__body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
}

.fun-collection__title {
  color: var(--text);
  font-size: var(--text-2xl);
  font-weight: 800;
  line-height: var(--leading-snug);
  text-wrap: balance;
}

.fun-collection__body .fun-card__note { flex: 0 1 auto; max-inline-size: 52ch; font-size: var(--text-base); }

.fun-collection__head:has(.fun-card__link:focus-visible) { outline: 2px solid var(--accent-400); outline-offset: -2px; }

@media (min-width: 56rem) {
  .fun-collection__head { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  .fun-collection__body { padding: var(--space-10); }
}

.fun-collection__games {
  padding: var(--space-5) var(--space-6) var(--space-6);
  border-block-start: 1px solid var(--line);
  background: rgb(0 0 0 / 18%);
}

.fun-collection__label {
  margin-block-end: var(--space-3);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
}

.fun-collection__list {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: minmax(0, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 36rem) { .fun-collection__list { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .fun-collection__list { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* Each game keeps the accent it has on the game-night page. */
.fun-game--code-words { --cat: #f5b833; }
.fun-game--intercept { --cat: #22d3ee; }
.fun-game--liars-dice { --cat: #e0b04f; }
.fun-game--lesser-evil { --cat: #8af34a; }

.fun-game {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-inline-size: 0;
  padding: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  transition: border-color var(--dur-base) var(--ease-out), background-color var(--dur-base) var(--ease-out);
}

.fun-game:hover { border-color: color-mix(in srgb, var(--cat) 45%, transparent); background: var(--surface-3); }
.fun-game:has(.fun-card__link:focus-visible) { border-color: var(--accent-400); }

.fun-game__art {
  flex: none;
  inline-size: 5.5rem;
  block-size: auto;
  aspect-ratio: 720 / 440;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--surface-3);
}

.fun-game__body { display: flex; flex-direction: column; gap: 0.125rem; min-inline-size: 0; }

.fun-game__title { color: var(--text); font-size: var(--text-base); font-weight: 800; line-height: var(--leading-snug); }

.fun-game .fun-card__kicker { font-size: var(--text-2xs); }
.fun-game .fun-card__note { font-size: var(--text-xs); line-height: var(--leading-normal); }

/* --- Closing ---------------------------------------------------------------- */
.fun-close {
  display: grid;
  gap: var(--space-5);
  margin-block-start: var(--space-16);
  padding-block-start: var(--space-10);
  border-block-start: 1px solid var(--line);
}

@media (min-width: 56rem) {
  .fun-close:has(.fun-close__story) { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); align-items: stretch; }
}

.fun-close__cta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-8);
  background: linear-gradient(160deg, rgb(30 133 230 / 10%), transparent 60%), var(--surface-1);
  border: 1px solid var(--line-brand);
  border-radius: var(--r-xl);
}

.fun-close__title { color: var(--text); font-size: var(--text-2xl); font-weight: 800; line-height: var(--leading-snug); text-wrap: balance; }

.fun-close__note { color: var(--text-muted); font-size: var(--text-base); line-height: var(--leading-loose); max-inline-size: 52ch; }

.fun-close__actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-block-start: var(--space-2); }

.fun-close__story { --cat: var(--brand-300); }

@media (min-width: 48rem) and (max-width: 55.99rem) {
  .fun-close__story .fun-card__art { inline-size: 36%; }
}

/* --- Narrow screens --------------------------------------------------------- */
@media (max-width: 47.99rem) {
  .fun-lab { --fun-nav-h: 3.25rem; padding-block-start: calc(var(--header-h) + var(--space-6)); }
  .fun-intro { padding-block-end: var(--space-6); }
  .fun-nav__link { padding-inline: var(--space-3); }

  /* Hint that the row scrolls: fade both ends. */
  .fun-nav__list {
    mask-image: linear-gradient(to right, transparent, #000 var(--space-4), #000 calc(100% - var(--space-4)), transparent);
    -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--space-4), #000 calc(100% - var(--space-4)), transparent);
    padding-inline: var(--space-2);
  }

  .fun-nav__inner { padding-inline: calc(var(--shell-pad) - var(--space-2)); }

  .fun-cat { padding-block-start: var(--space-10); }
  .fun-card__body { padding: var(--space-4) var(--space-5) var(--space-5); }
  .fun-collection__body { padding: var(--space-5); }
  .fun-collection__games { padding: var(--space-4) var(--space-5) var(--space-5); }
  .fun-close__cta { padding: var(--space-6); }
}

/*
  Phones: the work tools and privacy tools keep their full poster cards; the
  books, the playful tools and the standalone game turn into compact rows, so
  the page stays scannable instead of becoming one long column of posters.
*/
@media (max-width: 35.99rem) {
  .fun-cat--books .fun-card,
  .fun-cat--playful .fun-card,
  .fun-cat--games .fun-card--row { flex-direction: row; align-items: stretch; }

  .fun-cat--books .fun-card__art,
  .fun-cat--playful .fun-card__art,
  .fun-cat--games .fun-card--row .fun-card__art {
    inline-size: 34%;
    flex: none;
    aspect-ratio: auto;
    min-block-size: 100%;
    border-block-end: 0;
    border-inline-end: 1px solid var(--line);
  }

  .fun-cat--books .fun-card__body,
  .fun-cat--playful .fun-card__body,
  .fun-cat--games .fun-card--row .fun-card__body { gap: var(--space-1); padding: var(--space-4); }

  .fun-cat--books .fun-card__title,
  .fun-cat--playful .fun-card__title,
  .fun-cat--games .fun-card--row .fun-card__title { font-size: var(--text-lg); }

  .fun-cat--books .fun-card__note,
  .fun-cat--playful .fun-card__note,
  .fun-cat--games .fun-card--row .fun-card__note {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    font-size: var(--text-xs);
    line-height: var(--leading-normal);
  }

  /* The whole row is the link; the "open" line would only repeat it. */
  .fun-cat--books .fun-card__go,
  .fun-cat--playful .fun-card__go,
  .fun-cat--games .fun-card--row .fun-card__go { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .fun-card:hover,
  .fun-card:hover .fun-card__arrow,
  .fun-collection__head:hover .fun-card__arrow { transform: none; }
}
