:root {
  color-scheme: dark;
  --bg: #060912;
  --ink: #f7fbff;
  --muted: #8fb6c7;
  --cyan: #27d8ff;
  --lime: #d7ff35;
  --coral: #ff5d62;
  --pink: #ff66b3;
  --navy: #101827;
  --panel: rgba(8, 14, 28, 0.74);
  --line: rgba(247, 251, 255, 0.16);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 16% 12%, rgba(39, 216, 255, 0.22), transparent 24rem),
    radial-gradient(circle at 82% 86%, rgba(215, 255, 53, 0.12), transparent 20rem),
    linear-gradient(135deg, #07111f 0%, #0b1020 48%, #170d22 100%);
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2.6vw, 32px);
}

.game-panel {
  width: min(100%, 1320px);
  min-width: 0;
  display: grid;
  gap: 12px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 320px);
  gap: 12px;
  align-items: stretch;
}

.topbar,
.controls,
.hud,
.brand {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 190px;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid rgba(247, 251, 255, 0.16);
  border-radius: 8px;
  color: #07101a;
  font-size: 18px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--lime), #27d8ff);
  box-shadow: 0 12px 28px rgba(39, 216, 255, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(22px, 3vw, 38px);
  line-height: 0.94;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.brand p,
.hud span,
.control-key span,
.message p {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.hud {
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  gap: 8px;
}

.hud div {
  min-width: clamp(58px, 8vw, 114px);
  border: 1px solid rgba(247, 251, 255, 0.14);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(2, 7, 18, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.hud strong {
  display: block;
  margin-top: 3px;
  color: var(--lime);
  font-size: clamp(18px, 2.5vw, 30px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.screen-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100svh - 250px);
  max-width: calc((100svh - 250px) * 16 / 9);
  margin-inline: auto;
  border: 1px solid rgba(247, 251, 255, 0.18);
  border-radius: 8px;
  background: #03040c;
  box-shadow: var(--shadow), 0 0 0 1px rgba(39, 216, 255, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.leaderboard {
  position: relative;
  overflow: hidden;
  min-height: 100%;
  border: 1px solid rgba(247, 251, 255, 0.18);
  border-radius: 8px;
  padding: 12px;
  background:
    linear-gradient(180deg, rgba(39, 216, 255, 0.12), transparent 32%),
    rgba(5, 10, 22, 0.78);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
}

.leaderboard::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background:
    linear-gradient(90deg, transparent 0 48%, rgba(255, 255, 255, 0.22) 49% 51%, transparent 52%),
    repeating-linear-gradient(180deg, transparent 0 14px, rgba(255, 255, 255, 0.12) 15px 16px);
}

.leaderboard > * {
  position: relative;
  z-index: 1;
}

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

.leaderboard-heading p,
.score-card label,
.score-card p {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.leaderboard-heading h2 {
  margin-top: 2px;
  color: #fff8dc;
  font-size: 30px;
  line-height: 0.9;
  text-transform: uppercase;
}

.leaderboard-badge {
  display: grid;
  min-width: 66px;
  min-height: 32px;
  place-items: center;
  border: 1px solid rgba(215, 255, 53, 0.36);
  border-radius: 8px;
  color: var(--lime);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  background: rgba(215, 255, 53, 0.08);
}

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

.leaderboard-entry {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: center;
  min-height: 48px;
  border: 1px solid rgba(247, 251, 255, 0.12);
  border-radius: 8px;
  padding: 7px;
  background: rgba(2, 7, 18, 0.56);
}

.leaderboard-entry:nth-child(1) {
  border-color: rgba(215, 255, 53, 0.5);
  background: linear-gradient(90deg, rgba(215, 255, 53, 0.14), rgba(2, 7, 18, 0.62));
}

.leaderboard-rank {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  color: #07101a;
  font-size: 12px;
  font-weight: 900;
  background: var(--cyan);
}

.leaderboard-rider {
  min-width: 0;
}

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

.leaderboard-rider strong {
  color: var(--ink);
  font-size: 14px;
  text-transform: uppercase;
}

.leaderboard-rider span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.leaderboard-score {
  color: var(--lime);
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.leaderboard-empty {
  min-height: 92px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(247, 251, 255, 0.18);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  background: rgba(2, 7, 18, 0.44);
}

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

.score-card input,
.score-card button {
  min-height: 42px;
  border-radius: 8px;
  font: inherit;
  font-weight: 900;
}

.score-card input {
  min-width: 0;
  border: 1px solid rgba(247, 251, 255, 0.18);
  padding: 0 10px;
  color: var(--ink);
  background: rgba(2, 7, 18, 0.72);
  outline: none;
}

.score-card input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(39, 216, 255, 0.14);
}

.score-card button {
  border: 1px solid rgba(215, 255, 53, 0.38);
  color: #07101a;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--lime), #27d8ff);
  cursor: pointer;
}

.score-card button[disabled] {
  opacity: 0.5;
  cursor: progress;
}

.score-dialog {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(2, 5, 12, 0.68);
  backdrop-filter: blur(8px);
}

.score-dialog.is-hidden {
  display: none;
}

.score-card {
  position: relative;
  overflow: hidden;
  width: min(100%, 420px);
  display: grid;
  gap: 10px;
  border: 1px solid rgba(247, 251, 255, 0.2);
  border-radius: 8px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(39, 216, 255, 0.2), transparent 42%),
    linear-gradient(180deg, rgba(8, 14, 28, 0.96), rgba(4, 7, 16, 0.98));
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(215, 255, 53, 0.16);
}

.score-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.13;
  background: repeating-linear-gradient(180deg, transparent 0 12px, rgba(255, 255, 255, 0.22) 13px 14px);
}

.score-card > * {
  position: relative;
  z-index: 1;
}

.score-card h2 {
  color: #fff8dc;
  font-size: clamp(34px, 8vw, 54px);
  line-height: 0.9;
  text-transform: uppercase;
}

.score-card > strong {
  width: fit-content;
  border: 1px solid rgba(215, 255, 53, 0.36);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--lime);
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  background: rgba(2, 7, 18, 0.68);
}

.score-card > span {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.score-card .score-skip {
  min-height: 34px;
  border-color: rgba(247, 251, 255, 0.16);
  color: var(--muted);
  background: rgba(2, 7, 18, 0.5);
}

.screen-wrap::before,
.screen-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.screen-wrap::before {
  opacity: 0.18;
  background: linear-gradient(135deg, rgba(255,255,255,0.08), transparent 32%, rgba(39,216,255,0.06));
}

.screen-wrap::after {
  box-shadow: inset 0 0 52px rgba(0, 0, 0, 0.34);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.message {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-content: center;
  justify-items: center;
  gap: clamp(8px, 1.8vw, 16px);
  padding: 18px;
  text-align: center;
  background: linear-gradient(rgba(4, 8, 18, 0.18), rgba(4, 8, 18, 0.46));
  backdrop-filter: blur(2px);
}

.message.is-visible {
  display: grid;
}

.message p {
  color: var(--cyan);
}

.message h2 {
  max-width: 11ch;
  font-size: clamp(42px, 8vw, 96px);
  line-height: 0.9;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-shadow: 0 12px 34px rgba(0, 0, 0, 0.7);
}

.message span {
  max-width: 62ch;
  color: #fff8dc;
  font-size: clamp(15px, 2vw, 20px);
  line-height: 1.35;
  white-space: pre-line;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.message button {
  border: 1px solid rgba(247, 251, 255, 0.18);
  border-radius: 8px;
  padding: 14px 22px;
  color: #07101a;
  font-weight: 900;
  text-transform: uppercase;
  background: linear-gradient(135deg, var(--lime), #a9ff8f);
  box-shadow: 0 14px 32px rgba(215, 255, 53, 0.18);
  cursor: pointer;
}

.message button.is-hidden {
  display: none;
}

.message button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.message button:hover,
.message button:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 18px 38px rgba(215, 255, 53, 0.25);
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.controls {
  width: 100%;
  min-width: 0;
  justify-content: center;
  gap: 10px;
}

.control-key {
  min-width: 148px;
  min-height: 68px;
  border: 1px solid rgba(247, 251, 255, 0.16);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(8, 18, 34, 0.76);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  touch-action: none;
}

.control-key strong {
  display: block;
  margin-top: 3px;
  color: var(--cyan);
  font-size: 18px;
  text-transform: uppercase;
}

.control-key-primary {
  min-width: 178px;
  background: linear-gradient(180deg, rgba(39, 216, 255, 0.22), rgba(8, 18, 34, 0.84));
}

.control-key.is-active {
  transform: translateY(2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
}

@media (max-width: 820px) {
  .game-shell {
    align-items: start;
    padding: 8px;
  }

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

  .hud {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .hud div {
    min-width: 0;
    padding: 7px;
  }

  #game {
    height: 100%;
  }

  .screen-wrap {
    max-width: none;
    max-height: none;
  }

  .leaderboard {
    min-height: 0;
  }

  .leaderboard-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .leaderboard-score {
    grid-column: 2;
    font-size: 16px;
  }

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

  .control-key,
  .control-key-primary {
    min-width: 0;
    min-height: 64px;
  }

  .control-key strong {
    font-size: 13px;
  }
}

@media (max-width: 620px) {
  .brand-mark {
    width: 44px;
    height: 44px;
    font-size: 15px;
  }

  .hud strong {
    font-size: 17px;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .hud span,
  .control-key span {
    font-size: 9px;
  }

  .message h2 {
    max-width: 8ch;
    font-size: clamp(32px, 11vw, 48px);
  }

  .message span {
    max-width: 34ch;
    font-size: 13px;
  }

  .message-actions {
    gap: 8px;
  }

  .message button {
    padding: 12px 14px;
    font-size: 13px;
  }

  .leaderboard-list {
    grid-template-columns: 1fr;
  }
}
