/* Arcade chrome: an intro that flies into a cabinet screen, a game-select
   screen built on top of that same cabinet, then the chosen game full-focus
   with the cabinet gone entirely. Three screens, one dark ground, one amber
   accent throughout so the whole thing reads as one place. */

:root {
  --ink: #eef1f8;
  --ink-dim: #9aa3b8;
  --ink-faint: #5c6478;
  --line: rgba(255, 255, 255, 0.10);
  --bg: #04050a;
  --accent: #ffb454; /* amber, the arcade's colour. The lab stays blue. */
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  /* The ground is painted by html. If body paints it too, it lands on top of
     the negative z-index scene host below and the backdrop vanishes. */
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------- scene host */

/* The cabinet lives here for the intro and the select screen only. It is an
   empty shell until JS mounts a <lab-scene> into it, and is torn back down to
   empty the moment a game is showing. */
.scene-host {
  position: fixed;
  inset: 0;
  z-index: -2;
}

.scene-host lab-scene {
  position: fixed;
  inset: 0;
  display: block;
}

.scene-host lab-scene[data-state='unsupported'],
.scene-host lab-scene[data-state='error'] {
  background:
    radial-gradient(circle at 30% 30%, #241d3d 0, transparent 55%),
    radial-gradient(circle at 70% 70%, #16203d 0, transparent 55%),
    var(--bg);
}

/* --------------------------------------------------------------- shared */

/* Both the intro and the select screen sit full-bleed over the scene host,
   fixed so neither ever contributes to page scroll. */
.intro,
.select {
  position: fixed;
  inset: 0;
  transition: opacity 400ms ease;
}

/* ---------------------------------------------------------------- intro */

.intro {
  z-index: 4;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 1.5rem 1.8rem;
  cursor: pointer;
  opacity: 1;
}

.intro.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.intro-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-dim);
  text-decoration: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.intro-brand b { color: var(--ink); font-weight: 600; }
.intro-brand .mark { flex-shrink: 0; }

.intro-skip {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  color: var(--ink-faint);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

/* -------------------------------------------------------- select screen */

.select {
  z-index: 3;
  opacity: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 3.2rem 1.6rem 3rem;
}

.select.is-visible { opacity: 1; }

/* CRT treatment: faint scanlines, a vignette, and a soft amber glow pressed
   in from the edges, so the tiles read as though they are drawn on the same
   screen the intro just flew into. */
.select::before,
.select::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
.select::before {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0px,
    rgba(0, 0, 0, 0.16) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: multiply;
}
.select::after {
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(4, 5, 10, 0.82) 100%),
    radial-gradient(140% 60% at 50% 0%, rgba(255, 180, 84, 0.10) 0%, transparent 60%),
    radial-gradient(140% 60% at 50% 100%, rgba(255, 180, 84, 0.08) 0%, transparent 60%);
}

.select-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  /* auto top margin pairs with .tiles' auto bottom margin: the pair sits in
     the middle of the screen, and still scrolls if the tiles ever overflow. */
  margin-top: auto;
  margin-bottom: 2.4rem;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  color: var(--ink-dim);
}
.select-brand b { color: var(--ink); font-weight: 600; }

.tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.1rem;
  max-width: 64rem;
  width: 100%;
  margin-bottom: auto;
}

.tile {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  width: 15rem;
  padding: 1.6rem 1.3rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 10, 18, 0.72);
  backdrop-filter: blur(10px);
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}
.tile:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 180, 84, 0.35);
  background: rgba(14, 16, 26, 0.82);
}
.tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.tile-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.6rem;
  color: var(--ink); /* chess and any icon without its own fixed colours */
}

.tile-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.tile-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(255, 180, 84, 0.28);
  background: rgba(255, 180, 84, 0.07);
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
}

.tile-blurb {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--ink-dim);
}

/* ---------------------------------------------------------- game screen */

.game {
  min-height: 100vh;
  padding: 1.1rem 1.6rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: min(94vw, calc(76vh * 1.5));
  margin: 0 auto 0.9rem;
}

.back {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.back:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.24); }
.back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.game-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.state {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  min-width: 5.4rem;
  text-align: center;
  text-transform: uppercase;
}
.state[data-state='running'] { color: var(--accent); border-color: rgba(255, 180, 84, 0.35); }
.state[data-state='countdown'] { color: var(--ink); }

.gear {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink-dim);
  border-radius: 999px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.gear:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.24); }
.gear:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.gear.is-active { color: var(--accent); border-color: rgba(255, 180, 84, 0.35); }

/* ------------------------------------------------------------------ stage */

.stage {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* The package injects its own base stylesheet (width: 100%) after this one
   loads, so an ID selector is used here rather than the bare element: equal
   specificity would otherwise let that later rule win the cascade. */
#stage {
  width: min(94vw, calc(76vh * 1.5));
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
#stage:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- results */

.results {
  width: min(94vw, calc(76vh * 1.5));
  margin: 1rem auto 0;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  margin: 0;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.stats:empty { display: none; }

/* One label/value pair per <div>, so the flex gap lands between pairs rather
   than wedging itself between a label and its own value. */
.stat {
  display: flex;
  gap: 0.4rem;
}
.stat dt, .stat dd { margin: 0; }
.stat dt { color: var(--ink-faint); }
.stat dd { color: var(--ink); }

/* ----------------------------------------------------------- drawer */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 17.5rem;
  padding: 1.2rem 1.1rem 1.5rem;
  border-left: 1px solid var(--line);
  background: rgba(8, 10, 18, 0.92);
  backdrop-filter: blur(14px);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 260ms ease;
  z-index: 6;
}
.drawer.is-open { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.drawer-head-buttons { display: flex; gap: 0.4rem; }

.drawer-head h2 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.2rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.ghost:hover { color: var(--ink); border-color: rgba(255, 255, 255, 0.26); }
.ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------- controls */
/*
 * Kept from the previous single-panel layout: built from whatever a game
 * declares in meta.params (src/arcade.js's buildControls), so a new knob on
 * a game needs no change here.
 */

.controls { display: flex; flex-direction: column; gap: 0.7rem; }
.controls:empty { display: none; }

.control {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'label value' 'input input';
  gap: 0.3rem 0.5rem;
  align-items: center;
  transition: opacity 140ms ease;
}

/* Sensitivity and crosshair style only do anything in raw pointer mode, so
   the drawer greys them out rather than let a visitor turn a knob that is
   quietly connected to nothing. */
.control.is-disabled {
  opacity: 0.4;
}

.control-label {
  grid-area: label;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.control-value {
  grid-area: value;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.control input[type='range'] {
  grid-area: input;
  width: 100%;
  height: 2px;
  appearance: none;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 2px;
  cursor: pointer;
}

.control input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #04050a;
  cursor: pointer;
}

.control input[type='range']::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid #04050a;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.control input[type='range']:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.control input[type='checkbox'] { grid-area: input; justify-self: start; accent-color: var(--accent); }

.control-select {
  grid-area: input;
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.28rem 0.5rem;
  cursor: pointer;
}
.control-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A select has no numeric readout, so let the label use the full width. */
.control:has(.control-select) {
  grid-template-columns: 1fr;
  grid-template-areas: 'label' 'input';
}
.control:has(.control-select) .control-value { display: none; }

/* --------------------------------------------------------------- mobile */

@media (max-width: 900px) {
  .select { padding-top: 4rem; }
  .select-brand { font-size: 1rem; }
}

@media (max-width: 600px) {
  .intro { padding: 1.1rem; }
  .select { padding: 3.6rem 1.1rem 2.5rem; }
  .tiles { flex-direction: column; align-items: center; }
  .tile { width: 100%; max-width: 22rem; }

  .game { padding: 0.9rem 1rem 2rem; }
  .game-bar { width: 100%; }
  #stage,
  .results { width: 100%; }
  .game-title { font-size: 0.9rem; }

  /* The drawer becomes a bottom sheet: same content, docked to the bottom
     edge and sliding up instead of in from the side. */
  .drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    transform: translateY(100%);
  }
  .drawer.is-open { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .intro,
  .select,
  .tile,
  .control,
  .back,
  .gear,
  .ghost,
  .drawer {
    transition: none;
  }
}
