:root {
  --font-tic: "Source Code Pro", ui-monospace, monospace;
  --green: #6faa1e;
  --green-hi: #9cd93c;
  --green-deep: #3d6610;
  --gold: #ffd54a;
  --silver: #c8d0dc;
  --bronze: #d4956a;
  --bg: #06060c;
  --ease-out: cubic-bezier(0.25, 1, 0.5, 1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: var(--font-tic);
}
.dash {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
.dash-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.dash-fx__vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% 0%, rgba(111, 170, 30, 0.09) 0%, transparent 55%),
    radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.65) 100%);
}
.dash-fx__scan {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.14) 2px,
    rgba(0, 0, 0, 0.14) 4px
  );
  animation: scanDrift 12s linear infinite;
}
@keyframes scanDrift {
  from { transform: translateY(0); }
  to { transform: translateY(4px); }
}
.dash > *:not(.dash-fx) { position: relative; z-index: 1; }
.dash-titlebar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1vh, 10px);
  padding: clamp(10px, 1.6vh, 16px) clamp(16px, 3vw, 32px);
  flex-shrink: 0;
  text-align: center;
}
.dash-qr {
  position: absolute;
  right: clamp(12px, 2.5vw, 28px);
  bottom: clamp(14px, 2.5vh, 24px);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: clamp(8px, 1.2vh, 12px) clamp(10px, 1.5vw, 14px);
  pointer-events: none;
  border: 1px solid rgba(156, 217, 60, 0.3);
  border-radius: 6px;
  background: rgba(6, 6, 12, 0.72);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
.dash-qr canvas {
  display: block;
  width: clamp(80px, 11vw, 112px);
  height: clamp(80px, 11vw, 112px);
  border: 1px solid rgba(156, 217, 60, 0.35);
  border-radius: 4px;
  background: rgba(6, 6, 12, 0.95);
}
.dash-qr__label {
  font-size: clamp(8px, 1vw, 10px);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--green-hi);
  text-align: center;
  line-height: 1.3;
}
.cheer-zone {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cheer-layer {
  position: absolute;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  overflow: visible;
}
.cheer-burst {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: min(320px, 48vw);
  padding: 14px 18px;
  border: 2px solid rgba(156, 217, 60, 0.6);
  border-radius: 8px;
  background: rgba(6, 6, 12, 0.94);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7), 0 0 28px rgba(156, 217, 60, 0.25);
  left: var(--cheer-x, 50%);
  bottom: var(--cheer-y, 12%);
  transform: translate(-50%, 0) rotate(var(--cheer-rot, 0deg));
  opacity: 1;
  animation: cheerRise 5.5s var(--ease-out) forwards;
  backdrop-filter: blur(8px);
  z-index: 1;
}
.cheer-burst.is-visible {
  opacity: 1;
}
.cheer-burst--calm {
  animation: cheerRiseCalm 3.2s ease forwards;
}
.cheer-burst__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: clamp(10px, 1.1vw, 13px);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.3;
}
.cheer-burst__sender {
  color: rgba(255, 255, 255, 0.85);
  max-width: 8em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cheer-burst__arrow {
  color: rgba(156, 217, 60, 0.7);
  flex-shrink: 0;
}
.cheer-burst__target {
  color: var(--green-hi);
  font-weight: 900;
  max-width: 9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cheer-burst__sticker {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
}
.cheer-burst__sticker img {
  width: clamp(36px, 5vw, 48px);
  height: clamp(36px, 5vw, 48px);
  object-fit: contain;
  display: block;
}
@keyframes cheerRise {
  0% {
    opacity: 0;
    bottom: var(--cheer-y, 8%);
    transform: translate(-50%, 0) rotate(var(--cheer-rot, 0deg)) scale(0.9);
  }
  8% {
    opacity: 1;
    transform: translate(-50%, 0) rotate(var(--cheer-rot, 0deg)) scale(1.05);
  }
  88% {
    opacity: 1;
    bottom: 78%;
  }
  100% {
    opacity: 0;
    bottom: 88%;
    transform: translate(-50%, 0) rotate(var(--cheer-rot, 0deg)) scale(0.98);
  }
}
@keyframes cheerRiseCalm {
  0% {
    opacity: 0;
    bottom: var(--cheer-y, 8%);
  }
  12% { opacity: 1; }
  100% {
    opacity: 0;
    bottom: 70%;
  }
}
.dash-titlebar img {
  height: clamp(32px, 5vh, 52px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 14px rgba(156, 217, 60, 0.28));
}
.dash-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.dash-title h1 {
  font-size: clamp(18px, 2.8vw, 32px);
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.05;
  text-shadow: 0 0 40px rgba(156, 217, 60, 0.15);
}
.dash-title p {
  font-size: clamp(10px, 1.2vw, 13px);
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(156, 217, 60, 0.75);
  animation: kickerGlow 4s ease-in-out infinite;
}
@keyframes kickerGlow {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; color: var(--green-hi); }
}
.dash-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.stage-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  z-index: 0;
}
#stageCanvas {
  display: block;
  width: 100%;
  height: 100%;
}
#stageLabels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.runner-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transform: translate(-50%, -100%);
  text-align: center;
  font-family: var(--font-tic);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.85);
  transition: opacity 0.3s ease;
}
.runner-label.is-empty { opacity: 0.35; }
.runner-label__rank {
  font-size: clamp(10px, 1vw, 12px);
  font-weight: 700;
  letter-spacing: 0.28em;
}
.runner-label__name {
  font-size: clamp(14px, 1.6vw, 22px);
  font-weight: 900;
  letter-spacing: 0.06em;
  max-width: 12em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.runner-label__score {
  font-size: clamp(16px, 1.8vw, 26px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}
.runner-label--1 .runner-label__rank,
.runner-label--1 .runner-label__score { color: var(--gold); }
.runner-label--2 .runner-label__rank,
.runner-label--2 .runner-label__score { color: var(--silver); }
.runner-label--3 .runner-label__rank,
.runner-label--3 .runner-label__score { color: var(--bronze); }
.runner-label--flash .runner-label__name {
  animation: labelPop 0.6s var(--ease-out);
}
@keyframes labelPop {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.06); filter: brightness(1.4); }
  100% { transform: scale(1); filter: brightness(1); }
}
.runner-label__score.is-ticking { color: var(--green-hi) !important; }
.stage-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 65% 50% at 50% 38%, rgba(255, 213, 74, 0.04) 0%, transparent 55%),
    radial-gradient(ellipse 70% 55% at 50% 42%, transparent 0%, rgba(6, 6, 12, 0.5) 100%),
    linear-gradient(180deg, transparent 50%, rgba(6, 6, 12, 0.88) 100%);
}
.stage-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(156, 217, 60, 0.18) 0%, transparent 65%);
  transition: opacity 0.15s ease;
}
.stage-flash.is-on { opacity: 1; }
.lb-strip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  min-height: clamp(128px, 20vh, 200px);
  max-height: 28vh;
  border-top: 1px solid rgba(111, 170, 30, 0.3);
  background:
    linear-gradient(180deg, rgba(111, 170, 30, 0.06) 0%, transparent 40%),
    rgba(4, 4, 10, 0.96);
}
.lb-strip-head {
  padding: clamp(8px, 1.2vh, 12px) clamp(14px, 2vw, 24px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: clamp(9px, 1vw, 11px);
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.38);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.lb-count { color: var(--green-hi); }
.lb-cheer-live {
  font-size: clamp(8px, 0.9vw, 10px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green-hi);
  padding: 2px 8px;
  border: 1px solid rgba(156, 217, 60, 0.4);
  border-radius: 3px;
  animation: cheerLivePulse 2.5s ease-in-out infinite;
}
.lb-cheer-live.is-offline {
  color: #ffb478;
  border-color: rgba(255, 180, 120, 0.4);
  animation: none;
}
@keyframes cheerLivePulse {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}
.lb-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: clamp(4px, 0.8vh, 8px);
  padding: clamp(8px, 1.2vh, 12px) clamp(12px, 2vw, 24px);
  position: relative;
}
.lb-grid-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(6px, 1vw, 12px);
  min-height: 0;
}
.lb-grid-row:last-child {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.lb-cell {
  display: flex;
  align-items: center;
  gap: clamp(6px, 0.8vw, 10px);
  padding: clamp(4px, 0.6vh, 8px) clamp(8px, 1vw, 12px);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.02);
  font-size: clamp(11px, 1.1vw, 13px);
  font-weight: 600;
  letter-spacing: 0.03em;
  min-width: 0;
  animation: rowIn 0.45s var(--ease-out) backwards;
  transition: background 0.25s ease, border-color 0.25s ease;
}
.lb-cell--empty {
  opacity: 0.22;
  border-style: dashed;
}
.lb-cell--flash {
  animation: rowFlash 0.7s var(--ease-out);
}
.lb-cell--1 { border-color: rgba(255, 213, 74, 0.38); }
.lb-cell--2 { border-color: rgba(200, 208, 220, 0.32); }
.lb-cell--3 { border-color: rgba(212, 149, 106, 0.32); }
.lb-cell--1 .lb-cell-score { color: var(--gold); }
.lb-cell--2 .lb-cell-score { color: var(--silver); }
.lb-cell--3 .lb-cell-score { color: var(--bronze); }
@keyframes rowFlash {
  0% { background: rgba(156, 217, 60, 0.22); border-color: rgba(156, 217, 60, 0.35); }
  100% { background: transparent; border-color: rgba(255,255,255,0.05); }
}
.lb-cell-rank {
  flex-shrink: 0;
  width: 1.6em;
  color: rgba(255,255,255,0.38);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.lb-cell-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lb-cell-score {
  flex-shrink: 0;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,0.9);
}
.lb-empty, .lb-error, .lb-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 20px;
  text-align: center;
  color: rgba(255,255,255,0.45);
  font-size: 12px;
  letter-spacing: 0.08em;
  pointer-events: none;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.lb-error, .lb-status.lb-error { color: rgba(255, 180, 120, 0.9); }
#stageLoader {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(6,6,12,0.92);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  transition: opacity 0.4s;
}
#stageLoader::after {
  content: '';
  width: 48px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--green-hi), transparent);
  animation: loaderBar 1.2s ease-in-out infinite;
}
@keyframes loaderBar {
  0%, 100% { opacity: 0.35; transform: scaleX(0.6); }
  50% { opacity: 1; transform: scaleX(1); }
}
#stageLoader.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
  .lb-strip {
    max-height: min(40vh, 320px);
    min-height: clamp(180px, 32vh, 320px);
  }
  .lb-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-rows: auto;
    align-content: start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .lb-grid-row {
    display: contents;
  }
  .lb-cell {
    min-height: 34px;
  }
}
@media (max-width: 560px) {
  .lb-strip {
    max-height: min(44vh, 340px);
    min-height: clamp(200px, 36vh, 340px);
  }
  .lb-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .lb-cell {
    font-size: clamp(10px, 2.8vw, 12px);
    padding: 6px 8px;
    gap: 6px;
    min-height: 36px;
  }
  .lb-cell-rank {
    width: 1.35em;
  }
}
@media (prefers-reduced-motion: reduce) {
  .dash-title p,
  .dash-fx__scan,
  #stageLoader::after,
  .lb-cell,
  .runner-label--flash .runner-label__name { animation: none !important; }
  .cheer-burst:not(.cheer-burst--calm) {
    animation: none !important;
    opacity: 1;
  }
  .cheer-burst--calm { animation: cheerRiseCalm 3.2s ease forwards !important; }
  .stage-flash.is-on { opacity: 0.35; }
}
