/* Pixel2Playable. Dark arcade CRT, restrained. The type does the work. */

@font-face {
  font-family: "Geist Pixel";
  src: url("/static/fonts/GeistPixel-Square.woff2") format("woff2");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/GeistMono-Regular.woff2") format("woff2");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("/static/fonts/GeistMono-Bold.woff2") format("woff2");
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #08080A;
  --surface: #101013;
  --surface-2: #17171C;
  --line: #26262E;
  --text: #ECECEF;
  --dim: #7A7A87;
  --faint: #43434F;

  --accent: #FF5C00;
  --good: #3DDC97;
  --bad: #FF3B30;

  --display: "Geist Pixel", ui-monospace, monospace;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, monospace;

  --pad: clamp(16px, 3vw, 40px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
}

/* CRT. One overlay, nothing more. No aberration, no curvature, no flicker. */
.crt {
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,.5) 100%);
}

canvas, video, iframe, img.px { image-rendering: pixelated; }

/* ── shared atoms ─────────────────────────────────────────────────────── */

.label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--dim);
}
.accent { color: var(--accent); }
.rule { height: 1px; background: var(--line); border: 0; margin: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
}
.panel > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}

button {
  font: inherit; color: inherit; cursor: pointer;
  background: transparent; border: 1px solid var(--line);
  padding: 9px 16px;
  text-transform: uppercase; letter-spacing: .12em; font-size: 11px;
  transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease);
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.primary { border-color: var(--accent); color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent); color: #000; }

/* ── view switching ───────────────────────────────────────────────────── */

#idle, #run { display: none; }
/* both views are flex columns; the view switch must not clobber that */
body[data-view="idle"] #idle { display: flex; }
body[data-view="run"]  #run  { display: flex; }

/* ── idle ─────────────────────────────────────────────────────────────── */

/* No `display` here: it would outrank the view-switch rule above (same
   specificity, later wins) and #idle would never hide. */
#idle {
  min-height: 100vh;
  flex-direction: column; align-items: center; justify-content: center;
  padding: var(--pad); text-align: center;
}

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

/* The wordmark is a canvas so it can assemble itself out of its own pixels.
   The <h1> above it stays as real text for screen readers and page title. */
#wordmark { display: block; width: 100%; max-width: 1180px; height: auto; }

.tagline {
  margin: 18px 0 0;
  color: var(--dim);
  font-size: clamp(12px, 1.4vw, 15px);
  letter-spacing: .06em;
}

/* Twenty cartridges, not four. At the old size they took five rows and pushed
   the drop zone and the library off the screen, so the picker stopped reading as
   a picker and started reading as the page. Small tiles, two rows, done. */
.cartridges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin: clamp(22px, 3.2vh, 40px) 0 0;
  width: min(1180px, 100%);
}

.cart {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 5px 5px 7px;
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .15s var(--ease);
}
.cart:hover {
  border-color: var(--accent); background: var(--surface-2);
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 8px 24px -12px var(--accent);
  z-index: 2;
}
.cart video, .cart canvas {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  opacity: .92; transition: opacity .15s var(--ease);
}
.cart:hover video { opacity: 1; }
.cart .name {
  font-family: var(--display); font-size: 10px;
  text-transform: uppercase; letter-spacing: .04em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.cart[data-unknown] {
  border-style: dashed;
  border-color: var(--dim);
}
.cart[data-unknown] .name { color: var(--accent); }
.cart[data-unknown] .sub {
  font-size: 8px; color: var(--dim); text-transform: uppercase; letter-spacing: .06em;
  max-width: 100%; line-height: 1.4;
}

#drop {
  margin-top: 16px; width: min(760px, 100%);
  border: 1px dashed var(--line);
  padding: 20px;
  color: var(--dim);
  cursor: pointer;
  background: transparent;
  transition: border-color .15s var(--ease), color .15s var(--ease),
              background .15s var(--ease);
}
#drop:hover, #drop.over {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
#drop:active { background: color-mix(in srgb, var(--accent) 11%, transparent); }

/* Bring your own key. Quiet by default: most visitors want the demo button, and
   an API key field competing with it would make the page look like a signup. */
.byok {
  margin-top: 10px; width: min(760px, 100%);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex-wrap: wrap;
  font-size: 10px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--faint);
}
.byok button {
  border: 0; padding: 0; font-size: inherit; letter-spacing: inherit;
  color: var(--dim); text-decoration: underline; text-underline-offset: 3px;
}
.byok button:hover:not(:disabled) { color: var(--accent); }
.byok input {
  font: inherit; font-family: var(--mono); letter-spacing: .06em;
  text-transform: none;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); padding: 8px 10px; width: min(340px, 70vw);
}
.byok input:focus { outline: 0; border-color: var(--accent); }
.byok[hidden] { display: none; }
.byok button[hidden] { display: none; }

.account-row #who-state {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--dim);
}
.account-row .verified { border: 0; padding: 0; }
.account-row #who-signout {
  margin-left: 2px; padding-left: 10px;
  border-left: 1px solid var(--line);
}

/* Verified and self declared must never look alike. */
.verified {
  color: var(--good);
  border: 1px solid color-mix(in srgb, var(--good) 45%, transparent);
  padding: 2px 6px; letter-spacing: .12em;
}

/* ── library ──────────────────────────────────────────────────────────── */

/* Full bleed, so the grid runs off both edges instead of stopping at a tidy
   margin. The point is the impression that the shelf continues past the screen. */
.library {
  margin-top: clamp(24px, 4vh, 44px);
  width: 100vw;
  margin-left: calc(50% - 50vw);
  text-align: left;
}
.library > .label {
  padding: 0 clamp(16px, 3vw, 40px);
  text-align: center;
}

/* Numbers as reward. A count of what has been rebuilt and how well, in display
   type, so the shelf opens with a result instead of a heading. */
.lib-stats {
  display: flex; gap: clamp(20px, 4vw, 52px); flex-wrap: wrap;
  justify-content: center; text-align: center;
  padding: 0 clamp(16px, 3vw, 40px) 16px;
}
.lib-stats .stat {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.lib-stats .n {
  font-family: var(--display); font-size: clamp(24px, 3vw, 38px);
  line-height: 1; font-variant-numeric: tabular-nums;
}
.lib-stats .stat.hot .n { color: var(--good); }
.lib-stats .stat.warm .n { color: var(--accent); }
.library[hidden] { display: none; }
.library > .label { margin-bottom: 10px; }

/* A quantised fade, not a blur. Alpha steps in hard bands so the edge dissolves
   in blocks: a smooth gradient here would be the one soft edge on a page whose
   whole argument is pixels. Sideways only. There used to be a second, downward
   mask, but the list is laid out in full and the page simply ends below it, so
   the fade never coincided with the viewport edge: it just ghosted the last row
   of real, clickable runs at every scroll position. The sideways illusion works
   because the grid genuinely bleeds past both screen edges; the bottom one was
   faking a continuation that does not exist. */
#library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 12px;
  padding: 2px clamp(16px, 3vw, 40px) 0;
  --sides:
    linear-gradient(90deg,
      transparent 0 1%,
      rgba(0,0,0,.10) 1% 2.5%,
      rgba(0,0,0,.26) 2.5% 4%,
      rgba(0,0,0,.48) 4% 5.5%,
      rgba(0,0,0,.72) 5.5% 7%,
      rgba(0,0,0,.9) 7% 8.5%,
      #000 8.5% 91.5%,
      rgba(0,0,0,.9) 91.5% 93%,
      rgba(0,0,0,.72) 93% 94.5%,
      rgba(0,0,0,.48) 94.5% 96%,
      rgba(0,0,0,.26) 96% 97.5%,
      rgba(0,0,0,.10) 97.5% 99%,
      transparent 99% 100%);
  -webkit-mask-image: var(--sides);
  mask-image: var(--sides);
}

.run-card {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 8px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color .15s var(--ease), transform .15s var(--ease),
              background .15s var(--ease);
  /* Paused until the card is actually on screen. Firing the entrance at build
     time meant every card below the fold had already risen, unseen, before the
     visitor scrolled to it: the reward was being spent with nobody watching. */
  animation: rise .5s var(--ease) both;
  animation-play-state: paused;
}
.run-card.seen { animation-play-state: running; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.run-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 0 0 1px var(--accent), 0 10px 30px -10px var(--accent);
  z-index: 2;
}

/* Score drives the treatment. Every card looking identical meant a 94 read the
   same as a 27, so the eye had nowhere to land and nothing felt won. */
.run-card.tier-high {
  border-color: color-mix(in srgb, var(--good) 55%, var(--line));
  box-shadow: 0 0 22px -8px var(--good);
}
.run-card.tier-high .total { color: var(--good); }
.run-card.tier-mid .total { color: var(--accent); }
.run-card.tier-low { opacity: .62; }
.run-card.tier-low .total { color: var(--dim); }
.run-card:hover { opacity: 1; }

/* The thumbnail is the reconstruction running, not the source clip: the library
   is a wall of the games the model actually built. */
/* Full brightness. The reconstructions are the product; dimming them was
   dimming the only thing on this page worth looking at. */
.run-card .shot {
  width: 100%; aspect-ratio: 4 / 3; display: block;
  background: #000;
}

.run-card .meta {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.run-card .game {
  font-family: var(--display); font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em;
}
.run-card .total {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
  color: var(--accent); font-size: 18px;
}
.run-card .who {
  font-size: 10px; color: var(--dim);
  display: flex; align-items: center; gap: 5px;
  overflow: hidden; white-space: nowrap;
}
.run-card .who .tick { color: var(--good); }

/* Square, not round. Everything else on this page has hard edges, and one
   circle would be the only soft shape in the interface. */
.avatar {
  width: 14px; height: 14px; flex: none; display: block;
  border: 1px solid var(--line); object-fit: cover;
}
.byok .avatar { width: 18px; height: 18px; margin-right: 2px; }

@media (prefers-reduced-motion: reduce) { .run-card { animation: none; } }

#share { border-color: var(--accent); color: var(--accent); }
#share:hover { background: var(--accent); color: #000; }
#share[hidden] { display: none; }
#copy-link[hidden] { display: none; }
#copy-link { margin-right: 8px; }
footer.foot { align-items: center; }

/* ── run ──────────────────────────────────────────────────────────────── */

#run {
  flex-direction: column;
  min-height: 100vh;
  padding: var(--pad);
  gap: 14px;
  max-width: 1500px; margin: 0 auto; width: 100%;
}

#run > .top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 20px;
  flex-wrap: wrap;
}
#run .wordmark {
  font-family: var(--display); font-size: 20px;
  text-transform: uppercase; letter-spacing: .05em;
  cursor: pointer;
  /* Only the mark and the label are flex items. Wrapping the label in one span
     matters: bare text nodes become anonymous flex items, so PIXEL, 2 and
     PLAYABLE would each take the gap and the word would come apart. */
  display: flex; align-items: center; gap: 10px;
}
#run .wordmark img { display: block; flex: none; }
#run .wordmark .half { color: var(--accent); }
#run .meta { display: flex; gap: 18px; flex-wrap: wrap; }

/* stage */
.stage {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
@media (max-width: 860px) { .stage { grid-template-columns: 1fr; } }

.stage > section { display: flex; flex-direction: column; }
/* Capped so the header, stage, metrics and both lower panels fit one 900px
   viewport at once. The whole story has to be readable in a single frame. */
.stage .screen {
  position: relative;
  aspect-ratio: 4 / 3;
  max-height: 40vh;
  background: #000;
  display: grid; place-items: center;
  /* minmax(0, 1fr), not auto. An auto track sizes to the video's intrinsic
     4:3 height at full width, which is taller than the box once max-height
     bites, so height:100% resolved against the overflowing track and the
     bottom of the game was cropped away. */
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  overflow: hidden;
}
.stage video, .stage iframe {
  width: 100%; height: 100%; border: 0; display: block; object-fit: contain;
}
.stage .empty {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  color: var(--text); font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  pointer-events: none;
  /* The loader runs behind this, so the label needs its own ground to sit on. */
  background: rgba(8, 8, 10, .82);
  padding: 6px 12px;
  white-space: nowrap;
}

/* Colour carries state: polychrome means work in progress, orange means a
   finished result. The loader fills the five minutes of perception that would
   otherwise be a black rectangle, which is the longest dead moment in the run. */
#loader { position: absolute; inset: 0; width: 100%; height: 100%; }
#loader[hidden], .stage .empty[hidden] { display: none; }

/* the reconstruction side is the only orange thing on the page */
#recon.panel { border-color: color-mix(in srgb, var(--accent) 32%, var(--line)); }
#recon > header .label { color: var(--accent); }

/* The moment a game exists, PLAY is the payoff and should look like one. */
#play:not(:disabled) { border-color: var(--accent); color: var(--accent); }
#play:not(:disabled):hover { background: var(--accent); color: #000; }

.controls-hint { font-size: 10px; color: var(--dim); letter-spacing: .1em; text-transform: uppercase; }

/* metrics */
.metrics {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line);
}
@media (max-width: 700px) { .metrics { grid-template-columns: repeat(2, 1fr); } }

/* The headline number. The four components build up to it left to right, and
   until this cell existed the only place the total appeared was a log line in
   the trace, which is burying the one number the whole run exists to produce. */
.metric.metric-total {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, var(--line));
}
/* At or above the green line the whole cell agrees with itself, same as a
   tier-high card on the shelf. */
.metric.metric-total.is-good {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--good) 55%, var(--line));
}
.metric.metric-total:not(.is-null):not(.is-good) .v { color: var(--accent); }
.metric.metric-total:not(.is-null):not(.is-good) .bar > i { background: var(--accent); }
/* One flash when the run settles, then still. */
@keyframes totalpop {
  from { background: color-mix(in srgb, var(--accent) 26%, var(--surface)); }
  to   { background: var(--surface); }
}
.metric.metric-total.pop { animation: totalpop .9s var(--ease) 1; }

.metric { background: var(--surface); padding: 14px 16px; }
.metric .k { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.metric .v {
  font-family: var(--display); font-size: 26px; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.metric .bar { height: 3px; background: var(--surface-2); margin-top: 12px; overflow: hidden; }
.metric .bar > i {
  display: block; height: 100%; width: 0%;
  background: var(--accent);
  transition: width .4s var(--ease);
}
/* A pending metric is not a zero. It stripes while there is nothing to show,
   so an empty bar reads as waiting rather than as a score of nought. */
.metric.is-null .bar {
  background-image: repeating-linear-gradient(
    90deg,
    color-mix(in srgb, var(--accent) 22%, transparent) 0 6px,
    transparent 6px 14px);
  background-size: 20px 100%;
  animation: drift 900ms linear infinite;
}
@keyframes drift { to { background-position: 20px 0; } }
/* A finished or replayed run is idle: a still-drifting stripe on an n/a metric
   would be the page claiming work that is not happening. The pattern stays,
   the motion stops. */
.metrics.settled .metric.is-null .bar { animation: none; }

/* The freshest trace line glows for a moment, so a long-running stage still
   shows the run is alive. */
@keyframes flash { from { color: var(--accent); } to { color: var(--text); } }
#trace .line:last-child .m { animation: flash 1.2s var(--ease); }
.metric[data-judged] .k .label::after {
  content: " · model-judged"; color: var(--faint); letter-spacing: .1em;
}
.metric.is-good .v { color: var(--good); }
.metric.is-good .bar > i { background: var(--good); }
.metric.is-null .v { color: var(--faint); }

/* lower split */
.lower { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; flex: 1; min-height: 260px; }
@media (max-width: 860px) { .lower { grid-template-columns: 1fr; } }

.lower .body { padding: 14px; overflow: auto; max-height: 42vh; }
/* panel = header + scrolling body; the body must not count the header's height */
.lower > section { min-height: 0; display: flex; flex-direction: column; }
.lower > section > header { flex: none; }

/* On a real desktop the run view is a single-viewport dashboard: the whole
   story has to be readable in one frame, so the panels absorb the slack
   instead of the page growing a scrollbar. */
@media (min-width: 861px) and (min-height: 700px) {
  #run { height: 100vh; overflow: hidden; }
  .stage { flex: none; }
  .lower { flex: 1; min-height: 0; }
  .lower .body { max-height: none; flex: 1; min-height: 0; }
}

/* world model */
.wm-row {
  display: grid; grid-template-columns: 88px 1fr; gap: 12px;
  padding: 5px 0; align-items: baseline;
}
.wm-row .k { color: var(--dim); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.wm-row .v { font-variant-numeric: tabular-nums; }

.hyp { display: flex; gap: 10px; padding: 5px 0; align-items: baseline; }
.hyp .mark { width: 14px; flex: none; }
.hyp.yes .mark { color: var(--good); }
.hyp.no  .mark { color: var(--bad); }
.hyp .c { margin-left: auto; color: var(--faint); font-variant-numeric: tabular-nums; }

/* trace */
#trace .line { display: flex; gap: 10px; padding: 2px 0; }
#trace .t { color: var(--faint); flex: none; font-variant-numeric: tabular-nums; }
#trace .line.err .m { color: var(--bad); }
#trace .line.hi .m { color: var(--accent); }

footer.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding-top: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
