* { box-sizing: border-box; }

:root {
  /* The width the spin column reserves in the layout. It is the widget's
     OPEN size even while it rests collapsed, so opening it never re-frames
     the table (camera.js hudInsets reads this). */
  --spin-reserve: 150px;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--background);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

#hud {
  position: fixed;
  /*
    Inset by the device's safe area. In landscape the notch takes one side and
    the home indicator the other, and both run straight through this HUD —
    the match bar at the top and the power bar at the left are the first
    casualties. `env()` is 0 everywhere that has no cutout, so this costs
    nothing on a desktop.
  */
  inset: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  pointer-events: none; /* only the controls opt back in */
}

.panel {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  white-space: pre-line;
  max-width: 46ch;
}

/* Dev status line — opt-in with ?debug=1, which adds .debug to #hud. */
#status { display: none; }
#hud.debug #status {
  display: block;
  bottom: 14px;
  right: 14px;
  opacity: 0.4;
  font-size: 11px;
  max-width: 34ch;
}
@media (hover: hover) {
  #status:hover { opacity: 0.9; }
}

/* ============================================================
   Match bar — player cards + turn banner
   ============================================================ */

#matchbar {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.pcard {
  display: flex;
  /* Room for the shot-clock ring, which floats ~7px outside the avatar, and
     for the seconds badge that hangs below it. */
  gap: 18px;
  align-items: center;
  min-width: 306px;
  padding: 13px 18px 15px 15px;
  border-radius: 16px;
  background: var(--panel-fill);
  border: none;
  box-shadow: var(--control-shadow);
  backdrop-filter: blur(6px);
  transition: box-shadow 0.25s ease, opacity 0.25s ease;
  opacity: 0.86;
}

.pcard.right { padding: 13px 15px 15px 18px; }

.pcard.active {
  box-shadow: var(--panel-lift), 0 0 0 2px var(--accent-primary),
    0 0 26px color-mix(in srgb, var(--accent-primary) 45%, transparent);
  opacity: 1;
}

/* ---- avatar + shot-clock ring ----
   The active player is emphasised on the AVATAR FRAME, like the references
   (refs/02-aim Kate's gold frame, refs/8bb-aim Elena's green frame) — the
   banner is secondary. */
.pavatar {
  position: relative;
  width: 68px;
  height: 68px;
  flex: none;
  border-radius: 16px;
  display: grid;
  place-items: center;
  box-shadow: var(--control-shadow);
  /* Registered below, so the shot clock's colour cross-fades (gold, amber,
     red) on the ring, its glow and the badge together. */
  --clock-color: var(--accent-primary);
  transition: box-shadow 0.25s ease, --clock-color 0.6s ease;
}

@property --clock-color {
  syntax: "<color>";
  inherits: true;
  initial-value: #f5c542;
}

.pcard.active .pavatar {
  box-shadow: 0 0 0 3px var(--accent-primary), var(--control-shadow);
}

#pcard0 .pavatar { background: var(--primary-fill); }
#pcard1 .pavatar { background: var(--secondary-fill); }

.pavatar .pnum {
  font-size: 26px;
  font-weight: 800;
  color: var(--on-accent);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.pavatar .ring {
  position: absolute;
  /* Far enough out that the ring floats on a dark gutter instead of melting
     into the avatar fill (the path sits 4 of 64 units in, stroke 3). */
  left: -10px;
  top: -10px;
  /* An explicit size, not `inset: -10px` alone. An absolutely positioned SVG
     is a replaced element, so WebKit ignores the right/bottom offsets and
     sizes it to the avatar instead of the avatar plus the gutter: the ring
     came out avatar-sized and slid 10px up and left (iPad Safari; Chrome
     happened to stretch it). */
  width: calc(100% + 20px);
  height: calc(100% + 20px);
  /* No rotation: the squircle path in index.html already starts at top centre
     and runs clockwise. (A circle needed -90deg to start there; applying it to
     a square would move the start onto the left edge instead.) */
  pointer-events: none;
  overflow: visible;
}

/* While the clock runs, the ring is the active frame: drop the static outline
   so the two don't stack, and keep only a soft halo in the clock's colour. */
.pcard.active .pavatar.clock-live {
  box-shadow: 0 0 18px color-mix(in srgb, var(--clock-color, var(--accent-primary)) 35%, transparent),
    var(--control-shadow);
}
.pavatar.urgent { --clock-color: var(--status-warning); }
.pavatar.critical { --clock-color: var(--status-error); }

.ring-track {
  fill: none;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 5;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.ring-fg {
  fill: none;
  stroke: var(--clock-color);
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0;
  filter: drop-shadow(0 0 2.5px color-mix(in srgb, var(--clock-color) 70%, transparent));
  transition: opacity 0.3s ease;
}
.ring-tip {
  fill: #fff;
  opacity: 0;
  filter: drop-shadow(0 0 3px var(--clock-color)) drop-shadow(0 0 6px var(--clock-color));
  transition: opacity 0.3s ease;
}
.pavatar.clock-live .ring-track,
.pavatar.clock-live .ring-fg,
.pavatar.clock-live .ring-tip { opacity: 1; }

.pavatar .clock {
  position: absolute;
  left: 50%;
  bottom: -13px;
  transform: translateX(-50%);
  min-width: 28px;
  text-align: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--clock-color);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45),
    0 0 10px color-mix(in srgb, var(--clock-color) 40%, transparent);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--clock-color);
  transition: color 0.4s ease, border-color 0.4s ease, background-color 0.4s ease;
}
.pavatar .clock.tick { animation: clock-tick 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.3); }

.pavatar.critical .clock {
  color: var(--on-error);
  background: var(--status-error);
}
.pavatar.critical .clock.tick { animation: clock-tick-hard 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4); }

/* Critical seconds: one heartbeat per tick, in step with the badge. */
.pavatar.beat::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--status-error),
    inset 0 0 18px color-mix(in srgb, var(--status-error) 55%, transparent);
  animation: clock-beat 0.9s ease-out forwards;
}

.pavatar.timeout .ring-fg { stroke: var(--status-error); animation: flash 0.45s ease-in-out 3; }
.pavatar.timeout { animation: clock-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }

@keyframes clock-tick {
  0% { transform: translateX(-50%) scale(0.72); opacity: 0.4; }
  60% { transform: translateX(-50%) scale(1.08); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes clock-tick-hard {
  0% { transform: translateX(-50%) scale(1.32); }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes clock-beat {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

@keyframes clock-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

@keyframes flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  .pavatar .clock.tick,
  .pavatar.critical .clock.tick,
  .pavatar.timeout { animation: none; }
  .pavatar.beat::after { animation: none; opacity: 0.6; }
}

/* ---- card text ---- */
.pmeta { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; }
.pcard.right .pmeta { align-items: flex-end; text-align: right; }

.prow { display: flex; align-items: center; gap: 10px; }
.pcard.right .prow { flex-direction: row-reverse; }

.pname {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.09em;
  color: var(--text);
  white-space: nowrap;
}

.pcard.active .pname { color: var(--accent-primary); }

.pcard.bot .pname::after {
  content: "BOT";
  margin-left: 8px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  border: 1px solid var(--line-bright);
  border-radius: 4px;
  padding: 1px 4px;
  vertical-align: 2px;
}

.pgroup {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line-bright);
  color: var(--muted);
  white-space: nowrap;
}
.pgroup.solids { color: var(--accent-primary); border-color: var(--accent-line); }
.pgroup.stripes { color: var(--accent-secondary); border-color: var(--accent-secondary); }

/* Name-bar progress line (mirrors the shot-clock ring; the references' name
   bars carry a small progress bar — refs/02-aim, refs/03-power). */
.pprogress {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}
.pprogressfill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: var(--accent-primary);
  transition: background-color 0.6s ease;
}
.pprogressfill.urgent { background: var(--status-warning); }
.pprogressfill.critical { background: var(--status-error); }

/* One row of ball progress: potted chips then dark remaining pips, matching
   the references' single row (refs/03-power, refs/8bb-start). */
.prow2 { display: flex; align-items: center; gap: 8px; min-height: 20px; }
.pcard.right .prow2 { flex-direction: row-reverse; }

/* ---- remaining-ball pips (plain dark circles, like the references) ---- */
.pips { display: flex; gap: 5px; align-items: center; }
.pcard.right .pips { justify-content: flex-end; }

.pip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
}
.pip.open,
.pip.left {
  background: radial-gradient(circle at 34% 28%, var(--raised), var(--background) 72%);
  border: 1px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.6), 0 0 0 1px color-mix(in srgb, var(--accent-primary) 20%, transparent);
}
.pip.eight {
  background: #141414;
  border: 1px solid var(--accent-primary);
  width: 18px;
  height: 18px;
  color: #f2eee2; /* The 8-ball number is a fixed material marking. */
  font-size: 10px;
  font-weight: 800;
  display: grid;
  place-items: center;
  animation: pulse8 1.6s ease-in-out infinite;
}

@keyframes pulse8 {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-primary) 40%, transparent); }
  50% { box-shadow: 0 0 0 5px transparent; }
}

/* ---- potted-ball chips (they sit in the pip row, one per ball) ----
   The sphere and the white number disc are background layers, built per ball
   in hud.js; everything here is the frame around them. The number needs no
   halo now that it sits on the disc — it is printed, so it stays crisp. */
.chip {
  position: relative;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
  color: #1b1b20;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.55);
}

/* ---- turn banner (secondary: the avatar frames carry the turn emphasis) ---- */
#turnbanner {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 22px;
  border-radius: 12px;
  background: var(--panel-fill);
  border: none;
  box-shadow: var(--panel-lift), 0 0 0 2px color-mix(in srgb, var(--accent-primary) 55%, transparent);
  backdrop-filter: blur(6px);
  white-space: nowrap;
  opacity: 1;
}

#bannertext {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
}

#bannertag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--on-accent);
  background: linear-gradient(180deg,
    var(--accent-primary), var(--accent-primary));
  border-radius: 6px;
  padding: 3px 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), 0 2px 5px rgba(0, 0, 0, 0.45);
}

#turnbanner.swap #bannertext { animation: bannerIn 0.32s ease both; }

@keyframes bannerIn {
  from { opacity: 0; transform: translateY(-9px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Toast
   ============================================================ */

#toast {
  position: absolute;
  left: 50%;
  bottom: 196px;
  transform: translate(-50%, 16px);
  max-width: min(480px, 86vw);
  padding: 12px 20px 12px 17px;
  border-radius: 12px;
  background: var(--panel-fill);
  border: none;
  border-left: 4px solid var(--line-bright);
  box-shadow: var(--panel-lift);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.foul { border-left-color: var(--status-error); }
#toast.info { border-left-color: var(--status-warning); }

/* ============================================================
   Power bar — a framed side tube (refs/8bb-aim left, refs/03-power right).
   The side is a settings option; `.power-right` on #hud moves it.
   ============================================================ */

/* The tube: glass over a dark shaft, with the cue itself inside it (the
   targets put the cue in the bar, so power reads as pulling the cue back).
   The drag mapping is unchanged — top is 0%, bottom is 100%. */
#powerbar {
  position: absolute;
  left: 40px;
  bottom: 40px;
  width: 52px;
  height: 320px;
  background: linear-gradient(90deg, var(--background), var(--raised) 48%, var(--background));
  border: none;
  border-radius: 26px;
  box-shadow: 0 0 0 2px var(--accent-primary), inset 0 0 0 1px rgba(0, 0, 0, 0.8),
    inset 0 10px 18px rgba(0, 0, 0, 0.65), 0 8px 20px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
}

/* The cue lying in the tube, on TOP of everything else in it. The charge reads
   in the two channels either side of the cue, so the cue stays a cue instead of
   turning into a coloured slab at high power.

   Tapered with a clip-path — thin at the tip, full width at the butt — because
   a parallel-sided strip reads as a thermometer, not a cue. drop-shadow, not
   box-shadow: only the filter follows the clipped silhouette. */
#powerbar::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 7px;
  width: 22px;
  height: calc(100% - 14px);
  transform: translateX(-50%);
  clip-path: polygon(32% 0%, 68% 0%, 100% 100%, 0% 100%);
  background:
    linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.55) 0%, rgba(0, 0, 0, 0.12) 14%, rgba(255, 255, 255, 0.4) 33%,
      rgba(255, 255, 255, 0.1) 52%, rgba(0, 0, 0, 0.2) 74%, rgba(0, 0, 0, 0.55) 100%
    ),
    linear-gradient(
      180deg,
      #2d63b8 0 1.5%, #f1ecdf 1.5% 4%, #f0d9ac 4% 55%,
      #d8dde3 55% 57%, #1b0f0a 57% 82%, #15161a 82% 97%, #0b0b0d 97%
    );
  /* Two tight dark passes before the soft one: the pale maple shaft sits over a
     fill that sweeps green→amber→red, and without a rim it loses its edge
     against the amber half of that ramp. */
  filter:
    drop-shadow(0 0 1px rgba(0, 0, 0, 0.95)) drop-shadow(0 0 2px rgba(0, 0, 0, 0.75))
    drop-shadow(2px 1px 5px rgba(0, 0, 0, 0.7));
  pointer-events: none;
  z-index: 4;
}

/* Tick marks every 10%, on the glass over the charge and under the cue. */
#powerbar::after {
  content: "";
  position: absolute;
  inset: 8px 9px;
  background: repeating-linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.2) 0 2px,
    transparent 2px 10%
  );
  pointer-events: none;
  z-index: 2;
}

#powerfill {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 0%;
  background: #33d973;
  box-shadow: inset -6px 0 10px rgba(0, 0, 0, 0.35), inset 6px 0 10px rgba(255, 255, 255, 0.22);
  transition: none;
  z-index: 1;
}

/* The grip passes behind the cue (z below ::before), so it reads as two lugs on
   the tube rather than a band across the cue. */
#powerhandle {
  position: absolute;
  left: -6px;
  top: 0%;
  width: calc(100% + 12px);
  height: 16px;
  margin-top: -8px;
  background: linear-gradient(180deg, #ffffff, #aab4c1 60%, #7d8795);
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  z-index: 3;
}

#powerlabel {
  position: absolute;
  left: 40px;
  bottom: 370px;
  width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-primary);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Right-side placement (8 Ball Pool style; the setting mirrors the targets).
   It is the default; the landscape block at the end of the file lifts it
   clear of the spin and icon corner. */
#hud.power-right #powerbar { left: auto; right: 40px; }
#hud.power-right #powerlabel { left: auto; right: 40px; }

/* ---- fine-aim wheel ----
   The ribbed roller the mobile games put opposite the power control: roll it
   to trim the line a fraction of a degree at a time. It takes whichever edge
   the power bar is not on, and matches the bar's frame and size so the two
   read as a pair. hud.js scrolls the ribs (--wheel-offset) as it rolls. */
#aimwheel {
  position: absolute;
  right: 40px;
  bottom: 40px;
  width: 52px;
  height: 320px;
  border-radius: 26px;
  background: var(--background);
  box-shadow: 0 0 0 2px var(--accent-primary), inset 0 0 0 1px rgba(0, 0, 0, 0.8),
    0 8px 20px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  pointer-events: auto;
  cursor: ns-resize;
  touch-action: none;
  transition: box-shadow 0.15s ease;
}
#hud.power-right #aimwheel { right: auto; left: 40px; }

#aimwheel.rolling {
  box-shadow: 0 0 0 2px var(--accent-primary), inset 0 0 0 1px rgba(0, 0, 0, 0.8),
    0 0 18px color-mix(in srgb, var(--accent-primary) 45%, transparent),
    0 8px 20px rgba(0, 0, 0, 0.55);
}

/* The drum. Top to bottom it darkens toward both ends, so the flat stripes
   read as ribs turning over a cylinder; side to side it rounds off. */
#aimwheelribs {
  position: absolute;
  inset: 6px 7px;
  border-radius: 20px;
  background:
    linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.35) 18%, rgba(255, 255, 255, 0.1) 50%,
      rgba(0, 0, 0, 0.35) 82%, rgba(0, 0, 0, 0.9) 100%
    ),
    linear-gradient(90deg, rgba(0, 0, 0, 0.55), transparent 28%, transparent 72%, rgba(0, 0, 0, 0.55)),
    linear-gradient(180deg, #7a8391 0 2px, #22262d 2px 4px, #3b424d 4px 100%);
  background-size: 100% 100%, 100% 100%, 100% 12px;
  background-position: 0 0, 0 0, 0 var(--wheel-offset, 0px);
  pointer-events: none;
}

/* ---- spin pad (right edge, below the player card) ---- */
/*
  The spin widget rests as a small cue ball and opens to full size on a tap.

  It was the second-largest thing in the HUD — 150x150, nearly the area of a
  player card — and it sat open permanently in a right-hand column that also
  holds the player card, the menu icons and the in-play toggles. Four detached
  clusters down one edge read busier than the sum of their parts.

  Collapsed it still shows the contact point, so the current spin is legible
  at a glance without opening anything; the canvas keeps its 150px backing
  store either way, so the small state is a clean downscale rather than a
  coarser drawing.
*/
#spinpad {
  position: absolute;
  right: 24px;
  top: 168px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--surface);
  border: none;
  box-shadow: 0 0 0 3px var(--accent-primary), 0 0 0 6px rgba(0, 0, 0, 0.55),
    0 10px 22px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
  transition: width 0.18s ease, height 0.18s ease;
}

#hud.spin-open #spinpad {
  width: 150px;
  height: 150px;
}

#spinlabel {
  position: absolute;
  right: 24px;
  top: 330px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

#spinlabel.miscue {
  color: var(--status-error);
  font-weight: 700;
}

/* ---- buttons ---- */

/* Match-state rule pill sits just above the main buttons. Non-interactive,
   so it never steals a pointer from the table. */
#callrule {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  pointer-events: none;
}

.btn.small {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  border-radius: 9px;
  opacity: 0.92;
  box-shadow: var(--control-shadow);
}
.btn.small:active { transform: translateY(2px); }

/* Non-interactive rule pill in the same family as the small buttons. */
.pill.small {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  border-radius: 8px;
  color: var(--accent-primary);
  background: var(--surface);
  border: 1px solid var(--accent-line);
}

/* inline-flex would otherwise beat the hidden attribute's display:none. */
.pill.small[hidden] {
  display: none;
}

/* Inline "nominate a pocket" hint above the buttons. */
#callhint {
  position: absolute;
  left: 50%;
  bottom: 146px;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--accent-line);
  color: var(--accent-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
}

/* Ball-in-hand discovery hint (I2) — same family, cyan to match the ring. */
#bihhint {
  position: absolute;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  padding: 6px 15px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--accent-secondary);
  color: var(--accent-secondary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  animation: bihPulse 2.2s ease-in-out infinite;
}

@keyframes bihPulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-secondary) 28%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

#callhint.pulse { animation: hintPulse 0.65s ease; }

@keyframes hintPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  35% { transform: translateX(-50%) scale(1.09); }
}

/* Blocked SHOOT: visibly inert, still clickable so the hint can pulse. */
.btn.primary.disabled {
  background: var(--track);
  border-color: var(--track);
  color: var(--muted);
  cursor: not-allowed;
}
.btn.primary.disabled:hover { filter: none; }

.btn {
  background: var(--panel-fill);
  color: var(--text);
  border: none;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: var(--control-shadow);
  transition: transform 0.08s ease, filter 0.15s ease;
}
@media (hover: hover) {
  .btn:hover { filter: brightness(1.14); }
}
.btn:active { transform: translateY(3px); box-shadow: var(--control-shadow); }

/* The one action button carries the accent; everything else stays quiet. */
.btn.primary {
  background: var(--primary-fill);
  color: var(--on-accent);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn.lock { background: var(--secondary-fill); color: var(--on-accent); }
.btn.lock.locked { background: var(--primary-fill); }

/* ============================================================
   Result overlay
   ============================================================ */

#result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(7px);
  animation: scrimIn 0.3s ease both;
  pointer-events: auto; /* the table is not interactive while this is up */
}

#result[hidden] { display: none; }

/* Online: waiting for the other player, or a join that failed. */
#onlinewait {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(7px);
  animation: scrimIn 0.3s ease both;
  pointer-events: auto;
}
#onlinewait[hidden], #onlinewaitshare[hidden] { display: none; }
#onlinewait .rcard { display: grid; gap: 12px; justify-items: center; padding: 30px 32px 26px; }
#onlinewait .rtitle { margin: 4px 0 0; font-size: 26px; }
#onlinewait .rreason { margin: 0; }
#onlinewaitshare { display: grid; gap: 12px; justify-items: center; }
.roomcode {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.3em;
  padding-left: 0.3em; /* the last letter's spacing, mirrored, so it sits centred */
  color: var(--accent-primary);
  user-select: all;
}
#btnOnlineLobby { text-decoration: none; display: inline-block; }

.rcard {
  width: min(460px, 88vw);
  padding: 38px 40px 32px;
  border-radius: 22px;
  text-align: center;
  background: var(--panel-fill);
  border: none;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 0 3px var(--accent-primary),
    0 0 70px color-mix(in srgb, var(--accent-primary) 35%, transparent);
  pointer-events: auto;
  animation: cardIn 0.4s cubic-bezier(0.2, 1.3, 0.3, 1) both;
}

.reyebrow {
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--muted);
}

.rtitle {
  margin: 14px 0 8px;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-primary);
  text-shadow: 0 2px 14px color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.rreason {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 26px;
}

#btnRematch {
  min-width: 200px;
  font-size: 16px;
  letter-spacing: 0.08em;
}

@keyframes scrimIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Small screens
   ============================================================ */

/*
  Phones.

  The old rule here shrank the HUD on small screens — smaller avatars, 11px
  names, 11px banner — which is backwards: a phone is the device where the
  controls are furthest away and touched rather than clicked. What a small
  screen needs is fewer things, bigger, and in the corners the thumbs reach.
  Sizes therefore hold or grow here; only the things that do not fit are
  dropped.
*/
@media (max-width: 760px) {
  /* Bigger touch targets, not smaller ones: 44px is the usual floor. */
  .iconbtn { width: 44px; height: 44px; border-radius: 12px; }
  .icon { width: 22px; height: 22px; }
  .icon.lg { width: 24px; height: 24px; }

  /* The spin tools follow the spin pad to the bottom-right thumb arc. */
  #spintools { top: auto; bottom: 74px; right: 14px; }

  /* The dev status line is noise on a phone and overlaps everything. */
  #status { display: none; }

  /* Drop what does not fit; keep what is left readable at arm's length. */
  .pcard { min-width: 0; padding: 10px 12px 12px 13px; gap: 13px; }
  .pcard.right { padding: 10px 13px 12px 12px; }
  .pavatar { width: 48px; height: 48px; }
  .pavatar .pnum { font-size: 20px; }
  .pname { font-size: 13px; }
  .pgroup { display: none; } /* the group is on the rail already */
  #bannertext { font-size: 13px; }
  #turnbanner { padding: 8px 14px; }
  #spinpad { top: auto; bottom: 130px; }
  #spinlabel { top: auto; bottom: 292px; }
}


/* ============================================================
   Overlay sheets — settings and help
   ============================================================

   Written against the shared semantic roles in ui-theme.css. The interface
   palette follows the saved UI theme, independently of the table skin.

   The visual family is deliberately the result card's: same scrim, same
   gradient fill, same accent ring, same entrance. A player should read the
   settings sheet and the result card as the same object appearing twice.
*/

/* ---- scrim + sheet: see settings-sheet.css -------------------------- */

/* ---- icons -------------------------------------------------------- */

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.lg { width: 22px; height: 22px; }

/* ---- the HUD's icon buttons (gear / help) ------------------------- */

/*
  #corner is not a box in portrait: its children position themselves against
  #hud. Landscape turns it into the bottom-right row.
*/
#corner { display: contents; }

/* The right-hand column is already spoken for: the match bar ends at y=100
   and the spin pad starts at y=168. The icon bar is centred in that 68px
   band. If either of those ever moves, this has to move with it — there is
   a browser check that asserts the three do not overlap. */
/*
  Reset spin sits under the spin pad, and only once there is spin to clear.
  An empty offer was a permanent button that did nothing.
*/
#spintools {
  position: absolute;
  right: 24px;
  /* Follows the pad: it sits under whichever size the pad currently is. */
  top: 244px;
  transition: top 0.18s ease;
  display: none;
  gap: 8px;
  pointer-events: auto;
}

#hud.spin-set #spintools { display: flex; }
#hud.spin-open #spintools { top: 356px; }

/* Reset only exists when there is something to reset. With the contact point
   centred the button is a permanent offer to do nothing. */
#btnResetSpin { display: none; }
#hud.spin-set #btnResetSpin { display: grid; }

#iconbar {
  position: absolute;
  top: 112px;
  right: 24px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.iconbtn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 11px;
  color: var(--text);
  background: var(--panel-fill);
  box-shadow: var(--control-shadow);
  cursor: pointer;
}

@media (hover: hover) {
  .iconbtn:hover { filter: brightness(1.14); }
}
.iconbtn:active { transform: translateY(2px); }
.iconbtn:focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }

/* Option groups, segmented controls, steppers, switches and the slider live in
 * settings-sheet.css with the sheet itself. */

/* ---- help sheet --------------------------------------------------- */

/* Action on the left, the input that performs it on the right. */
.helprow {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.optgroup .helprow:first-of-type { border-top: none; }

.helprow > span:first-child { flex: 1; }

.helprow > .keys {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

/* A keycap. Also used for a mouse gesture, so it reads as "do this". */
kbd {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--track);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 0 rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  white-space: nowrap;
}

/* The live rules list: what THIS table is playing, read from the core. */
.rulelist { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 2px; }

.rulechip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-primary);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent-primary) 45%, transparent);
}

/* A rule this table does NOT enforce: shown, but visibly off, so the list is
   the same length on every table and the player learns the full set. */
.rulechip.off {
  color: var(--muted);
  border-color: var(--line);
  background: var(--recess);
}

.rulechip .icon { width: 14px; height: 14px; }

/* ---- phones -------------------------------------------------------- */

/*
  Phones.

  The old rule here shrank the HUD on small screens — smaller avatars, 11px
  names, 11px banner — which is backwards: a phone is the device where the
  controls are furthest away and touched rather than clicked. What a small
  screen needs is fewer things, bigger, and in the corners the thumbs reach.
  Sizes therefore hold or grow here; only the things that do not fit are
  dropped.
*/
@media (max-width: 760px) {
  /* Bigger touch targets, not smaller ones: 44px is the usual floor. */
  .iconbtn { width: 44px; height: 44px; border-radius: 12px; }
  .icon { width: 22px; height: 22px; }
  .icon.lg { width: 24px; height: 24px; }

  /* The spin tools follow the spin pad to the bottom-right thumb arc. */
  #spintools { top: auto; bottom: 74px; right: 14px; }

  /* The dev status line is noise on a phone and overlaps everything. */
  #status { display: none; }

  /* The spin pad moves up on small screens, so the icon bar goes to the
     opposite corner rather than fighting it. */
  #iconbar { top: auto; bottom: 14px; left: 14px; right: auto; }

}

/* ============================================================
   Viewport overrides
   ============================================================

   These live at the end deliberately. They override rules defined further up
   at the same specificity, so source order is what makes them win — put this
   block before `#spintools` and that element ends up with both `top` and
   `bottom` set, which stretches it 125px tall and straight through the spin
   pad. (That is not hypothetical; the landscape-phone layout check caught
   exactly that.)
*/

/*
  Short viewports — which is what a phone in landscape actually is.

  The rest of this file positions the right-hand column from the TOP
  (#spinpad at 168px, #spintools below it) and the power bar at a fixed 320px
  tall. Both assume a desktop's height. A landscape iPhone is 393px tall, so
  the spin tools land off the bottom of the screen and the power bar collides
  with the match bar.

  Keying this on height rather than width is the point: the phone that breaks
  this layout is 852px WIDE. Every width-based rule in this file sails past it.
*/
@media (max-height: 560px) {
  #matchbar { top: 8px; }

  /*
    Compact the match bar. Every pixel it takes is a pixel of table: at 393px
    tall it was claiming a quarter of the screen, and the reference games keep
    their equivalent strip to well under half that.

    `min-width` and `flex` are part of the same job: 290px per card plus the
    banner totals 860px inside an 820px bar, so the row overflowed and Player
    2's card was cut 56px off the right edge. The existing fix for that lives
    in the max-WIDTH rule, which a landscape phone at 852px wide never
    matches.
  */
  .pcard { padding: 8px 10px 9px 11px; gap: 11px; min-width: 0; flex: 0 1 auto; }
  .pcard.right { padding: 8px 11px 9px 10px; }
  .pavatar { width: 38px; height: 38px; }
  .pavatar .pnum { font-size: 17px; }
  .pavatar .clock { bottom: -10px; min-width: 20px; padding: 0 5px; font-size: 10px; border-width: 1px; }
  .pname { font-size: 11px; }
  .pprogress { display: none; }
  #turnbanner { padding: 5px 12px; min-width: 0; flex: 0 1 auto; }
  #bannertext { font-size: 11px; }
  #bihhint { padding: 4px 10px; font-size: 11px; }

  /* Fit the bar to what is actually there, and keep its % readout with it. */
  #powerbar, #aimwheel { height: calc(100vh - 170px); bottom: 24px; }
  #powerlabel { bottom: calc(100vh - 142px); }

  #spinlabel { display: none; } /* the pad itself shows the contact point */

  /* Developer noise, and it sits on top of the controls at this size. */
  #status { display: none; }
}

/*
  Every landscape, on every device. The bottom-right cluster is the layout:
  the spin widget, then settings and help stacked in the corner. It used to
  be only the short-viewport rule, so a landscape iPad or a desktop window
  kept the old column under the match bar.

  Stacking the two icons keeps them in one spot. A row would shove the
  open-spin reserve across the cloth.

  This block is last on purpose. A landscape phone is also under 760px wide,
  and that rule parks the icon bar on the bottom left. Same specificity, so
  source order is what puts the cluster back in the corner.
*/
@media (orientation: landscape) {
  #corner {
    display: flex;
    flex-direction: row;
    align-items: center;
    position: absolute;
    right: 12px;
    bottom: 12px;
    /* 16px leaves the spin ball's 6px ring clear of the icon stack. */
    gap: 16px;
    pointer-events: none;
  }
  #spinpad {
    position: static;
    top: auto;
    right: auto;
    bottom: auto;
  }
  #iconbar {
    position: static;
    flex-direction: column;
    top: auto;
    right: auto;
    bottom: auto;
    left: auto;
  }
  #spinlabel { display: none; }

  /* Whichever of the power bar and the aim wheel is on the right stands in
     the column above the corner, clear of the spin ball even when it is open
     (150px) and of the reset button above it. */
  #hud.power-right #powerbar,
  #hud:not(.power-right) #aimwheel {
    right: 14px;
    bottom: 190px;
    height: min(320px, calc(100vh - 350px));
  }
  #hud.power-right #powerlabel {
    right: 14px;
    bottom: calc(190px + min(320px, calc(100vh - 350px)) + 10px);
  }
  /* Reset sits above the spin ball, out of the icon stack. */
  #spintools,
  #hud.spin-open #spintools {
    position: absolute;
    top: auto;
    right: auto;
    left: 0;
    bottom: calc(100% + 8px);
  }
}

/*
  A landscape phone has no room for a column above the corner (it would leave
  the right-hand control about 40px tall), so the right-hand control runs the
  full height at the edge and the corner cluster steps in beside it. Last,
  so it beats the landscape block above.
*/
@media (orientation: landscape) and (max-height: 560px) {
  /* Slimmer and nearer the edges than on a tablet: with a control on each
     side, every pixel here comes out of the table. */
  #powerbar, #powerlabel, #aimwheel { width: 42px; }
  #hud:not(.power-right) #powerbar,
  #hud:not(.power-right) #powerlabel,
  #hud.power-right #aimwheel { left: 14px; }
  #corner { right: 66px; }
  #hud.power-right #powerbar,
  #hud:not(.power-right) #aimwheel {
    right: 12px;
    bottom: 24px;
    height: calc(100vh - 170px);
  }
  #hud.power-right #powerlabel { right: 12px; bottom: calc(100vh - 142px); }
}

/*
  Portrait keeps the power bar on the left whatever the setting, and has no
  aim wheel: the bottom-right is the spin ball's, and the portrait HUD has no
  second edge to give. The table is rarely played upright; this keeps it as
  it was.
*/
@media (orientation: portrait) {
  #hud.power-right #powerbar,
  #hud.power-right #powerlabel { left: 40px; right: auto; }
  #aimwheel { display: none; }
}
