/* The Lab: the site's one dark band. 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); }

.lab__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-5);
  margin-block-start: var(--sp-8);
}
@media (min-width: 64rem) {
  .lab__grid { grid-template-columns: 1fr 1fr; gap: var(--sp-6); }
}

.lab-tile {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-3);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--night-ink) 3%, transparent);
  box-shadow: var(--shadow-night);
}
.lab-tile__stage {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: calc(var(--r-lg) - var(--sp-3));
  background: var(--night);
  box-shadow: inset 0 0 0 1px var(--night-line);
  container-type: inline-size;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.lab-tile__stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.lab-tile__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  padding-inline: var(--sp-3);
  padding-block-end: var(--sp-2);
}
.lab-tile__meta h3 { font-size: var(--fs-h3); font-weight: 600; line-height: 1.25; }

/* 1. fluid - the no-WebGL2 field */
.lab-tile__stage.is-fallback {
  background:
    radial-gradient(circle at 30% 70%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 55%),
    conic-gradient(from var(--lab-a) at 60% 40%, var(--night), color-mix(in srgb, var(--accent) 70%, 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; } }

/* 2. type */
.lab-type {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 21cqi;
  font-weight: 300;
  line-height: 1.15;
  color: var(--night-ink);
  cursor: default;
}
.lab-type span { display: inline-block; transform-origin: 50% 80%; }

/* 3. spring */
.lab-spring__disc {
  position: absolute;
  inset: 0;
  margin: auto;
  width: clamp(72px, 18cqi, 112px);
  aspect-ratio: 1;
  border-radius: var(--r-full);
  background: radial-gradient(circle at 35% 30%, var(--night-ink), var(--accent) 60%);
  box-shadow: 0 0 0 1px var(--night-line), 0 18px 40px color-mix(in srgb, var(--accent) 35%, transparent);
  cursor: grab;
  touch-action: none;
}
.lab-tile__stage.is-dragging .lab-spring__disc { cursor: grabbing; }

/* 4. hex */
.lab-hex { position: absolute; inset: var(--sp-3); width: calc(100% - 2 * var(--sp-3)); height: calc(100% - 2 * var(--sp-3)); }
.lab-hex__cell { cursor: pointer; outline: none; }
.lab-hex__cell polygon {
  fill: color-mix(in srgb, var(--night-ink) 4%, transparent);
  stroke: var(--night-line);
  stroke-width: 0.5;
  transition: fill var(--dur-fast) ease, stroke var(--dur-fast) ease;
}
.lab-hex__cell:active polygon { fill: color-mix(in srgb, var(--night-ink) 14%, transparent); }
.lab-hex__cell:focus-visible polygon { stroke: var(--night-ink); stroke-width: 1.2; }
.lab-hex__piece {
  fill: var(--accent);
  stroke: var(--night-ink);
  stroke-width: 0.6;
  opacity: 0;
  transform: scale(0.6);
  transform-box: fill-box;
  transform-origin: center;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-fast) ease;
  pointer-events: none;
}
.lab-hex__cell[aria-pressed="true"] .lab-hex__piece { opacity: 1; transform: none; }

@media (hover: hover) {
  .lab-hex__cell:hover polygon { fill: color-mix(in srgb, var(--night-ink) 10%, transparent); stroke: color-mix(in srgb, var(--night-ink) 40%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  .lab-tile__stage.is-fallback { animation: none; }
  .lab-hex__piece { transition-property: opacity; transform: none; }
}
