/* The 3D stage: a slot with a poster (the flat picture or drawing the server rendered) that the stage takes
   over when its first frame is drawn. The view has its size from the first paint, so nothing moves when the
   3D arrives. A page sets the shape with --stage-ratio and the widest it may get with --stage-max.
   The canvas is clear around what it draws: the studio's wall and floor are this background, and a car's
   shadow and its image in the floor are laid over it. */
.stage { margin: 0 auto; position: relative; width: 100%; max-width: var(--stage-max, 45rem); display: flex; flex-direction: column; gap: 0.5rem; }
.stage-view {
  position: relative; width: 100%; aspect-ratio: var(--stage-ratio, 3 / 2); overflow: hidden;
  border: 1px solid var(--rule);
  /* A light studio: the wall is the page's surface, the floor a shade under it (a shade over it in dark). */
  background: var(--surface);
  background: radial-gradient(120% 95% at 50% 100%, color-mix(in srgb, var(--surface), var(--muted) 16%), var(--surface) 72%);
  /* The browser skips the stage's rendering work while it is far from the screen, and says so to the stage. */
  content-visibility: auto;
}
@media (min-width: 40rem) {
  .stage-view { aspect-ratio: var(--stage-ratio, 16 / 9); }
}
.stage-poster { position: absolute; inset: 0; transition: opacity 0.2s ease-out, visibility 0s; }
.stage-poster > svg { position: absolute; left: 5%; top: 6%; width: 90%; height: 88%; max-width: none; margin: 0; }
.stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; opacity: 0; transition: opacity 0.25s ease-out;
  touch-action: pan-y; cursor: grab; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.stage canvas.is-grabbed { cursor: grabbing; }
.stage canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
/* The takeover: the 3D car arrives where the poster's car is, at its size (src/stage/viewer.ts), and fades in over it;
   the poster leaves once it is covered. Nothing moves until both are done. */
.stage[data-stage-state="live"] canvas { opacity: 1; }
.stage[data-stage-state="live"] .stage-poster { opacity: 0; visibility: hidden; transition: opacity 0.2s ease-out 0.2s, visibility 0s 0.4s; }

/* Over the canvas: how to turn it, and the total of each side of a balance. */
.stage-hint {
  position: absolute; left: 50%; bottom: 0.45rem; translate: -50% 0; max-width: calc(100% - 1rem); white-space: nowrap; pointer-events: none;
  padding: 0.15rem 0.6rem; border-radius: 999px; background: color-mix(in srgb, var(--surface) 82%, transparent);
  font: 500 0.72rem/1.4 var(--body); color: var(--muted); transition: opacity 0.4s ease-out;
}
.stage-hint.gone, .stage:not([data-stage-state="live"]) .stage-hint { opacity: 0; }
.stage-tags { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.35s ease-out; }
.stage[data-stage-state="live"] .stage-tags { opacity: 1; }
.stage-tag {
  position: absolute; left: 0; top: 0; display: inline-flex; align-items: center; white-space: nowrap; will-change: transform;
  padding: 0.12rem 0.55rem 0.12rem 0.45rem; border-radius: 999px; background: color-mix(in srgb, var(--surface) 86%, transparent);
  font: 700 0.84rem/1.3 var(--display); color: var(--ink);
}
/* Its identity mark: the first car's colour, or the second's. */
.stage-tag i { flex: none; width: 0.7rem; height: 0.7rem; margin-right: 0.35rem; border-radius: 50%; background: var(--hl); border: 1.5px solid #0d1626; }
.stage-tag-b i { background: var(--b); border-color: var(--ink); }
.stage-note { text-align: center; text-wrap: pretty; }

/* The credit of the generic 3D models, under a stage that shows one (src/site/stage-slot.ts, `stageCredit`): in
   sight wherever such a model is, as its licence asks. */
.stage-credit { margin: 4px auto 14px; max-width: 36rem; text-align: center; text-wrap: pretty; font: 500 0.65625rem/1.4 var(--label); color: var(--muted); font-variant-numeric: tabular-nums; }
.stage-credit a { color: inherit; text-underline-offset: 2px; }

/* The points of a viewer's car that answer a question (src/stage/spots.ts): a yellow dot with an ink ring that
   follows the car as it turns, and hides while its side faces away; it opens its label, a popover of the page.
   Its target is 44 px; the dot is 12 (a "?" when the source does not give the figure). The dots wait until the car
   is touched or turned (`is-woken`): at rest the car is alone. Then they pulse three times, never under reduced motion. */
.stage-spots { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.35s ease-out; }
.stage[data-stage-state="live"] .stage-spots { opacity: 1; }
.stage:not([data-stage-state="live"]) .stage-spot { visibility: hidden; }
.stage-spot {
  position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: none; cursor: pointer; pointer-events: auto; will-change: transform;
  -webkit-tap-highlight-color: transparent; transition: opacity var(--quick) ease-out, visibility 0s;
}
.stage-spot.is-away, .stage-spots:not(.is-woken) .stage-spot { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity var(--quick) ease-out, visibility 0s var(--quick); }
.stage-spot i {
  position: relative; display: grid; place-items: center; width: 12px; height: 12px; border-radius: 50%;
  background: var(--paint); box-shadow: 0 0 0 2px var(--paint-edge), 0 0 0 3.5px var(--card);
  font: 800 11px/1 var(--display); font-style: normal; color: var(--on-paint); transition: scale var(--quick) var(--ease);
}
.stage-spot.is-unknown i { width: 17px; height: 17px; }
.stage-spot.is-open i { scale: 1.35; box-shadow: 0 0 0 2px var(--paint-edge), 0 0 0 5px var(--card); }
.stage-spot:active i { scale: 0.9; }
.stage-spot:focus-visible { outline: 2px solid var(--ink); outline-offset: -8px; }
@media (hover: hover) {
  .stage-spot:hover i { scale: 1.3; }
}
@media (prefers-reduced-motion: no-preference) {
  .stage-spots.is-woken:not(.is-used) .stage-spot i::after {
    content: ""; position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 2px var(--paint); opacity: 0;
    animation: stage-spot-pulse 2s var(--ease) 3;
  }
}
@keyframes stage-spot-pulse {
  0% { opacity: 0.85; scale: 1; }
  70%, 100% { opacity: 0; scale: 2.6; }
}
