:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #101827;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 14px;
  background:
    radial-gradient(circle at 30% 18%, rgba(125, 224, 255, 0.14), transparent 34%),
    linear-gradient(140deg, #13213a 0%, #25344b 55%, #17333b 100%);
}

.stage {
  position: relative;
  width: 560px;
  max-width: calc(100vw - 28px);
  height: min(calc(100vh - 28px), 880px);
  height: min(calc(100dvh - 28px), 880px);
  min-height: 560px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #7bd7f6;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: manipulation;
  cursor: pointer;
}

.hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 10px;
  pointer-events: none;
}

.score-pill,
.icon-button,
.panel,
.primary-button,
.name-row input,
.name-row button,
.scoreboard-title button {
  border: 2px solid #163444;
  border-radius: 8px;
  box-shadow: 0 5px 0 rgba(16, 43, 57, 0.28);
}

.score-pill {
  min-width: 104px;
  padding: 8px 12px 7px;
  background: rgba(255, 246, 205, 0.92);
  color: #162c38;
  text-align: center;
}

.score-pill span {
  display: block;
  font-size: 12px;
  line-height: 1;
  color: rgba(22, 44, 56, 0.72);
}

.score-pill strong {
  display: block;
  font-size: 30px;
  line-height: 1;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  width: 46px;
  height: 46px;
  pointer-events: auto;
  cursor: pointer;
  background: rgba(255, 246, 205, 0.92);
  color: #162c38;
  font-size: 23px;
  font-weight: 900;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(7, 20, 30, 0.26);
}

.overlay.is-visible {
  display: flex;
}

.panel {
  width: min(100%, 390px);
  max-height: calc(100dvh - 46px);
  overflow: auto;
  padding: 18px;
  background: rgba(255, 246, 205, 0.94);
  color: #172d38;
}

.panel h1 {
  margin: 0;
  font-size: clamp(38px, 12vw, 56px);
  line-height: 0.95;
  font-weight: 1000;
  letter-spacing: 0;
  text-align: center;
  text-shadow: 0 4px 0 rgba(64, 123, 139, 0.28);
}

.panel p {
  margin: 10px 0 14px;
  font-size: 16px;
  line-height: 1.25;
  text-align: center;
}

.primary-button,
.name-row button {
  width: 100%;
  height: 50px;
  cursor: pointer;
  background: #ffcc3d;
  color: #342300;
  font-size: 20px;
  font-weight: 900;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.name-form {
  margin: 0 0 14px;
}

.name-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 800;
}

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

.name-row input {
  width: 100%;
  min-width: 0;
  height: 48px;
  padding: 0 10px;
  background: #fffdf1;
  color: #172d38;
  font-size: 18px;
  font-weight: 800;
}

.name-row button {
  height: 48px;
  font-size: 16px;
}

.scoreboard {
  margin: 0 0 14px;
  border: 2px solid rgba(22, 52, 68, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  overflow: hidden;
}

.scoreboard-title {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 9px 0 12px;
  border-bottom: 2px solid rgba(22, 52, 68, 0.18);
  font-weight: 900;
}

.scoreboard-title button {
  width: 30px;
  height: 28px;
  cursor: pointer;
  background: #e7f7ff;
  color: #172d38;
  line-height: 1;
  box-shadow: none;
}

#scoreList {
  min-height: 210px;
  margin: 0;
  padding: 7px 10px 9px 34px;
}

#scoreList li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 4px 0;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

#scoreList .empty {
  display: block;
  margin-left: -22px;
  padding: 36px 0;
  text-align: center;
  color: rgba(23, 45, 56, 0.7);
}

.overlay:not(.is-visible) .panel {
  display: none;
}

@media (max-width: 460px) {
  .game-shell {
    padding: 0;
  }

  .stage {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
  }

  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
  }

  .score-pill {
    min-width: 92px;
    padding: 7px 10px 6px;
  }

  .score-pill strong {
    font-size: 26px;
  }

  .panel {
    max-height: calc(100dvh - 28px);
    padding: 14px;
  }

  #scoreList {
    min-height: 184px;
  }
}
