/* The Lab: the site's one dark band, and one game built from the site's mechanisms. Behaviour: js/lab.js. Roles: design.md */
@property --lab-a {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

.lab {
  background: var(--night);
  color: var(--night-ink);
}
.lab .label { color: var(--night-muted); }
.lab__lede { max-width: 62ch; margin-block-start: var(--sp-5); color: var(--night-muted); }

/* ---------- the game ---------- */
.game { margin-block-start: var(--sp-8); }
.game__hud {
  display: flex;
  gap: var(--sp-7);
  align-items: flex-end;
  margin-block-end: var(--sp-3);
}
.game__stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.game__stat b {
  font-family: var(--font-display);
  font-size: var(--fs-h3);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.game__track {
  block-size: var(--sp-1);
  margin-block-end: var(--sp-4);
  border-radius: var(--r-full);
  background: var(--night-line);
  overflow: hidden;
}
.game__time {
  display: block;
  block-size: 100%;
  background: var(--accent);
  transform-origin: calc(50% - 50% * var(--dir)) 50%; /* drains toward the inline-start edge, from the --dir token */
}
.game__stage {
  position: relative;
  aspect-ratio: 16 / 9;
  max-block-size: calc(100svh - var(--sp-10)); /* never taller than the screen: a round can't trap a short (landscape) phone, and the HUD and End stay in view */
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--night);
  box-shadow: var(--shadow-night);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.game__stage.is-playing { touch-action: none; cursor: crosshair; } /* mid-round a drag aims; between rounds the page scrolls */
.game__stage > canvas { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; }
.game__board { outline: none; }
.game__board:focus-visible { box-shadow: inset 0 0 0 2px var(--night-ink); }

.game__panel {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-5);
  background: color-mix(in srgb, var(--night) 72%, transparent);
  text-align: center;
}
.game__panel[hidden] { display: none; }
.game__title { font-size: var(--fs-display); font-weight: 700; line-height: 1.15; }
.game__text { max-inline-size: 44ch; color: var(--night-muted); }
.game__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-3); }
.btn--ghost { background: transparent; color: var(--night-ink); box-shadow: inset 0 0 0 1px var(--night-ink); }
.js .game__nojs, html:not(.js) .game__actions { display: none; }
.game__end {
  display: block;
  min-block-size: 44px;
  margin-block-end: var(--sp-3);
  margin-inline-start: auto;
  padding-inline: var(--sp-4);
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--night-ink);
  box-shadow: inset 0 0 0 1px var(--night-line);
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
}
.game__end[hidden] { display: none; }
.game__help { margin-block-start: var(--sp-4); font-size: var(--fs-small); color: var(--night-muted); }
.game__live { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* no WebGL2: an ambient conic field behind the board */
.game__stage.is-fallback {
  background:
    radial-gradient(circle at 30% 70%, color-mix(in srgb, var(--accent) 35%, transparent), transparent 55%),
    conic-gradient(from var(--lab-a) at 60% 40%, var(--night), color-mix(in srgb, var(--accent) 40%, transparent), var(--night), var(--night-line), var(--night));
  animation: lab-swirl 14s linear infinite; /* SLOW_OK: ambient field, not an input response */
}
@keyframes lab-swirl { to { --lab-a: 360deg; } }

/* phones: a taller board, the stats closer together */
@media (max-width: 47.99rem) {
  .game__stage { aspect-ratio: 4 / 5; }
  .game__hud { gap: var(--sp-5); }
  .game__title { font-size: var(--fs-h3); }
}

/* short screens (a landscape phone): the board is capped to the screen, so its panel tightens to fit it */
@media (max-height: 30rem) {
  .game__stage { max-block-size: calc(100svh - var(--sp-8)); } /* the HUD above may scroll away; only the board holds the touch */
  .game__panel { gap: var(--sp-2); padding: var(--sp-3); }
  .game__title { font-size: var(--fs-h3); }
  .game__text { font-size: var(--fs-small); }
}

@media (prefers-reduced-motion: reduce) {
  .game__stage.is-fallback { animation: none; }
}
