/* The board: dark lit pucks laid over one unbroken violet wire.

   Three stacked layers in the same coordinate space, all sized from --ar, which
   ui/board.js sets from the generated board:
     1. .track   — the wire, under the tiles, seen only in the gaps and margins
     2. .board   — the tiles themselves, placed by their serpentine row/col
     3. .chutes  — the slides, over the tiles, because a chute you cannot see
                   where it matters is not a warning

   Everything inside a tile is measured against that tile in container units, so
   a 30-space board and a 40-space board both read without a single breakpoint. */

.board-stage {
  position: relative;
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: var(--ar, 1.5);
  margin: auto;
  isolation: isolate;

  /* The tile's own box cannot use its own container units, so its keyline and
     corner come off the viewport — the same trick the board is drawn with. */
  --tile-r: clamp(6px, 0.95vw, 14px);
  --tile-bd: clamp(1.5px, 0.24vw, 3px);
}

/* ---- 1. the wire ---- */

.track {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.track__halo {
  fill: none;
  stroke: color-mix(in srgb, var(--violet) 26%, transparent);
  stroke-width: 28;
  stroke-linecap: round;
}

.track__glow {
  fill: none;
  stroke: color-mix(in srgb, var(--violet) 72%, transparent);
  stroke-width: 12;
  stroke-linecap: round;
}

/* Marching dashes: the wire states its direction even when nobody is moving. */
.track__wire {
  fill: none;
  stroke: var(--wire);
  stroke-width: 4.5;
  stroke-dasharray: 6 12;
  stroke-linecap: round;
  animation: wire-march var(--dur-march) linear var(--anim-iter);
}

@keyframes wire-march {
  to { stroke-dashoffset: -36; }
}

.track__arrow { fill: var(--wire); }

/* The spaces the active player just rolled, burnt into the same wire — it runs
   straight through a hairpin when the roll crosses one. */
.track__liveglow {
  fill: none;
  stroke: color-mix(in srgb, var(--accent) 55%, transparent);
  stroke-width: 22;
  stroke-linecap: round;
}

.track__live {
  fill: none;
  stroke: var(--accent-hi);
  stroke-width: 6.5;
  stroke-linecap: round;
  stroke-dasharray: 16 10;
  animation: wire-march-hot var(--dur-march-hot) linear var(--anim-iter);
}

@keyframes wire-march-hot {
  to { stroke-dashoffset: -52; }
}

/* ---- 2. the tiles ---- */

.board {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  /* The tile is the container everything inside it is measured against, in both
     axes — a six-row board makes tiles wider than they are tall and the type has
     to follow the shorter one. */
  container-type: size;
  position: absolute;
  z-index: 3;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background-color: var(--tone-fill);
  background-image: var(--fill-lit);
  border: var(--tile-bd) solid var(--tone-edge);
  border-radius: var(--tile-r);
  /* No per-tile glow. Thirty glows is a haze, not emphasis. */
  box-shadow:
    0 3px 0 var(--slab),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  user-select: none;
  -webkit-user-select: none;
}

/* A space with counters on it lifts over its neighbours, so the ones that
   straddle its edge are never clipped by the next tile along. */
.tile.is-occupied { z-index: 4; }

/* Hue is never the only cue: every kind also carries its own border style or
   surface texture, so the board still reads in greyscale. */
.tile__tex {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--tile-r) - 2px);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* ---- the face ---- */

.tile__face {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3cqh;
  min-width: 0;
  min-height: 0;
  padding: 14cqh 4cqw 6cqh;
  text-align: center;
  overflow: hidden;
  transition: padding var(--dur-mid) var(--ease-out);
}

/* Room along the bottom for the counters standing here. They straddle the edge,
   so the tile only has to give up half a counter of face. */
.tile.is-occupied .tile__face { padding-bottom: 20cqh; }

.tile__icon {
  font-family: var(--font-emoji);
  font-size: min(27cqw, 30cqh);
  line-height: 1;
}

.tile__label {
  max-width: 100%;
  font-family: var(--font-display);
  font-weight: 900;
  line-height: 1.04;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: #FFF4FA;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
  overflow-wrap: break-word;
  /* The fallback first, then the fit: a cap of the display face runs about
     0.8em wide, so 118cqw / longest word is the size at which that word just
     fills the tile. The caps stop a short label becoming a headline. */
  font-size: 14cqw;
  font-size: min(18cqw, 21cqh, calc(118cqw / var(--w, 8)));
}

/* ---- the step number ---- */

/* It sits on the edge the player walks in from, so the numbers trace the
   direction the ribbon runs. Quiet on purpose — a reference, not a label. */
.tile__step {
  position: absolute;
  top: 3cqh;
  left: 6cqw;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: min(12cqw, 15cqh);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--tone-edge);
  opacity: 0.85;
  pointer-events: none;
}

.tile__step--right { left: auto; right: 6cqw; }

/* ---- the kinds ---- */

/* Deck spaces keep the tone mapgen gave them; the fixed kinds carry a hue of
   their own so two different spaces are never the same colour by accident. */

.tile--safe { --tone: var(--mint); }
.tile--duel,
.tile--melee { --tone: var(--info); }
.tile--hydration { --tone: var(--water); }
.tile--allDrink { --tone: var(--prize); }

.tile--forward,
.tile--back {
  --tone: var(--violet);
  border-style: dotted;
}

.tile[data-deck="house-dares"],
.tile[data-deck="bar-feats"] {
  --tone: var(--wild);
  border-style: dashed;
}

.tile--start,
.tile--end {
  --tone: #FFFFFF;
  --tone-fill: #2A2049;
}

.tile--start { border-style: dashed; }

.tile--duel .tile__tex,
.tile--melee .tile__tex,
.tile--end .tile__tex {
  opacity: 0.1;
  background:
    conic-gradient(#fff 0 25%, transparent 0 50%, #fff 0 75%, transparent 0);
  background-size: 14cqw 14cqw;
}

.tile--end .tile__tex { opacity: 0.16; }

.tile--allDrink .tile__tex {
  opacity: 0.16;
  background: radial-gradient(circle at 50% 50%, var(--flare-hi) 0 1.6cqw, transparent 2.2cqw);
  background-size: 11cqw 11cqw;
}

.tile--safe .tile__tex {
  opacity: 0.13;
  background: radial-gradient(circle at 50% 50%, var(--mint) 0 1.8cqw, transparent 2.4cqw);
  background-size: 13cqw 13cqw;
}

.tile--hydration .tile__tex {
  opacity: 0.12;
  background: repeating-linear-gradient(180deg,
    var(--water) 0 1.8cqh, transparent 1.8cqh 10cqh);
}

/* ---- the shot: the only solid, screaming tile on a board of dark pucks ---- */

/* Its face says one word. Where it drops you is drawn on the board as a slide,
   and what it costs you is dealt as a card when you land on it. */
.tile--shot {
  --tone: var(--danger);
  --tone-edge: #20000A;
  background-color: var(--blaze);
  background-image: linear-gradient(180deg, var(--blaze-hi) 0%, var(--blaze) 42%, var(--blaze-deep) 100%);
  box-shadow:
    0 4px 0 var(--slab-deep),
    0 0 30px -4px var(--blaze),
    inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.tile--shot .tile__tex {
  opacity: 0.18;
  background: radial-gradient(circle at 50% 50%, #20000A 0 1.7cqw, transparent 2.3cqw);
  background-size: 12cqw 12cqw;
}

.tile--shot .tile__step { color: #2A0008; opacity: 0.9; }

.tile--shot .tile__label { font-size: min(22cqw, 26cqh, calc(150cqw / var(--w, 4))); }
.tile--end .tile__label { font-size: min(20cqw, 24cqh, calc(140cqw / var(--w, 6))); }

/* ---- whose turn it is ---- */

/* The ring is the active player's own colour, so the board answers "where am I"
   at the same glance as "who is up". */
.tile.is-active {
  z-index: 6;
  border-color: #FFF1F7;
  animation: tile-breathe var(--dur-breathe) var(--ease-in-out) var(--anim-iter) alternate;
  box-shadow:
    0 4px 0 var(--slab),
    0 0 0 5px color-mix(in srgb, var(--pc, var(--accent)) 75%, transparent),
    0 0 46px 4px color-mix(in srgb, var(--pc, var(--accent)) 70%, transparent);
}

@keyframes tile-breathe {
  from {
    box-shadow:
      0 4px 0 var(--slab),
      0 0 0 4px color-mix(in srgb, var(--pc, var(--accent)) 60%, transparent),
      0 0 30px 0 color-mix(in srgb, var(--pc, var(--accent)) 45%, transparent);
  }
  to {
    box-shadow:
      0 4px 0 var(--slab),
      0 0 0 8px color-mix(in srgb, var(--pc, var(--accent)) 26%, transparent),
      0 0 56px 6px color-mix(in srgb, var(--pc, var(--accent)) 85%, transparent);
  }
}

/* ---- the roll, counted onto the spaces it crossed ---- */

.tile__pip {
  position: absolute;
  top: -8cqh;
  right: -5cqw;
  z-index: 8;
  display: grid;
  place-items: center;
  width: min(26cqw, 32cqh);
  height: min(26cqw, 32cqh);
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: min(14cqw, 17cqh);
  font-weight: 700;
  line-height: 1;
  color: #180530;
  background: #FFF1F7;
  border: 2px solid #180530;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

.tile__pip--final {
  width: min(32cqw, 38cqh);
  height: min(32cqw, 38cqh);
  font-size: min(17cqw, 20cqh);
  color: #2A0518;
  background: var(--accent);
  box-shadow: 0 0 22px color-mix(in srgb, var(--accent) 90%, transparent);
}

/* ---- 3. the chutes ---- */

/* Drawn over the tiles and routed through the gutter between rows wherever it
   can be, so a slide is visible for its whole length. It reads in the Shot
   tile's own red rather than hazard yellow — three high-contrast yellow-on-black
   ribbons crawling across the board fought the tiles for attention and never
   stopped moving. Solid, still, and the same colour as where it starts. */
/* The line is the whole explanation — no plate, no numbers. It sits back at rest
   so the board still reads as a grid, and comes up while someone is riding it. */
.chute {
  opacity: 0.42;
  transition: opacity var(--dur-fast, 140ms) ease-out;
}

.chute.is-firing { opacity: 1; }

.chutes {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.chute__glow {
  fill: none;
  stroke: color-mix(in srgb, var(--blaze) 18%, transparent);
  stroke-width: 18;
  stroke-linecap: round;
}

.chute__body {
  fill: none;
  stroke: #1C0008;
  stroke-width: 9;
  stroke-linecap: round;
  opacity: 0.94;
}

.chute__marks {
  fill: none;
  stroke: color-mix(in srgb, var(--blaze-hi) 70%, #FFFFFF);
  stroke-width: 3.5;
  stroke-linecap: round;
  opacity: 0.85;
}

.chute__mouth {
  fill: var(--blaze);
  stroke: #1C0008;
  stroke-width: 4;
}

.chute__tip {
  fill: color-mix(in srgb, var(--blaze-hi) 70%, #FFFFFF);
  stroke: #1C0008;
  stroke-width: 3;
}



/* ---- player tokens ---- */

/* Counters straddle the bottom edge of their space and hang into the empty
   gutter below it, the way a piece sits on a board rather than inside a box. */
.tile__tokens {
  position: absolute;
  left: 3cqw;
  right: 3cqw;
  bottom: -11cqh;
  z-index: 7;
  display: flex;
  flex-wrap: wrap-reverse;
  align-items: flex-end;
  justify-content: center;
  gap: 1cqh 0;
  pointer-events: none;
}

.token {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: min(25cqw, 31cqh);
  height: min(25cqw, 31cqh);
  border-radius: 50%;
  background: var(--pc, var(--surface));
  border: 2px solid #12062A;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 2px 5px rgba(0, 0, 0, 0.7),
    0 0 16px -2px var(--pc, var(--violet));
}

/* Counters overlap rather than shrink, so six players still fit one space. */
.token + .token { margin-left: -7cqw; }

.token__initial {
  font-family: var(--font-display);
  font-size: min(13cqw, 16cqh);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  /* The seat colour dropped into ink, so any swatch keeps a readable letter. */
  color: color-mix(in srgb, var(--pc, var(--text)) 18%, #12062A);
}

.token.is-you {
  box-shadow:
    0 0 0 2px var(--prize),
    0 2px 5px rgba(0, 0, 0, 0.7),
    0 0 16px -2px var(--pc, var(--violet));
}

.token.is-active {
  box-shadow:
    0 0 0 2px #fff,
    0 2px 5px rgba(0, 0, 0, 0.7),
    0 0 22px 3px color-mix(in srgb, var(--accent) 90%, transparent);
}

.token.is-offline { opacity: 0.4; }

.token.is-hopping { animation: token-land var(--dur-move) var(--ease-pop); }

@keyframes token-land {
  0% { transform: translateY(var(--hop-lift)) scale(1.35); }
  100% { transform: none; }
}

/* The counter riding a slide. It is a free copy laid over the whole stage and
   flown along the chute's own curve, so it passes over the board rather than
   through it. */
.token--riding {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9;
  width: 3.4%;
  aspect-ratio: 1;
  height: auto;
  margin: 0;
  pointer-events: none;
  box-shadow:
    0 0 0 2px #fff,
    0 4px 10px rgba(0, 0, 0, 0.8),
    0 0 26px 5px color-mix(in srgb, var(--blaze) 90%, transparent);
}

.token--riding .token__initial { font-size: 0.85rem; }

/* ---- narrow ---- */

/* Below the fold the ribbon keeps a readable size and scrolls inside its own
   frame rather than shrinking the labels out of legibility. */
@media (max-width: 900px) {
  .board-wrap {
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }

  .board-wrap > * { flex: 0 0 auto; }

  .board-stage {
    width: 38rem;
    max-width: none;
    height: auto;
  }
}
