:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #05070d;
  color: #f7f8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: radial-gradient(circle at 50% 12%, #19213a 0%, #080b13 42%, #03040a 100%);
}

button {
  font: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    radial-gradient(circle at 50% 20%, rgba(66, 100, 210, 0.2), transparent 38%),
    #05070d;
  background-size: 44px 44px, 44px 44px, 100% 100%, 100% 100%;
}

.game-shell.is-shaking {
  animation: crash-shake 340ms ease-out;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hud {
  position: absolute;
  z-index: 4;
  top: max(16px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}

.score-group,
.results > div {
  min-width: 92px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(5, 7, 13, 0.56);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(14px);
}

.combo-group {
  border-color: rgba(255, 216, 94, 0.28);
}

.combo-group strong {
  color: #ffd85e;
}

.score-label {
  display: block;
  margin-bottom: 2px;
  color: #aab3d6;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.score-group strong,
.results strong {
  display: block;
  color: #fffdf4;
  font-size: clamp(1.1rem, 4vw, 1.65rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.audio-controls {
  display: flex;
  gap: 8px;
  margin-left: auto;
  pointer-events: auto;
}

.icon-button {
  width: 64px;
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: #eef3ff;
  background: rgba(10, 14, 26, 0.68);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  pointer-events: auto;
}

.icon-button span {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.05;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.48;
  transform: none;
}

.icon-button:hover,
.icon-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  outline: none;
  border-color: rgba(255, 216, 94, 0.85);
  transform: translateY(-1px);
}

.overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(76px, env(safe-area-inset-top)) 20px max(30px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 52%, rgba(21, 31, 57, 0.68), rgba(5, 7, 13, 0.82));
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.pause-overlay {
  z-index: 3;
  background: radial-gradient(circle at 50% 48%, rgba(21, 31, 57, 0.5), rgba(5, 7, 13, 0.72));
}

.pause-panel {
  width: min(360px, 100%);
  padding: 26px;
  border: 1px solid rgba(114, 236, 255, 0.22);
  border-radius: 8px;
  text-align: center;
  background: rgba(7, 10, 19, 0.78);
  box-shadow: 0 24px 78px rgba(0, 0, 0, 0.42), inset 0 0 34px rgba(114, 236, 255, 0.06);
  backdrop-filter: blur(18px);
}

.pause-panel h2 {
  margin-top: 4px;
  color: #ffffff;
  text-shadow: 0 0 28px rgba(114, 236, 255, 0.42);
}

.menu-panel {
  width: min(420px, 100%);
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  text-align: center;
  background: rgba(7, 10, 19, 0.84);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.45), inset 0 0 40px rgba(87, 128, 255, 0.05);
  backdrop-filter: blur(20px);
}

.new-best {
  width: fit-content;
  margin: 14px auto 0;
  padding: 7px 11px;
  border: 1px solid rgba(255, 216, 94, 0.46);
  border-radius: 8px;
  color: #fff3af;
  background: rgba(255, 216, 94, 0.12);
  box-shadow: 0 0 28px rgba(255, 216, 94, 0.18);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.eyebrow {
  margin: 0 0 8px;
  color: #ffd85e;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow.danger {
  color: #ff5d6c;
}

h1,
h2 {
  margin: 0;
  color: #ffffff;
  font-size: clamp(2.75rem, 14vw, 5.75rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow: 0 0 28px rgba(84, 132, 255, 0.42);
}

h2 {
  font-size: clamp(2.15rem, 10vw, 4.15rem);
}

.menu-copy {
  max-width: 31ch;
  margin: 16px auto 22px;
  color: #c7cdea;
  font-size: 1rem;
  line-height: 1.5;
}

.primary-button {
  width: min(260px, 100%);
  min-height: 52px;
  border: 1px solid rgba(255, 216, 94, 0.72);
  border-radius: 8px;
  color: #090b10;
  background: linear-gradient(180deg, #fff2a6, #ffc640);
  box-shadow: 0 12px 34px rgba(255, 198, 64, 0.25);
  cursor: pointer;
  font-weight: 900;
}

.small-button,
.text-button {
  min-height: 38px;
  border: 1px solid rgba(255, 216, 94, 0.5);
  border-radius: 8px;
  color: #fff3af;
  background: rgba(255, 216, 94, 0.1);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.text-button {
  min-height: 30px;
  padding: 0 9px;
  color: #aab3d6;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
}

.hint {
  margin: 14px 0 0;
  color: #8f98bd;
  font-size: 0.86rem;
}

.results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0 20px;
}

.rank-result {
  grid-column: 1 / -1;
}

.rank-result strong {
  color: #72ecff;
}

.leaderboard-card {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 216, 94, 0.035) 1px, transparent 1px),
    rgba(255, 255, 255, 0.035);
  background-size: 100% 30px, 100% 100%;
  text-align: left;
}

.gameover-board {
  margin: 0 0 18px;
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.leaderboard-list li {
  display: grid;
  grid-template-columns: 2.2ch 4ch 1fr auto;
  gap: 8px;
  align-items: baseline;
  color: #e9edff;
  font-family: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(114, 236, 255, 0.12);
}

.leaderboard-list .entry-rank {
  color: #ffd85e;
  font-weight: 900;
}

.leaderboard-list .entry-initials {
  color: #ffffff;
  font-weight: 900;
}

.leaderboard-list .entry-label {
  color: #8f98bd;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .entry-score {
  color: #72ecff;
  font-weight: 900;
}

.leaderboard-list li:first-child .entry-score,
.leaderboard-list li:first-child .entry-initials {
  color: #ffd85e;
}

.empty-board {
  color: #8f98bd;
}

.initials-form {
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid rgba(255, 216, 94, 0.42);
  border-radius: 8px;
  background: rgba(255, 216, 94, 0.09);
  text-align: left;
}

.initials-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

#initialsInput {
  min-width: 0;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fffdf4;
  background: rgba(5, 7, 13, 0.68);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
}

@keyframes crash-shake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  15% {
    transform: translate3d(-9px, 5px, 0);
  }

  32% {
    transform: translate3d(8px, -4px, 0);
  }

  48% {
    transform: translate3d(-6px, -3px, 0);
  }

  66% {
    transform: translate3d(5px, 3px, 0);
  }

  82% {
    transform: translate3d(-2px, 2px, 0);
  }
}

@media (max-width: 520px) {
  .hud {
    gap: 8px;
    flex-wrap: wrap;
  }

  .score-group {
    min-width: 76px;
    padding: 9px 10px;
  }

  .icon-button {
    width: 58px;
  }

  .menu-panel {
    max-height: calc(100dvh - 88px);
    padding: 22px 18px;
  }

  .leaderboard-list li {
    grid-template-columns: 2ch 3.6ch 1fr auto;
    gap: 6px;
    font-size: 0.78rem;
  }
}
