:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef4f5;
  color: #102024;
  --panel: #ffffff;
  --line: #d7e2e5;
  --muted: #5f747a;
  --accent: #0f6d7a;
  --accent-strong: #0b4f5a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
}

button.tab {
  background: transparent;
  color: #27464d;
  border: 1px solid transparent;
}

button.tab.active {
  background: var(--panel);
  border-color: #c7d8dc;
  color: var(--accent-strong);
}

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

#disconnectButton {
  background: #51666c;
}

.shell {
  width: min(980px, calc(100% - 32px));
  margin: 24px auto;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 4px 0;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-picker {
  min-width: 190px;
}

.device-picker select {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  border: 1px solid #c5d4d8;
  border-radius: 6px;
  padding: 0 10px;
  background: white;
  color: #102024;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

p {
  margin: 6px 0 0;
  color: #4c6268;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.status-grid div,
.view,
.controls,
.actions,
.stored-panel,
.log-panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.view {
  display: none;
  margin-bottom: 16px;
  padding: 16px;
}

.view.active {
  display: block;
}

.primary-readout span,
.buddy-readout span,
.overview-grid span,
.instrument-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.primary-readout strong {
  display: block;
  margin-top: 8px;
  font-size: 36px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.primary-readout p {
  font-size: 18px;
}

.instrument-grid,
.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.overview-grid {
  grid-template-columns: repeat(4, 1fr);
}

.instrument-grid div,
.overview-grid div {
  min-height: 78px;
  border: 1px solid #d7e2e5;
  border-radius: 6px;
  padding: 12px;
}

.instrument-grid strong,
.overview-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 19px;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.map-toolbar span,
.map-readout span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.map-toolbar strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.map-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.map-actions button {
  min-height: 38px;
  padding: 0 12px;
}

.map-actions button.active {
  background: #6f7f2a;
}

.map-download {
  display: grid;
  grid-template-columns: minmax(130px, auto) minmax(132px, 1fr) minmax(112px, 0.8fr) auto minmax(160px, 1fr);
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 0 2px;
  border-top: 1px solid #d7e2e5;
}

.map-download label {
  min-width: 0;
}

.map-download label:first-child {
  display: flex;
  align-items: center;
  min-height: 42px;
  color: #27464d;
  font-weight: 700;
}

.map-download input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin: 0 8px 0 0;
}

.map-download input[type="number"] {
  min-height: 38px;
}

.map-download button {
  min-height: 38px;
  padding: 0 12px;
}

#mapTileStatus {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

#mapZoomInButton,
#mapZoomOutButton {
  width: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.map-canvas-frame {
  position: relative;
  width: 100%;
  min-height: 360px;
  aspect-ratio: 16 / 10;
  border: 1px solid #c7d8dc;
  border-radius: 8px;
  overflow: hidden;
  background: #ddecf0;
  touch-action: none;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.map-readout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.map-readout div {
  min-height: 64px;
  border: 1px solid #d7e2e5;
  border-radius: 6px;
  padding: 10px 12px;
}

.map-readout strong {
  display: block;
  margin-top: 6px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.buddy-layout {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 22px;
  align-items: center;
}

.bearing-dial {
  position: relative;
  width: 190px;
  aspect-ratio: 1;
  border: 2px solid #bfd1d5;
  border-radius: 50%;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    conic-gradient(from 0deg, #0f6d7a, #82aeb6, #d7e2e5, #0f6d7a) border-box;
}

.bearing-dial::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #102024;
  transform: translate(-50%, -50%);
}

.bearing-dial span {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  color: #0f5360;
  font-weight: 700;
}

#bearingNeedle {
  position: absolute;
  left: calc(50% - 3px);
  top: 28px;
  width: 6px;
  height: 68px;
  border-radius: 6px;
  background: #d2493f;
  transform-origin: 50% 67px;
  transform: rotate(0deg);
}

.buddy-readout strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
}

dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0 0;
}

dt {
  color: #5f747a;
  font-size: 13px;
}

dd {
  margin: 6px 0 0;
  font-size: 22px;
  font-weight: 700;
}

.status-grid div {
  min-height: 76px;
  padding: 14px;
}

.status-grid span,
label {
  display: block;
  color: #5f747a;
  font-size: 13px;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  margin-bottom: 16px;
}

input {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  border: 1px solid #c5d4d8;
  border-radius: 6px;
  padding: 0 10px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

#exportState {
  color: var(--muted);
  font-size: 13px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #f7fafb;
}

.stored-panel {
  padding: 14px;
  margin-bottom: 16px;
}

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

h2 {
  margin: 0;
  font-size: 18px;
}

#clearStoredButton {
  min-height: 34px;
  padding: 0 12px;
}

#storedExports {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

#storedExports li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #d7e2e5;
  border-radius: 6px;
  min-height: 44px;
  padding: 8px 10px;
}

#storedExports span {
  overflow-wrap: anywhere;
}

#storedExports button {
  min-height: 32px;
  padding: 0 10px;
}

.log-panel {
  min-height: 300px;
  padding: 0;
  overflow: hidden;
}

pre {
  min-height: 300px;
  max-height: 52vh;
  margin: 0;
  padding: 14px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 760px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .instrument-grid,
  .overview-grid,
  .map-readout,
  .buddy-layout,
  dl,
  .controls {
    grid-template-columns: 1fr;
  }

  .map-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .map-actions {
    justify-content: flex-start;
  }

  .map-download {
    grid-template-columns: 1fr;
  }

  #mapTileStatus {
    min-height: 24px;
  }

  .map-canvas-frame {
    min-height: 320px;
    aspect-ratio: 3 / 4;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-readout strong {
    font-size: 28px;
  }

  #storedExports li {
    align-items: stretch;
    flex-direction: column;
  }
}
