/* =============================================================================
   bust.fun — DICE styles  (games-foundation refactor; premium polish pass)
   -----------------------------------------------------------------------------
   Game-SPECIFIC styles for this module. Linked from index.html. Synthwave tokens
   only (tokens.css); NO hard-coded palette. Owned by the dice team.

   Polish goals (the roll reveal is the star):
     - neon win/lose meter with a luminous split + soft track glow
     - a marker (the win-line) that reads clearly and animates smoothly
     - a result dot that SLIDES to roll/100 then SETTLES with a spring + glow ring
     - outcome-tinted dot (win=green, near-miss=amber, loss=red) — paint-only,
       it lands AFTER the server /play response (never pre-revealed by the core)
   All motion is gated behind prefers-reduced-motion (see the block at the foot).
   ========================================================================== */

/* =============================================================================
   Dice meter — the track the marker + roll dot live on
   ========================================================================== */
.dice-meter {
  position: relative;
  /* FILL: the meter is the hero — a TALL band that fills the display column's spare
     height (capped on big screens, floored so it stays usable on short ones) and is
     full-width. The track + marker + dot are vertically centered within it.
     T3 (frame-audit) — the old clamp(120px,34vh,300px) capped the band at 300px inside
     a ~712px desktop display column, leaving a wide empty band above + below it (the
     board read as a thin strip floating in a tall dark box). Grow the band to fill the
     column: a larger vh fraction + a higher ceiling, still floored so short laptops stay
     usable. (Mobile keeps its own tighter cap below so it never dominates the phone.) */
  flex: 1 1 auto; min-height: 0;
  height: clamp(140px, 48vh, 460px);
  display: flex; flex-direction: column; justify-content: center;
  margin: var(--sp-4) 0 var(--sp-2);
  /* room for the dot's settle ring + glow so nothing clips */
  overflow: visible;
  /* INTERACTIVE: the whole tall band is the draggable target (press/drag/click anywhere sets the win-line;
     x is measured against the inner track in JS). touch-action:none lets a touch-drag scrub without panning. */
  cursor: grab;
  touch-action: none;
}
.dice-meter.is-dragging,
.dice-meter:active { cursor: grabbing; }

/* The win/lose track. The CSS var --split (0..100%) is the win-line position; the
   gradient hard-stops there so the lose side and win side are unambiguous. The
   ::before adds a soft additive bloom so it reads as neon, not a flat bar.

   The roll axis runs LOW (0, left) → HIGH (9999, right). DEFAULT = roll-UNDER:
   you WIN when roll < target, so the WINNING region is to the LEFT of the win-line
   (low rolls) and the LOSING region is to the RIGHT — hence win-LEFT / lose-RIGHT
   below. (Earlier this was inverted: the track painted the winning under-region red,
   so a green winning dot landed in a red zone — visually misleading. Now the dot's
   server-decided colour and the track region it lands in always agree.) */
.dice-track {
  position: absolute;
  left: 0; right: 0; top: 50%;
  transform: translateY(-50%);
  /* a thicker bar to match the taller meter (was 10px on a 52px meter) */
  height: clamp(12px, 2.4vh, 22px);
  border-radius: var(--r-pill);
  /* the whole .dice-meter band owns pointer interaction (press/drag/click sets the win-line); the marker +
     dot are pointer-transparent so they never steal the press. The track itself just shows the dragging
     cursor while scrubbing (the band sets .is-dragging) — see .dice-marker / .dice-roll-dot below. */
  background: linear-gradient(90deg,
    var(--win), var(--win) var(--split, 50%),
    var(--lose) var(--split, 50%), var(--lose));
  border: 1px solid var(--line-2);
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, .35),
    0 0 0 1px rgba(0, 0, 0, .15);
  transition: background var(--dur-2) var(--ease-out);
}
/* roll-OVER flips which side wins: you win when roll > target, so the WINNING region
   is to the RIGHT of the win-line (high rolls) → lose-LEFT / win-RIGHT. */
.dice-track.over {
  background: linear-gradient(90deg,
    var(--lose), var(--lose) var(--split, 50%),
    var(--win) var(--split, 50%), var(--win));
}
/* additive neon bloom under the track (win glow + lose glow either side of the split).
   Mirrors the track's win-LEFT / lose-RIGHT default (roll-under). */
.dice-track::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(90deg,
    var(--win-glow), var(--win-glow) var(--split, 50%),
    var(--lose-glow) var(--split, 50%), var(--lose-glow));
  filter: blur(7px);
  opacity: .55;
  transition: background var(--dur-2) var(--ease-out);
}
.dice-track.over::before {
  background: linear-gradient(90deg,
    var(--lose-glow), var(--lose-glow) var(--split, 50%),
    var(--win-glow) var(--split, 50%), var(--win-glow));
}

/* =============================================================================
   Pre-reveal "rolling" anticipation (issue #5)
   The roll dot is hidden until the /play response, so on a fast round there is
   almost no visible "the dice are rolling" beat. While .is-rolling is set (Bet
   pressed → dot lands), a soft sheen sweeps the track + the marker breathes, so
   there is a clear "rolling" stage even when the server responds in <100ms. The
   class is added on bust:bet and removed when the dot takes over (showDiceRoll).
   Reduced-motion no-ops both (see the foot of this file).
   ========================================================================== */
.dice-track.is-rolling::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(100deg,
    transparent 30%, rgba(255, 255, 255, .42) 50%, transparent 70%);
  background-size: 220% 100%;
  mix-blend-mode: screen;
  animation: dice-rolling-sheen 700ms var(--ease-out) infinite;
}
@keyframes dice-rolling-sheen {
  0%   { background-position: 140% 0; }
  100% { background-position: -40% 0; }
}
.dice-meter.is-dragging .dice-track.is-rolling::after { animation: none; } /* don't fight an active drag */

/* The win-LINE marker (where the threshold sits). A thin neon bar with a glow cuff;
   slides smoothly as the target slider moves. */
.dice-marker {
  position: absolute;
  top: 50%;
  width: clamp(4px, .7vw, 6px);
  /* a tall neon win-line that spans most of the meter height (was a fixed 34px) */
  height: clamp(56px, 16vh, 150px);
  border-radius: 3px;
  background: #fff;
  box-shadow:
    0 0 0 3px var(--brand-glow),
    0 0 12px var(--brand-glow);
  transform: translate(-50%, -50%);
  /* the marker is a VISUAL win-line; the track underneath owns all pointer interaction, so the marker is
     pointer-transparent (a press exactly on it still scrubs the track). The grab cursor + the hover/active
     swell below come from the track, signalling the whole bar is draggable. */
  pointer-events: none;
  transition: left var(--dur-2) var(--ease-out),
    width var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
  z-index: 2;
}
/* draggable affordance: the win-line swells + glows brighter when the user hovers or scrubs the meter,
   so it reads as a grabbable handle (the band is the hit area; the marker is the visual handle). */
.dice-meter:hover .dice-marker,
.dice-meter.is-dragging .dice-marker {
  width: clamp(6px, 1vw, 9px);
  box-shadow: 0 0 0 4px var(--brand-glow), 0 0 18px var(--brand-glow);
}
/* while a bet is rolling, the win-line "breathes" (a soft glow pulse) as anticipation (issue #5). */
.dice-track.is-rolling ~ .dice-marker {
  animation: dice-marker-breathe 700ms var(--ease-in-out, ease-in-out) infinite;
}
@keyframes dice-marker-breathe {
  0%, 100% { box-shadow: 0 0 0 3px var(--brand-glow), 0 0 12px var(--brand-glow); }
  50%      { box-shadow: 0 0 0 5px var(--brand-glow), 0 0 22px var(--brand-glow); }
}
/* clamp flash (issue #8): a direction flip that forces the target into the new range briefly flares the
   win-line gold so the otherwise-silent value jump is acknowledged. Self-removing via .clamped (re-added
   by flashClamp on each forced clamp). */
.dice-marker.clamped {
  animation: dice-marker-clamp 520ms var(--ease-out);
}
@keyframes dice-marker-clamp {
  0%   { box-shadow: 0 0 0 3px var(--brand-glow), 0 0 12px var(--brand-glow); }
  25%  { box-shadow: 0 0 0 6px var(--gold-glow), 0 0 26px var(--gold); background: var(--gold); }
  100% { box-shadow: 0 0 0 3px var(--brand-glow), 0 0 12px var(--brand-glow); background: #fff; }
}
/* the roll dot must never intercept a track press either (it's purely a result reveal). */
.dice-roll-dot { pointer-events: none; }

/* =============================================================================
   The roll dot — THE STAR. It is hidden until handleResult() paints the server's
   roll, then it slides to roll/100 and settles. Outcome class (.win/.near/.lose)
   tints it; the ::after ring is the "settle" pop.
   ========================================================================== */
.dice-roll-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  /* a bigger landing dot to read clearly on the now-tall meter (was 26px) */
  width: clamp(30px, 5.5vh, 52px);
  height: clamp(30px, 5.5vh, 52px);
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px var(--gold-glow), 0 0 6px var(--gold);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  z-index: 3;
  /* the SLIDE: a long, eased horizontal travel; the settle (scale/opacity) is the
     spring tween below. transition kept here so a reduced-motion override can null it. */
  transition:
    left var(--dur-4) var(--ease-out),
    transform var(--dur-3) var(--ease-spring),
    opacity var(--dur-2) linear,
    background var(--dur-2) linear,
    box-shadow var(--dur-2) linear;
}
.dice-roll-dot.show {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

/* outcome tints (applied by the fx hook / core paint — presentation only) */
.dice-roll-dot.win {
  background: var(--win);
  box-shadow: 0 0 22px var(--win-glow), 0 0 8px var(--win);
}
.dice-roll-dot.near {
  background: var(--warn);
  box-shadow: 0 0 22px var(--warn-glow), 0 0 8px var(--warn);
}
.dice-roll-dot.lose {
  background: var(--lose);
  box-shadow: 0 0 18px var(--lose-glow), 0 0 6px var(--lose);
}

/* the SETTLE RING — a single expanding/fading halo when the dot lands. Driven by the
   .settle class (added by the core after the slide), self-removing via animationend. */
.dice-roll-dot::after {
  content: "";
  position: absolute;
  inset: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  border: 2px solid currentColor;
  color: var(--gold);
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
}
.dice-roll-dot.win::after  { color: var(--win); }
.dice-roll-dot.near::after { color: var(--warn); }
.dice-roll-dot.lose::after { color: var(--lose); }
.dice-roll-dot.settle::after {
  animation: dice-settle-ring var(--dur-4) var(--ease-out) forwards;
}
@keyframes dice-settle-ring {
  0%   { width: 8px;  height: 8px;  opacity: .9; }
  100% { width: 64px; height: 64px; opacity: 0; }
}

/* the LANDING THUMP — a quick squash/overshoot on the dot itself when it lands. */
.dice-roll-dot.settle {
  animation: dice-settle-pop var(--dur-3) var(--ease-spring);
}
@keyframes dice-settle-pop {
  0%   { transform: translate(-50%, -50%) scale(1); }
  40%  { transform: translate(-50%, -50%) scale(1.45); }
  70%  { transform: translate(-50%, -50%) scale(.88); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* =============================================================================
   Near-miss micro-label (issue #7) — "So close!" above the dot on a near-miss
   loss, so the amber dot's distinct state is legible. Slides in with the dot
   (it's positioned at the dot's left%). Amber to match the near-miss tint, and
   clearly distinct from the red loss + the green win. aria-hidden (the outcome
   is already announced via the verdict card). Pointer-transparent.
   ========================================================================== */
.dice-near-label {
  position: absolute;
  top: 50%;
  /* stack ABOVE the rolled-number popover (which sits just above the dot) on a near-miss */
  margin-top: clamp(-96px, -13vh, -78px);
  transform: translate(-50%, -50%) scale(.7);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--warn-soft, rgba(255, 184, 77, .12));
  border: 1px solid var(--warn);
  color: var(--warn);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  z-index: 4;
  text-shadow: 0 0 8px var(--warn-glow);
  transition: left var(--dur-4) var(--ease-out),
    opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}
.dice-near-label.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* =============================================================================
   Rolled-number popover (Stake-style) — the exact rolled value ABOVE the dot on EVERY
   roll, so the player reads the result on the 0-100 scale right where the dot lands.
   Rides in with the dot (positioned at the dot's left%); outcome-tinted to match it.
   ========================================================================== */
.dice-roll-value {
  position: absolute;
  top: 50%;
  margin-top: clamp(-58px, -8vh, -44px); /* just above the landing dot */
  transform: translate(-50%, -50%) scale(.7);
  padding: 3px 11px;
  border-radius: var(--r-pill);
  background: var(--glass-bg-strong, rgba(14, 14, 22, .82));
  border: 1px solid var(--line-3);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: var(--fs-md); font-weight: 700; letter-spacing: .01em;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  pointer-events: none; opacity: 0; z-index: 4;
  text-shadow: 0 0 8px rgba(0, 0, 0, .55);
  transition: left var(--dur-4) var(--ease-out),
    opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-spring);
}
.dice-roll-value.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
/* a small downward pointer tying the popover to the dot */
.dice-roll-value::after {
  content: ""; position: absolute; left: 50%; top: 100%;
  transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: var(--line-3);
}
.dice-roll-value.win  { border-color: var(--win);  color: var(--win);  box-shadow: 0 0 14px var(--win-glow); }
.dice-roll-value.win::after  { border-top-color: var(--win); }
.dice-roll-value.near { border-color: var(--warn); color: var(--warn); box-shadow: 0 0 14px var(--warn-glow); }
.dice-roll-value.near::after { border-top-color: var(--warn); }
.dice-roll-value.lose { border-color: var(--lose); color: var(--lose); box-shadow: 0 0 14px var(--lose-glow); }
.dice-roll-value.lose::after { border-top-color: var(--lose); }

/* =============================================================================
   Scale row beneath the meter
   ========================================================================== */
.dice-scale {
  position: relative;
  height: 1.35em;
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
/* STATIC Stake-style reference ticks at their EXACT positions, so "50" is dead-centre and every tick lines
   up with the meter + dot (which map value/100 onto the 0-100 axis). Endpoints hug the edges; 25/50/75 centred. */
.dice-scale span { position: absolute; top: 0; }
.dice-scale span:nth-child(1) { left: 0; }                                   /* 0   - left edge */
.dice-scale span:nth-child(2) { left: 25%;  transform: translateX(-50%); }   /* 25 */
.dice-scale span:nth-child(3) { left: 50%;  transform: translateX(-50%); }   /* 50  - dead centre */
.dice-scale span:nth-child(4) { left: 75%;  transform: translateX(-50%); }   /* 75 */
.dice-scale span:nth-child(5) { left: 100%; transform: translateX(-100%); }  /* 100 - right edge */

/* =============================================================================
   Mobile: the desktop board-fill grows the meter to fill a tall desktop column;
   on a phone the display column is short + the controls stack BELOW the board, so a
   ~460px band would push the bet controls further off-screen. Cap the band tighter on
   mobile so the board stays a sensible height (the rest of T2 — sticky bet / scroll the
   board into view — is the shared layout fix reported to the lead).
   ========================================================================== */
@media (max-width: 640px) {
  .dice-meter { height: clamp(120px, 28vh, 240px); }
}

/* =============================================================================
   Reduced-motion: the dot must STILL appear and land at roll/100 (legibility), but
   with NO slide / spring / ring motion — it just snaps to its final position.
   This satisfies the HARD a11y bar: reduced-motion no-ops all MOTION.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .dice-track,
  .dice-track::before,
  .dice-marker { transition: none; }
  .dice-roll-dot {
    transition: opacity var(--dur-1) linear, background var(--dur-1) linear;
    transform: translate(-50%, -50%) scale(1);
  }
  .dice-roll-dot.show { transform: translate(-50%, -50%) scale(1); }
  .dice-roll-dot.settle { animation: none; }
  .dice-roll-dot.settle::after { animation: none; }
  /* no-op the new anticipation/flash motion under reduced-motion (the states still apply, just no motion). */
  .dice-track.is-rolling::after { animation: none; opacity: 0; }
  .dice-track.is-rolling ~ .dice-marker { animation: none; }
  .dice-marker.clamped { animation: none; }
  .dice-near-label {
    transition: opacity var(--dur-1) linear;
    transform: translate(-50%, -50%) scale(1);
  }
  .dice-near-label.show { transform: translate(-50%, -50%) scale(1); }
  .dice-roll-value {
    transition: opacity var(--dur-1) linear;
    transform: translate(-50%, -50%) scale(1);
  }
  .dice-roll-value.show { transform: translate(-50%, -50%) scale(1); }
}

/* ---- recent-rolls history strip (rail, below the preview) — presentation only, NEVER a predictor.
   Ported from limbo's history pattern; chips show the landed roll on the 0.00–99.99 dice scale, win=green. ---- */
.dice-history { margin-top: var(--sp-3); }
.dice-history-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-1);
}
.dice-history-k {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: var(--tracking-cap);
  font-weight: var(--fw-semi); color: var(--muted);
}
.dice-history-note { font-size: var(--fs-xs); color: var(--muted); opacity: .8; }
.dice-history-chips {
  display: flex; flex-wrap: wrap; gap: var(--sp-1);
  min-height: calc(var(--fs-xs) + 12px); /* reserve one row so empty↔filled don't shift (CLS-safe) */
  align-content: flex-start;
}
.dice-chip {
  padding: 2px var(--sp-2); border-radius: var(--r-sm);
  font-size: var(--fs-xs); font-weight: var(--fw-semi); font-variant-numeric: tabular-nums;
  border: 1px solid var(--line-2); white-space: nowrap;
}
.dice-chip.is-win { color: var(--win-2); background: var(--win-soft); border-color: var(--win); }
.dice-chip.is-loss { color: var(--muted); background: var(--surface-2); border-color: var(--line-2); }
.dice-history-empty { font-size: var(--fs-xs); color: var(--muted); opacity: .75; }
