/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: 'Courier New', Courier, monospace; font-size: 13px; background: #0a0e14; color: #b3c7d8; }

/* ===== App Layout ===== */
#app {
  display: flex;
  width: 100%;
  height: 100vh;
}

/* ===== Controls Panel ===== */
#controls {
  width: 320px;
  min-width: 320px;
  overflow-y: auto;
  background: #0f1620;
  border-right: 1px solid #1a2636;
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1a2636;
  padding-bottom: 8px;
  margin-bottom: 4px;
}
#controls h1 {
  font-size: 18px;
  color: #5fcde4;
  text-transform: uppercase;
  letter-spacing: 2px;
}
#btnCheatSheet {
  background: none;
  border: 1px solid #1e2a3a;
  color: #5fcde4;
  font-size: 16px;
  width: 30px;
  height: 26px;
  padding: 0;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1;
}
#btnCheatSheet:hover {
  background: #1a2636;
  border-color: #5fcde4;
}
#controls section {
  background: #121a26;
  border: 1px solid #1e2a3a;
  border-radius: 4px;
  padding: 8px 10px;
}
#controls section h2 {
  font-size: 11px;
  text-transform: uppercase;
  color: #7899b0;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
#controls label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  margin: 3px 0;
}
#controls input, #controls select, #controls textarea {
  background: #0a0e14;
  border: 1px solid #263040;
  color: #b3c7d8;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 2px;
  width: 100px;
  text-align: right;
}
/* Hide number spinners */
#controls input[type="number"]::-webkit-inner-spin-button,
#controls input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
#controls input[type="number"] { -moz-appearance: textfield; }
#controls input[type="checkbox"] { width: auto; }
#controls input[type="range"] { width: 80px; }
.dv { width: 56px; text-align: right; font-size: 10px; color: #5fcde4; }
#distortionParams .dv { width: 52px; }
#controls select { width: auto; min-width: 100px; text-align: left; }
#controls textarea { width: 100%; text-align: left; font-size: 10px; }
/* Inline field group (e.g. pose translation x y z on same line) */
.field-row {
  display: flex;
  gap: 4px;
  margin: 3px 0;
  align-items: center;
}
.field-row label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  flex: 1;
  min-width: 0;
}
.field-row label span { min-width: 10px; color: #7899b0; }
.field-row input[type="number"] { width: 48px; min-width: 0; }
/* Fullscreen button */
#imager-ctrl {
  display: flex;
  justify-content: flex-end;
  padding: 1px 2px;
  gap: 4px;
}
#imager-ctrl button {
  background: #1a2636;
  border: 1px solid #304050;
  color: #7899b0;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 2px;
  cursor: pointer;
}
#imager-ctrl button:hover { background: #263040; color: #b3c7d8; }
.pv-btn {
  background: #1a2636;
  border: 1px solid #304050;
  color: #7899b0;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 2px;
  cursor: pointer;
  white-space: nowrap;
}
.pv-btn:hover { background: #263040; color: #b3c7d8; }
.readout {
  font-size: 11px;
  color: #8899aa;
  padding: 2px 0;
}
.readout span { color: #5fcde4; }

/* ===== Stage ===== */
#stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 420px;
  grid-template-rows: 1fr 140px;
  gap: 2px;
  padding: 2px;
  background: #060a10;
}
#stage.fullscreen #world-container,
#stage.fullscreen #controls,
#stage.fullscreen #mtf-container,
#stage.fullscreen #imager-dual {
  display: none !important;
}
#stage.fullscreen {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
#stage.fullscreen #imager-container {
  grid-column: 1;
  grid-row: 1;
}
#world-container {
  grid-column: 1;
  grid-row: 1;
  position: relative;
  background: #000;
  border-radius: 2px;
  overflow: hidden;
}
#world { width: 100%; height: 100%; display: block; }
#imager-container {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #0a0e14;
  border-radius: 2px;
  padding: 2px;
  overflow: hidden;
}
#imager, #imager-dual {
  background: #000;
  border-radius: 2px;
  /* display size controlled by JS to maintain sensor aspect ratio */
}
#mtf-container {
  grid-column: 1 / 3;
  grid-row: 2;
  background: #0a0e14;
  border-radius: 2px;
  overflow: hidden;
}
#mtfplot { width: 100%; height: 100%; display: block; }

/* ===== Scrollbar ===== */
#controls::-webkit-scrollbar { width: 6px; }
#controls::-webkit-scrollbar-track { background: #0a0e14; }
#controls::-webkit-scrollbar-thumb { background: #1e2a3a; border-radius: 3px; }

/* ===== CV Cheat Sheet Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,10,16,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: #121a26;
  border: 1px solid #1e2a3a;
  border-radius: 6px;
  width: 580px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #1e2a3a;
}
.modal-title {
  font-size: 14px;
  color: #5fcde4;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.modal-close {
  background: none;
  border: none;
  color: #7899b0;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 2px;
}
.modal-close:hover { color: #b3c7d8; background: #1a2636; }
.modal-body { padding: 16px; }
.modal-footer {
  padding: 8px 16px;
  border-top: 1px solid #1e2a3a;
  text-align: center;
  font-size: 10px;
  color: #556;
}
.cs-section { margin-bottom: 16px; }
.cs-section h3 {
  font-size: 12px;
  color: #7899b0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  border-bottom: 1px solid #1a2636;
  padding-bottom: 4px;
}
.cs-formula {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 8px 0;
  padding: 6px 10px;
  background: #0a0e14;
  border-radius: 3px;
}
.cs-label {
  font-size: 11px;
  color: #8899aa;
}
.cs-formula code {
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: #b3c7d8;
  line-height: 1.6;
}
.cs-formula code sub { color: #5fcde4; font-size: 11px; }
.cs-hint { color: #445; font-style: italic; font-size: 10px; }
