:root {
  color-scheme: dark;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #050608;
  color: #f5f5f5;
}

body {
  margin: 0;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem 0;
}

.game-shell {
  width: min(1120px, 98vw);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.playfield {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

h1,
h2 {
  margin: 0;
  font-weight: 700;
  color: #ff7b26;
  text-shadow: 0 0 8px rgba(255, 123, 38, 0.8);
}

.hud {
  display: flex;
  gap: 1.5rem;
  font-size: 1.1rem;
}

#score-label strong {
  color: #ffec63;
}

#high-score-label strong {
  color: #9ddcff;
}

#status-label {
  color: #9ddcff;
}

.canvas-wrapper {
  position: relative;
  border: 2px solid #3b1c46;
  border-radius: 12px;
  background: radial-gradient(circle at top, #1a0f23, #060308 68%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  padding-bottom: var(--canvas-extra-space, 0px);
}

.canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  touch-action: none;
  transition: transform 160ms ease-out;
  transform-origin: top left;
}

.controls,
.leaderboard,
.hazards {
  background: rgba(20, 8, 26, 0.65);
  border: 1px solid rgba(255, 123, 38, 0.35);
  padding: 1rem;
  border-radius: 10px;
  line-height: 1.5;
}

.controls ul {
  list-style: square;
  margin: 0.25rem 0 0;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.4rem;
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.leaderboard ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: rgba(8, 4, 12, 0.55);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.95rem;
}

.leaderboard .entry-rank {
  font-weight: 600;
  color: #ffec63;
  margin-right: 0.75rem;
}

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

.leaderboard .entry-score {
  font-variant-numeric: tabular-nums;
  color: #9ddcff;
  margin-left: 0.75rem;
}

.leaderboard-empty {
  text-align: center;
  opacity: 0.7;
}

kbd {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 0.85rem;
}

.game-shell.shake-screen {
  animation: screenShake 0.7s ease-in-out;
}

@keyframes screenShake {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-14px, 10px, 0);
  }
  40% {
    transform: translate3d(12px, -12px, 0);
  }
  60% {
    transform: translate3d(-10px, 8px, 0);
  }
  80% {
    transform: translate3d(8px, -10px, 0);
  }
}

.score-burst {
  position: fixed;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 20;
}

.score-burst span {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  font-size: clamp(2.2rem, 6vw, 4.5rem);
  font-weight: 700;
  color: #ffec63;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.45);
  animation: scoreScatter 0.8s ease-out forwards;
}

@keyframes scoreScatter {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) rotate(var(--rot))
      scale(0.6);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  body {
    padding: 0.75rem 0.5rem 2.5rem;
  }

  .game-shell {
    padding: 1rem;
    gap: 0.75rem;
  }

  .game-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .hud {
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 1rem;
  }

  .leaderboard {
    font-size: 0.95rem;
  }

  .controls,
  .hazards {
    font-size: 0.95rem;
  }
}

@media (max-width: 720px) {
  body {
    padding: 0;
    min-height: 100vh;
  }

  .game-shell {
    width: 100vw;
    max-width: none;
    padding: clamp(0.75rem, 3vw, 1.25rem);
    gap: clamp(0.75rem, 4vw, 1.25rem);
    box-sizing: border-box;
  }

  .playfield {
    gap: clamp(0.75rem, 4vw, 1.2rem);
  }

  .canvas-wrapper {
    border-radius: clamp(16px, 5vw, 24px);
    overflow: hidden;
    padding-bottom: 0;
    aspect-ratio: 1 / 1;
    position: relative;
  }

  .game-header {
    position: static;
    transform: none;
    width: 100%;
    background: linear-gradient(180deg, rgba(12, 10, 18, 0.9), rgba(12, 10, 18, 0.45));
    padding: clamp(0.75rem, 3.5vw, 1.1rem);
    border-radius: clamp(12px, 5vw, 18px);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45);
    flex-direction: column;
    align-items: flex-start;
    gap: clamp(0.35rem, 2.5vw, 0.6rem);
  }

  .game-header h1 {
    font-size: clamp(1.35rem, 7vw, 1.9rem);
  }

  .hud {
    width: 100%;
    justify-content: space-between;
    gap: clamp(0.4rem, 2.5vw, 0.9rem);
    font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  }

  .canvas-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    width: auto;
    height: auto;
  }

  .controls,
  .leaderboard,
  .hazards {
    font-size: clamp(0.95rem, 3.4vw, 1.1rem);
    padding: clamp(0.9rem, 3.5vw, 1.2rem);
  }
}

@media (max-width: 600px) {
  body {
    padding-bottom: 3rem;
  }

  .game-shell {
    padding-bottom: 0;
  }
}
