:root {
  --ink: #eef6ff;
  --muted: #b5c6d9;
  --surface: rgba(6, 14, 26, 0.72);
  --surface-strong: rgba(6, 14, 26, 0.9);
  --outline: rgba(190, 226, 255, 0.22);
  --accent-warm: #ffb347;
  --accent-cool: #5dd7ff;
  --accent-good: #67f2a5;
  --accent-danger: #ff6b57;
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  color: var(--ink);
  font-family: 'Trebuchet MS', 'Avenir Next', sans-serif;
  background:
    radial-gradient(circle at 18% -8%, rgba(93, 215, 255, 0.3), rgba(9, 17, 31, 0) 45%),
    radial-gradient(circle at 85% 102%, rgba(255, 179, 71, 0.26), rgba(9, 17, 31, 0) 45%),
    linear-gradient(150deg, #061022, #102944 55%, #0b1f31 100%);
}

canvas {
  display: block;
}

#loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 11, 20, 0.95);
  color: var(--ink);
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  z-index: 120;
}

#menu-toggle {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 90;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--outline);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
}

.top-buttons {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 92px);
  margin: 0;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--outline);
  backdrop-filter: blur(10px);
}

.top-buttons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--outline);
  background: rgba(9, 20, 34, 0.74);
  color: var(--ink);
  font-size: 14px;
  text-decoration: none;
}

.top-buttons a:hover,
.top-buttons a:focus-visible {
  background: rgba(93, 215, 255, 0.24);
  border-color: rgba(93, 215, 255, 0.62);
  outline: none;
}

#hud {
  position: fixed;
  top: 72px;
  left: 12px;
  z-index: 70;
  width: min(300px, calc(100vw - 24px));
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--outline);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hud-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.hud-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-warm);
}

.hud-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 10px;
}

.hud-item {
  border-radius: 10px;
  border: 1px solid rgba(186, 223, 255, 0.16);
  padding: 8px;
  background: rgba(6, 14, 26, 0.55);
}

.hud-item-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.hud-item-value {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  font-weight: 700;
}

.hud-meter {
  margin-bottom: 9px;
}

.hud-meter:last-child {
  margin-bottom: 0;
}

.hud-meter-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.meter-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(186, 223, 255, 0.14);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transition: width 0.2s ease;
}

.meter-fill.shield {
  background: linear-gradient(90deg, #ff7a66, #ffd099);
}

.meter-fill.fuel {
  background: linear-gradient(90deg, #58c8f8, #78ffd1);
}

.meter-fill.distance {
  background: linear-gradient(90deg, #ffb347, #ffe295);
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  background: rgba(4, 10, 18, 0.62);
  backdrop-filter: blur(2px);
}

#overlay[hidden] {
  display: none;
}

.overlay-card {
  width: min(480px, calc(100vw - 28px));
  padding: 26px;
  border-radius: 16px;
  border: 1px solid var(--outline);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay-card h2 {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 4vw, 2rem);
}

.overlay-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.45;
}

#overlay-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 700;
  color: #08243f;
  background: linear-gradient(120deg, #7fe8ff, #ffda9f);
  cursor: pointer;
}

#overlay-action:hover,
#overlay-action:focus-visible {
  filter: brightness(1.08);
  outline: none;
}

#controls {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 75;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}

#joystick-zone {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

#joystick-base {
  width: min(36vw, 150px);
  height: min(36vw, 150px);
  min-width: 112px;
  min-height: 112px;
  border-radius: 999px;
  border: 1px solid rgba(188, 226, 255, 0.34);
  background:
    radial-gradient(circle at 34% 28%, rgba(141, 212, 255, 0.28), rgba(10, 19, 34, 0.72) 64%),
    rgba(6, 14, 26, 0.68);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.24);
  display: grid;
  place-items: center;
}

#joystick-knob {
  width: 44%;
  height: 44%;
  min-width: 46px;
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid rgba(188, 226, 255, 0.46);
  background:
    radial-gradient(circle at 36% 30%, rgba(203, 240, 255, 0.7), rgba(88, 179, 231, 0.34) 54%),
    rgba(20, 45, 73, 0.84);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.32);
  transform: translate3d(0, 0, 0);
  transition: transform 0.05s linear;
}

#joystick-zone.active #joystick-base {
  border-color: rgba(143, 226, 255, 0.56);
  box-shadow: inset 0 0 28px rgba(93, 215, 255, 0.18);
}

#action-buttons {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  pointer-events: auto;
}

.control-btn {
  min-width: 60px;
  min-height: 54px;
  border-radius: 12px;
  border: 1px solid rgba(188, 226, 255, 0.3);
  background: rgba(5, 13, 25, 0.66);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  touch-action: none;
  user-select: none;
  cursor: pointer;
}

.control-btn.fly {
  font-size: 18px;
  color: #10243d;
  border-color: rgba(255, 215, 160, 0.62);
  background: linear-gradient(140deg, rgba(130, 233, 255, 0.92), rgba(255, 201, 130, 0.9));
}

.control-btn.small {
  font-size: 13px;
  min-width: 68px;
}

.control-btn:active,
.control-btn[aria-pressed='true'] {
  background: rgba(93, 215, 255, 0.35);
}

#instruction-chip {
  position: fixed;
  right: 14px;
  top: 74px;
  z-index: 70;
  max-width: min(360px, calc(100vw - 30px));
  border-radius: 12px;
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--muted);
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.4;
}

@media (max-width: 900px) {
  #menu-toggle {
    display: inline-flex;
  }

  .top-buttons {
    left: 8px;
    right: 8px;
    transform: translateY(-16px);
    opacity: 0;
    pointer-events: none;
    max-width: none;
    justify-content: flex-start;
    overflow-x: auto;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .top-buttons::-webkit-scrollbar {
    display: none;
  }

  body.nav-open .top-buttons {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  body.nav-open #hud {
    top: 8px;
    left: 8px;
  }

  #hud {
    top: 8px;
    left: 8px;
    width: min(198px, calc(100vw - 16px));
    padding: 7px;
    border-radius: 9px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  }

  #instruction-chip {
    top: auto;
    bottom: 150px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
}

@media (max-width: 720px) {
  #hud {
    top: 6px;
    left: 6px;
    width: min(168px, calc(100vw - 12px));
    padding: 5px;
    border-radius: 8px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
  }

  .hud-header {
    margin-bottom: 4px;
  }

  .hud-title {
    font-size: 8px;
    letter-spacing: 0.07em;
  }

  .hud-value {
    font-size: 12px;
  }

  .hud-grid {
    gap: 4px;
    grid-template-columns: 1fr;
    margin-bottom: 4px;
  }

  #hud .hud-grid .hud-item:last-child {
    display: none;
  }

  .hud-item {
    padding: 4px;
    border-radius: 6px;
  }

  .hud-item-label {
    font-size: 8px;
  }

  .hud-item-value {
    font-size: 11px;
  }

  .hud-meter {
    margin-bottom: 4px;
  }

  .hud-meter-label {
    font-size: 8px;
    margin-bottom: 2px;
  }

  .meter-track {
    height: 4px;
  }

  #hud .hud-meter:last-child {
    display: none;
  }

  #controls {
    gap: 8px;
    bottom: 8px;
    left: 8px;
    right: 8px;
  }

  #joystick-base {
    width: 108px;
    height: 108px;
    min-width: 108px;
    min-height: 108px;
  }

  #joystick-knob {
    min-width: 42px;
    min-height: 42px;
  }

  #action-buttons {
    min-width: 66px;
    gap: 6px;
  }

  .control-btn {
    min-width: 56px;
    min-height: 44px;
    font-size: 12px;
  }

  .control-btn.fly {
    font-size: 14px;
  }

  .control-btn.small {
    font-size: 11px;
    min-width: 56px;
  }
}
