* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #000;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#controls {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  background: rgb(4 6 8);
  padding: 16px;
  border-radius: 12px;
  width: 320px;
  color: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-height: 90vh;
  overflow-y: auto;
}

/* Scrollbar for controls */
#controls::-webkit-scrollbar { width: 6px; }
#controls::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
#controls::-webkit-scrollbar-thumb { background: rgba(77, 208, 225, 0.5); border-radius: 3px; }

h1 {
  font-size: 18px;
  margin-bottom: 20px;
  color: white;
  text-align: center;
  letter-spacing: 0px;
}

.control-group { margin-bottom: 18px; }

label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 13px;
  color: #b0bec5;
}

.value {
  color: #4dd0e1;
  font-weight: bold;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #4dd0e1;
  cursor: pointer;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(77, 208, 225, 0.5);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #4dd0e1;
  cursor: pointer;
  border-radius: 50%;
  border: none;
  box-shadow: 0 2px 8px rgba(77, 208, 225, 0.5);
}

select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: #000;
  color: #fff;
  border: 1px solid rgba(77, 208, 225, 0.35);
  outline: none;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

select:hover { background: #0b0b0b; }

select:focus {
  background: #0b0b0b;
  border-color: rgba(77, 208, 225, 0.8);
  box-shadow: 0 0 0 3px rgba(77, 208, 225, 0.15);
}

/* Dropdown options */
select option {
  background: #000;
  color: #fff;
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 25px;
}

button {
  padding: 12px;
  background: rgba(77, 208, 225, 0.2);
  color: #4dd0e1;
  border: 1px solid #4dd0e1;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: bold;
  transition: all 0.3s ease;
}

button:hover {
  background: rgba(77, 208, 225, 0.3);
  box-shadow: 0 4px 12px rgba(77, 208, 225, 0.3);
}

button:active { transform: scale(0.95); }

#stats {
  margin-top: 20px;
  font-size: 11px;
  color: #78909c;
  text-align: center;
  line-height: 1.6;
}

.stat-line {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
}

/* Move legend to top when Ground BC is selected */
#legend.legend-top{
  top: calc(18px + env(safe-area-inset-top));
  bottom: auto;
}

#legend {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 1001;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

#legend-title {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.75);
}

#legendBar {
  width: 260px;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  outline: 1px solid rgba(255,255,255,0.10);
}

#legend-labels {
  width: 260px;
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(255,255,255,0.70);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.icon-btn svg {
  fill: currentColor;
  display: block;
}

/* --- Sensor toggle switch --- */
.switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: #000;
  border: 1px solid rgba(77, 208, 225, 0.35);
  border-radius: 999px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease, background 0.2s ease;
}
.switch input:checked + .slider {
  background: #0b0b0b;
  border-color: rgba(77, 208, 225, 0.8);
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: #4dd0e1;
}

/* --- Sensor probe overlay --- */
#sensor {
  position: absolute;
  z-index: 8;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.90);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.45);
  display: none;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
#sensor:active { cursor: grabbing; }

#sensor::before,
#sensor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255,255,255,0.70);
  transform: translate(-50%, -50%);
}
#sensor::before { width: 10px; height: 1px; }
#sensor::after  { width: 1px; height: 10px; }

#sensorReadout {
  position: absolute;
  left: 22px;
  top: -10px;
  min-width: 200px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  backdrop-filter: blur(8px);
  pointer-events: none;
  color: rgba(255,255,255,0.9);
  font-size: 11px;
  line-height: 1.45;
}
#sensorReadout .k { color: rgba(255,255,255,0.65); }
#sensorReadout .v { color: #4dd0e1; font-weight: 600; }

input[type="range"]:disabled {
  filter: grayscale(1);
  cursor: not-allowed;
}

.full-btn{
  margin-top: 10px;
  width: 100%;
}

/* --- Data collection panel --- */
#dataPanel {
  margin-top: 10px;
  display: none;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(0,0,0,0.35);
  border-radius: 10px;
  padding: 10px;
}

#dataPanel .data-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

#dataPanel .data-actions button {
  flex: 1 1 auto;
  padding: 10px;
}

#dataWrap {
  max-height: 160px;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

#dataTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
}

#dataTable thead th {
  position: sticky;
  top: 0;
  background: rgba(0,0,0,0.85);
  color: rgba(255,255,255,0.80);
  text-align: left;
  padding: 6px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  white-space: nowrap;
}

#dataTable tbody td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.80);
  white-space: nowrap;
}

#dataTable tbody tr:nth-child(2n) td {
  background: rgba(255,255,255,0.03);
}

/* scrollbar for data table */
#dataWrap::-webkit-scrollbar { width: 6px; }
#dataWrap::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
#dataWrap::-webkit-scrollbar-thumb { background: rgba(77,208,225,0.35); border-radius: 3px; }

#canvas { touch-action: none; }

/* --- Collapsible controls panel --- */

/* Outer panel: animates height */
#controls{
  width: 320px;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: max-height 0.25s ease;
  scrollbar-gutter: stable;
  padding-right: 10px;
}

/* Header row */
.controls-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom: 14px;
}

/* Title in header */
.controls-header h1{
  flex: 1;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

/* Body */
#controlsBody{
  overflow: visible;
  max-height: none;
  transition: opacity 0.15s ease;
}

/* Collapsed */
#controls.collapsed{
  max-height: 58px;
  overflow: hidden;
}

#controls.collapsed #controlsBody{
  opacity: 0;
  pointer-events: none;
  display: none;
}

#panelToggle svg{
  transition: transform 0.2s ease;
}

#controls.collapsed #panelToggle svg{
  transform: rotate(180deg);
}

#controls.collapsed .controls-header{
  cursor: pointer;
}

#controls.collapsed .controls-header{ margin-bottom: 0; }
#controls:not(.collapsed) .controls-header{ margin-bottom: 14px; }

.info-icon{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  background: transparent;
  border: none;
  color: #b0bec5;
  cursor: pointer;
}

.info-icon:hover{
  color: #b0bec5;
  opacity: 0.85;
}

.info-icon:focus{
  outline: none;
  box-shadow: 0 0 0 3px rgba(176, 190, 197, 0.20);
  border-radius: 10px;
}

.info-icon svg{
  fill: currentColor;
  display: block;
}

.modal{
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
}
.modal.open{ display: block; }

.modal-backdrop{
  position:absolute;
  inset:0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
}

.modal-card{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 24px));
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgb(4 6 8);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.65);
  color: rgba(255,255,255,0.9);
}

.modal-head{
  position: relative;
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 12px;
  padding: 14px 14px 10px 14px;
  padding-right: 56px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  flex: 0 0 auto;
}

.modal-title{
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #4dd0e1;
}
.modal-subtitle{
  margin-top: 4px;
  font-size: 12px;
  color: rgba(255,255,255,0.60);
}

.modal-close{
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  line-height: 1;
  font-size: 18px;
}

.modal-close:hover{
  background: rgba(255,255,255,0.10);
}

.modal-body{
  padding: 12px 16px 10px 16px;
  font-size: 13px;
  line-height: 1.55;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-body h3{
  margin: 10px 0 6px 0;
  font-size: 13px;
  color: rgba(255,255,255,0.85);
}
.modal-body ul{
  margin: 0 0 8px 18px;
  color: rgba(255,255,255,0.78);
}
.modal-body li{ margin: 4px 0; }

.modal-note{
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(77, 208, 225, 0.22);
  background: rgba(77, 208, 225, 0.08);
  color: rgba(255,255,255,0.80);
}

.modal-foot{
  padding: 12px 14px 14px 14px;
  border-top: 1px solid rgba(255,255,255,0.10);
  display:flex;
  justify-content:flex-end;
}
.modal-ok{
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(77, 208, 225, 0.55);
  background: rgba(77, 208, 225, 0.18);
  color: #4dd0e1;
  cursor:pointer;
}
.modal-ok:hover{
  background: rgba(77, 208, 225, 0.26);
}

/* Bottom-left CoolApp link (clean text only) */
#coolapp-link{
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 1002;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;

  color: rgba(255,255,255,0.65);
  text-decoration: none;

  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;

  transition: opacity 0.2s ease, transform 0.2s ease;
}

#coolapp-link:hover{
  opacity: 0.95;
  transform: translateY(-1px);
  text-decoration: none; /* keep no underline */
}

#coolapp-link:focus{
  outline: none;
  text-decoration: none;
  /* optional: subtle focus ring without background/border */
  text-shadow: 0 0 0.6px rgba(77, 208, 225, 0.45);
}

.modal-contact{
  margin-top: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255,255,255,0.78);
}

.modal-contact a{
  color: #4dd0e1;
  text-decoration: none;
}

.modal-contact a:hover,
.modal-contact a:focus{
  text-decoration: none; /* no underline on hover */
}
/* --- Info modal CTA block --- */
.modal-cta-wrap{
  margin-top: 14px;
}

.modal-cta{
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  text-decoration: none;          /* no underline */
  color: inherit;                 /* keep modal text color */
}

.modal-cta:hover,
.modal-cta:focus,
.modal-cta:active,
.modal-cta:visited{
  text-decoration: none;          /* no underline on hover/visited */
  color: inherit;
}

.modal-cta-thumb{
  width: 120px;
  height: 72px;
  border-radius: 10px;
  background: rgba(0,0,0,0.35);
  border: 1px solid rgba(255,255,255,0.10);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.modal-cta-thumb-text{
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.modal-cta-title{
  font-size: 13px;
  font-weight: 700;
  color: rgba(255,255,255,0.78);
  margin-bottom: 2px;
}

.modal-cta-sub{
  font-size: 12px;
  color: rgba(255,255,255,0.70);
  line-height: 1.35;
}

/* --- Contact line at end of modal --- */
.modal-contact{
  margin-top: 12px;
  font-size: 12px;
  color: rgba(255,255,255,0.75);
}

.modal-email{
  color: #4dd0e1;
  text-decoration: none;          /* no underline */
}

.modal-email:hover,
.modal-email:visited{
  text-decoration: none;          /* no underline on hover/visited */
  color: #4dd0e1;
}

/* Visually hidden but still in the DOM (SEO/semantics/accessibility-friendly) */
.visually-hidden{
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

