:root {
  color-scheme: dark;
  --bg: #000;
  --panel: #050505;
  --panel-soft: #111;
  --ink: #fff;
  --muted: #d4d4d8;
  --line: #3f3f46;
  --accent: #14b8a6;
  --accent-dark: #5eead4;
  --accent-soft: #173b39;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

input::placeholder {
  color: #a1a1aa;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  height: 100dvh;
  min-height: 640px;
}

.app-shell.is-map-only {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 100dvh;
  height: 100dvh;
  min-height: 100dvh;
}

.app-shell.is-map-only .control-panel {
  display: none;
}

.map-stage {
  height: 100%;
  position: relative;
  min-width: 0;
}

.map {
  height: 100%;
  min-height: 100%;
  background: #cfddd8;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.map *,
.leaflet-container,
.leaflet-container * {
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
}

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

.topbar {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: flex-start;
  left: max(18px, env(safe-area-inset-left));
  pointer-events: none;
  position: absolute;
  right: 18px;
  top: max(18px, env(safe-area-inset-top));
  z-index: 700;
}

.topbar > div:first-child,
.status-pill,
.compass-card,
.vario-card,
.readout,
.control-panel {
  backdrop-filter: blur(18px);
  background: rgba(0, 0, 0, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: var(--shadow);
}

.topbar > div:first-child {
  border-radius: 8px;
  padding: 8px 11px;
}

.topbar .eyebrow {
  margin: 0;
}

.map-mode-toggle,
.map-locate-button {
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 850;
  min-height: 34px;
  padding: 6px 12px;
  pointer-events: auto;
}

.map-locate-button {
  background: #000;
  border-color: rgba(255, 255, 255, 0.3);
  align-items: center;
  display: grid;
  font-size: 1.25rem;
  height: 34px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 38px;
}

.map-mode-toggle[aria-pressed="true"] {
  background: #000;
}

.eyebrow {
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.15rem, 2.4vw, 1.85rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.25rem;
  line-height: 1.15;
}

.status-pill {
  border-radius: 999px;
  color: var(--accent-dark);
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 760;
  margin-top: 8px;
  padding: 6px 10px;
  white-space: nowrap;
}

.status-pill.is-warning {
  color: var(--warning);
}

.status-pill.is-danger {
  color: var(--danger);
}

.compass-card {
  align-items: center;
  border-radius: 8px;
  display: grid;
  gap: 5px;
  justify-items: center;
  padding: 9px 8px;
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: 78px;
  width: 54px;
  z-index: 700;
}

.compass-card span {
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1;
}

.compass-card strong {
  color: var(--ink);
  font-size: 0.78rem;
  line-height: 1;
}

.vario-card {
  border-radius: 8px;
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 8px;
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: 166px;
  width: 74px;
  z-index: 700;
}

.vario-head {
  align-items: center;
  display: flex;
  gap: 4px;
  justify-content: space-between;
  width: 100%;
}

.vario-head span {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.vario-head button {
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 900;
  line-height: 1;
  min-height: 20px;
  min-width: 32px;
  padding: 4px 6px;
}

.vario-head button[aria-pressed="false"] {
  background: #27272a;
}

.vario-card strong {
  color: var(--ink);
  font-size: 1.18rem;
  line-height: 1;
}

.vario-card small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
}

.vario-card em {
  color: var(--muted);
  font-size: 0.64rem;
  font-style: normal;
  font-weight: 800;
  line-height: 1;
}

.vario-card.is-climb strong,
.vario-card.is-climb em {
  color: #4ade80;
}

.vario-card.is-sink strong,
.vario-card.is-sink em {
  color: var(--danger);
}

.vario-card.is-off {
  opacity: 0.72;
}

.compass-dial {
  align-items: center;
  background: #050505;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: grid;
  height: 34px;
  justify-items: center;
  position: relative;
  width: 34px;
}

.compass-dial::after {
  background: var(--ink);
  border-radius: 999px;
  content: "";
  height: 5px;
  position: absolute;
  width: 5px;
}

.compass-needle {
  height: 28px;
  position: relative;
  transform: rotate(0deg);
  transform-origin: center;
  transition: transform 180ms ease;
  width: 8px;
}

.compass-needle::before,
.compass-needle::after {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  content: "";
  left: 0;
  position: absolute;
}

.compass-needle::before {
  border-bottom: 14px solid var(--danger);
  top: 0;
}

.compass-needle::after {
  border-top: 14px solid var(--accent-dark);
  bottom: 0;
}

.readout {
  border-radius: 8px;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  left: max(18px, env(safe-area-inset-left));
  max-width: calc(100% - 36px);
  padding: 12px;
  position: absolute;
  z-index: 700;
}

.readout div,
.info-strip div {
  background: rgba(0, 0, 0, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 10px;
}

.readout-with-zoom {
  padding-right: 56px !important;
  position: relative;
}

.readout-zoom-button {
  align-items: center;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
  color: #fff;
  display: grid;
  font-size: 2rem;
  font-weight: 900;
  height: 44px;
  justify-content: center;
  line-height: 1;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
}

.readout-zoom-button:active {
  transform: translateY(-50%) scale(0.96);
}

.readout span,
.info-strip span,
.file-control span,
.waypoint-form span {
  color: var(--muted);
  display: block;
  font-size: 0.74rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.readout strong {
  display: block;
  font-size: 1.48rem;
  line-height: 1.05;
}

.speed-plan-hud {
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  bottom: calc(100% + 10px);
  box-shadow: var(--shadow);
  left: 0;
  padding: 8px 9px;
  pointer-events: none;
  position: absolute;
  right: 0;
  z-index: 2;
}

.speed-plan-hud[hidden] {
  display: none;
}

.speed-plan-hud span {
  color: var(--muted);
  display: block;
  font-size: 0.66rem;
  font-weight: 850;
  line-height: 1;
  margin: 0 0 5px;
  text-transform: uppercase;
}

.speed-plan-hud strong {
  align-items: baseline;
  display: flex;
  font-size: 1.02rem;
  gap: 6px;
  line-height: 1;
  white-space: nowrap;
}

.speed-plan-hud b {
  color: #fff;
  font-weight: 900;
}

.speed-plan-hud em {
  color: var(--muted);
  font-style: normal;
  font-weight: 800;
}

.info-strip strong {
  display: block;
  font-size: 1.05rem;
  line-height: 1.1;
}

.control-panel {
  background: rgba(0, 0, 0, 0.96);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.panel-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.icon-button {
  align-items: center;
  background: var(--accent);
  border-radius: 8px;
  color: #fff;
  display: inline-grid;
  flex: 0 0 38px;
  font-size: 1.12rem;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.control-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.primary-button,
.ghost-button {
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 760;
  min-height: 38px;
  padding: 8px 10px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover,
.icon-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: var(--accent-soft);
  color: #fff;
}

.ghost-button:hover {
  background: #20514d;
}

.route-tools {
  display: grid;
  gap: 8px;
}

.flight-plan-panel {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.mini-section-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.mini-section-header strong {
  display: block;
  font-size: 1rem;
  line-height: 1.1;
}

.compact-button {
  min-height: 32px;
  padding: 6px 9px;
}

.search-control {
  display: grid;
  gap: 5px;
}

.search-control span,
.search-control label,
.plan-stats span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.plan-search-row {
  align-items: center;
  display: grid;
  gap: 7px;
  grid-template-columns: minmax(0, 1fr) 82px;
}

.search-control input {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  padding: 7px 9px;
  width: 100%;
}

.plan-search-row .compact-button {
  min-height: 38px;
  padding-inline: 8px;
}

.plan-results {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  max-height: 164px;
  overflow-y: auto;
}

.plan-results[hidden] {
  display: none;
}

.plan-result-button {
  background: var(--panel);
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-items: stretch;
  min-width: 0;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.plan-result-button:last-child {
  border-bottom: 0;
}

.plan-result-button:disabled {
  cursor: default;
  opacity: 0.72;
}

.plan-result-message {
  cursor: default;
  grid-template-columns: 1fr;
}

.plan-result-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.plan-result-button strong {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.plan-result-button small {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.plan-result-add {
  align-self: center;
  background: var(--accent-soft);
  border-radius: 999px;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 5px 8px;
  white-space: nowrap;
}

.plan-result-button.is-added .plan-result-add {
  background: #14532d;
  color: #dcfce7;
}

.plan-actions,
.plan-stats {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.plan-stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
}

.plan-stats strong {
  display: block;
  font-size: 1rem;
  line-height: 1.1;
  margin-top: 4px;
}

.plan-list {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  max-height: 138px;
  overflow-y: auto;
  padding: 0;
}

.plan-list li {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  padding: 7px 8px;
}

.plan-list em {
  align-items: center;
  background: var(--accent);
  border-radius: 999px;
  color: #fff;
  display: grid;
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 800;
  height: 24px;
  justify-items: center;
  width: 24px;
}

.plan-list strong {
  display: block;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-list span {
  color: var(--muted);
  display: block;
  font-size: 0.74rem;
  margin-top: 2px;
}

.plan-list button {
  background: #3f1111;
  border-radius: 8px;
  color: #fecaca;
  font-weight: 800;
  height: 30px;
  width: 30px;
}

.wake-control,
.airspace-control,
.traffic-control {
  align-items: center;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  min-height: 38px;
  padding: 8px 10px;
}

.wake-control input,
.airspace-control input,
.traffic-control input {
  accent-color: var(--accent);
  height: 18px;
  margin: 0;
  width: 18px;
}

.wake-control span,
.airspace-control span,
.traffic-control span {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 760;
  min-width: 0;
}

.wake-control strong,
.airspace-control strong,
.traffic-control strong {
  color: var(--accent-dark);
  font-size: 0.76rem;
  white-space: nowrap;
}

.wake-control.is-warning strong,
.airspace-panel.is-warning strong,
.traffic-panel.is-warning strong {
  color: var(--warning);
}

.wake-control.is-danger strong,
.airspace-panel.is-danger strong,
.traffic-panel.is-danger strong {
  color: var(--danger);
}

.airspace-panel,
.traffic-panel {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 9px;
}

.airspace-control,
.traffic-control {
  background: var(--panel);
  padding: 8px 9px;
}

.airspace-legend {
  display: grid;
  gap: 5px;
}

.airspace-legend span {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.76rem;
  font-weight: 700;
  gap: 7px;
}

.airspace-legend i {
  border-radius: 4px;
  display: inline-block;
  height: 13px;
  width: 22px;
}

.legend-danger {
  background: rgba(220, 38, 38, 0.3);
  border: 2px solid #dc2626;
}

.legend-controlled {
  background: rgba(127, 29, 29, 0.34);
  border: 2px solid #7f1d1d;
}

.legend-military {
  background: transparent;
  border: 2px dashed #fbbf24;
}

.airspace-panel p,
.traffic-panel p {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
  margin: 0;
}

.airspace-popup {
  display: grid;
  gap: 5px;
  min-width: 180px;
}

.airspace-popup strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.airspace-popup span,
.airspace-popup small {
  color: var(--muted);
}

.airspace-popup ul {
  margin: 0;
  padding-left: 17px;
}

.traffic-marker {
  align-items: center;
  background: #0f172a;
  border: 2px solid #fff;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.26);
  color: #fff;
  display: flex;
  height: 30px;
  justify-content: center;
  line-height: 1;
  transform: rotate(var(--traffic-rotation, 0deg));
  width: 30px;
}

.traffic-marker svg {
  display: block;
  fill: currentColor;
  height: 20px;
  width: 20px;
}

.traffic-popup {
  display: grid;
  gap: 5px;
  min-width: 170px;
}

.traffic-popup strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.traffic-popup span {
  color: var(--muted);
}

.traffic-popup ul {
  margin: 0;
  padding-left: 17px;
}

.file-control,
.waypoint-form label {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
  padding: 10px;
}

.file-control input {
  color: var(--muted);
  display: block;
  max-width: 100%;
}

.waypoint-form {
  display: grid;
  gap: 8px;
}

.waypoint-form[hidden] {
  display: none;
}

.waypoint-form input,
.waypoint-form select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 38px;
  padding: 7px 9px;
  width: 100%;
}

.inline-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.info-strip {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.note {
  background: #211705;
  border: 1px solid #92400e;
  border-radius: 8px;
  color: #fde68a;
  font-size: 0.9rem;
  line-height: 1.45;
  padding: 10px;
}

.app-credit {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
  padding: 2px 4px 0;
  text-align: center;
}

.leaflet-control-zoom {
  border: 0 !important;
  box-shadow: var(--shadow);
}

.leaflet-control-zoom a {
  border-color: var(--line) !important;
  color: var(--ink) !important;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip,
.leaflet-tooltip {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}

.leaflet-popup-content-wrapper {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.leaflet-container a.leaflet-popup-close-button {
  color: var(--ink);
}

.pilot-marker {
  align-items: center;
  background: #14b8a6;
  border: 4px solid #fff;
  border-radius: 999px;
  box-shadow:
    0 0 0 3px rgba(15, 23, 42, 0.36),
    0 0 0 10px rgba(20, 184, 166, 0.2),
    0 10px 24px rgba(15, 118, 110, 0.4);
  display: grid;
  height: 42px;
  justify-content: center;
  position: relative;
  transform: rotate(var(--pilot-heading, 0deg));
  transform-origin: center;
  transition: transform 180ms ease;
  width: 42px;
}

.pilot-marker::before {
  animation: pilotPulse 1.8s ease-out infinite;
  border: 2px solid rgba(20, 184, 166, 0.42);
  border-radius: inherit;
  content: "";
  inset: -10px;
  position: absolute;
}

.pilot-marker::after {
  -webkit-clip-path: polygon(50% 0, 88% 76%, 60% 65%, 50% 100%, 40% 65%, 12% 76%);
  background: #fff;
  clip-path: polygon(50% 0, 88% 76%, 60% 65%, 50% 100%, 40% 65%, 12% 76%);
  content: "";
  filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.38));
  height: 30px;
  position: relative;
  transform: translateY(-1px);
  width: 20px;
}

@keyframes pilotPulse {
  0% {
    opacity: 0.8;
    transform: scale(0.72);
  }

  100% {
    opacity: 0;
    transform: scale(1.35);
  }
}

.waypoint-marker {
  align-items: center;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(20, 33, 31, 0.22);
  color: #fff;
  display: grid;
  font-size: 0.75rem;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.flight-plan-marker {
  align-items: center;
  background: #7c3aed;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(76, 29, 149, 0.26);
  color: #fff;
  display: grid;
  font-size: 0.78rem;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.waypoint-start {
  background: #0f766e;
}

.waypoint-landing {
  background: #2563eb;
}

.waypoint-hazard {
  background: #dc2626;
}

.waypoint-thermal {
  background: #ca8a04;
}

.waypoint-note {
  background: #52525b;
}

.popup-content {
  display: grid;
  gap: 6px;
  min-width: 150px;
}

.popup-content strong {
  font-size: 0.95rem;
}

.popup-content span {
  color: var(--muted);
}

.popup-content button {
  background: #3f1111;
  border-radius: 8px;
  color: #fecaca;
  font-weight: 760;
  padding: 8px 10px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(500px, 68dvh) auto;
    height: auto;
    min-height: 100dvh;
  }

  .control-panel {
    border-radius: 0;
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: minmax(520px, 70dvh) auto;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    flex-direction: row;
    gap: 8px;
    right: max(12px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
  }

  .topbar > div:first-child {
    padding: 7px 10px;
  }

  .compass-card {
    right: 12px;
    top: 58px;
  }

  .vario-card {
    right: 12px;
    top: 144px;
  }

  .readout {
    bottom: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    left: 12px;
    max-width: calc(100% - 24px);
    right: 12px;
  }

  .readout strong {
    font-size: 1.35rem;
  }

  .readout-with-zoom {
    padding-right: 52px !important;
  }

  .readout-zoom-button {
    height: 42px;
    right: 7px;
    width: 42px;
  }

  .info-strip strong {
    font-size: 0.95rem;
  }

  .control-panel {
    gap: 10px;
    padding: 12px 10px 16px;
  }
}
