:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --panel: rgba(18, 18, 18, 0.84);
  --panel-strong: rgba(30, 30, 30, 0.94);
  --line: rgba(255, 255, 255, 0.13);
  --text: #f3f1ea;
  --muted: #aba7a0;
  --bone: #f3f1ea;
  --steel: #777872;
  --ash: #2f302e;
  --red: #ef1f24;
  --blood: #8f1017;
  --amber: #d7a43d;
  --danger: #ff353b;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 118%, rgba(239, 31, 36, 0.24), transparent 35%),
    linear-gradient(135deg, rgba(143, 16, 23, 0.2), transparent 38%),
    linear-gradient(235deg, rgba(119, 120, 114, 0.12), transparent 46%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.014) 0 1px, transparent 1px 38px);
  opacity: 0.34;
}

button {
  font: inherit;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  width: 100vw;
  height: 100vh;
  padding: 8px;
}

.hud {
  display: grid;
  grid-template-columns: minmax(174px, 0.74fr) minmax(320px, 1.5fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 42%),
    linear-gradient(90deg, rgba(239, 31, 36, 0.1), transparent 38%),
    rgba(9, 7, 8, 0.93);
  box-shadow:
    var(--shadow),
    inset 0 1px rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(18px);
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo-mark {
  display: grid;
  place-items: center;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(239, 31, 36, 0.95), rgba(243, 241, 234, 0.84)),
    #151515;
  color: #080808;
  font-weight: 950;
  letter-spacing: 0;
  box-shadow: inset 0 -8px 18px rgba(0, 0, 0, 0.25);
}

h1 {
  margin: 0;
  overflow: hidden;
  color: var(--bone);
  font-size: clamp(1.05rem, 2.2vw, 1.55rem);
  line-height: 1.05;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.identity p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.meter-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, 1fr)) minmax(190px, 1.55fr);
  gap: 8px;
  min-width: 0;
}

.metric,
.health {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
}

.metric span,
.health-label,
.stat-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric strong,
.stat-grid strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  color: #fff;
  font-size: 1rem;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.health {
  display: grid;
  grid-template-columns: auto minmax(150px, 1fr) 52px;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  border-color: rgba(239, 31, 36, 0.3);
  background:
    linear-gradient(135deg, rgba(239, 31, 36, 0.16), rgba(255, 255, 255, 0.055)),
    rgba(0, 0, 0, 0.22);
}

.health-track {
  display: block;
  overflow: hidden;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.08), rgba(0,0,0,0.32)),
    rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.42),
    0 0 20px rgba(239, 31, 36, 0.12);
}

.health-track span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), transparent 45%),
    linear-gradient(90deg, #ff252b 0%, var(--amber) 50%, var(--bone) 100%);
  transform: scaleX(0.5);
  transform-origin: left center;
  transition: transform 160ms ease;
  box-shadow: 0 0 18px rgba(255, 53, 59, 0.42);
}

.health strong {
  overflow: hidden;
  color: var(--bone);
  font-size: 1rem;
  font-weight: 950;
  letter-spacing: 0;
  text-align: right;
  text-shadow: 0 0 14px rgba(239, 31, 36, 0.42);
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.music-status {
  display: grid;
  place-items: center;
  min-width: 124px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(239, 31, 36, 0.32);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(239, 31, 36, 0.18), rgba(255, 255, 255, 0.06)),
    rgba(239, 31, 36, 0.1);
  color: #ffe8e8;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}

.music-status.muted {
  border-color: rgba(255, 90, 95, 0.32);
  background: rgba(255, 90, 95, 0.1);
  color: #ffd8d8;
}

.music-toggle.active {
  border-color: rgba(239, 31, 36, 0.68);
  background: rgba(239, 31, 36, 0.16);
  color: #ffe8e8;
}

.music-toggle:not(.active) {
  border-color: rgba(255, 90, 95, 0.38);
  background: rgba(255, 90, 95, 0.12);
  color: #ffd8d8;
}

.icon-button,
.segmented button,
.track-button,
.primary-action {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  font-weight: 900;
}

.icon-button:hover,
.segmented button:hover,
.track-button:hover,
.primary-action:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(120px, 156px) minmax(0, 1fr) minmax(120px, 156px);
  gap: 8px;
  min-height: 0;
}

.panel {
  min-height: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.07), transparent 38%),
    linear-gradient(180deg, rgba(143, 16, 23, 0.1), transparent 72%),
    rgba(9, 7, 8, 0.86);
  box-shadow:
    var(--shadow),
    inset 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.panel-title {
  margin: 0 0 9px;
  color: var(--bone);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-title.compact {
  margin-top: 16px;
}

.setlist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.track-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 3px;
  width: 100%;
  min-height: 52px;
  padding: 9px;
  text-align: left;
}

.track-button span {
  overflow: hidden;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-button small {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 800;
}

.track-button.active {
  border-color: rgba(239, 31, 36, 0.72);
  background:
    linear-gradient(90deg, rgba(239, 31, 36, 0.22), rgba(243, 241, 234, 0.08)),
    rgba(255, 255, 255, 0.08);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.segmented button {
  min-width: 0;
  min-height: 38px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.segmented button.active {
  border-color: rgba(215, 164, 61, 0.74);
  color: #fff3ce;
  background: rgba(215, 164, 61, 0.2);
}

.arena-wrap {
  position: relative;
  overflow: hidden;
  min-width: 0;
  min-height: min(72vh, 620px);
  border: 4px solid #100b10;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 42%, rgba(239, 31, 36, 0.18), transparent 34%),
    #12070d;
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(255,255,255,0.08),
    inset 0 0 0 1px rgba(255,255,255,0.06),
    inset 0 0 72px rgba(239,31,36,0.1);
}

.arena-wrap::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  border: 1px solid rgba(239, 31, 36, 0.28);
  border-radius: inherit;
  box-shadow:
    inset 0 0 32px rgba(239, 31, 36, 0.14),
    0 0 28px rgba(0, 0, 0, 0.45);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.screen-shine {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 46%, rgba(0,0,0,0.34) 100%),
    linear-gradient(115deg, rgba(255, 255, 255, 0.1), transparent 22%, transparent 75%, rgba(255, 255, 255, 0.06)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.032) 0 1px, transparent 1px 4px);
  mix-blend-mode: screen;
  opacity: 0.46;
}

.start-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  pointer-events: auto;
}

.game-shell[data-state="playing"] .start-layer,
.game-shell[data-state="paused"] .start-layer {
  opacity: 0;
  pointer-events: none;
}

.ready-chip {
  min-width: 112px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(17, 17, 15, 0.82);
  color: var(--bone);
  font-weight: 950;
  text-align: center;
  text-transform: uppercase;
  box-shadow: var(--shadow);
}

.primary-action {
  min-width: 142px;
  min-height: 50px;
  padding: 0 22px;
  border-color: rgba(239, 31, 36, 0.72);
  background:
    linear-gradient(135deg, rgba(239, 31, 36, 0.92), rgba(243, 241, 234, 0.86)),
    #1a1a1a;
  color: #080808;
  font-weight: 950;
  text-transform: uppercase;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.34);
}

.performance {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
}

.judge {
  display: grid;
  place-items: center;
  min-height: 84px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(239, 31, 36, 0.2), rgba(119, 120, 114, 0.16)),
    rgba(255, 255, 255, 0.055);
  color: #fff;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 950;
  letter-spacing: 0;
  text-align: center;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.leaderboard {
  min-width: 0;
}

.leaderboard ol {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.048);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.leaderboard li strong,
.leaderboard li span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard li strong {
  color: var(--bone);
}

.leaderboard li span {
  color: var(--muted);
  text-align: right;
}

.wave-panel {
  display: grid;
  grid-template-columns: repeat(8, minmax(8px, 1fr));
  align-items: end;
  gap: 7px;
  min-height: 126px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.wave-panel span {
  display: block;
  height: 28%;
  min-height: 22px;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, var(--bone), var(--red), var(--blood));
  transform-origin: bottom center;
  animation: wave 740ms ease-in-out infinite alternate;
}

.wave-panel span:nth-child(2) {
  animation-delay: -110ms;
}

.wave-panel span:nth-child(3) {
  animation-delay: -240ms;
}

.wave-panel span:nth-child(4) {
  animation-delay: -320ms;
}

.wave-panel span:nth-child(5) {
  animation-delay: -180ms;
}

.wave-panel span:nth-child(6) {
  animation-delay: -390ms;
}

.wave-panel span:nth-child(7) {
  animation-delay: -70ms;
}

.wave-panel span:nth-child(8) {
  animation-delay: -280ms;
}

@keyframes wave {
  from {
    transform: scaleY(0.42);
  }
  to {
    transform: scaleY(1);
  }
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .game-shell {
    min-height: 100vh;
    height: auto;
  }

  .hud {
    grid-template-columns: 1fr auto;
  }

  .meter-strip {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .hud-actions {
    justify-content: end;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .setlist {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .setlist .panel-title {
    grid-column: 1 / -1;
  }

  .setlist .panel-title.compact {
    margin-top: 4px;
  }

  .segmented {
    grid-column: 1 / -1;
  }

  .arena-wrap {
    min-height: 62vh;
  }

  .performance {
    grid-template-columns: 0.8fr 1fr 1fr;
    grid-template-rows: auto;
  }
}

@media (max-width: 640px) {
  .game-shell {
    padding: 8px;
    gap: 8px;
  }

  .hud {
    gap: 8px;
    padding: 8px;
  }

  .hud-actions {
    grid-column: 1 / -1;
  }

  .logo-mark {
    flex-basis: 42px;
    width: 42px;
    height: 42px;
  }

  .meter-strip {
    grid-template-columns: repeat(3, 1fr);
  }

  .health {
    grid-column: 1 / -1;
  }

  .setlist {
    grid-template-columns: 1fr;
  }

  .track-button {
    min-height: 46px;
  }

  .arena-wrap {
    min-height: 58vh;
  }

  .performance {
    grid-template-columns: 1fr;
  }

  .wave-panel {
    min-height: 78px;
  }
}
