:root {
  color-scheme: light;
  --background: #f5f5f7;
  --surface: #ffffff;
  --surface-muted: #f0f0f2;
  --text: #1d1d1f;
  --secondary: #6e6e73;
  --line: #d2d2d7;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --radius: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #000000;
  --surface: #1c1c1e;
  --surface-muted: #2c2c2e;
  --text: #f5f5f7;
  --secondary: #a1a1a6;
  --line: #3a3a3c;
  --accent: #2997ff;
  --accent-hover: #40a9ff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --background: #000000;
    --surface: #1c1c1e;
    --surface-muted: #2c2c2e;
    --text: #f5f5f7;
    --secondary: #a1a1a6;
    --line: #3a3a3c;
    --accent: #2997ff;
    --accent-hover: #40a9ff;
  }
}

* { box-sizing: border-box; }

html {
  min-width: 300px;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, p, dl, dd { margin-top: 0; }
a { color: inherit; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }

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

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

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid rgba(0, 0, 0, .08);
  background: rgba(245, 245, 247, .8);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.header-inner,
.catalog-main,
.play-main {
  width: min(1080px, calc(100% - 48px));
  margin-inline: auto;
}

.header-inner {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.logo {
  color: var(--text);
  text-decoration: none;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .16em;
}

.nav-note {
  color: var(--secondary);
  font-size: .75rem;
}

.header-actions { display: flex; align-items: center; gap: 14px; }
.theme-toggle { position: relative; width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; color: var(--text); background: var(--surface-muted); cursor: pointer; }
.theme-toggle:hover { background: var(--line); }
.theme-icon { width: 14px; height: 14px; border: 2px solid currentColor; border-radius: 50%; transition: transform .2s ease, background .2s ease; }
:root[data-theme="dark"] .theme-icon { border-width: 0 0 2px 2px; border-radius: 0 0 0 14px; background: transparent; transform: rotate(-35deg); }
:root[data-theme="dark"] .site-header { border-color: rgba(255,255,255,.1); background: rgba(0,0,0,.74); }
:root[data-theme="dark"] .catalog-toolbar { border-color: rgba(255,255,255,.08); background: rgba(28,28,30,.78); }
:root[data-theme="dark"] .button:not(.button-primary) { color: var(--text); background: #2c2c2e; }
:root[data-theme="dark"] .button:not(.button-primary):hover { background: #3a3a3c; }
:root[data-theme="dark"] .card-metadata,
:root[data-theme="dark"] .process-list li { border-color: #38383a; }
:root[data-theme="dark"] .game-card:hover { box-shadow: 0 10px 28px rgba(0,0,0,.35); }

.catalog-main { padding-block: 76px 88px; }
.catalog-intro { max-width: 760px; margin-bottom: 64px; }
.eyebrow,
.model-label {
  margin-bottom: 10px;
  color: var(--secondary);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .035em;
}
.eyebrow { color: var(--accent); text-transform: uppercase; }
.model-label strong { color: var(--text); font-weight: 600; }

.catalog-intro h1,
.game-copy h1 {
  margin-bottom: 16px;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  line-height: 1.02;
  letter-spacing: -.052em;
  font-weight: 700;
}

.lede {
  max-width: 650px;
  margin-bottom: 0;
  color: var(--secondary);
  font-size: 1.12rem;
  line-height: 1.5;
}

.catalog-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(0, 0, 0, .07);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .78);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.search-field { position: relative; }
.search-icon {
  position: absolute;
  top: 50%;
  left: 15px;
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--secondary);
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}
.search-icon::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 1.5px;
  right: -5px;
  bottom: -3px;
  background: var(--secondary);
  transform: rotate(45deg);
  transform-origin: left center;
}

.search-field input,
.sort-field select {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: var(--surface-muted);
}
.search-field input { padding: 0 14px 0 42px; }
.search-field input::placeholder { color: #86868b; }
.search-field input:focus,
.sort-field select:focus { background: var(--surface); }

.sort-field { display: flex; align-items: center; gap: 8px; }
.sort-field label { color: var(--secondary); font-size: .8rem; white-space: nowrap; }
.sort-field select { min-width: 135px; padding: 0 34px 0 12px; cursor: pointer; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 0;
  border-radius: 9px;
  color: var(--text);
  background: #e8e8ed;
  cursor: pointer;
  font-weight: 600;
  line-height: 1;
}
.button:hover { background: #dedee3; }
.button-primary { color: #fff; background: var(--accent); }
.button-primary:hover { background: var(--accent-hover); }
.search-button { min-height: 44px; }

.clear-link,
.text-link,
.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
}
.clear-link { padding: 8px 6px; }
.clear-link:hover,
.text-link:hover,
.back-link:hover { text-decoration: underline; }

.results-summary {
  min-height: 22px;
  display: flex;
  gap: 5px;
  margin: 22px 2px 16px;
  color: var(--secondary);
  font-size: .82rem;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.game-card {
  min-width: 0;
  border-radius: var(--radius);
  background: var(--surface);
  transition: transform .2s ease, box-shadow .2s ease;
}
.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .07);
}

.card-link {
  min-height: 280px;
  display: flex;
  flex-direction: column;
  padding: 24px;
  color: inherit;
  text-decoration: none;
  border-radius: inherit;
}
.card-content { flex: 1; }
.game-card h2 {
  margin-bottom: 10px;
  font-size: 1.45rem;
  line-height: 1.2;
  letter-spacing: -.025em;
}
.card-description {
  display: -webkit-box;
  overflow: hidden;
  margin-bottom: 24px;
  color: var(--secondary);
  font-size: .92rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-metadata,
.game-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 0;
}
.card-metadata {
  padding-top: 17px;
  border-top: 1px solid #ededf0;
}
.card-metadata div,
.game-meta div { min-width: 0; }
.card-metadata dt,
.game-meta dt {
  margin-bottom: 2px;
  color: var(--secondary);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.card-metadata dd,
.game-meta dd {
  margin: 0;
  color: var(--text);
  font-size: .8rem;
  font-weight: 600;
}

.empty-state {
  padding: 76px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}
.empty-state h2 { margin-bottom: 8px; font-size: 1.25rem; }
.empty-state p { margin-bottom: 14px; color: var(--secondary); }

.play-main { padding-block: 30px 72px; }
.back-link { display: inline-flex; gap: 7px; margin-bottom: 36px; }
.play-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 32px;
  margin-bottom: 26px;
}
.game-copy h1 { margin-bottom: 12px; font-size: clamp(2.4rem, 5vw, 3.8rem); }
.game-description { max-width: 680px; margin-bottom: 20px; color: var(--secondary); }
.game-meta { gap: 28px; }
.play-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.button-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  display: block;
  overflow: visible;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: square;
  stroke-linejoin: miter;
  vector-effect: non-scaling-stroke;
}
.new-random-icon circle { fill: currentColor; stroke: none; }

.game-frame-shell {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background: #111113;
}
.game-frame-shell:fullscreen { border-radius: 0; }
.game-frame {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #111113;
  opacity: 0;
  transition: opacity .2s ease;
}
.game-frame.is-loaded { opacity: 1; }
.frame-loading {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-items: center;
  color: #a1a1a6;
  font-size: .88rem;
}
.frame-loading::before {
  content: "";
  width: 24px;
  height: 24px;
  display: block;
  margin: 0 auto 12px;
  border: 2px solid #3a3a3c;
  border-top-color: #a1a1a6;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.game-frame.is-loaded + .frame-loading { display: none; }

.instructions {
  margin-top: 24px;
  padding: 26px 28px;
  border-radius: var(--radius);
  background: var(--surface);
}
.instructions h2 { margin-bottom: 7px; font-size: 1rem; }
.instructions p { margin-bottom: 0; color: var(--secondary); white-space: pre-line; }

.surprise-button {
  width: fit-content;
  margin-top: 24px;
  text-decoration: none;
  border-radius: 999px;
  letter-spacing: .025em;
  transition: background .18s ease, transform .18s ease;
}
.surprise-button:hover { transform: translateY(-1px); }
.how-it-works {
  display: grid;
  grid-template-columns: minmax(220px, .75fr) minmax(0, 1.5fr);
  gap: 56px;
  margin-bottom: 56px;
  padding: 40px;
  border-radius: var(--radius);
  background: var(--surface);
}
.how-heading h2 { max-width: 300px; margin: 0; font-size: clamp(1.8rem, 3.5vw, 2.7rem); line-height: 1.08; letter-spacing: -.04em; }
.process-list { margin: 0; padding: 0; list-style: none; }
.process-list li { display: grid; grid-template-columns: 34px 1fr; column-gap: 14px; padding: 18px 0; border-bottom: 1px solid #ededf0; }
.process-list li:first-child { padding-top: 0; }
.process-list li:last-child { padding-bottom: 0; border-bottom: 0; }
.process-list span { grid-row: 1 / 3; color: var(--accent); font-size: .72rem; font-weight: 700; }
.process-list strong { font-size: .96rem; line-height: 1.3; }
.process-list p { margin: 5px 0 0; color: var(--secondary); font-size: .86rem; }
.card-art { aspect-ratio: 16 / 10; display: grid; place-items: center; overflow: hidden; margin: -16px -16px 22px; border-radius: 8px; background: var(--surface-muted); }
.card-art img { width: 56%; height: 56%; object-fit: contain; border-radius: 18%; }
.game-logo { width: 72px; height: 72px; display: block; margin-bottom: 20px; border-radius: 18%; object-fit: contain; }

/* Random Game Button play stage: game-first, nearly viewport-filling. */
@font-face {
  font-family: "Spline Sans Mono";
  src: url("/static/fonts/SplineSansMono.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Instrument Serif";
  src: url("/static/fonts/InstrumentSerif-Regular.woff2") format("woff2");
  font-display: swap;
}
.play-body { color: #f8f3e8; background: #0d0d0d; font-family: "Spline Sans Mono", ui-monospace, monospace; }
.play-body .play-main { width: calc(100% - 24px); max-width: none; margin: 0 auto; padding: 12px 0 72px; }
.play-commandbar { min-height: 68px; display: grid; grid-template-columns: minmax(120px, .35fr) minmax(0, 1fr) auto; align-items: center; gap: 24px; padding: 0 8px; }
.play-wordmark { font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-decoration: none; }
.play-identity { min-width: 0; display: flex; align-items: baseline; justify-content: center; gap: 12px; }
.play-identity .model-label { flex: 0 0 auto; margin: 0; color: #9b9589; font-size: .58rem; text-transform: uppercase; }
.play-identity h1 { overflow: hidden; margin: 0; font-family: "Instrument Serif", Georgia, serif; font-size: clamp(1.45rem, 2.5vw, 2.35rem); font-weight: 400; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.play-body .play-actions { flex-wrap: nowrap; }
.play-body .button { min-height: 40px; border: 1px solid #3b3934; border-radius: 0; color: #f8f3e8; background: transparent; font-size: .68rem; text-decoration: none; }
.play-body .button:hover { border-color: #d7ff43; background: #d7ff43; color: #171713; }
.play-body .new-random-button { border-color: #d7ff43; color: #d7ff43; }
.play-body .button-primary { border-color: #f8f3e8; background: #f8f3e8; color: #171713; }
.play-body .game-frame-shell { width: 100%; height: calc(100vh - 92px); height: calc(100dvh - 92px); min-height: 460px; max-height: 1080px; aspect-ratio: auto; border: 1px solid #32302c; border-radius: 3px; }
.play-body .game-frame-shell:fullscreen { width: 100%; height: 100%; max-height: none; border: 0; }
.play-details { display: grid; grid-template-columns: minmax(0, 1.25fr) auto; gap: 54px; padding: 68px clamp(8px, 4vw, 68px) 0; }
.play-details .game-copy { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 24px; align-items: start; }
.play-details .game-logo { width: 76px; height: 76px; margin: 0; border-radius: 3px; }
.play-details .game-copy h2 { margin: 0 0 14px; font-family: "Instrument Serif", Georgia, serif; font-size: clamp(2.6rem, 5vw, 5.5rem); font-weight: 400; line-height: .86; }
.play-details .game-description { max-width: 820px; color: #aaa397; font-size: .82rem; line-height: 1.65; }
.play-details .game-meta { min-width: 340px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px 38px; align-content: start; }
.play-details .game-meta dt { color: #7f796e; font-size: .55rem; letter-spacing: .06em; }
.play-details .game-meta dd { margin: 7px 0 0; font-size: .78rem; }
.play-details .instructions { grid-column: 1 / -1; margin: 16px 0 0; padding: 30px 0 0; border-top: 1px solid #34322e; border-radius: 0; background: transparent; }
.play-details .instructions h2 { color: #d7ff43; font-size: .62rem; letter-spacing: .08em; }
.play-details .instructions p { max-width: 940px; color: #aaa397; font-size: .82rem; line-height: 1.7; }

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

@media (max-width: 840px) {
  .game-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .catalog-toolbar { grid-template-columns: minmax(200px, 1fr) auto auto; }
  .clear-link { grid-column: 1 / -1; justify-self: end; padding-block: 0; }
  .play-heading { grid-template-columns: 1fr; align-items: start; }
  .how-it-works { grid-template-columns: 1fr; gap: 34px; }
}

@media (max-width: 600px) {
  .header-inner, .catalog-main, .play-main { width: min(100% - 28px, 1080px); }
  .header-inner { min-height: 50px; }
  .nav-note { display: none; }
  .catalog-main { padding-block: 50px 64px; }
  .catalog-intro { margin-bottom: 30px; }
  .catalog-intro h1 { font-size: clamp(2.5rem, 13vw, 3.4rem); }
  .catalog-toolbar { grid-template-columns: 1fr; padding: 9px; }
  .sort-field { display: grid; grid-template-columns: auto 1fr; }
  .clear-link { grid-column: auto; justify-self: center; padding: 6px; }
  .search-button { width: 100%; }
  .results-summary { margin-top: 18px; }
  .game-grid { grid-template-columns: 1fr; }
  .how-it-works { margin-bottom: 40px; padding: 28px 24px; }
  .card-link { min-height: 245px; }
  .play-main { padding-top: 24px; }
  .back-link { margin-bottom: 28px; }
  .play-actions { width: 100%; }
  .play-actions .button { flex: 1; }
  .game-frame-shell { border-radius: 10px; }
  .instructions { padding: 22px; }
}

@media (max-width: 700px) {
  .play-body .play-main { width: calc(100% - 12px); padding-top: 6px; }
  .play-commandbar { min-height: 108px; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; gap: 8px 6px; padding: 8px 4px 10px; }
  .play-wordmark { align-self: start; font-size: .6rem; letter-spacing: .055em; }
  .play-identity { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .play-identity h1 { font-size: 1.45rem; }
  .play-body .play-actions { grid-column: 2; grid-row: 1; width: auto; gap: 6px; }
  .play-body [data-action="fullscreen"] { display: none; }
  .play-body .play-actions .button { min-width: 44px; min-height: 44px; padding: 0 11px; }
  .play-body .play-actions .button span:last-child { display: none; }
  .play-body .game-frame-shell { height: calc(100dvh - 126px); min-height: 430px; border-radius: 2px; }
  .play-details { grid-template-columns: 1fr; gap: 36px; padding: 54px 12px 0; }
  .play-details .game-copy { grid-template-columns: 54px minmax(0, 1fr); gap: 16px; }
  .play-details .game-logo { width: 54px; height: 54px; }
  .play-details .game-meta { min-width: 0; grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
