/* Ladybug Race. The garden is drawn in SVG; this is the frame around it, the
   rhythm bar and the crawl buttons. Same tokens as the rest of the arcade. */

.race-surface {
  text-align: center;
  padding: clamp(10px, 3vw, 22px) 0 18px;
}

.race-heat {
  margin: 0 0 8px;
}

.race-title {
  font: 400 clamp(25px, 4vw, 40px)/1.15 var(--display);
  margin: 0 0 18px;
  color: var(--ink);
}

/* ------------------------------------------------------------ track picker */

.race-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 16px;
}

.race-track {
  font-size: 13px;
  padding: 9px 15px;
}

.race-track.chosen {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  box-shadow: 0 4px 0 var(--red-deep);
}

/* -------------------------------------------------------------- the garden */

.race-stage {
  position: relative;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
  background: var(--surface);
}

/* The whole course, always. Neither bug may leave the screen. */
.race-scene {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1000 / 430;
  --trail: #e8c49d;
  --trail-edge: #cfa276;
}

.race-trail {
  fill: none;
  stroke: var(--trail-edge);
  stroke-width: 38;
  stroke-linecap: round;
  opacity: .9;
}

.race-trail-top {
  fill: none;
  stroke: var(--trail);
  stroke-width: 30;
  stroke-linecap: round;
}

.race-trail-dashes {
  fill: none;
  stroke: #ffffff;
  stroke-width: 2.5;
  stroke-dasharray: 9 15;
  stroke-linecap: round;
  opacity: .55;
}

.race-lane-rose .race-trail {
  stroke: #c9718c;
}

.race-lane-cream .race-trail {
  stroke: #c8a06a;
}

.race-post-label {
  font: 700 15px var(--font);
  letter-spacing: 2px;
  fill: #fff;
}

.race-bug {
  transition: none;
}

.race-spark {
  font-size: 34px;
  fill: #c9366a;
  animation: race-spark .9s ease-out forwards;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes race-spark {
  from { opacity: .95; transform: translateY(0) scale(.5); }
  to { opacity: 0; transform: translateY(-34px) scale(1.25); }
}

.race-firefly {
  animation: race-firefly 3.4s ease-in-out var(--delay, 0s) infinite;
  transform-box: fill-box;
  transform-origin: center;
}

@keyframes race-firefly {
  0%, 100% { opacity: .15; transform: translate(0, 0); }
  50% { opacity: .9; transform: translate(var(--drift, 6px), -10px); }
}

/* The line over the garden: countdown, then encouragement. */
.race-callout {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  margin: 0;
  padding: 0 12px;
  font: 700 clamp(17px, 3.2vw, 28px) var(--display);
  color: #95445e;
  pointer-events: none;
}

/* Its own little pill, so the words read over tulips, water or moonlight. */
.race-callout span {
  display: inline-block;
  max-width: 100%;
  padding: 2px 16px;
  border-radius: 999px;
  background: #fffaf8d6;
  box-shadow: 0 2px 10px #8d475f1f;
}

.race-callout[data-tone="count"] {
  font-size: clamp(22px, 4.6vw, 38px);
}

.race-callout[data-tone="count"] span {
  animation: race-count .5s var(--bounce) both;
}

.race-callout[data-tone="hurry"] {
  color: #a5123f;
}

.race-callout[data-tone="done"] {
  color: #7b304c;
}

@keyframes race-count {
  from { opacity: 0; transform: scale(.7); }
  to { opacity: 1; transform: scale(1); }
}

/* ------------------------------------------------------------- the boards */

.race-boards {
  display: grid;
  gap: 10px;
  margin: 16px 0 12px;
}

.race-board {
  padding: 10px 13px;
  text-align: left;
  background: #fff9f8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .25s var(--ease);
}

.race-board.leading {
  border-color: var(--line-strong);
}

.race-board.done {
  background: #fdeff2;
}

.race-board-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.race-board-top b {
  overflow-wrap: anywhere;
}

.race-place {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--muted);
}

.race-bar {
  position: relative;
  height: 10px;
  margin: 8px 0 7px;
  background: var(--surface-sunk);
  border-radius: 999px;
  overflow: hidden;
}

.race-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #e58aa6, #c5496c);
}

.race-board-cream .race-bar-fill {
  background: linear-gradient(90deg, #f3cf94, #cf9a55);
}

.race-pips {
  display: flex;
  gap: 6px;
}

.race-pip {
  width: 22px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
}

.race-pip.won {
  background: var(--red);
  border-color: var(--red-deep);
}

.race-board-cream .race-pip.won {
  background: #d3af63;
  border-color: #a9832f;
}

/* ------------------------------------------------------------- the rhythm */

.race-beats {
  margin: 14px 0 6px;
}

.race-beat-who {
  margin: 10px 0 4px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .4px;
  color: var(--muted);
  text-align: left;
}

.race-beat {
  position: relative;
  height: 46px;
  background: linear-gradient(#fdeef3, #f8e2ea);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  --fly: 54px;
  --flow: 0; /* 0 at a standing start, 1 at a full streak */
}

/* The bar warms as the streak builds, so the firefly speeding up reads as a
   reward rather than the page glitching. */
.race-beat::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  border: 1px solid #f0a73c;
  opacity: calc(var(--flow) * .85);
  pointer-events: none;
}

/* The marker never leaves the bar, so it runs along a rail inset by its own
   radius. The sweet spot is measured on the same rail, which is what keeps
   what you see and what the server scores in agreement. */
.race-beat-rail {
  position: absolute;
  inset: 5px 22px;
}

.race-beat-band {
  position: absolute;
  top: -5px;
  bottom: -5px;
  left: var(--band, 35%);
  right: var(--band, 35%);
  border-radius: 999px;
  background: radial-gradient(ellipse at center, #ffd98a 0, #ffcf6f88 58%, transparent 80%);
  opacity: calc(.78 + var(--flow) * .22);
  transition: background .18s var(--ease);
}

.race-beat.on-beat .race-beat-band {
  background: radial-gradient(ellipse at center, #fff0b8 0, #ffd36a 62%, #ffd36a33 88%);
}

/* The marker itself is just a point on the rail; the firefly hangs off it with
   its lantern on that exact spot, and its antennae may overhang the bar. */
.race-beat-mark {
  position: absolute;
  top: 50%;
  left: 0;
  width: 0;
  height: 0;
}

.race-fly {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--fly);
  height: auto;
  overflow: visible;
  transform: translate(-50%, -50%);
}

.race-beat-mark[data-facing="left"] .race-fly {
  transform: translate(-50%, -50%) scaleX(-1);
}

.race-fly-wing {
  fill: url(#race-fly-wing);
  stroke: #dfaebf;
  stroke-width: .75;
  transform-box: fill-box;
  transform-origin: 96% 62%;
  animation: race-fly-flap .13s linear infinite alternate;
}

.race-fly-wing-front {
  animation-direction: alternate-reverse;
}

.race-fly-vein {
  fill: none;
  stroke: #e8c2cd;
  stroke-width: .5;
  opacity: .8;
  transform-box: fill-box;
  transform-origin: 100% 40%;
  animation: race-fly-flap .13s linear infinite alternate;
}

.race-fly-halo,
.race-fly-lantern {
  transform-box: fill-box;
  transform-origin: center;
  animation: race-fly-breathe 1.7s ease-in-out infinite;
}

.race-beat.on-beat .race-fly-halo {
  animation: none;
  transform: scale(1.35);
  opacity: 1;
}

.race-beat.hit .race-fly-halo {
  transform: scale(1.7);
}

@keyframes race-fly-flap {
  from { transform: rotate(-11deg) scaleY(.72); }
  to { transform: rotate(6deg) scaleY(1); }
}

@keyframes race-fly-breathe {
  0%, 100% { transform: scale(.92); opacity: .82; }
  50% { transform: scale(1.06); opacity: 1; }
}

.race-beat-label {
  margin: 0 0 4px;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
}

/* ----------------------------------------------------------- the controls */

.race-controls {
  display: grid;
  gap: 12px;
  margin: 16px 0 10px;
}

.race-controls[data-layout="pair"] {
  grid-template-columns: 1fr 1fr;
}

.race-crawl {
  min-height: 108px;
  padding: 14px;
  background: linear-gradient(#fff3e7, #ffe6d8);
  border: 2px solid #eac7b6;
  border-radius: var(--radius-lg);
  box-shadow: 0 7px 0 #d3a79b;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .06s linear, box-shadow .06s linear;
}

.race-crawl b {
  display: block;
  font: 600 clamp(18px, 3vw, 24px) var(--font);
}

.race-crawl small {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.race-crawl:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #d3a79b;
}

.race-crawl-rose {
  background: linear-gradient(#fff1f4, #fbdae2);
  border-color: #e6aebd;
  box-shadow: 0 7px 0 #c98da0;
}

.race-crawl-rose:active {
  box-shadow: 0 2px 0 #c98da0;
}

.race-crawl-cream {
  background: linear-gradient(#fff8ea, #fbecd0);
  border-color: #e0c48e;
  box-shadow: 0 7px 0 #c5a469;
}

.race-crawl-cream:active {
  box-shadow: 0 2px 0 #c5a469;
}

.race-action {
  justify-self: center;
  min-width: 220px;
}

.race-note {
  margin: 4px 0 0;
}

/* ------------------------------------------------------------ party lanes */

/* One lane per seat: the trail keeps its garden colours, the line down the
   middle and the name at the gate wear the seat's colour. */
.race-lane-party .race-trail {
  stroke: var(--seat);
  opacity: .55;
}

.race-lane-party .race-trail-dashes {
  stroke: var(--seat);
  opacity: .85;
  stroke-width: 3.5;
}

.race-lane-name {
  font: 700 20px var(--font);
  fill: var(--seat);
  stroke: #fffaf8;
  stroke-width: 5px;
  stroke-linejoin: round;
  paint-order: stroke;
}

.race-scene-party .race-post-label {
  font-size: 14px;
}

.race-boards-party {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.race-board-party {
  padding: 7px 10px;
  border-left: 4px solid var(--seat);
}

.race-board-party .race-board-top {
  font-size: 13px;
}

.race-board-party .race-bar {
  height: 8px;
  margin: 6px 0 5px;
}

.race-board-party .race-bar-fill,
.race-board-party.race-board-cream .race-bar-fill {
  background: linear-gradient(90deg, var(--seat-soft), var(--seat));
}

.race-board-party .race-pip.won,
.race-board-party.race-board-cream .race-pip.won {
  background: var(--seat);
  border-color: var(--seat);
}

.race-board-party.done {
  background: color-mix(in srgb, var(--seat-soft) 45%, #fff9f8);
}

.race-watching {
  margin: 0;
  font-weight: 600;
  color: var(--muted);
}

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

@media (min-width: 620px) {
  .race-boards:not(.race-boards-party) {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 500px) {
  .race-boards-party {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .race-board-party {
    padding: 6px 8px;
  }

  .race-lane-name {
    font-size: 26px;
    stroke-width: 6px;
  }
}

@media (max-width: 500px) {
  .race-beat {
    height: 42px;
    --fly: 44px;
  }

  .race-beat-rail {
    inset: 5px 17px;
  }

  .race-crawl {
    min-height: 96px;
    padding: 12px 8px;
  }

  .race-crawl small {
    font-size: 11px;
  }

  .race-action {
    min-width: 0;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .race-spark,
  .race-firefly,
  .race-fly-wing,
  .race-fly-vein,
  .race-fly-halo,
  .race-fly-lantern,
  .race-callout[data-tone="count"] span {
    animation: none;
  }
}
