:root {
  color-scheme: dark;
  font-family: "Trebuchet MS", "Gill Sans", "Segoe UI", sans-serif;
  background: #050609;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #050609;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#modeSelect {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(10, 18, 32, 0.8), rgba(3, 5, 9, 0.95));
  z-index: 2;
  pointer-events: auto;
}

#onlineSelect {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(10, 18, 32, 0.8), rgba(3, 5, 9, 0.95));
  z-index: 2;
  pointer-events: auto;
}

#onlineSelect.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#modeSelect.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.mode-card {
  background: rgba(6, 10, 18, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 20px 26px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
  min-width: 260px;
}

.mode-title {
  font-size: 16px;
  font-weight: 700;
  color: #e6edf7;
  margin-bottom: 14px;
}

.mode-button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 24, 40, 0.85);
  color: #e6edf7;
  border-radius: 8px;
  font-size: 13px;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.mode-button:hover {
  transform: translateY(-1px);
  background: rgba(35, 52, 85, 0.9);
}

.mode-subtitle {
  font-size: 13px;
  opacity: 0.7;
  margin: 6px 0 14px;
}

.mode-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.room-code {
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  font-size: 14px;
  letter-spacing: 2px;
  background: rgba(0, 0, 0, 0.3);
  min-width: 70px;
  text-align: center;
}

.room-input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  text-transform: uppercase;
  width: 120px;
}

.mode-button.secondary {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.aim-gear {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(8, 15, 28, 0.48);
  color: #e6edf7;
  font-size: 16px;
  cursor: pointer;
  z-index: 6;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  opacity: 0.62;
}

.aim-gear:hover {
  opacity: 0.92;
}

.aim-gear.hidden {
  display: none;
}

.room-info {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: calc(max(10px, env(safe-area-inset-left)) + 42px);
  z-index: 6;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(9, 17, 31, 0.36);
  color: rgba(224, 236, 255, 0.68);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  pointer-events: none;
}

.room-info.hidden {
  display: none;
}

.aim-select {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 14, 0.55);
  z-index: 4;
  pointer-events: auto;
}

.aim-select.hidden {
  display: none;
}

.aim-card {
  background: rgba(6, 10, 18, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 16px 18px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  text-align: center;
  min-width: 220px;
}

.aim-title {
  font-size: 13px;
  font-weight: 700;
  color: #e6edf7;
  margin-bottom: 10px;
}

.aim-button {
  display: block;
  width: 100%;
  margin: 6px 0;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 24, 40, 0.85);
  color: #e6edf7;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.aim-button:hover {
  transform: translateY(-1px);
  background: rgba(35, 52, 85, 0.9);
}

.aim-help {
  margin-top: 10px;
  padding: 10px;
  text-align: left;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 14, 26, 0.75);
  color: rgba(222, 235, 255, 0.92);
  font-size: 11px;
  line-height: 1.35;
}

.aim-help-title {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #d7e8ff;
}

.touch-hud {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  --touch-center-y: max(104px, calc(env(safe-area-inset-bottom) + 88px));
  --touch-stick-size: 162px;
  --touch-stick-half: 81px;
  --touch-knob-size: 64px;
  --touch-knob-half: 32px;
  --touch-fire-size: 104px;
  --touch-fire-half: 52px;
  --touch-stack-btn-w: 68px;
  --touch-stack-btn-h: 56px;
  --touch-stack-half: 56px;
}

.touch-hud.hidden {
  display: none;
}

.touch-stick {
  position: absolute;
  width: var(--touch-stick-size);
  height: var(--touch-stick-size);
  pointer-events: auto;
  touch-action: none;
}

.touch-move {
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(var(--touch-center-y) - var(--touch-stick-half));
}

.touch-stick-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(215, 235, 255, 0.33);
  background: radial-gradient(circle at 35% 30%, rgba(86, 132, 198, 0.42), rgba(13, 22, 36, 0.6));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--touch-knob-size);
  height: var(--touch-knob-size);
  margin-left: calc(-1 * var(--touch-knob-half));
  margin-top: calc(-1 * var(--touch-knob-half));
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.42);
  background: radial-gradient(circle at 35% 35%, rgba(210, 235, 255, 0.5), rgba(60, 94, 145, 0.75));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
}

.touch-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border: 1px solid rgba(215, 235, 255, 0.28);
  background: linear-gradient(170deg, rgba(30, 55, 92, 0.56), rgba(10, 20, 36, 0.54));
  color: #eaf4ff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-radius: 12px;
  padding: 9px 14px;
  min-width: 54px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.36);
}

.touch-btn:active,
.touch-btn.touch-active {
  background: linear-gradient(170deg, rgba(58, 106, 170, 0.72), rgba(20, 36, 58, 0.68));
  transform: scale(0.98);
}

.touch-stack {
  position: absolute;
  right: max(128px, calc(env(safe-area-inset-right) + 112px));
  bottom: calc(var(--touch-center-y) - var(--touch-stack-half));
  display: flex;
  flex-direction: column;
  gap: 0;
  pointer-events: auto;
  border-radius: 13px;
  overflow: hidden;
  border: 1px solid rgba(215, 235, 255, 0.3);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

.touch-stack-btn {
  position: static;
  width: var(--touch-stack-btn-w);
  height: var(--touch-stack-btn-h);
  min-width: var(--touch-stack-btn-w);
  padding: 0;
  border: 0;
  border-radius: 0;
  font-size: 24px;
  line-height: 1;
  background: linear-gradient(170deg, rgba(30, 55, 92, 0.56), rgba(10, 20, 36, 0.54));
}

.touch-stack-btn + .touch-stack-btn {
  border-top: 1px solid rgba(215, 235, 255, 0.24);
}

.touch-jump {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.touch-duck {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.touch-fire {
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(var(--touch-center-y) - var(--touch-fire-half));
  width: var(--touch-fire-size);
  height: var(--touch-fire-size);
  min-width: var(--touch-fire-size);
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(215, 235, 255, 0.34);
  background: linear-gradient(175deg, rgba(44, 82, 136, 0.64), rgba(12, 24, 42, 0.58));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
}

.orientation-guard {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(16, 28, 46, 0.94), rgba(3, 6, 11, 0.98));
}

.orientation-guard.hidden {
  display: none;
}

.orientation-card {
  width: min(84vw, 360px);
  border-radius: 14px;
  border: 1px solid rgba(190, 224, 255, 0.25);
  background: rgba(8, 16, 28, 0.86);
  padding: 18px 18px 16px;
  text-align: center;
  box-shadow: 0 20px 36px rgba(0, 0, 0, 0.45);
}

.orientation-title {
  color: #d6ebff;
  font-size: 18px;
  font-weight: 700;
}

.orientation-text {
  margin-top: 10px;
  color: rgba(214, 235, 255, 0.84);
  font-size: 13px;
  line-height: 1.35;
}

@media (max-width: 700px) {
  .touch-hud {
    --touch-center-y: max(92px, calc(env(safe-area-inset-bottom) + 76px));
    --touch-stick-size: 144px;
    --touch-stick-half: 72px;
    --touch-knob-size: 56px;
    --touch-knob-half: 28px;
    --touch-fire-size: 92px;
    --touch-fire-half: 46px;
    --touch-stack-btn-w: 60px;
    --touch-stack-btn-h: 50px;
    --touch-stack-half: 50px;
  }

  .touch-btn {
    font-size: 12px;
  }

  .touch-stack {
    right: max(112px, calc(env(safe-area-inset-right) + 90px));
  }

  .touch-fire {
    right: max(12px, env(safe-area-inset-right));
  }
}
