* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #05080b;
  color: #f6f1df;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

.shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-rows: auto auto minmax(340px, 64vh) auto auto;
  gap: 12px;
}

.intro {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 52px);
  line-height: 0.95;
  letter-spacing: 0;
}

a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #4c7488;
  border-radius: 8px;
  color: #d9fff4;
  text-decoration: none;
  font-weight: 800;
  background: #101a22;
}

a:hover {
  border-color: #7fffd4;
}

.hud,
.controls {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.hud > div,
.controls > div,
button {
  min-height: 54px;
  border: 1px solid #2f4858;
  background: #101a22;
  border-radius: 8px;
}

.hud > div {
  display: grid;
  align-content: center;
  padding: 8px 12px;
  border-bottom: 3px solid transparent;
}

.meter {
  display: block;
  width: 100%;
  height: 4px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #2f4858;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: #f7d66b;
  transition: width 120ms ease;
}

span {
  color: #9ab1bd;
  font-size: 12px;
}

strong {
  font-size: 22px;
  line-height: 1.1;
}

.threat-safe {
  border-bottom-color: #4c7488 !important;
}

.threat-arm {
  border-bottom-color: #ffb347 !important;
}

.threat-shield {
  border-bottom-color: #7fffd4 !important;
}

.threat-hull {
  border-bottom-color: #ff2f7d !important;
}

#game {
  width: 100%;
  height: 100%;
  border: 1px solid #2f4858;
  border-radius: 8px;
  background: #07111b;
  touch-action: none;
}

.touch-controls {
  display: none;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
}

.controls {
  grid-template-columns: minmax(0, 2fr) minmax(130px, 1fr) 110px;
}

.controls > div:first-child {
  display: grid;
  align-content: center;
  padding: 8px 12px;
}

.shield {
  position: relative;
  overflow: hidden;
}

.shield::before {
  content: "Shield";
  position: absolute;
  z-index: 1;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #d9fff4;
  font-size: 13px;
}

#shield {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1a756d, #7fffd4);
  transition: width 120ms ease;
}

button {
  cursor: pointer;
  color: #07111b;
  background: #f7d66b;
  border-color: #f7d66b;
  font-weight: 800;
  font-size: 15px;
}

button:hover {
  filter: brightness(1.08);
}

.touch-controls button {
  min-height: 52px;
  color: #d9fff4;
  background: #101a22;
  border-color: #4c7488;
  font-size: 18px;
  touch-action: none;
  user-select: none;
}

.touch-controls button:nth-child(2) {
  color: #07111b;
  background: #f7d66b;
  border-color: #f7d66b;
}

/* Title screen + game over overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 11, 0.88);
  backdrop-filter: blur(4px);
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  display: grid;
  gap: 18px;
  text-align: center;
  padding: 36px 28px;
  border: 1px solid #2f4858;
  border-radius: 12px;
  background: #101a22;
  background:
    radial-gradient(circle at 72% 30%, #f7d66b22, transparent 40%),
    radial-gradient(circle at 28% 72%, #7fffd418, transparent 36%),
    #101a22;
  max-width: 380px;
  width: calc(100% - 32px);
}

.overlay-content h2 {
  margin: 0;
  font-size: clamp(28px, 7vw, 44px);
  line-height: 1;
}

.overlay-content .best-score {
  color: #f7d66b;
  font-size: 16px;
}

.overlay-content .new-best {
  color: #7fffd4;
  font-weight: 800;
  font-size: 18px;
}

#start-btn,
#play-again-btn {
  min-height: 52px;
  font-size: 18px;
}

.controls-hint {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.controls-hint li {
  color: #c9d5da;
  font-size: 14px;
  line-height: 1.4;
  padding-left: 16px;
  position: relative;
}

.controls-hint li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: #f7d66b;
}

@media (max-width: 620px) {
  body {
    padding: 8px;
  }

  .shell {
    grid-template-rows: auto auto minmax(320px, 58vh) auto;
  }

  .intro {
    display: grid;
    align-items: start;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .controls {
    grid-template-columns: 1fr;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}
