* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a2b3a;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: #f0f0f0;
  touch-action: none;
}

#gl {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 0;
  outline: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 18, 24, 0.92);
  backdrop-filter: blur(6px);
  transition: opacity 0.35s ease, visibility 0.35s;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.dialog {
  text-align: center;
  max-width: 90%;
  width: 420px;
  padding: 2rem;
  border-radius: 16px;
  background: rgba(30, 40, 45, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.dialog h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  letter-spacing: -0.02em;
}

.dialog p {
  margin: 0 0 1.5rem;
  opacity: 0.75;
  font-size: 0.95rem;
  line-height: 1.45;
}

#start-btn, .toggle, .m-btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 0.75rem 1.4rem;
  background: #3d7a9e;
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
  touch-action: manipulation;
}

#start-btn:hover, .toggle:hover, .m-btn:hover { background: #4a8db3; }
#start-btn:active, .toggle:active, .m-btn:active { transform: scale(0.96); }

.ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.hud {
  position: absolute;
  pointer-events: auto;
}

.top-left {
  top: 0.8rem;
  left: 0.8rem;
  max-width: min(92%, 340px);
}

.top-left h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
  opacity: 0.95;
}

.status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.status span {
  background: rgba(15, 25, 30, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.28rem 0.55rem;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.badge {
  background: rgba(180, 60, 50, 0.85) !important;
}

.bottom-left {
  bottom: 0.8rem;
  left: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hint {
  background: rgba(15, 25, 30, 0.7);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

kbd {
  display: inline-block;
  min-width: 1.6rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 0.15rem 0.3rem;
  font-family: inherit;
  font-size: 0.72rem;
}

.top-right {
  top: 0.8rem;
  right: 0.8rem;
  width: 240px;
}

.panel {
  background: rgba(15, 25, 30, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 0.75rem;
  backdrop-filter: blur(4px);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.row:last-child { margin-bottom: 0; }

.row label {
  font-size: 0.8rem;
  opacity: 0.85;
  min-width: 70px;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: #3d7a9e;
}

.toggles {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
}

.toggle, .m-btn {
  padding: 0.45rem 0.7rem;
  font-size: 0.75rem;
  border-radius: 8px;
  background: rgba(60, 90, 105, 0.85);
}

.toggle.active, .m-btn.active { background: #3d7a9e; }

#mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}

.joystick {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.2);
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

.knob {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.05s;
}

.mobile-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: auto;
}

.m-btn {
  min-width: 72px;
  text-align: center;
}

.mobile-only { display: none; }
.desktop-only { display: inherit; }

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inherit !important; }
  #desktop-hints { display: none !important; }

  .top-left { max-width: 70%; }
  .top-left h2 { font-size: 1rem; }
  .status span { font-size: 0.72rem; padding: 0.22rem 0.4rem; }

  .top-right { width: auto; left: 0.8rem; right: 0.8rem; top: auto; bottom: 7.2rem; }
  .panel { padding: 0.55rem; }
  .row { margin-bottom: 0.3rem; }
}

@media (max-width: 600px) {
  .dialog { padding: 1.4rem; width: 92%; }
  .dialog h1 { font-size: 1.6rem; }

  .joystick { width: 84px; height: 84px; }
  .knob { width: 32px; height: 32px; }

  .top-right { bottom: 6.6rem; }
}

@media (pointer: coarse) {
  .desktop-only { display: none !important; }
  .mobile-only { display: inherit !important; }
}
