:root {
  --bg: #05070f;
  --panel: rgba(15, 23, 42, 0.6);
  --panel-border: rgba(148, 163, 184, 0.18);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #facc15;
  --accent-2: #22d3ee;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
  background-size: 44px 44px;
  color: var(--text);
  font-family: var(--font);
  display: flex;
  justify-content: center;
  padding: 28px 16px 56px;
  touch-action: manipulation;
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
}

body::before {
  width: 55vmax;
  height: 55vmax;
  left: -18vmax;
  top: -22vmax;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.5) 0%, transparent 65%);
  animation: drift-a 22s ease-in-out infinite alternate;
}

body::after {
  width: 50vmax;
  height: 50vmax;
  right: -15vmax;
  bottom: -20vmax;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.32) 0%, transparent 65%);
  animation: drift-b 26s ease-in-out infinite alternate;
}

@keyframes drift-a {
  to {
    transform: translate(9vmax, 7vmax) scale(1.12);
  }
}

@keyframes drift-b {
  to {
    transform: translate(-7vmax, -9vmax) scale(1.15);
  }
}

.game-shell {
  width: 100%;
  max-width: 900px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.2), rgba(34, 211, 238, 0.15));
  border: 1px solid var(--panel-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 24px rgba(2, 6, 23, 0.4);
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(92deg, #fde68a 0%, var(--accent) 40%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 2px 0 0;
  font-size: 11px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.best-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: #fde68a;
  background: rgba(250, 204, 21, 0.08);
  border: 1px solid rgba(250, 204, 21, 0.4);
  box-shadow: 0 0 20px rgba(250, 204, 21, 0.12);
}

.best-chip b {
  font-size: 15px;
  letter-spacing: 0;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.header-hint {
  color: var(--muted);
  font-size: 13px;
}

kbd {
  background: rgba(2, 6, 23, 0.8);
  border: 1px solid var(--panel-border);
  border-bottom-width: 3px;
  border-radius: 7px;
  padding: 2px 8px;
  font-size: 12px;
  color: var(--text);
  font-family: var(--font);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 18px;
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: 400px minmax(280px, 360px);
    justify-items: stretch;
    align-items: start;
    gap: 22px;
  }
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(420px, 100%);
}

@media (min-width: 960px) {
  .side-col {
    width: 100%;
  }
}

.stage-wrap {
  position: relative;
  width: min(400px, 100%);
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    0 0 0 1px rgba(148, 163, 184, 0.14),
    0 0 44px rgba(99, 102, 241, 0.18),
    0 30px 70px -18px rgba(2, 6, 23, 0.8);
}

.stage-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 70px rgba(2, 6, 23, 0.4);
  pointer-events: none;
  z-index: 2;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  background: #0a102b;
  cursor: pointer;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.55);
  backdrop-filter: blur(6px) saturate(1.3);
  -webkit-backdrop-filter: blur(6px) saturate(1.3);
  animation: fade-in 0.25s ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: 88%;
  max-width: 310px;
  text-align: center;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.92) 0%, rgba(15, 23, 42, 0.95) 100%);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 18px;
  padding: 22px 20px 20px;
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: card-in 0.32s cubic-bezier(0.18, 0.89, 0.32, 1.18) both;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.94);
  }
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.overlay-card p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
}

.scoreboard {
  background: rgba(2, 6, 23, 0.5);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.score-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
}

.score-value {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.new-best {
  color: #fde68a;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(250, 204, 21, 0.1);
  border: 1px solid rgba(250, 204, 21, 0.45);
  animation: glow-pulse 1.6s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(250, 204, 21, 0);
  }
  50% {
    box-shadow: 0 0 16px rgba(250, 204, 21, 0.45);
  }
}

.score-form {
  margin-bottom: 14px;
  text-align: left;
}

.score-form label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(2, 6, 23, 0.5);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-row input::placeholder {
  color: rgba(148, 163, 184, 0.6);
}

.form-row input:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}

.form-row button,
.overlay-actions button {
  padding: 9px 16px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  background: linear-gradient(135deg, #fde047 0%, var(--accent) 45%, #fb923c 100%);
  color: #1c1017;
  box-shadow: 0 6px 18px rgba(250, 204, 21, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.form-row button:hover,
.overlay-actions button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 10px 26px rgba(250, 204, 21, 0.35);
}

.form-row button:active,
.overlay-actions button:active {
  transform: translateY(0) scale(0.98);
}

.form-row button:focus-visible,
.overlay-actions button:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.form-message {
  font-size: 13px;
  color: var(--accent-2);
  min-height: 18px;
}

.form-message.error {
  color: #f87171;
}

.overlay-actions {
  margin-top: 2px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 16px 40px -20px rgba(2, 6, 23, 0.9);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--panel-border), transparent);
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  transition: background 0.15s ease;
  animation: row-in 0.4s ease both;
}

.leaderboard li:hover {
  background: rgba(148, 163, 184, 0.07);
}

.leaderboard li:nth-child(1) {
  animation-delay: 0.03s;
}

.leaderboard li:nth-child(2) {
  animation-delay: 0.06s;
}

.leaderboard li:nth-child(3) {
  animation-delay: 0.09s;
}

.leaderboard li:nth-child(4) {
  animation-delay: 0.12s;
}

.leaderboard li:nth-child(5) {
  animation-delay: 0.15s;
}

.leaderboard li:nth-child(6) {
  animation-delay: 0.18s;
}

.leaderboard li:nth-child(7) {
  animation-delay: 0.21s;
}

.leaderboard li:nth-child(8) {
  animation-delay: 0.24s;
}

.leaderboard li:nth-child(9) {
  animation-delay: 0.27s;
}

.leaderboard li:nth-child(10) {
  animation-delay: 0.3s;
}

@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.leaderboard .rank {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}

.leaderboard .rank-medal {
  font-size: 15px;
  background: transparent;
}

.leaderboard li.top1 .rank {
  background: rgba(250, 204, 21, 0.12);
  border-color: rgba(250, 204, 21, 0.4);
}

.leaderboard li.top2 .rank {
  background: rgba(203, 213, 225, 0.1);
  border-color: rgba(203, 213, 225, 0.35);
}

.leaderboard li.top3 .rank {
  background: rgba(217, 119, 6, 0.12);
  border-color: rgba(217, 119, 6, 0.4);
}

.leaderboard .rank-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .rank-score {
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.leaderboard .empty {
  color: var(--muted);
  font-size: 13px;
  animation: none;
}

.controls-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.controls-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}

.controls-list .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.hidden {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
