:root {
  color-scheme: dark;
  --ink: #f9fff7;
  --muted: #b9c9c0;
  --night: #101820;
  --panel: rgba(16, 24, 32, 0.88);
  --panel-strong: rgba(7, 12, 18, 0.94);
  --line: rgba(255, 255, 255, 0.18);
  --lime: #a7ff2f;
  --green: #04c45c;
  --yellow: #ffd43b;
  --orange: #ff7a1a;
  --pink: #ff3d81;
  --cyan: #39d5ff;
  --danger: #ff4b4b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  --radius: 8px;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 212, 59, 0.2), transparent 28rem),
    radial-gradient(circle at 92% 12%, rgba(57, 213, 255, 0.18), transparent 30rem),
    linear-gradient(140deg, #101820 0%, #17212b 38%, #092116 100%);
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: clamp(10px, 2vw, 18px);
  gap: 10px;
}

.topbar {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  background: rgba(4, 10, 15, 0.66);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #000;
}

.brand-ball {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #111 0 18%, transparent 19%),
    conic-gradient(from 18deg, #f7f7f7 0 12%, #111 13% 21%, #f7f7f7 22% 35%, #111 36% 46%, #f7f7f7 47% 61%, #111 62% 72%, #f7f7f7 73% 100%);
  border: 2px solid #f7f7f7;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vw, 18px);
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  font-size: 0.92rem;
}

.hud strong {
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
}

.power-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.power-badges span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  color: #06120d;
  background: var(--lime);
  font-size: 0.78rem;
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: #08130e;
  background: var(--yellow);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.22);
}

.icon-button[aria-pressed="false"] {
  color: var(--ink);
  background: #33414a;
}

.game-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: stretch;
  border-radius: var(--radius);
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.18);
  background: #0b2517;
  box-shadow: var(--shadow);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  min-height: 360px;
  display: block;
  background: #0b2517;
  touch-action: manipulation;
}

.game-stage.is-shaking {
  animation: hitShake 360ms linear;
}

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 390px);
  gap: clamp(12px, 2.4vw, 24px);
  align-items: center;
  padding: clamp(14px, 3vw, 34px);
  background:
    linear-gradient(90deg, rgba(5, 10, 14, 0.9), rgba(5, 10, 14, 0.42) 58%, rgba(5, 10, 14, 0.82)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 9px);
}

.screen[hidden] {
  display: none;
}

.screen-panel,
.leaderboard-panel {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.screen-panel {
  max-width: 610px;
  padding: clamp(18px, 4vw, 34px);
}

.screen-panel.compact {
  max-width: 500px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--lime);
  font-family: system-ui, sans-serif;
  font-size: 0.86rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 4px 4px 0 #000, 7px 7px 0 rgba(255, 61, 129, 0.58);
}

h1 {
  font-size: clamp(4rem, 14vw, 9.5rem);
  line-height: 0.82;
}

h2 {
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.9;
}

.start-form {
  margin-top: clamp(18px, 5vw, 36px);
  font-family: system-ui, sans-serif;
}

.start-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 900;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 52px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.42);
  outline: none;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(57, 213, 255, 0.18);
}

.name-row button,
.button-row button {
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius);
  color: #07130d;
  background: var(--lime);
  font-weight: 1000;
  text-transform: uppercase;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.24);
}

.secondary-button {
  color: var(--ink) !important;
  background: #24343d !important;
}

.form-error,
.leaderboard-status,
.submit-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--danger);
  font-family: system-ui, sans-serif;
  font-size: 0.92rem;
  font-weight: 800;
}

.submit-status {
  color: var(--muted);
}

.leaderboard-panel {
  align-self: stretch;
  min-height: 310px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 16px;
  background: var(--panel-strong);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading h2 {
  font-size: 1.15rem;
  font-family: system-ui, sans-serif;
  line-height: 1.1;
  text-shadow: none;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: #06120d;
  background: var(--yellow);
  font-family: system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 900;
}

.leaderboard-list {
  display: grid;
  gap: 7px;
  align-content: start;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: system-ui, sans-serif;
}

.leaderboard-list li {
  min-height: 38px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.075);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.leaderboard-list .rank {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #07130d;
  background: var(--yellow);
  font-weight: 1000;
}

.leaderboard-list .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.leaderboard-list .score {
  color: var(--lime);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
}

.result-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  margin: 22px 0 10px;
  font-family: system-ui, sans-serif;
}

.result-grid span {
  color: var(--muted);
  font-weight: 900;
}

.result-grid strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--yellow);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes hitShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-8px, 4px, 0);
  }
  40% {
    transform: translate3d(7px, -4px, 0);
  }
  60% {
    transform: translate3d(-5px, 2px, 0);
  }
  80% {
    transform: translate3d(4px, -2px, 0);
  }
}

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

  .app-shell {
    min-height: 100dvh;
    padding: 8px;
  }

  .topbar {
    grid-template-columns: minmax(92px, 1fr) auto;
  }

  .hud {
    grid-column: 1 / -1;
    order: 3;
    justify-content: flex-start;
    overflow-x: auto;
    padding-top: 2px;
  }

  .game-stage {
    min-height: calc(100dvh - 94px);
  }

  #gameCanvas {
    min-height: calc(100dvh - 94px);
  }

  .screen {
    position: absolute;
    grid-template-columns: 1fr;
    align-content: start;
    overflow-y: auto;
  }

  .screen-panel,
  .leaderboard-panel {
    width: 100%;
  }

  h1 {
    font-size: clamp(3.8rem, 22vw, 6.2rem);
  }
}

@media (max-width: 520px) {
  .brand-mark {
    font-size: 1.05rem;
  }

  .name-row {
    grid-template-columns: 1fr;
  }

  .name-row button,
  .button-row button {
    width: 100%;
  }

  .leaderboard-list li {
    grid-template-columns: 32px minmax(0, 1fr) auto;
  }
}
