* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #04121c; }
body { font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif; color: #d9f4ff; }
#screen { position: fixed; inset: 0; }
#screen canvas { display: block; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.meter { position: absolute; top: 14px; width: 34vw; max-width: 240px; height: 16px;
  background: rgba(4, 22, 33, 0.72); border: 1px solid rgba(90, 220, 255, 0.4);
  border-radius: 9px; overflow: hidden; }
.meter label { position: absolute; left: 8px; top: 0; line-height: 16px; font-size: 10px;
  letter-spacing: 1px; z-index: 2; color: #bfeaf7; }
#bar-o2 { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #23b5e8, #6fe3ff); border-radius: 9px; transition: width .2s; }
#bar-hull { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, #ff9a3d, #ffd16b); border-radius: 9px; transition: width .2s; }
.meter .fill { position: absolute; inset: 0; border-radius: 9px; }
.meter.low .fill { animation: blink 0.6s infinite alternate; }
@keyframes blink { from { filter: brightness(1); } to { filter: brightness(2); } }
.meter-o2 { left: 14px; }
.meter-hull { right: 14px; text-align: right; }

#hud-stats { position: absolute; top: 40px; left: 14px; font-size: 14px; line-height: 1.7;
  text-shadow: 0 1px 4px #000; }
#hud-stats b { color: #79ffd7; }
#hud-sonar-wrap { position: absolute; top: 40px; right: 14px; width: 120px; height: 10px;
  border: 1px solid rgba(90, 220, 255, 0.4); border-radius: 6px; overflow: hidden;
  background: rgba(4, 22, 33, 0.72); }
#bar-sonar { position: absolute; inset: 0; width: 0%; background: #3fe8ff; transition: width .15s; }
#bar-sonar.ready { background: #35ffc3; box-shadow: 0 0 8px #35ffc3; }
#hud-sonar-wrap label { position: absolute; top: 12px; right: 0; font-size: 10px; letter-spacing: 1px; }

#flash { position: fixed; inset: 0; opacity: 0; background: transparent;
  transition: opacity .5s ease-out; pointer-events: none; z-index: 8; }
#msg { position: fixed; top: 18%; left: 50%; transform: translateX(-50%);
  font-size: clamp(16px, 3.4vw, 26px); letter-spacing: 2px; color: #aef5ff;
  text-shadow: 0 0 14px #17c9ff; opacity: 0; transition: opacity .4s; pointer-events: none; z-index: 9; }
#msg.show { opacity: 1; }

.overlay { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; text-align: center;
  background: radial-gradient(ellipse at center, rgba(6, 34, 52, 0.82), rgba(2, 10, 16, 0.95));
  padding: 20px; }
.overlay.hidden { display: none; }
.overlay h2 { font-size: clamp(28px, 6vw, 52px); letter-spacing: 4px; color: #8ff5ff;
  text-shadow: 0 0 22px rgba(64, 220, 255, 0.7); }
.overlay .lines { font-size: clamp(13px, 2.2vw, 17px); line-height: 1.9; color: #bfe3ee; max-width: 640px; }
.overlay .keys { color: #7fd8ff; }
.overlay button { pointer-events: auto; cursor: pointer; margin-top: 8px;
  font: inherit; font-size: 18px; letter-spacing: 3px; padding: 14px 42px; border-radius: 40px;
  color: #04222e; background: linear-gradient(180deg, #66ffe0, #21c7a8);
  border: none; box-shadow: 0 0 26px rgba(60, 255, 210, 0.45); }
.overlay button:active { transform: scale(0.96); }

#touch { position: fixed; inset: auto 0 0 0; z-index: 9; pointer-events: none; }
.tbtn { pointer-events: auto; position: fixed; width: 64px; height: 64px; border-radius: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; letter-spacing: 1px; color: #cfeef7; user-select: none;
  background: rgba(10, 40, 58, 0.55); border: 1px solid rgba(110, 220, 255, 0.45);
  touch-action: none; }
.tbtn.on { background: rgba(60, 190, 230, 0.65); }
#tb-thrust { right: 16px; bottom: 96px; width: 74px; height: 74px; border-radius: 37px; }
#tb-reverse { right: 100px; bottom: 16px; }
#tb-sonar { right: 16px; bottom: 16px; }
#tb-left { left: 16px; bottom: 64px; }
#tb-right { left: 152px; bottom: 64px; }
#tb-up { left: 84px; bottom: 128px; }
#tb-down { left: 84px; bottom: 0px; }
@media (min-width: 900px) { #touch { display: none; } }
