html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #3f81bd;
  color: rgba(255, 255, 255, 0.92);
  font: 13px -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Pre-game plane selector ───────────────────────────────────────────── */
#plane-selector {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(8, 14, 26, 0.72), rgba(3, 6, 14, 0.92));
  backdrop-filter: blur(8px);
}

#plane-selector[hidden] {
  display: none;
}

.selector-panel {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  text-align: center;
}

.selector-title {
  font-size: clamp(22px, 4vw, 30px);
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5);
}

.selector-sub {
  margin-top: 6px;
  font-size: 13.5px;
  color: rgba(255, 255, 255, 0.7);
}

.plane-grid {
  margin-top: 22px;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.plane-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  cursor: pointer;
  font: inherit;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.plane-card:hover,
.plane-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(120, 200, 255, 0.7);
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

.plane-card-thumb {
  aspect-ratio: 16 / 10;
  width: 100%;
  border: 0;
  background: linear-gradient(135deg, #0f1e33, #14304e);
  display: block;
  pointer-events: none; /* clicks fall through to the card button */
}

/* ?preview mode: strip everything but the rotating plane. */
body.preview-mode #hud-top,
body.preview-mode #hud-bottom,
body.preview-mode #settings,
body.preview-mode #plane-selector,
body.preview-mode #touch-controls,
body.preview-mode #radio,
body.preview-mode #weather-status {
  display: none !important;
}

.plane-card-body {
  padding: 12px 14px 14px;
  text-align: left;
}

.plane-card-name {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.plane-card-cta {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(61, 220, 132, 0.92);
  color: #04140a;
  font-size: 12.5px;
  font-weight: 800;
}

body.michael {
  filter: brightness(0.75) sepia(1);
  transform: none;
}

body.amanda {
  filter: saturate(4);
  transform: none;
}

body.jimmy {
  filter: invert(1);
  transform: none;
}

body.tracey {
  filter: hue-rotate(90deg);
  transform: none;
}

body.trevor {
  filter: blur(2px) brightness(1.25) contrast(1.5) hue-rotate(180deg) saturate(0.5);
  transform: rotate(-1deg) scaleX(-1.05) scaleY(1.05);
}

canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

#overlay {
  pointer-events: none;
}

#hud-top,
#hud-bottom {
  position: fixed;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  padding: 0 10px;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(10px);
}

#hud-top {
  top: 0;
  left: 0;
  right: 0;
  justify-content: space-between;
}

#hud-bottom {
  left: 0;
  bottom: 0;
  right: 0;
  gap: 5px;
}

#hud-top strong {
  font-weight: 600;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#tiles,
#status {
  color: rgba(255, 255, 255, 0.68);
}

#hud-bottom span {
  min-width: 78px;
  margin-right: 1px;
}

#weather-status {
  position: fixed;
  top: 42px;
  right: 12px;
  z-index: 4;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 600;
  letter-spacing: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

#weather-status.visible {
  opacity: 1;
}

#status {
  flex: 1;
  min-width: 0;
  margin-right: 0;
}

#metar {
  min-width: max-content;
  margin-left: auto;
  margin-right: 0;
  text-align: right;
  color: rgba(255, 255, 255, 0.68);
}

#metar.event {
  color: rgba(255, 255, 255, 0.92);
  cursor: pointer;
}

#radio {
  position: fixed;
  left: 50%;
  top: 48px;
  z-index: 4;
  width: max-content;
  max-width: min(760px, calc(100vw - 48px));
  padding: 9px 14px;
  border-radius: 8px;
  color: rgba(255, 245, 190, 0.94);
  background: rgba(0, 0, 0, 0.48);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  font-size: 17px;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

#radio.visible {
  opacity: 1;
}

button {
  min-height: 24px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.12);
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button:hover {
  background: rgba(255, 255, 255, 0.18);
}

button:focus,
button:focus-visible,
button:active {
  outline: none;
  box-shadow: none;
}

button.active {
  color: rgba(20, 24, 28, 0.92);
  background: rgba(255, 235, 145, 0.82);
}

button.active:hover {
  background: rgba(255, 242, 174, 0.9);
}

/* ── Touch controls (mobile) ───────────────────────────────────────────── */
#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 8;
  pointer-events: none; /* only the stick + buttons take input */
}

#touch-controls[hidden] {
  display: none;
}

#touch-stick {
  position: absolute;
  left: 22px;
  bottom: 26px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.34);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  touch-action: none;
}

#touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), inset 0 0 0 1.5px rgba(255, 255, 255, 0.5);
  transition: transform 40ms linear;
}

#touch-buttons {
  position: absolute;
  right: 20px;
  bottom: 24px;
  display: grid;
  grid-template-columns: repeat(2, auto);
  gap: 10px;
  justify-items: end;
  pointer-events: none;
}

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.42);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.24);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  -webkit-user-select: none;
  user-select: none;
}

.touch-btn:active {
  background: rgba(255, 255, 255, 0.28);
}

.touch-btn.touch-fire {
  grid-column: 1 / span 2;
  justify-self: center;
  width: 76px;
  height: 76px;
  background: rgba(255, 64, 64, 0.7);
  font-size: 14px;
}

.touch-btn.touch-fire:active {
  background: rgba(255, 90, 90, 0.9);
}

/* ── Settings menu ─────────────────────────────────────────────────────── */
#settings {
  position: fixed;
  top: 42px;
  right: 12px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.settings-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

#settings-toggle,
#fullscreen-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
}

#settings-toggle:hover,
#fullscreen-button:hover {
  background: rgba(0, 0, 0, 0.62);
}

#settings.open #settings-toggle {
  color: rgba(20, 24, 28, 0.95);
  background: rgba(255, 235, 145, 0.9);
}

#settings-panel {
  width: min(300px, calc(100vw - 24px));
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding: 12px;
  border-radius: 12px;
  background: rgba(8, 12, 20, 0.82);
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(14px);
}

.settings-section {
  padding: 10px 2px;
}

.settings-section + .settings-section {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-title {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}

.settings-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* PvP on/off toggle in the on-screen cluster (next to Fullscreen + Settings).
   Off = Passive (neutral, green "safe" dot); On = combat (red). */
#pvp-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 15px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

/* Status dot: green when safe (off), red when armed (on). */
#pvp-button::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(61, 220, 132, 0.95);
  box-shadow: 0 0 0 3px rgba(61, 220, 132, 0.22);
}

#pvp-button.pvp {
  color: #fff;
  background: rgba(255, 64, 64, 0.92);
}

#pvp-button.pvp::before {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.28);
}

/* The explicit display above would otherwise override the `hidden` attribute,
   so restore hiding when the button is hidden (solo / no multiplayer). */
#pvp-button[hidden] {
  display: none;
}

.settings-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
}

.settings-check input {
  margin-top: 2px;
  accent-color: rgba(255, 235, 145, 0.9);
}

.settings-check span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-check small {
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  line-height: 1.35;
}

.controls-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 0;
}

.controls-list dt {
  font-weight: 700;
  color: rgba(255, 245, 190, 0.95);
}

.controls-list dd {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
}

.controls-note {
  margin: 10px 0 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 11.5px;
  line-height: 1.4;
}

/* ── Admin buildings-alignment tool ─────────────────────────────────── */
#align-open {
  margin-top: 8px;
  width: 100%;
  background: rgba(20, 200, 255, 0.14);
  border: 1px solid rgba(20, 200, 255, 0.5);
  color: #bfefff;
}
#align-open:hover { background: rgba(20, 200, 255, 0.24); }

#align-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none; /* let drags fall through to the scene canvas */
}
#align-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  max-width: 320px;
  pointer-events: auto;
  background: rgba(8, 12, 22, 0.9);
  border: 1px solid rgba(120, 170, 255, 0.4);
  border-radius: 10px;
  padding: 12px 14px;
  color: #e8f0ff;
  font-family: inherit;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.align-title { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.align-help { font-size: 11.5px; line-height: 1.45; color: rgba(230, 240, 255, 0.75); }
#align-values {
  margin: 10px 0;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 7px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: #7ef0ff;
}
.align-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.align-actions button {
  flex: 1;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #e8f0ff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.align-actions button:hover { background: rgba(255, 255, 255, 0.16); }
#align-close { background: rgba(255, 90, 90, 0.16); border-color: rgba(255, 90, 90, 0.4); }
#align-open[hidden], #align-overlay[hidden] { display: none; }
