/* ---------- The Obsidian Pulse stage (public/js/pulse-stage.js) ----------
   The stage is the design box of one scene preset (1920 x 1080, 1440 x 1080, 1080 x 1440 or
   1080 x 1920), scaled uniformly to fit its host and centred in it; the host shows the scene's own
   darkness around it (the letterbox). Inside: the rendered environment as a background, the
   camera element carrying the CSS 3D table plane (the same camera as the render, so DOM cards lie
   on the rendered felt), and a flat HUD over everything.

   Nothing here moves by itself: no transition, no animation, so reduced motion needs no rule. The
   motion engine animates transforms and opacity on the plane's children and on the shadows; the
   stage only places them (CSSOM transforms, never inline attributes).

   Scoped to .hb-stage-host, .hb-stage and the parts the script builds. */

.hb-stage-host {
  position: relative; overflow: hidden;
  background: #0a0612; /* the letterbox: the scene's own darkness */
}

/* The design box: left/top 0 and a translate + scale written by fit(). `perspective` is the
   render's (projectionMatrix[5] * height / 2) with its origin at the centre of the box, which is
   where the camera element's transform-origin is too. */
.hb-stage {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  overflow: hidden;
  background: #0a0612;
  perspective-origin: 50% 50%;
  user-select: none; -webkit-user-select: none;
  contain: layout;
}

/* The render: one image per preset, 2x where the device needs it, stretched to the box exactly
   (the image was rendered at the box's size). */
.hb-stage > .hb-scene {
  position: absolute; inset: 0;
  background-color: #0a0612;
  background-repeat: no-repeat;
  background-position: 50% 50%;
  background-size: 100% 100%;
  pointer-events: none;
}

/* The camera element: the stage box, origin at its centre, carrying translateZ(P) matrix3d(C)
   translate(w/2, h/2) (CSS3DRenderer's camera transform). It and the plane keep 3D. */
.hb-stage > .hb-cam {
  position: absolute; left: 0; top: 0;
  transform-origin: 50% 50% 0;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  pointer-events: none;
}

/* The table plane: table.w x table.h, centred on the world origin by translate(-50%, -50%), its y
   turned to run toward the player by the object matrix. Cards here are --h 200 (140 x 200). */
.hb-cam > .hb-plane {
  position: absolute; left: 0; top: 0;
  --h: 200px;
  transform-origin: 50% 50% 0;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  pointer-events: auto;
  /* a resting card's own contact shadow: tight, so it reads as the card's edge on the felt; the
     cast shadow of a lifted card is its .hb-shadow element */
  --hb-card-shadow: 0 .6px 1.2px rgba(0, 0, 0, .55);
}

/* Everything on the plane is laid out at its top left and placed by its transform alone
   (the placement contract), turning about its own centre. The card and stack selectors repeat
   the rule at a higher specificity than the deck's own `.card.hb-card` (position: relative) and
   `.hb-stack`, whatever order the stylesheets load in. */
.hb-plane > *, .hb-plane > .card.hb-card, .hb-plane > .hb-stack, .hb-plane > .hb-card.hb-stack {
  position: absolute; left: 0; top: 0; margin: 0;
  transform-origin: 50% 50% 0;
}

/* The motion engine's layer: the whole plane, in 3D, never taking a pointer. */
.hb-plane > .hb-fx {
  inset: 0; width: auto; height: auto;
  overflow: visible;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  pointer-events: none;
  contain: none;
}
.hb-fx > * { position: absolute; left: 0; top: 0; }

/* A cast shadow: the card's footprint on the felt, offset away from the key light by the card's
   height, softer and fainter the higher the card (--hb-sh-blur and --hb-sh-a from shadowFor), and
   reaching a little past the footprint (--hb-sh-spread, the penumbra's ring, drawn as a spread
   box-shadow so the element's transform stays the placement contract; the engine's own flight
   shadows scale instead and leave it at 0). Anywhere on the plane: a card's shadow sits right
   before it, in whatever layer the table keeps the card in. The engine animates its transform
   and opacity like a card's. */
.hb-plane .hb-shadow, .hb-fx > .hb-shadow {
  position: absolute; left: 0; top: 0;
  width: 140px; height: 200px;
  border-radius: calc(var(--h, 200px) * .1);
  background: rgba(0, 0, 0, var(--hb-sh-a, .5));
  box-shadow: 0 0 0 var(--hb-sh-spread, 0px) rgba(0, 0, 0, var(--hb-sh-a, .5));
  filter: blur(var(--hb-sh-blur, 3px));
  transform-origin: 50% 50% 0;
  pointer-events: none;
  will-change: transform, opacity;
}

/* The HUD: 2D, in stage px, over the scene; only its pieces take a pointer. */
.hb-stage > .hb-hud {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none;
}
.hb-hud > * { position: absolute; left: 0; top: 0; pointer-events: auto; }

@media (forced-colors: active) {
  .hb-plane .hb-shadow, .hb-fx > .hb-shadow { display: none; }
}

/* The Lite performance profile (.pa-lite on the felt, public/js/perf-profile.js): no cast shadows on
   the plane at all; each one is a blurred, spread box, the costliest thing the table paints. */
.pa-felt.pa-lite .hb-plane .hb-shadow { display: none; }
