:root {
  color-scheme: dark;
  --cyan: #05d8ff;
  --green: #00ff3b;
  --magenta: #d100ff;
  --amber: #e3c700;
  --white: #d6d6d6;
  --muted: #8b8b8b;
  --panel: #050505;
  --page: #111317;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0b0d10;
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: "Roboto Mono", "Consolas", "Lucida Console", monospace;
  padding: 16px;
}

.app-shell {
  width: min(100%, 960px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 42px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 32px));
  color: var(--green);
  background: transparent;
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.35;
  text-shadow: 0 0 5px rgb(0 255 59 / 55%);
}

.toast[hidden] {
  display: none;
}

.mobile-controls-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 40;
  display: block;
  min-width: 72px;
  color: var(--green);
  background: rgb(0 0 0 / 78%);
  border: 1px solid var(--green);
  border-radius: 6px;
  text-shadow: 0 0 5px rgb(0 255 59 / 55%);
}

.display-column {
  justify-self: center;
  width: min(100%, calc(100vmin - 32px), 960px);
  display: grid;
  gap: 12px;
}

.instrument {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  min-width: 0;
  max-width: 960px;
  overflow: hidden;
  background: #000;
  border: 2px solid #24282d;
  border-radius: 8px;
}

.instrument.hud-mirror {
  filter: brightness(1.75) saturate(1.35) contrast(1.5);
  transform: scaleY(-1);
}

#ndCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.readout,
.radios,
.ta-only {
  position: absolute;
  z-index: 2;
  font-family: "Roboto Mono", "Consolas", "Lucida Console", monospace;
  pointer-events: none;
  text-shadow: 0 0 4px #000;
}

.readout {
  top: 16px;
  display: flex;
  gap: 12px;
  align-items: baseline;
  color: var(--green);
  font-size: clamp(15px, 2.05vw, 22px);
  line-height: 1;
}

.readout span {
  color: var(--white);
}

.readout strong {
  color: var(--green);
  font-weight: 500;
}

.top-left {
  left: 20px;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.speed-row,
.wind-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wind-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--white);
  font-size: clamp(14px, 1.9vw, 20px);
}

.wind-values {
  display: flex;
  align-items: center;
  gap: 0;
}

.wind-values strong {
  color: var(--green);
}

.wind-values span {
  color: var(--white);
}

.wind-arrow {
  position: relative;
  display: inline-block;
  width: 28px;
  height: 2px;
  background: var(--green);
  transform-origin: 50% 50%;
}

.wind-arrow[hidden] {
  display: none;
}

.wind-arrow::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -5px;
  border-left: 10px solid var(--green);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.top-center {
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.top-center strong {
  color: var(--green);
  font-size: clamp(13px, 1.25vw, 17px);
  letter-spacing: 0;
}

.top-center span {
  color: #bdbdbd;
  font-size: clamp(18px, 2.2vw, 25px);
}

.top-right {
  right: 20px;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  color: var(--green);
}

.top-right span:last-child {
  color: var(--green);
}

.top-right span:first-of-type {
  color: var(--cyan);
}

.distance-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.distance-line strong {
  color: var(--green);
}

.distance-line em {
  color: var(--cyan);
  font-style: normal;
}

.radios {
  bottom: 22px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  color: #a9a9a9;
  font-size: clamp(16px, 2.25vw, 24px);
  line-height: 0.95;
}

.radio-text {
  color: var(--white);
  display: grid;
  gap: 3px;
}

.radios strong {
  color: var(--white);
  font-weight: 400;
}

.radios em {
  color: var(--green);
  font-style: normal;
}

.radios em i {
  color: var(--cyan);
  font-style: normal;
  margin-left: 5px;
}

.bottom-left {
  left: 28px;
}

.bottom-right {
  right: 28px;
  justify-content: flex-end;
  text-align: right;
}

.radio-symbol {
  flex: 0 0 auto;
  width: 22px;
  height: 72px;
  margin-top: -3px;
  fill: none;
  stroke: var(--white);
  stroke-width: 8;
  stroke-linecap: butt;
  stroke-linejoin: miter;
}

.ta-only {
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(50%, 470px);
  border: 2px solid #bcbcbc;
  color: #bcbcbc;
  text-align: center;
  font-size: clamp(16px, 2.2vw, 24px);
  line-height: 1.05;
  letter-spacing: 0.08em;
  background: rgba(0, 0, 0, 0.72);
}

.controls {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  width: min(86vw, 360px);
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
  background: #080a0d;
  border: 1px solid #2c333b;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
  transition: transform 180ms ease;
}

.controls.collapsed {
  transform: translateX(-100%);
}

.controls-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.controls-header strong {
  color: #dfe7ea;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.controls-header button {
  display: none;
}

.controls-body {
  display: grid;
  gap: 10px;
}

.controls.collapsed .controls-body {
  display: none;
}

.control-row {
  padding-top: 5px;
  display: grid;
  gap: 6px;
}

.control-row[hidden] {
  display: none;
}

label {
  color: #aeb4ba;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

select,
input,
button {
  font: inherit;
}

select,
input[type="number"],
input[type="url"],
input[type="text"],
input[type="file"] {
  width: 100%;
  min-height: 34px;
  color: #f2f6f8;
  background: #11161c;
  border: 1px solid #333b45;
  border-radius: 6px;
  padding: 0 10px;
}

input::placeholder {
  color: #66707b;
}

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

output {
  color: var(--cyan);
  font-size: 12px;
}

.control-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #0d1015;
  border: 1px solid #242b33;
  border-radius: 8px;
}

.control-section h2,
.control-section summary {
  position: relative;
  margin: 0;
  color: #dfe7ea;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  list-style: none;
  line-height: 1;
  padding-left: 14px;
  text-transform: uppercase;
}

.control-section summary::-webkit-details-marker {
  display: none;
}

.control-section summary::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid #dfe7ea;
  transform: translateY(-50%);
}

.control-section[open] summary::before {
  transform: translateY(-50%) rotate(90deg);
}

.control-section h2 {
  cursor: default;
  padding-left: 0;
}

.control-section h2::before {
  display: none;
}

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

.layer-toggles {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.layer-toggle-hint {
  position: relative;
  min-width: 0;
}

.layer-toggle-hint::after {
  content: attr(data-hint);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  z-index: 5;
  width: max-content;
  max-width: 210px;
  color: var(--white);
  background: #050505;
  border: 1px solid var(--white);
  border-radius: 4px;
  padding: 6px 7px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0;
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  text-align: center;
}

.layer-toggle-hint:hover::after,
.layer-toggle-hint:focus-within::after {
  opacity: 1;
}

.layer-toggle-hint button {
  width: 100%;
}

.layer-toggles button {
  position: relative;
  min-height: 36px;
  padding: 18px 4px 4px;
  color: #b9bec2;
  background: #25292e;
  border-color: #444a51;
  border-radius: 2px;
  font-size: 15px;
  line-height: 1;
  text-align: center;
}

.layer-toggles button span {
  position: absolute;
  top: 4px;
  left: 8px;
  right: 8px;
  height: 2px;
  background: #8b8f93;
  border-radius: 1px;
  box-shadow:
    0 5px 0 #8b8f93,
    0 10px 0 #8b8f93;
}

.layer-toggles button.active span {
  background: var(--green);
  box-shadow:
    0 5px 0 var(--green),
    0 10px 0 var(--green),
    0 0 5px rgb(0 255 59 / 55%);
}

.layer-toggles button:disabled {
  color: #6b7075;
  cursor: not-allowed;
  opacity: 0.65;
}

.segmented,
.control-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

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

button {
  min-height: 34px;
  color: #dfe7ea;
  background: #121820;
  border: 1px solid #333d48;
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  border-color: #6f7a86;
}

button.active {
  color: #001014;
  background: var(--cyan);
  border-color: var(--cyan);
}

.layer-toggles button.active {
  color: #e2e6e8;
  background: #25292e;
  border-color: #4d555d;
}

.check-row {
  padding-top: 5px;
  position: relative;
  display: grid;
  grid-template-columns: 62px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  color: #dfe7ea;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}

.check-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-row::before {
  content: "";
  grid-column: 1;
  width: 54px;
  height: 54px;
  background: #020304;
  border: 2px solid var(--white);
  border-radius: 10px;
  box-shadow: inset 0 0 8px rgb(255 255 255 / 12%);
}

.check-row::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 4px;
  width: 54px;
  color: var(--amber);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0 5px rgb(227 199 0 / 65%);
}

.check-row.fault::after,
.check-row[data-state="fault"]::after {
  content: "FAULT";
}

.check-row span {
  grid-column: 2;
}

.check-row span::before {
  content: "OFF";
  position: absolute;
  bottom: 10px;
  left: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  min-height: 16px;
  color: var(--white);
  border: 2px solid var(--white);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 0 4px rgb(255 255 255 / 35%);
}

.check-row input:checked + span::before {
  content: "ON";
  color: var(--cyan);
  border: 2px solid var(--cyan);
  text-shadow: 0 0 5px rgb(5 216 255 / 65%);
}

.check-row input:focus-visible + span::before {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

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

.debug-panel {
  border-top: 1px solid #252b33;
  padding-top: 10px;
}

.debug-panel summary {
  position: relative;
  color: #aeb4ba;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.08em;
  list-style: none;
  padding-left: 14px;
  text-transform: uppercase;
}

.debug-panel summary::-webkit-details-marker {
  display: none;
}

.debug-panel summary::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid #aeb4ba;
  transform: translateY(-50%);
}

.debug-panel[open] summary::before {
  transform: translateY(-50%) rotate(90deg);
}

.debug-log {
  width: 100%;
  max-height: 220px;
  margin: 10px 0 0;
  overflow: auto;
  color: #9ff7b0;
  background: #030405;
  border: 1px solid #26302b;
  border-radius: 6px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.navaid-panel {
  background: #050607;
  border: 1px solid #2f353d;
  border-radius: 8px;
  overflow: hidden;
}

.navaid-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 14px;
  color: #dfe7ea;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.08em;
  list-style-position: outside;
  text-transform: uppercase;
}

.navaid-panel summary span {
  color: var(--cyan);
}

.navaid-table-wrap {
  max-height: 260px;
  overflow: auto;
  border-top: 1px solid #252b33;
}

.navaid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.35;
}

.navaid-table th,
.navaid-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #171d23;
  text-align: left;
  white-space: nowrap;
}

.navaid-table th {
  position: sticky;
  top: 0;
  color: var(--cyan);
  background: #090c10;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.navaid-table td {
  color: #c8d0d4;
}

.navaid-table td:first-child {
  color: var(--green);
  font-weight: 700;
}

.site-footer {
  width: min(100%, 1240px);
  margin-top: 12px;
  color: #7f858c;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

@media (max-width: 920px) {
  body {
    align-items: stretch;
    justify-content: flex-start;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .controls-header,
  .controls-body {
    grid-column: 1 / -1;
  }

  .controls-body {
    grid-template-columns: 1fr;
  }

  .control-section {
    align-content: start;
  }

  .segmented,
  .control-actions,
  .check-row,
  .debug-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  body {
    padding: 8px;
  }

  .display-column {
    width: min(100%, calc(100vmin - 16px));
  }

  .controls {
    width: min(88vw, 330px);
    grid-template-columns: 1fr;
  }

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

  .readout {
    top: 10px;
  }

  .top-left {
    left: 10px;
  }

  .top-right {
    right: 10px;
  }

  .bottom-left {
    left: 12px;
  }

  .bottom-right {
    right: 12px;
  }
}
