:root {
  --primary: #2c7be5;
  --primary-tint: #dbecff;
  --success: #2e7d32;
  --warning: #d97706;
  --error: #c62828;
  --surface: #ffffff;
  --surface-alt: #f3f3f3;
  --border: #9a9a9a;
  --text: #1f1f1f;
  --text-secondary: #555555;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--surface-alt);
  color: var(--text);
  font-family: var(--font);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#view-live {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid #d8d8d8;
  position: sticky;
  top: 0;
  z-index: 4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
}

.brand-sub {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #800000;
  border-left: 1px solid #d8d8d8;
  padding-left: 10px;
  line-height: 1.1;
}

#status {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 42%;
  text-align: right;
}

#status[data-kind="ok"] { color: var(--success); }
#status[data-kind="warn"] { color: var(--warning); }
#status[data-kind="err"] { color: var(--error); }

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.compass-sight {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.compass-sight-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 6px;
  transform: translateX(-50%);
  background: #000;
  border-left: 2px solid #fff;
  border-right: 2px solid #fff;
  box-sizing: border-box;
}

.live-toolbar {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 52px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0;
}

.toolbar-style {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  padding: 4px 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.live-toolbar .btn {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}

.map-float-btn {
  position: absolute;
  top: 96px;
  right: 10px;
  z-index: 2;
  appearance: none;
  width: 40px;
  height: 40px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.map-float-btn img {
  display: block;
  width: 100%;
  height: 100%;
}

.map-float-btn.active {
  background: var(--primary-tint);
}

.map-float-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.user-location {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid #fff;
  box-shadow: 0 0 0 6px rgba(44, 123, 229, 0.28);
}

.toolbar-style select {
  min-width: 120px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--text);
}

#live-cards, #view-pilots {
  padding: 10px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#live-dock {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#live-cards {
  padding: 0;
  gap: 0;
}

#view-pilots {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.view-live .site-mark {
  display: none;
}

.empty {
  margin: 8px 0;
  color: var(--text-secondary);
  line-height: 1.4;
}

.card {
  background: var(--surface);
  border: 1px solid #d8d8d8;
  border-radius: var(--radius);
  padding: 12px;
}

.live-card.stale { border-color: var(--warning); }

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h3,
.dock-row h3 {
  margin: 0;
  font-size: 16px;
}

.form-card .card-head h3 {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-pick {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
}

.color-pick input[type="color"] {
  appearance: none;
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #c4c4c4;
  background: transparent;
  cursor: pointer;
}

.color-pick input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-pick input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

.color-pick input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 50%;
}

#add-pilot-btn {
  width: 100%;
}

.dock-card {
  padding: 8px 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
}

.dock-empty {
  margin: 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid #d8d8d8;
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
}

.dock-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dock-row h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 28%;
}

.dock-row .icon-btn {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
}

.dock-metrics {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dock-details {
  margin: 8px 0 0;
}

.dock-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.dock-actions-main,
.dock-actions-end {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dock-actions [data-action="wind"] {
  margin-left: 12px;
}

.dock-actions-end {
  margin-left: auto;
}

.icon-btn {
  appearance: none;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--primary-tint);
  cursor: pointer;
}

.icon-btn img {
  display: block;
  width: 100%;
  height: 100%;
}

.icon-btn[disabled] {
  background: #e9ecef;
  cursor: default;
  opacity: 0.45;
}

.icon-btn.active,
.icon-btn[aria-pressed="true"] {
  background: var(--primary);
}

.icon-btn.active img,
.icon-btn[aria-pressed="true"] img {
  filter: brightness(10);
}

.live-card.expanded [data-action="expand"] img {
  transform: rotate(180deg);
}

.meta {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: 0 0 12px;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin: 0 0 12px;
}

.metrics .wide { grid-column: 1 / -1; }

.metrics dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.metrics dd {
  margin: 2px 0 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

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

.actions .wide {
  grid-column: 1 / -1;
}

.btn, select, input {
  font: inherit;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 10px 12px;
  min-height: 42px;
  cursor: pointer;
}

.btn.ghost {
  background: var(--primary-tint);
  color: var(--primary);
}

.btn:disabled {
  background: #e9ecef;
  color: #7a7a7a;
  cursor: default;
}

.btn.small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.form-card label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.pid-hint {
  margin: -4px 0 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.form-card input:not([type="color"]), .prefs select {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
}

.prefs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.prefs label.wide,
.prefs .prefs-actions { grid-column: 1 / -1; }

.prefs-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.help {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.site-mark {
  margin: 0 12px 8px;
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

.site-mark a {
  color: #800000;
  font-weight: 650;
  text-decoration: none;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-top: 1px solid #d8d8d8;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}

.bottom-nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 12px;
  min-height: 48px;
  cursor: pointer;
  font-weight: 600;
}

.bottom-nav button[aria-current="page"] {
  color: var(--primary);
}

.map-pilot-dot {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--marker, var(--primary));
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.map-pilot-dot.selected {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--marker, var(--primary)) 70%, #fff);
}

.map-pilot-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: 650 12px var(--font);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.map-flight-goal {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.map-flight-goal-dot {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--marker, #800000);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.map-flight-goal-name {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 2px 12px;
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  font: 650 22px var(--font);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.map-flight-goal.selected .map-flight-goal-dot {
  box-shadow:
    0 0 0 3px #fff,
    0 0 0 8px var(--marker, #800000);
}

.map-flight-goal.selected .map-flight-goal-name {
  background: var(--marker, #800000);
  color: #fff;
  outline: 3px solid #fff;
  font-weight: 750;
}

.mailbox-meta {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.wind-card {
  padding: 10px;
}

.wind-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wind-card-head h3 {
  margin: 0;
  flex: 1 1 auto;
  font-size: 15px;
}

.wind-card-head .wind-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

.wind-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}

.wind-at {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wind-bearing-group {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.wind-bearing {
  width: 3.2em;
  min-width: 3.2em;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 45px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  appearance: textfield;
}

.wind-bearing::-webkit-outer-spin-button,
.wind-bearing::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.wind-unit {
  flex: 0 0 auto;
  font-size: 18px;
  font-weight: 650;
  color: var(--text-secondary);
}

.wind-card .compass-btn {
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  margin-left: auto;
  padding: 8px;
}

.wind-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.wind-actions .btn {
  flex: 1 1 auto;
}

.compass-btn img {
  transform-origin: 50% 50%;
}

.compass-btn.live {
  background: var(--primary);
}

.compass-btn.live img {
  filter: brightness(10);
  transition: transform 0.12s linear;
}

.compass-btn.locked {
  background: var(--success);
}

.compass-btn.locked img {
  filter: brightness(10);
}

.map-goal {
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 16px solid var(--marker, var(--primary));
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.maplibregl-ctrl-attrib {
  font-size: 10px;
}

[hidden] { display: none !important; }
