/* ───────── Theme tokens ───────── */
:root {
  --bg: #0d0f1a;
  --surface: #161a2b;
  --surface-2: #1d2238;
  --border: #2a3050;
  --text: #e8eaf6;
  --muted: #9aa2c8;
  --accent: #ffcc33;
  --accent-ink: #1a1300;
  --pink: #ff4d8d;
  --teal: #3de0c5;
  --link: #ffcc33;
  --eyebrow: #3de0c5;
  --plus: #ffcc33;
  --focus: #ffcc33;
  --grid-dot: rgba(255, 255, 255, 0.05);
  --header-bg: rgba(13, 15, 26, 0.74);
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.42);
  --pill-shadow: 0 6px 18px -6px rgba(255, 204, 51, 0.55);
  --focus-glow: rgba(255, 204, 51, 0.16);
  --shimmer: rgba(255, 255, 255, 0.07);
  --glow-1: 0.2;
  --glow-2: 0.15;
  --glow-3: 0.13;
  --radius: 14px;
  --maxw: 1120px;
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --ease-spring: cubic-bezier(0.34, 1.45, 0.64, 1);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f5ef;
  --surface: #ffffff;
  --surface-2: #efede3;
  --border: #dcd9cc;
  --text: #1b1d2e;
  --muted: #5b6080;
  --link: #8a5a00;
  --eyebrow: #0b7a69;
  --plus: #8a5a00;
  --focus: #9a5f00;
  --grid-dot: rgba(27, 29, 46, 0.07);
  --header-bg: rgba(246, 245, 239, 0.8);
  --shadow: 0 16px 36px rgba(27, 29, 46, 0.14);
  --pill-shadow: 0 6px 16px -6px rgba(180, 120, 0, 0.5);
  --focus-glow: rgba(180, 120, 0, 0.16);
  --shimmer: rgba(255, 255, 255, 0.9);
  --glow-1: 0.3;
  --glow-2: 0.16;
  --glow-3: 0.18;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
  scroll-padding-top: 84px;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 16px; top: -56px;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  transition: top 0.25s var(--ease), opacity 0.2s ease;
}
.skip:focus { top: 12px; opacity: 1; }

/* ───────── Ambient background ───────── */
/* Browsers fill the elastic-overscroll bounce area with the flat page colour, so the glow must
   fade to fully transparent at the very top edge or it meets that flat colour in a hard line. */
.aurora {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 680px;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(transparent 0, #000 220px, #000 calc(100% - 300px), transparent);
  mask-image: linear-gradient(transparent 0, #000 220px, #000 calc(100% - 300px), transparent);
}
.aurora::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--grid-dot) 1.5px, transparent 1.5px);
  background-size: 22px 22px;
}
.aurora i {
  position: absolute;
  border-radius: 50%;
  will-change: transform;
}
.aurora i:nth-child(1) {
  width: 560px; height: 560px; left: -6%; top: -130px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 68%);
  opacity: var(--glow-1);
  animation: drift-a 22s ease-in-out infinite alternate;
}
.aurora i:nth-child(2) {
  width: 520px; height: 520px; right: -4%; top: -70px;
  background: radial-gradient(circle, var(--pink) 0%, transparent 68%);
  opacity: var(--glow-2);
  animation: drift-b 27s ease-in-out infinite alternate;
}
.aurora i:nth-child(3) {
  width: 460px; height: 460px; left: 38%; top: 130px;
  background: radial-gradient(circle, var(--teal) 0%, transparent 68%);
  opacity: var(--glow-3);
  animation: drift-c 31s ease-in-out infinite alternate;
}
@keyframes drift-a { to { transform: translate3d(110px, 70px, 0) scale(1.14); } }
@keyframes drift-b { to { transform: translate3d(-120px, 60px, 0) scale(1.1); } }
@keyframes drift-c { to { transform: translate3d(-90px, -40px, 0) scale(1.18); } }

/* ───────── Header ───────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid transparent;
  background: transparent;
  /* Identity filter at rest: a live blur/saturate here would tint the glow behind the header
     and leave a visible band at the top of the page. It only kicks in once scrolled. */
  -webkit-backdrop-filter: blur(0) saturate(1);
  backdrop-filter: blur(0) saturate(1);
  transition: background-color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease,
    -webkit-backdrop-filter 0.35s ease, backdrop-filter 0.35s ease;
}
.site-header.scrolled {
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  background: var(--header-bg);
  border-bottom-color: var(--border);
  box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.55);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font: 700 1.1rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.01em;
}
.brand img { display: block; border-radius: 7px; transition: transform 0.5s var(--ease-spring); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 20px;
}
.site-nav a {
  position: relative;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.25s ease;
}
.site-nav a::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -5px;
  height: 2px;
  border-radius: 2px;
  background: var(--link);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s var(--ease);
}
.site-nav a:focus-visible::after { transform: scaleX(1); }

.icon-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 38px; height: 38px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.25s ease, background-color 0.35s ease, transform 0.2s var(--ease);
}
.icon-btn:active { transform: scale(0.9); }

.theme-toggle .icon {
  position: absolute;
  inset: 0;
  margin: auto;
  transition: transform 0.6s var(--ease-spring), opacity 0.3s ease;
}
.theme-toggle .moon { transform: rotate(-90deg) scale(0.3); opacity: 0; }
:root[data-theme="light"] .theme-toggle .sun { transform: rotate(90deg) scale(0.3); opacity: 0; }
:root[data-theme="light"] .theme-toggle .moon { transform: none; opacity: 1; }

@media (hover: hover) {
  .site-nav a:hover { color: var(--text); }
  .site-nav a:hover::after { transform: scaleX(1); }
  .icon-btn:hover { border-color: var(--accent); }
  .brand:hover img { transform: rotate(-8deg) scale(1.1); }
}

/* ───────── Hero ───────── */
.hero {
  position: relative;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 44px 16px 40px;
}
.eyebrow {
  margin: 0 0 14px;
  color: var(--eyebrow);
  font: 600 0.8rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.hero h1 {
  margin: 0 0 18px;
  font-size: clamp(2.2rem, 6vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.lede {
  max-width: 56ch;
  margin: 0;
  color: var(--muted);
  font-size: 1.1rem;
  text-wrap: pretty;
}

/* ───────── Game browser ───────── */
.browser {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 16px 64px;
  flex: 1;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 260px;
  max-width: 380px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  transition: border-color 0.25s ease, box-shadow 0.35s ease, background-color 0.35s ease, color 0.25s ease;
}
.search:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 4px var(--focus-glow);
  color: var(--text);
}
.search input {
  flex: 1;
  min-width: 0;
  padding: 12px 0;
  background: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
}
.search input::placeholder { color: var(--muted); }

.chips {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 38px;
}
.chip-pill {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  z-index: -1;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: var(--pill-shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.5s var(--ease), width 0.5s var(--ease), height 0.5s var(--ease), opacity 0.3s ease;
}
.chip-pill.ready { opacity: 1; }

.chip {
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  font: 600 0.9rem/1 inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.3s ease, border-color 0.3s ease, background-color 0.25s ease, transform 0.2s var(--ease);
}
.chip:active { transform: scale(0.94); }
.chip[aria-pressed="true"] {
  color: var(--accent-ink);
  border-color: transparent;
}
@media (hover: hover) {
  .chip:hover { color: var(--text); border-color: var(--muted); }
  .chip[aria-pressed="true"]:hover { color: var(--accent-ink); border-color: transparent; }
}

.count {
  min-height: 1em;
  margin: 22px 0 14px;
  color: var(--muted);
  font: 500 0.85rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
}

.results {
  position: relative;
  min-height: 340px;
}

/* ───────── Grid + cards ───────── */
.grid {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
  gap: 18px;
}
.grid > li { min-width: 0; }
.grid > li.ghost { position: absolute; margin: 0; pointer-events: none; z-index: 0; }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.45s var(--ease), border-color 0.25s ease, box-shadow 0.45s var(--ease), background-color 0.35s ease;
}
.card:active { transform: translateY(-1px) scale(0.985); transition-duration: 0.12s; }

.thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--surface-2);
}
.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.8s var(--ease);
}
.thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.24) 50%, transparent 65%);
  transform: translateX(-120%);
  transition: transform 0.9s var(--ease);
  pointer-events: none;
}
.thumb .letter {
  font: 800 3.4rem/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.6s var(--ease-spring);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px 16px 16px;
  flex: 1;
}
.card-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 8px;
  margin-top: auto;
  padding-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}
.card-meta > span { min-width: 0; max-width: 100%; }
.tag {
  padding: 3px 9px;
  background: var(--surface-2);
  border-radius: 999px;
  font-weight: 600;
  color: var(--text);
  transition: background-color 0.35s ease;
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-5px);
    border-color: var(--accent);
    box-shadow: var(--shadow);
  }
  .card:hover .thumb img { transform: scale(1.07); }
  .card:hover .thumb::after { transform: translateX(120%); }
  .card:hover .thumb .letter { transform: scale(1.14) rotate(-4deg); }
}
.card:focus-visible { transform: translateY(-3px); }

/* "Add a game" card */
.card.add {
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 220px;
  padding: 24px;
  text-align: center;
  background: transparent;
  border: 2px dashed var(--border);
  color: var(--muted);
}
.card.add .plus {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--plus);
  font: 700 1.8rem/1 ui-monospace, monospace;
  transition: transform 0.6s var(--ease-spring), background-color 0.35s ease;
}
.card.add strong { color: var(--text); font-size: 1.05rem; }
.card.add span { font-size: 0.9rem; }
@media (hover: hover) {
  .card.add:hover { color: var(--text); box-shadow: none; }
  .card.add:hover .plus { transform: rotate(90deg) scale(1.08); }
}

/* Loading skeleton */
.skeleton-grid .sk {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.sk-thumb, .sk-line {
  background: linear-gradient(100deg, var(--surface-2) 30%, var(--shimmer) 50%, var(--surface-2) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}
.sk-thumb { aspect-ratio: 16 / 10; }
.sk-line { height: 12px; margin: 14px 16px 0; border-radius: 6px; }
.sk-line:last-child { width: 55%; margin-bottom: 18px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ───────── Empty state + buttons ───────── */
.empty {
  margin: 8px 0 24px;
  padding: 40px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.empty h3 { margin: 0 0 8px; font-size: 1.3rem; }
.empty p { max-width: 52ch; margin: 0 auto 18px; color: var(--muted); text-wrap: pretty; }
.empty[hidden] { display: none; }

.btn {
  display: inline-block;
  padding: 11px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 10px;
  font: 700 0.95rem/1 inherit;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.25s var(--ease), box-shadow 0.35s var(--ease), filter 0.25s ease;
}
.btn:active { transform: scale(0.95); }
@media (hover: hover) {
  .btn:hover { transform: translateY(-2px); box-shadow: var(--pill-shadow); filter: brightness(1.06); }
  .btn:active { transform: scale(0.95); }
}

/* ───────── Footer ───────── */
.site-footer {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 16px 40px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}
.site-footer p { margin: 0 0 6px; }

/* ───────── Entrance choreography ───────── */
@media (prefers-reduced-motion: no-preference) {
  @keyframes rise {
    from { opacity: 0; transform: translateY(18px); }
  }
  @keyframes fade-down {
    from { opacity: 0; transform: translateY(-10px); }
  }
  .header-inner { animation: fade-down 0.7s var(--ease) backwards; }
  .hero .eyebrow { animation: rise 0.8s var(--ease) 60ms backwards; }
  .hero h1 { animation: rise 0.9s var(--ease) 140ms backwards; }
  .hero .lede { animation: rise 0.9s var(--ease) 240ms backwards; }
  .toolbar { animation: rise 0.9s var(--ease) 340ms backwards; }
  .count { animation: rise 0.9s var(--ease) 420ms backwards; }
}

/* ───────── Theme switch ───────── */
/* Circular reveal (View Transitions). The clip-path itself is animated from JS. */
html.theme-vt::view-transition-old(root),
html.theme-vt::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
html.theme-vt::view-transition-old(root) { z-index: 1; }
html.theme-vt::view-transition-new(root) { z-index: 2; }

/* Fallback for browsers without View Transitions: a soft crossfade of every colour. */
html.theme-fade,
html.theme-fade *,
html.theme-fade *::before,
html.theme-fade *::after {
  transition: background-color 0.45s ease, color 0.45s ease, border-color 0.45s ease,
    fill 0.45s ease, stroke 0.45s ease, box-shadow 0.45s ease, opacity 0.45s ease !important;
}

/* ───────── Responsive ───────── */
@media (max-width: 560px) {
  .site-nav a { display: none; }
  .hero { padding-top: 32px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
}

/* ───────── Reduced motion: no movement at all ───────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
