:root {
  color-scheme: dark;
  --bg: #0d0f14;
  --bg-2: #13161d;
  --bg-3: #1b1f2a;
  --fg: #eef1f7;
  --muted: #8a93a6;
  --border: #262b37;
  --accent: #2d6cdf;
  --historical: #d1a154;
  --latest: #eac12b;
  --faithful: #3ca0ff;
  --modern: #3bd07a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, #171c28 0%, #0a0c10 70%);
  color: var(--fg);
  min-height: 100svh;
}

a { color: inherit; }

/* ---------- Shell ---------- */
.museum {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 24px;
}

.museum-header h1 {
  margin: 0 0 4px;
  letter-spacing: 0.5px;
  font-size: clamp(22px, 3vw, 34px);
  background: linear-gradient(90deg, #ffd166, #e56fb8 40%, #6dc3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.museum-header p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.museum-header .legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

.museum-header .legend .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.museum-header .legend .dot {
  width: 9px; height: 9px; border-radius: 50%;
  display: inline-block;
}

.legend .dot.historical { background: var(--historical); }
.legend .dot.latest     { background: var(--latest); }
.legend .dot.faithful   { background: var(--faithful); }
.legend .dot.modern     { background: var(--modern); }

/* ---------- Cart rack ---------- */
.rack {
  display: flex;
  gap: 18px;
  overflow-x: auto;
  padding: 8px 4px 24px;
  scroll-snap-type: x mandatory;
  /* The rack is just below the header; give carts some breathing room so the lift/focus
     ring transforms don't clip against the edges of the container. */
}

.rack::-webkit-scrollbar { height: 8px; }
.rack::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Each cart is a real GBA cartridge vector image with a colour-customized label overlaid
 * inside the cart's label cut-out. Container = cart SVG (200:122 aspect); label overlay
 * is absolutely positioned at the sticker region. */
.cart {
  --cart-color: #4a51d9;
  --cart-accent: #ffffff;
  position: relative;
  flex: 0 0 auto;
  width: 168px;
  aspect-ratio: 200 / 122;
  background: transparent url('./images/gba-cart.svg') center/100% 100% no-repeat;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
  border: 0;
  padding: 0;
  cursor: pointer;
  scroll-snap-align: start;
  transform-origin: 50% 100%;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1.2),
              filter 0.3s ease;
}

/* Position the colour label inside the cart's sticker rectangle. Percentages are tuned to
 * the gba-cart.svg viewBox (370 70 200 122) so the label hugs the inner dark rectangle. */
.cart-label {
  position: absolute;
  left: 14.5%;
  top: 26.5%;
  width: 74%;
  height: 63%;
  border-radius: 2px;
  background: var(--cart-color);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35),
              inset 0 2px 0 rgba(255, 255, 255, 0.18),
              inset 0 -2px 0 rgba(0, 0, 0, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cart-cover {
  flex: 1;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18) 0%, rgba(255, 255, 255, 0) 60%),
    linear-gradient(135deg,
      color-mix(in oklab, var(--cart-color) 50%, #fff) 0%,
      color-mix(in oklab, var(--cart-color) 85%, #000) 100%);
  position: relative;
  overflow: hidden;
}

.cart-cover::after {
  /* Soft scanline veil so the cover reads as an LCD-screen still, not a flat colour patch. */
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg,
    rgba(255, 255, 255, 0.12) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
  pointer-events: none;
}

.cart-title {
  padding: 3px 6px 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-align: center;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  text-transform: uppercase;
  border-top: 1px solid rgba(0, 0, 0, 0.4);
}

.cart-badge {
  position: absolute;
  top: 14%;
  right: 8%;
  background: var(--cart-accent, var(--accent));
  color: #111;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  z-index: 1;
}

.cart:hover, .cart:focus-visible {
  transform: translateY(-6px) rotate(-1deg);
  outline: none;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55)) brightness(1.05);
}

.cart.is-selected {
  transform: translateY(-12px) scale(1.06);
  filter: drop-shadow(0 18px 32px rgba(0, 0, 0, 0.6)) brightness(1.08);
  animation: cart-insert 0.45s cubic-bezier(0.2, 0.8, 0.2, 1.2);
}

@keyframes cart-insert {
  0%   { transform: translateY(0)     scale(1); }
  40%  { transform: translateY(-28px) scale(1.08); }
  100% { transform: translateY(-12px) scale(1.06); }
}

.rack[data-has-selection="true"] .cart:not(.is-selected) {
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35)) brightness(0.7) saturate(0.7);
}

/* ---------- Version spine ---------- */
.spine-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}

.spine-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.5px;
}

.spine {
  position: relative;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 8px;
}

.spine::before {
  /* Horizontal timeline rail behind the nodes. */
  content: '';
  position: absolute;
  left: 0; right: 0; top: 16px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.version-node {
  position: relative;
  z-index: 1;
  min-width: 72px;
  padding: 6px 10px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.version-node:hover { transform: translateY(-2px); }
.version-node .dot {
  width: 10px; height: 10px; border-radius: 50%;
  margin-bottom: 2px;
  background: var(--border);
}
.version-node.kind-historical .dot { background: var(--historical); }
.version-node.kind-latest     .dot { background: var(--latest); }
.version-node.kind-faithful   .dot { background: var(--faithful); }
.version-node.kind-modern     .dot { background: var(--modern); }

.version-node .label { font-size: 12px; letter-spacing: 0.4px; font-weight: 600; }
.version-node .year  { font-size: 10px; color: var(--muted); }

.version-node.is-active {
  border-color: currentColor;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent);
  transform: translateY(-2px);
}
.version-node.is-active .label { color: #fff; }
.version-node.kind-historical.is-active { color: var(--historical); }
.version-node.kind-latest.is-active     { color: var(--latest); }
.version-node.kind-faithful.is-active   { color: var(--faithful); }
.version-node.kind-modern.is-active     { color: var(--modern); }

.version-node[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* ---------- Stage (player, full-width) ----------
 * Notes are rendered above the stage (between the spine and the player), so the stage just
 * hosts the GBA shell and its control strip at full container width.
 */
.stage { display: block; }
.stage-player-col { display: flex; flex-direction: column; }

/* Stage player is the GBA console SVG with the iframe overlaid exactly where the LCD sits.
 * The LCD rectangle in gba-console.svg lives at roughly (93.7, 36.4, 148.3, 100.0) inside
 * the 335x192 viewBox → the percentages below. Keep these in sync with that SVG! */
.stage-player {
  position: relative;
  aspect-ratio: 335 / 192;
  background: transparent url('./images/gba-console.svg') center/100% 100% no-repeat;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
  padding: 0;
}

.stage-player .screen {
  position: absolute;
  left: 28%;
  top: 19%;
  width: 44.3%;
  height: 52.1%;
  border-radius: 2px;
  overflow: hidden;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.5), inset 0 0 8px rgba(0, 0, 0, 0.6);
}

.stage-player canvas#player-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  /* Keep GBA pixels crisp instead of letting the browser bilinear-blend them. */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Compact status overlay shown while booting / loading a ROM / surfacing fatal errors. */
.player-status {
  position: absolute;
  inset: auto 0 0 0;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #cfd4e0;
  font-size: 10px;
  letter-spacing: 0.4px;
  pointer-events: none;
}
.player-status.hidden { display: none; }
.player-status.error { color: #ffb4b4; background: rgba(120, 0, 0, 0.65); }

.stage-player[data-crt="true"] .screen::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.25) 0 2px, transparent 2px 4px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  mix-blend-mode: multiply;
}

/* Fullscreen: keep the GBA shell's 335:192 ratio inside a black void. The fullscreen API
 * auto-sizes the element to the viewport, so we clamp width to `min(100vw, 100vh * ratio)`
 * and let aspect-ratio drive height. The `::backdrop` fills the surrounding letterbox. */
.stage-player:fullscreen,
.stage-player:-webkit-full-screen {
  aspect-ratio: 335 / 192;
  width: min(100vw, calc(100vh * 335 / 192));
  height: auto;
  max-width: 100vw;
  max-height: 100vh;
  margin: auto;
}
.stage-player:fullscreen::backdrop,
.stage-player:-webkit-full-screen::backdrop {
  background: #000;
}

/* Keyboard-hint row sits just above the stage-controls strip; it's the only row of prose
 * between the GBA shell and the control toolbar, so we keep it compact and muted. */
.stage-hints {
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.2px;
}
.stage-hints .kbd {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--bg-3);
  border-radius: 4px;
  padding: 1px 5px;
  font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--fg);
}

.stage-controls {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.stage-controls .slot,
.stage-controls .volume {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.3px;
}

.stage-controls .slot select,
.stage-controls .volume input[type=range] {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font: inherit;
  font-size: 13px;
}

.stage-controls .volume input[type=range] {
  accent-color: #3ad66c;
  width: 120px;
  padding: 0;
}

.stage-controls button {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.stage-controls button:hover { background: #262c3a; }

/* GBA-style power LED: small round dot, dim/black when off, saturated green with glow when on. */
.stage-controls .led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #1a1e2a;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6),
              inset 0 1px 0 rgba(255, 255, 255, 0.06);
  flex: 0 0 auto;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.stage-controls button.is-on .led {
  background: radial-gradient(circle at 35% 30%, #b9ffc7 0%, #3ad66c 55%, #10883b 100%);
  box-shadow: 0 0 6px rgba(58, 214, 108, 0.75),
              inset 0 0 0 1px rgba(0, 0, 0, 0.35),
              inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.stage-controls button.is-on { border-color: rgba(58, 214, 108, 0.55); }

.stage-notes {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.stage-notes .eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-notes h2 {
  margin: 0;
  font-size: 20px;
}

.stage-notes .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.stage-notes .meta strong {
  color: var(--fg);
}

.stage-notes p {
  margin: 0;
  color: #cfd4e0;
  line-height: 1.5;
  font-size: 14px;
}

.stage-notes .links {
  margin-top: auto;
  display: flex;
  gap: 10px;
  font-size: 13px;
}

.stage-notes .links a {
  color: var(--accent);
  text-decoration: none;
}
.stage-notes .links a:hover { text-decoration: underline; }

.kbd {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--fg);
  border-radius: 4px;
  padding: 1px 5px;
  font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .stage-notes { padding: 14px 16px; }
  .stage-notes h2 { font-size: 18px; }
}
