/* ---------- Tokens ---------- */
:root {
  --bg: #0b0b0d;
  --card: #141418;
  --card-2: #1b1b21;
  --outline: rgba(255, 197, 61, 0.22);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f5f3ee;
  --muted: #a3a1a8;
  --faint: #6c6a72;
  --accent: #ffc53d;
  --accent-ink: #ffc53d;
  --on-accent: #1a1300;
  --glow: rgba(255, 197, 61, 0.38);
  --spotlight: rgba(255, 197, 61, 0.09);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --font: 'Outfit', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f7f5ef;
  --card: #ffffff;
  --card-2: #fffdf6;
  --outline: rgba(214, 150, 0, 0.32);
  --line: rgba(20, 20, 24, 0.09);
  --text: #16151a;
  --muted: #5d5b63;
  --faint: #94929a;
  --accent-ink: #946000;
  --glow: rgba(240, 170, 0, 0.32);
  --spotlight: rgba(255, 197, 61, 0.22);
  color-scheme: light;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(900px 420px at 50% -140px, var(--spotlight), transparent 70%) no-repeat, var(--bg);
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font: inherit;
  color: inherit;
}

img {
  display: block;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

main {
  flex: 1;
  width: 100%;
  padding: 0 16px;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle:active {
  transform: scale(0.92);
}

.theme-toggle svg {
  grid-area: 1 / 1;
  width: 18px;
  height: 18px;
  transition: transform 0.45s var(--spring), opacity 0.25s;
}

:root[data-theme='dark'] .i-moon,
:root[data-theme='light'] .i-sun {
  opacity: 0;
  transform: rotate(-90deg) scale(0.4);
}

/* ---------- Brand ---------- */
.brand-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 36px 16px 0;
  text-align: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.brand-logo {
  width: 112px;
  height: auto;
  overflow: visible;
  view-transition-name: brand-logo;
}

.brand-name {
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  view-transition-name: brand-name;
}

.brand-name span {
  color: var(--accent);
}

:root[data-theme='light'] .brand-name span {
  color: #e09f00;
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.is-home .brand-logo {
  animation: bob 4.5s ease-in-out infinite;
}

@keyframes bob {
  50% {
    transform: translateY(-5px) rotate(-2deg);
  }
}

/* Compact brand on category pages */
.is-cat .brand-wrap {
  padding-top: 18px;
}

.is-cat .brand {
  flex-direction: row;
  gap: 10px;
}

.is-cat .brand-logo {
  width: 54px;
}

.is-cat .brand-name {
  font-size: 22px;
}

/* Small screens: left-align the compact brand so it clears the theme button */
@media (max-width: 560px) {
  .is-cat .brand-wrap {
    align-items: flex-start;
    padding-top: 14px;
  }
  .is-cat .brand-logo {
    width: 48px;
  }
  .is-cat .brand-name {
    font-size: 20px;
  }
  .is-cat .theme-toggle {
    top: 13px;
  }
}

.tip {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.tip a {
  color: var(--accent-ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  transition: opacity 0.2s;
}

.tip a:hover {
  opacity: 0.8;
}

/* ---------- The nine blocks ---------- */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 18px);
  max-width: 780px;
  margin: 28px auto 0;
}

.tile {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 1.6vw, 16px);
  padding: 12px;
  border: 2px solid var(--outline);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--card-2), var(--card));
  text-align: center;
  animation: pop 0.55s var(--ease) both;
  animation-delay: calc(var(--i) * 40ms);
  transition: transform 0.35s var(--ease), border-color 0.25s, box-shadow 0.35s;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover,
.tile:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 30px -4px var(--glow), inset 0 0 24px -14px var(--glow);
  transform: translateY(-4px);
  outline: none;
}

.tile:active {
  transform: translateY(-1px) scale(0.97);
  transition-duration: 0.1s;
}

.tile-art {
  width: clamp(76px, 14vw, 124px);
  height: auto;
  aspect-ratio: 1;
}

.tile-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tile-name {
  font-size: clamp(16px, 2.3vw, 21px);
  font-weight: 700;
  line-height: 1.15;
}

.tile-count {
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: color 0.25s;
}

.tile:hover .tile-count {
  color: var(--accent-ink);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
}

/* Phones: rows of two; the odd ninth block runs full width */
@media (max-width: 560px) {
  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .tile {
    border-radius: 20px;
  }
  .tile-art {
    width: 88px;
  }
  .tile-name {
    font-size: 18px;
  }
  .tile:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    aspect-ratio: auto;
    flex-direction: row;
    gap: 18px;
    padding: 22px;
  }
  .tile:last-child:nth-child(odd) .tile-text {
    align-items: flex-start;
  }
}

/* ---------- Category pills ---------- */
.pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  max-width: 1140px;
  margin: 20px auto 0;
  padding: 0 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  padding: 6px 14px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.2s, background-color 0.2s, transform 0.2s;
}

.pill-art {
  width: 24px;
  height: 24px;
}

.pill:hover {
  border-color: var(--accent);
}

.pill:active {
  transform: scale(0.96);
}

.pill[aria-current='page'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

@media (max-width: 640px) {
  .pills {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    mask-image: linear-gradient(90deg, #000 85%, transparent);
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .pills::-webkit-scrollbar {
    display: none;
  }
}

/* ---------- Category page ---------- */
.cat {
  max-width: 752px;
  margin: 0 auto;
}

.cat-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 36px;
}

.cat-art {
  width: clamp(84px, 16vw, 112px);
  height: auto;
  aspect-ratio: 1;
}

.cat-head h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 52px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
}

.cat-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.group h2 {
  margin: 32px 0 10px;
  padding-left: 4px;
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.links {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.links li {
  animation: pop 0.45s var(--ease) both;
  animation-delay: calc(var(--i) * 25ms + 60ms);
}

.link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  transition: transform 0.25s var(--ease), border-color 0.2s, background-color 0.2s, box-shadow 0.3s;
}

.link:hover,
.link:focus-visible {
  border-color: var(--accent);
  background: var(--card-2);
  box-shadow: 0 10px 28px -14px var(--glow);
  transform: translateY(-2px);
  outline: none;
}

.link:active {
  transform: scale(0.99);
}

.fav {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--accent-ink);
  font-size: 18px;
  font-weight: 700;
}

.fav img {
  position: absolute;
  width: 26px;
  height: 26px;
  object-fit: contain;
}

/* White plate behind real favicons so dark logos stay visible */
.fav:has(img) {
  background: #fff;
}

.fav:has(img) > span {
  visibility: hidden;
}

.link-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.link-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.link-name {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.25;
}

.link-desc {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.link-host {
  color: var(--faint);
}

.tag {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.tag-pick {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.link-arrow {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--faint);
  transition: transform 0.3s var(--spring), color 0.2s;
}

.link:hover .link-arrow {
  color: var(--accent-ink);
  transform: translate(2px, -2px);
}

@media (max-width: 480px) {
  .link {
    gap: 12px;
    padding: 12px 14px 12px 12px;
  }
  .link-host {
    display: none;
  }
}

.note {
  margin: 24px 0 0;
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.back {
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  margin: 36px auto 0;
  padding: 10px 18px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  transition: border-color 0.2s, transform 0.2s;
}

.back svg {
  width: 18px;
  height: 18px;
}

.back:hover {
  border-color: var(--accent);
}

.back:active {
  transform: scale(0.96);
}

/* ---------- 404 ---------- */
.lost {
  padding-top: 48px;
  text-align: center;
}

.lost h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 44px);
  font-weight: 800;
}

.lost p {
  color: var(--muted);
}

/* ---------- Footer ---------- */
.footer {
  margin-top: 64px;
  padding: 24px 16px 36px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 13px;
  text-align: center;
}

.footer p {
  margin: 4px 0;
}

.footer a {
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- Cartoon art ----------
   Each illustration (lib/art.mjs) is made of named parts. Hovering a block,
   or the header on a category page, plays a bounce plus a gag for that character.
   On phones, app.js adds .play instead (when a block scrolls into view or is tapped). */
.art,
.nest {
  overflow: visible;
}

.art :is(.char, .body, .eye, .btn, .pop, .spark, .float, .topbook, .reel, .note, .fall, .shackle, .ad, .ground),
.nest .egg {
  transform-box: fill-box;
  transform-origin: center;
}

.art .char {
  transform-origin: 50% 100%;
}

/* Extras that only appear while animating */
.art :is(.spark, .float, .note, .fall, .ad) {
  opacity: 0;
}

/* Idle: everyone blinks now and then, each on their own beat */
.art .eye,
.nest .eye {
  animation: blink 5s infinite;
  animation-delay: calc(var(--i, 0) * 0.45s + 1s);
}

.pill-art .eye {
  animation: none;
}

/* Bounce on hover; on category pages the character bounces in once on arrival */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art .char {
  animation: boing 0.7s var(--ease) both;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art .ground {
  animation: squash-shadow 0.7s var(--ease) both;
}

.cat-art .char {
  animation: boing-in 0.8s 0.25s var(--ease) both;
}

/* Games: controller wiggles, buttons flash like an arcade cabinet */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-games .body {
  animation: wiggle 0.22s ease-in-out infinite alternate;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-games .btn {
  animation: flash 0.5s steps(1) infinite;
  animation-delay: var(--d);
}

/* Movies: popcorn pops */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-movies .pop {
  animation: hop 0.6s cubic-bezier(0.3, 0.7, 0.4, 1) infinite;
  animation-delay: var(--d);
}

/* Live Sports: trophy rocks and sparkles */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-sports .body {
  transform-origin: 50% 100%;
  animation: rock 0.5s ease-in-out infinite alternate;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-sports .spark {
  animation: twinkle 1.05s ease-in-out infinite;
  animation-delay: var(--d);
}

/* Software: code floats off the screen, cursor blinks */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-software .float {
  animation: float-up 1.3s ease-out infinite;
  animation-delay: var(--d);
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-software .cursor {
  animation: cursor 0.6s steps(1) infinite;
}

/* Books: the top book flips up */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-books .topbook {
  transform-origin: 0% 100%;
  animation: lift 0.9s ease-in-out infinite;
}

/* Music: tape reels (its eyes) spin, the cassette thumps, notes float */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-music .reel {
  animation: spin 0.8s linear infinite;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-music .body {
  transform-origin: 50% 100%;
  animation: thump 0.3s ease-in-out infinite alternate;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-music .note {
  animation: note-up 1.3s ease-out infinite;
  animation-delay: var(--d);
}

/* Anime: petals spin around the face, loose petals drift down */
.art-anime .petals {
  transform-box: view-box;
  transform-origin: 60px 62px;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-anime .petals {
  animation: spin 1.8s linear infinite;
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-anime .fall {
  animation: fall 1.5s ease-in infinite;
  animation-delay: var(--d);
}

/* VPN: the padlock pops open and snaps shut */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-vpn .shackle {
  animation: unlock 1.1s var(--ease) infinite;
}

/* AdBlockers: ads fly in and get bonked away */
:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-adblockers .ad {
  animation: bonk 1.6s ease-in infinite;
  animation-delay: var(--d);
}

:is(.tile:hover, .tile:focus-visible, .tile.play, .cat-head:hover, .cat-head.play) .art-adblockers .body {
  animation: block 1.6s infinite;
}

/* Logo: eggs jiggle on hover */
.brand:hover .nest .egg {
  transform-origin: 50% 100%;
  animation: wiggle 0.25s ease-in-out infinite alternate;
  animation-delay: var(--d);
}

@keyframes blink {
  0%, 94%, 100% { transform: scaleY(1); }
  97% { transform: scaleY(0.1); }
}

@keyframes boing {
  0% { transform: none; }
  15% { transform: scale(1.14, 0.84); }
  40% { transform: translateY(-14px) scale(0.9, 1.12); }
  60% { transform: scale(1.08, 0.92); }
  78% { transform: scale(0.97, 1.03); }
  100% { transform: none; }
}

@keyframes boing-in {
  0% { transform: translateY(-24px) scale(0.9, 1.12); opacity: 0; }
  35% { transform: scale(1.14, 0.84); opacity: 1; }
  60% { transform: translateY(-6px) scale(0.96, 1.05); }
  100% { transform: none; }
}

@keyframes squash-shadow {
  40% { transform: scale(0.7); opacity: 0.12; }
}

@keyframes wiggle {
  from { transform: rotate(-7deg); }
  to { transform: rotate(7deg); }
}

@keyframes flash {
  50% { fill: #fff; }
}

@keyframes hop {
  0%, 100% { transform: none; }
  45% { transform: translateY(-16px) rotate(25deg); }
}

@keyframes rock {
  from { transform: rotate(-6deg); }
  to { transform: rotate(6deg); }
}

@keyframes twinkle {
  0% { opacity: 0; transform: scale(0) rotate(0); }
  50% { opacity: 1; transform: scale(1.2) rotate(90deg); }
  100% { opacity: 0; transform: scale(0) rotate(180deg); }
}

@keyframes float-up {
  0% { opacity: 0; transform: translateY(8px) scale(0.6); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-26px) scale(1.1); }
}

@keyframes cursor {
  50% { opacity: 0; }
}

@keyframes lift {
  0%, 100% { transform: none; }
  35%, 55% { transform: translateY(-14px) rotate(-14deg); }
  80% { transform: rotate(2deg); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes thump {
  to { transform: scale(1.05, 0.95); }
}

@keyframes note-up {
  0% { opacity: 0; transform: translate(0, 6px) rotate(-10deg); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translate(6px, -28px) rotate(15deg); }
}

@keyframes fall {
  0% { opacity: 0; transform: translate(0, -6px) rotate(0); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(10px, 62px) rotate(220deg); }
}

@keyframes unlock {
  0%, 100% { transform: none; }
  30%, 65% { transform: translateY(-11px); }
}

@keyframes bonk {
  0% { opacity: 0; transform: translateX(30px); }
  15% { opacity: 1; }
  42% { transform: translateX(2px); }
  50% { transform: translate(8px, -8px) rotate(25deg); }
  85% { opacity: 0; transform: translate(40px, -40px) rotate(120deg); }
  100% { opacity: 0; }
}

@keyframes block {
  0%, 38%, 50%, 88%, 100% { transform: none; }
  42%, 92% { transform: translateX(-4px) rotate(-3deg); }
}

/* ---------- Page transitions ---------- */
@view-transition {
  navigation: auto;
}

::view-transition-group(*) {
  animation-duration: 0.45s;
  animation-timing-function: var(--ease);
}

::view-transition-old(root) {
  animation: 0.18s ease both vt-out;
}

::view-transition-new(root) {
  animation: 0.3s var(--ease) both vt-in;
}

@keyframes vt-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-in {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
