:root {
  color-scheme: dark;
  --top-panel-height: clamp(460px, calc(100vh - 132px), 760px);
  --bg: #101316;
  --panel: #171b20;
  --panel-2: #1f252b;
  --text: #f4f7f8;
  --muted: #91a0a8;
  --line: #303941;
  --accent: #49d3b4;
  --accent-2: #ffbf4f;
  --danger: #ff5c69;
  --sky: #5fb7f0;
  --ground: #8c6842;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(73, 211, 180, 0.15), transparent 28rem),
    linear-gradient(135deg, #101316 0%, #151a1f 54%, #111418 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1820px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 16px 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1rem, 2vw, 2.1rem);
  line-height: 1;
}

h2 {
  font-size: 1.05rem;
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.backlink {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
}

.backlink:hover,
.backlink:focus {
  color: var(--accent);
  border-color: rgba(73, 211, 180, 0.4);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(73, 211, 180, 0.16);
  color: var(--accent);
  font-weight: 800;
}

.status-pill.danger {
  background: rgba(255, 92, 105, 0.15);
  color: var(--danger);
}

.status-time {
  color: var(--muted);
  font-size: 0.92rem;
}

.dashboard {
  display: grid;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.top-grid {
  display: grid;
  grid-template-columns: minmax(520px, 40fr) minmax(520px, 40fr) minmax(300px, 20fr);
  grid-template-rows: var(--top-panel-height);
  gap: 12px;
  align-items: stretch;
  min-width: 1380px;
}

.bottom-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.right-controls {
  display: grid;
  grid-template-rows: auto auto;
  gap: 12px;
  align-content: start;
  height: var(--top-panel-height);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-gutter: stable;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015)), var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.hero-panel {
  height: var(--top-panel-height);
  min-height: 0;
  padding: 14px;
  display: block;
}

.horizon {
  position: relative;
  overflow: hidden;
  height: 100%;
  border-radius: 8px;
  background: #111;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.esp-link-dot {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 5;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.18), 0 0 18px rgba(255, 92, 105, 0.56);
}

.esp-link-dot.connected {
  background: #9eff8a;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.18), 0 0 18px rgba(158, 255, 138, 0.62);
}

.esp-link-dot.disconnected {
  background: var(--danger);
}

.horizon-sky {
  position: absolute;
  inset: -42%;
  background: linear-gradient(var(--sky) 0 50%, var(--ground) 50% 100%);
  transform-origin: center;
  transition: transform 180ms ease;
}

.horizon-ground,
.horizon-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
}

.horizon-line {
  height: 2px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.5);
}

.aircraft-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.aircraft-mark::before,
.aircraft-mark::after,
.aircraft-mark span {
  content: "";
  display: block;
  background: #fff;
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.35);
}

.aircraft-mark::before,
.aircraft-mark::after {
  position: absolute;
  width: min(22vw, 150px);
  height: 5px;
  border-radius: 999px;
}

.aircraft-mark::before {
  transform: translateX(calc(-50% - 22px));
}

.aircraft-mark::after {
  transform: translateX(calc(50% + 22px));
}

.aircraft-mark span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.plane-readout,
.map-readout {
  position: absolute;
  z-index: 3;
  color: #fff8b8;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.08;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.36);
}

.battery-readout {
  top: 42px;
  right: 38px;
  font-size: clamp(1.4rem, 2.5vw, 3rem);
  text-align: right;
}

.altitude-readout {
  left: 34px;
  top: 42%;
  font-size: clamp(1.35rem, 2.3vw, 2.7rem);
}

.climb-readout {
  right: 28px;
  top: 42%;
  font-size: clamp(1.25rem, 2.15vw, 2.6rem);
  text-align: right;
}

.speed-readout {
  left: 34px;
  bottom: 108px;
  display: grid;
  gap: 14px;
  font-size: clamp(1.25rem, 2.3vw, 2.8rem);
}

.controls-title span,
.control-row span {
  color: var(--muted);
  font-size: 0.82rem;
}

.controls-panel,
.flight-panel,
.mission-panel,
.map-panel {
  padding: 14px;
}

.map-panel {
  display: flex;
  flex-direction: column;
  height: var(--top-panel-height);
  min-height: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.panel-title > span:not(.status-pill) {
  color: var(--accent-2);
  font-size: 0.86rem;
  font-weight: 800;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--text);
  font-weight: 800;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.control-form,
.command-form,
.mission-form {
  display: grid;
  gap: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: 76px 1fr 48px;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101418;
  color: var(--text);
  font: inherit;
}

select {
  min-height: 38px;
  padding: 0 12px;
}

textarea {
  min-height: 140px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

.select-row,
.mission-form label {
  display: grid;
  gap: 8px;
}

.select-row span,
.mission-form label span {
  color: var(--muted);
  font-size: 0.82rem;
}

.throttle input[type="range"] {
  accent-color: var(--accent-2);
}

output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 800;
}

.control-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0;
}

.split-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.command-actions {
  grid-template-columns: 1fr;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #252c33;
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.24);
}

.danger-button {
  background: rgba(255, 92, 105, 0.15);
  color: #ff9aa3;
}

.map-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101418;
  overflow: hidden;
}

.leaflet-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  outline: 0;
  font: inherit;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  border: 0;
  filter: saturate(0.92) brightness(0.92);
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 900;
  pointer-events: none;
}

.leaflet-control-container .leaflet-top {
  top: 0;
}

.leaflet-control-container .leaflet-bottom {
  bottom: 0;
}

.leaflet-control-container .leaflet-left {
  left: 0;
}

.leaflet-control-container .leaflet-right {
  right: 0;
}

.leaflet-control {
  position: relative;
  z-index: 900;
  clear: both;
  pointer-events: auto;
}

.leaflet-left .leaflet-control {
  margin-left: 12px;
}

.leaflet-top .leaflet-control {
  margin-top: 12px;
}

.leaflet-bar {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(16, 20, 24, 0.86);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}

.leaflet-bar a {
  display: block;
  width: 32px;
  height: 32px;
  line-height: 30px;
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 900;
  text-align: center;
  text-decoration: none;
  background: rgba(31, 37, 43, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.leaflet-bar a:last-child {
  border-bottom: 0;
}

.leaflet-bar a:hover {
  background: rgba(55, 65, 75, 0.98);
}

.leaflet-control-attribution {
  margin: 0 8px 8px 0;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(16, 20, 24, 0.72);
  color: var(--muted);
  font-size: 0.68rem;
}

.leaflet-control-attribution a {
  color: var(--accent);
}

.map-viewport {
  position: relative;
  flex: 1;
  min-height: 0;
}

.map-empty {
  position: absolute;
  inset: 0;
  z-index: 6;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #101418;
  background-size: 36px 36px;
  color: var(--muted);
}

.map-marker {
  width: 18px;
  height: 18px;
  border: 4px solid var(--danger);
  border-radius: 50%;
  box-shadow: 0 0 0 10px rgba(255, 92, 105, 0.12);
}

.drone-map-marker-icon {
  width: 30px;
  height: 30px;
}

.drone-map-marker-icon span {
  display: block;
  width: 16px;
  height: 16px;
  margin: 3px;
  border: 4px solid #ff5c69;
  border-radius: 50%;
  background: #101418;
  box-shadow:
    0 0 0 8px rgba(255, 92, 105, 0.18),
    0 2px 12px rgba(0, 0, 0, 0.45);
}

.map-link {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 701;
  display: inline-flex;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.map-source-status {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 700;
  display: grid;
  gap: 6px;
  max-width: min(280px, calc(100% - 32px));
}

.map-source-status span,
.source-readout {
  display: inline-flex;
  width: fit-content;
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(16, 20, 24, 0.76);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1.1;
}

.map-source-status span.active {
  color: var(--accent);
  border-color: rgba(73, 211, 180, 0.36);
}

.source-readout {
  right: 18px;
  top: 58px;
  color: var(--accent);
}

.source-readout.fallback {
  color: var(--accent-2);
}

.sat-readout {
  z-index: 700;
  top: 16px;
  right: 18px;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 1rem;
}

.sat-readout span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.sat-readout strong {
  font-size: clamp(1.4rem, 2.2vw, 2.8rem);
}

.coords-readout {
  z-index: 700;
  left: 28px;
  bottom: 22px;
  max-width: min(360px, calc(100% - 190px));
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(16, 20, 24, 0.76);
  color: #fff8b8;
  font-size: clamp(0.85rem, 1.1vw, 1.05rem);
  font-weight: 800;
  white-space: nowrap;
}

.form-error {
  margin: 0;
  color: #ff9aa3;
  font-weight: 700;
}

@media (max-width: 1500px) {
  .top-grid {
    grid-template-columns: minmax(520px, 40fr) minmax(520px, 40fr) minmax(300px, 20fr);
  }
}

@media (max-width: 1120px) {
  .hero-panel {
    height: var(--top-panel-height);
  }
}

@media (max-width: 860px) {
  .topbar {
    display: block;
  }

  .bottom-grid {
    display: block;
  }

  .status-strip {
    margin-top: 14px;
    justify-content: flex-start;
  }

  .panel {
    margin-bottom: 16px;
  }

  .hero-panel {
    height: auto;
  }

  .horizon {
    min-height: 320px;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding: 16px 0;
  }

  .control-actions,
  .split-actions {
    grid-template-columns: 1fr;
  }

  .control-row {
    grid-template-columns: 1fr 52px;
  }

  .control-row span {
    grid-column: 1 / -1;
  }
}
