:root {
  color-scheme: light;
  --ink: #172033;
  --panel: rgba(255, 255, 255, 0.9);
  --line: rgba(23, 32, 51, 0.14);
  --blue: #2563eb;
  --green: #14804a;
  --red: #d13f32;
  --gold: #d79b14;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #e8f4ff;
  color: var(--ink);
}

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.game-shell {
  width: min(100vw, 1120px);
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  position: relative;
}

.highscore-panel {
  width: 100%;
  margin: 18px 0 16px;
  padding: 14px 16px;
  border: 1px solid rgba(23, 32, 51, 0.14);
  border-radius: 8px;
  background: #f8fbff;
  text-align: left;
}

.highscore-panel h2 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.1;
}

.highscore-panel ol {
  margin: 0;
  padding-left: 24px;
}

.highscore-panel li {
  padding: 2px 0;
  font-size: 15px;
  font-weight: 800;
}

.highscore-panel span {
  display: inline-flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

#highscoreStatus {
  margin: 8px 0 0;
  color: #4a5568;
  font-size: 12px;
  line-height: 1.25;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: #c9e9ff;
  box-shadow: 0 14px 45px rgba(19, 56, 101, 0.18);
  touch-action: none;
}

.fullscreen-button {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid rgba(23, 32, 51, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  color: #172033;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 12px 28px rgba(19, 56, 101, 0.14);
  backdrop-filter: blur(6px);
}

.fullscreen-button:hover {
  background: rgba(255, 255, 255, 0.96);
}

.fullscreen-button:disabled {
  display: none;
}

.controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(48px, 1fr));
  gap: 8px;
  position: relative;
  z-index: 3;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 46px;
  padding: 0 12px;
  color: white;
  background: var(--blue);
  font: 700 18px/1 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

button:active {
  transform: translateY(1px);
}

#downBtn,
#upBtn {
  background: var(--green);
}

#fireBtn {
  background: var(--gold);
  color: #201400;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 24, 40, 0.46);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(440px, 100%);
  border-radius: 8px;
  padding: 24px;
  background: white;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.panel h1 {
  margin: 0 0 10px;
  font-size: 34px;
  line-height: 1.08;
}

.panel p {
  margin: 0 0 18px;
  color: #4a5568;
  font-size: 16px;
  line-height: 1.45;
}

.score-form {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  padding: 14px;
  border-radius: 8px;
  background: #f4f8ff;
  text-align: left;
}

.score-form.hidden {
  display: none;
}

.score-form label {
  font-weight: 800;
}

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

.score-row input {
  min-height: 46px;
  border: 2px solid rgba(23, 32, 51, 0.16);
  border-radius: 8px;
  padding: 0 12px;
  text-transform: uppercase;
  font: 900 22px/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-align: center;
}

.score-message {
  min-height: 20px;
  margin: 0;
  font-size: 13px;
}

@media (max-width: 620px) {
  .game-shell {
    width: 100vw;
    height: 100dvh;
    padding: 6px 6px max(6px, env(safe-area-inset-bottom));
    gap: 8px;
  }

  .fullscreen-button {
    top: 12px;
    right: 12px;
    width: 40px;
    min-height: 40px;
    font-size: 23px;
  }

  .controls {
    grid-template-columns: repeat(5, minmax(42px, 1fr));
    gap: 6px;
  }

  button {
    min-height: 48px;
    font-size: 16px;
    padding: 0 8px;
  }

  canvas {
    border-radius: 6px;
  }

  .highscore-panel {
    padding: 10px 12px;
  }

  .highscore-panel li {
    font-size: 13px;
  }

  .score-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) and (orientation: portrait) {
  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #fireBtn {
    grid-column: 2;
    grid-row: 1;
  }

  #leftBtn,
  #rightBtn {
    grid-row: 2;
  }

  #leftBtn {
    grid-column: 1;
  }

  #rightBtn {
    grid-column: 3;
  }

  #downBtn {
    grid-column: 1;
    grid-row: 1;
  }

  #upBtn {
    grid-column: 3;
    grid-row: 1;
  }
}

.device-phone .game-shell {
  max-width: none;
}

.device-tablet .game-shell {
  max-width: none;
}
