:root {
  --bg: #080a14;
  --panel: rgba(9, 14, 30, 0.82);
  --panel-strong: rgba(11, 18, 38, 0.94);
  --line: #2d416c;
  --text: #f9fbff;
  --muted: #9cb0d2;
  --gold: #ffd166;
  --cyan: #50dcff;
  --green: #70e485;
  --red: #ff5a77;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #1e2d52 0, #080a14 46%, #05060a 100%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.mobile-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
}

.page {
  display: none;
  width: min(430px, 100%);
  min-height: min(932px, calc(100vh - 24px));
}

.page.is-active {
  display: block;
}

.select-page {
  position: relative;
  overflow: hidden;
  padding: 18px 14px 96px;
  border: 2px solid #31466e;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(5, 8, 20, 0.1), rgba(5, 8, 20, 0.86)),
    url("./assets/background/background_vertical.png") center / cover;
  box-shadow: 0 24px 84px rgba(0, 0, 0, 0.48);
  image-rendering: pixelated;
}

.topbar,
.action-dock,
.run-hud,
.victory-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar {
  position: relative;
  align-items: flex-start;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 38px;
  line-height: 1.2;
}

.subtitle {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.01em;
}

.icon-button,
.primary-button,
.secondary-button,
.round-tab,
.team-button,
.hud-button,
.boost-button {
  border: 2px solid var(--line);
  color: var(--text);
  background: #10182f;
  cursor: pointer;
}

.icon-button,
.hud-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 28px;
  font-weight: 900;
}

.champion-card {
  display: none;
  margin: 18px 0 14px;
  padding: 14px;
  border: 2px solid rgba(80, 220, 255, 0.5);
  background: var(--panel);
}

.champion-card.is-visible {
  display: block;
}

.champion-card span {
  color: var(--gold);
  font-size: 12px;
  font-weight: 900;
}

.champion-card strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
  line-height: 1.08;
}

.champion-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.round-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.round-tab {
  min-height: 40px;
  padding: 8px 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.round-tab.is-active {
  border-color: var(--cyan);
  color: var(--text);
  background: #12324b;
}

.bracket {
  display: grid;
  gap: 12px;
}

.round-column {
  display: none;
}

.round-column.is-active {
  display: block;
}

.round-title {
  margin: 0 0 10px;
  color: var(--gold);
  font-size: 15px;
  font-weight: 900;
}

.match-list {
  display: grid;
  gap: 10px;
}

.match-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 2px solid rgba(80, 220, 255, 0.22);
  background: rgba(5, 9, 22, 0.72);
}

.team-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  font-weight: 900;
}

.team-button:disabled {
  color: #5d6982;
  cursor: not-allowed;
}

.team-button.is-winner {
  border-color: var(--green);
  background: #15371f;
  color: #eaffee;
}

.seed {
  color: var(--muted);
  font-size: 11px;
}

.action-dock {
  position: absolute;
  z-index: 10;
  left: 14px;
  right: 14px;
  bottom: 14px;
  gap: 10px;
  padding: 10px;
  border: 2px solid rgba(80, 220, 255, 0.3);
  background: rgba(6, 9, 22, 0.88);
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 0 13px;
  font-weight: 900;
}

.primary-button {
  flex: 1;
  border-color: var(--gold);
  background: #3b2b0e;
  color: #fff3bf;
}

.primary-button:disabled {
  border-color: #34435f;
  background: #13192d;
  color: #65728e;
  cursor: not-allowed;
}

.secondary-button {
  border-color: var(--cyan);
  background: #0e2838;
  color: #d8f8ff;
}

.run-page {
  min-height: auto;
}

.runner-stage {
  position: relative;
  width: min(430px, calc(100vw - 24px));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 3px solid #31466e;
  border-radius: 22px;
  background: #07101f;
  box-shadow: 0 24px 84px rgba(0, 0, 0, 0.52);
  image-rendering: pixelated;
}

.wide-bg,
.ground-strip,
.hero-sprite,
.ball-sprite,
.opponent-sprite {
  position: absolute;
  image-rendering: pixelated;
  user-select: none;
  pointer-events: none;
}

.wide-bg {
  left: 0;
  width: auto;
  max-width: none;
  height: 100%;
  transform: translate3d(0, 0, 0);
}

.far-bg {
  z-index: 1;
  opacity: 0;
  height: 100%;
  display: none;
}

.main-bg {
  z-index: 2;
}

.ground-strip {
  z-index: 3;
  left: 0;
  bottom: 9.5%;
  width: auto;
  max-width: none;
  height: 26%;
  transform: translate3d(0, 0, 0);
  display: none;
}

.runner-stage::after {
  content: "";
  position: absolute;
  z-index: 8;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 8, 18, 0.28), transparent 38%, rgba(5, 8, 18, 0.16)),
    linear-gradient(90deg, rgba(0, 0, 0, 0.24), transparent 20%, transparent 80%, rgba(0, 0, 0, 0.28));
}

.run-hud {
  position: absolute;
  z-index: 20;
  top: 12px;
  left: 12px;
  right: 12px;
  min-height: 54px;
  gap: 8px;
  padding: 6px;
  border: 2px solid rgba(80, 220, 255, 0.65);
  background: rgba(6, 10, 24, 0.82);
}

.run-hud div {
  min-width: 0;
  text-align: center;
}

.run-hud span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}

.run-hud strong {
  display: block;
  max-width: 160px;
  overflow: hidden;
  color: var(--gold);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#scoreLabel {
  min-width: 58px;
  color: var(--text);
  text-align: right;
  font-size: 11px;
  font-weight: 900;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.music-btn {
  width: 32px;
  height: 22px;
  font-size: 13px;
  border-color: var(--cyan);
}

.music-btn.muted {
  color: var(--muted);
  border-color: var(--muted);
  opacity: 0.5;
}

.topbar-actions {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dqd-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  image-rendering: pixelated;
  object-fit: cover;
  display: block;
}

.progress-track {
  position: absolute;
  z-index: 19;
  top: 78px;
  left: 18px;
  right: 18px;
  height: 8px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(5, 8, 18, 0.6);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--gold);
}

.encounter-label {
  position: absolute;
  z-index: 18;
  top: 94px;
  left: 50%;
  min-width: 54%;
  padding: 8px;
  border: 2px solid var(--gold);
  background: rgba(16, 12, 6, 0.86);
  color: #fff2be;
  text-align: center;
  font-size: 12px;
  font-weight: 900;
  transform: translateX(-50%);
}

.hero-sprite {
  z-index: 12;
  left: 9%;
  bottom: 18%;
  height: 30%;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.34));
  animation: runner-bob 360ms steps(2) infinite;
}

.hero-sprite.kick {
  height: 31%;
  animation: kick-pop 360ms steps(3);
}

.hero-sprite.win {
  left: 23%;
  bottom: 33%;
  height: 32%;
  animation: victory-bob 680ms steps(2) infinite;
}

.ball-sprite {
  z-index: 13;
  left: 28%;
  bottom: 19.5%;
  width: 12%;
  max-width: 54px;
  filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.28));
}

.ball-sprite.boost {
  animation: ball-boost 360ms steps(3);
}

.opponent-sprite {
  z-index: 11;
  right: -34%;
  bottom: 18%;
  height: 29%;
  transform: scaleX(-1);
  transition: right 400ms linear, transform 260ms steps(3), opacity 220ms linear;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.34));
}

.opponent-sprite.enter {
  right: 13%;
}

.opponent-sprite.hit {
  right: -12%;
  opacity: 0;
  transform: scaleX(-1) rotate(-14deg) translateY(-18px);
}

.shockwave {
  position: absolute;
  z-index: 10;
  left: 35%;
  bottom: 31%;
  width: 18px;
  height: 18px;
  border: 4px solid #f9fdff;
  box-shadow: 0 0 0 6px var(--cyan), 0 0 0 12px rgba(80, 220, 255, 0.34);
  transform: scale(0);
}

.shockwave.is-active {
  animation: shock 460ms steps(4);
}

.hit-burst {
  position: absolute;
  z-index: 15;
  right: 22%;
  bottom: 36%;
  width: 96px;
  height: 80px;
}

.hit-burst i {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--gold);
  box-shadow: 0 0 0 3px #fff;
  animation: burst 540ms steps(4);
}

.hit-burst i:nth-child(1) { left: 6px; top: 26px; }
.hit-burst i:nth-child(2) { left: 28px; top: 4px; background: var(--cyan); }
.hit-burst i:nth-child(3) { left: 50px; top: 28px; }
.hit-burst i:nth-child(4) { left: 22px; top: 54px; background: var(--red); }
.hit-burst i:nth-child(5) { left: 72px; top: 12px; background: var(--green); }
.hit-burst i:nth-child(6) { left: 66px; top: 54px; background: #fff; }

.boost-button {
  display: none;
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 18px;
  width: min(220px, calc(100% - 48px));
  min-height: 54px;
  border-color: var(--gold);
  background: rgba(59, 43, 14, 0.9);
  color: #fff3bf;
  font-size: 18px;
  font-weight: 900;
  transform: translateX(-50%);
}

.victory-panel {
  position: absolute;
  z-index: 30;
  left: 20px;
  right: 20px;
  bottom: 88px;
  padding: 14px;
  border: 2px solid var(--gold);
  background: rgba(8, 11, 24, 0.9);
  text-align: center;
}

.victory-panel span {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
}

.victory-panel strong {
  display: block;
  margin: 5px 0 14px;
  color: var(--gold);
  font-size: 24px;
}

.victory-actions {
  gap: 8px;
}

.victory-actions .primary-button,
.victory-actions .secondary-button {
  flex: 1;
}

@keyframes runner-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@keyframes kick-pop {
  0%, 100% { transform: translate(0, 0); }
  45% { transform: translate(12px, -7px); }
}

@keyframes victory-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes ball-boost {
  0%, 100% { transform: translate(0, 0) scale(1); }
  45% { transform: translate(28px, -8px) scale(1.08); }
}

@keyframes shock {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(9); opacity: 0; }
}

@keyframes burst {
  0% { transform: scale(0); opacity: 1; }
  100% { transform: scale(1.8) translateY(-28px); opacity: 0; }
}

.confetti-container {
  position: absolute;
  z-index: 25;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -12px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  88%  { opacity: 1; }
  100% { transform: translateY(850px) rotate(540deg); opacity: 0; }
}

@media (max-width: 380px) {
  .round-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .champion-card strong {
    font-size: 24px;
  }

  .action-dock {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-button,
  .primary-button {
    width: 100%;
  }
}
