/*
 * Text-free white room.
 *
 *   .room       the playable surface (positioned inside .play)
 *   .scene      one transparent canvas: ball, its real cast shadow and the
 *               real black goal lattice (z < 0), all drawn in 3D
 *   .goal       the flat black goal, laid exactly over the projected lattice
 *               (its size comes from scene.goalGeometry(), uniform projection)
 *   .handle     invisible focusable button on the ball: all pointer input
 *   .reveal     link to the lit destination, visually an arrow
 *
 * The goal is drawn from ONE bar width: the frame padding, the grid gap and
 * the cells' insets are the same --bar-w, so every opening is an equal square
 * by construction, at every viewport size and device pixel ratio.
 */

:root {
  --paper: #ffffff;
  --ink: #000000;
  --ink-quiet: #a3a39f;
  --cell-green: #1f9d57;
  --cell-red: #d1453b;
  --edge: clamp(14px, 3vw, 40px);
  --bar: 60px;
  --goal-x: 0px;
  --goal-y: 0px;
  --goal-w: 320px;
  --goal-h: 140px;
  --bar-w: 3px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 500 15px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 40;
  padding: 8px 12px;
  border-radius: 4px;
  background: var(--ink);
  color: var(--paper);
  transform: translateY(-200%);
}
.skip:focus-visible {
  transform: none;
}

/* ------------------------------------------------------------------ bar */

.bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--edge) * 0.5) var(--edge);
  pointer-events: none;
}

.control {
  pointer-events: auto;
  display: inline-grid;
  place-items: center;
  inline-size: 44px;
  block-size: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-quiet);
  text-decoration: none;
  cursor: pointer;
  transition: color 160ms ease;
}
.control:hover {
  color: var(--ink);
}
.control[hidden] {
  display: none;
}
.control:focus-visible,
.handle:focus-visible {
  /* quiet: a focused ball must never read as a black outline around the ball */
  outline: 2px solid var(--ink-quiet);
  outline-offset: 3px;
}

.icon {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ----------------------------------------------------------------- play */

main {
  position: fixed;
  inset: 0;
}

.play {
  position: absolute;
  inset: 0;
}

/* The room occupies the stage below the control bar and inside the edges. */
.room {
  position: absolute;
  inset: calc(var(--bar) + var(--edge)) var(--edge) var(--edge);
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.scene__canvas {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  display: block;
}

/* The PNG render of the real ball: shown until the GLB verifies, or when
   WebGL is unavailable. It is never the old design. */
.scene__fallback {
  position: absolute;
  left: 50%;
  top: 70%;
  display: none;
  inline-size: 10%;
  block-size: auto;
  translate: -50% -50%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.scene__fallback.is-shown {
  display: block;
}

/* ----------------------------------------------------------------- goal */

/* Placed and sized from the projected lattice in CSS px (--goal-*). Bars are
   pure black; openings are white (the room behind). No radius, no shadow. */
.goal {
  position: absolute;
  z-index: 2;
  left: var(--goal-x);
  top: var(--goal-y);
  inline-size: var(--goal-w);
  block-size: var(--goal-h);
  padding: var(--bar-w);
  background: var(--ink);
  pointer-events: none;
}

.goal__grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: var(--bar-w);
  inline-size: 100%;
  block-size: 100%;
}

.cell {
  position: relative;
  min-inline-size: 0;
  min-block-size: 0;
  aspect-ratio: 1;
  place-self: center;
  inline-size: 100%;
  background: var(--paper);
}

/* ------------------------------------------------------------ outcomes */

/* A real pass lights the cell's opening green; a bar strike its opening red.
   Both are DOM state on the real cell, drawn over the lattice, never a light. */
.cell--bad {
  outline: 1px dotted red; /* diagnostic only: never square */
}
.cell[data-lit="green"] {
  background: var(--cell-green);
}
.cell[data-lit="red"] {
  background: var(--cell-red);
}

/* --------------------------------------------------------------- handle */

/* Invisible button over the projected ball; all pointer input lands here.
   It follows the real resting ball, so a settled ball can be shot again from
   where it stopped. */
.handle {
  position: absolute;
  z-index: 3;
  left: var(--ball-x, 50%);
  top: var(--ball-y, 70%);
  inline-size: var(--ball-size, 150px);
  block-size: var(--ball-size, 150px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  translate: -50% -50%;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.handle:active {
  cursor: grabbing;
}
.handle[hidden] {
  display: none;
}

/* Charge and aim feedback. Both are silent (aria-hidden), one-pixel-quiet
   marks in the same projection as the real ball and goal; neither is a
   second source of truth. */
.charge {
  position: absolute;
  z-index: 3;
  left: var(--ball-x, 50%);
  top: var(--ball-y, 70%);
  inline-size: calc(var(--ball-size, 150px) * 1.34);
  block-size: calc(var(--ball-size, 150px) * 1.34);
  translate: -50% -50%;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: conic-gradient(
    from -90deg,
    rgba(0, 0, 0, 0.52) calc(var(--charge, 0) * 1turn),
    rgba(0, 0, 0, 0.1) 0
  );
  -webkit-mask: radial-gradient(closest-side, transparent 95%, #000 96%);
  mask: radial-gradient(closest-side, transparent 95%, #000 96%);
  transition: opacity 120ms ease;
}
.play[data-state="charging"] .charge {
  opacity: 1;
}

.aim {
  position: absolute;
  z-index: 3;
  left: var(--aim-x, 50%);
  top: var(--aim-y, 50%);
  inline-size: 7px;
  block-size: 7px;
  translate: -50% -50%;
  border: 1.5px solid rgba(0, 0, 0, 0.55);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 100ms ease;
}
.aim[data-on="true"] {
  opacity: 1;
}

.status {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------ preferences */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* Forced colours: keep black bars and distinguish the two states by the
   platform's own colours. */
@media (forced-colors: active) {
  .goal {
    background: CanvasText;
  }
  .cell {
    background: Canvas;
  }
  .cell[data-lit="green"] {
    background: Highlight;
  }
  .cell[data-lit="red"] {
    border: 2px solid CanvasText;
    background: repeating-linear-gradient(45deg, CanvasText 0 6px, Canvas 6px 12px);
    forced-color-adjust: none;
  }
  .icon {
    stroke: ButtonText;
  }
}

@media (max-width: 600px) {
  :root {
    --edge: 12px;
    --bar: 52px;
  }
}

@media (max-height: 520px) {
  :root {
    --bar: 44px;
  }
}
