body {
  margin: 0;
  background: #111;
  color: #fff;
  font-family: system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#app {
  /* Positioned ancestor so #debug-canvas's absolute top:0/left:0 anchors to
     this box (and therefore to #canvas's rendered box) instead of the page's
     initial containing block. The 12px spacing that used to live on #canvas
     as margin-top lives here instead: #app is a flex item of body, which
     makes it a block-formatting-context root, so a margin-top on #canvas
     (its first in-flow child) would NOT collapse away -- it would visibly
     offset #canvas 12px below #app's top edge while #debug-canvas's top:0
     stayed flush with #app, breaking alignment. Keeping the spacing on #app
     itself avoids that mismatch. */
  position: relative;
  margin-top: 12px;
}

/*
 * #debug-canvas overlays #canvas pixel-for-pixel: same mirror transform and
 * the same CSS-vs-backing-store scaling, so handle dots line up with what
 * the user actually sees.
 */
#canvas,
#debug-canvas {
  transform: scaleX(-1);
  max-width: 100%;
  height: auto;
}

#canvas {
  background: #000;
}

#status {
  margin: 8px 0;
  font-size: 14px;
  opacity: 0.8;
}

#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

#style-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.style-btn {
  padding: 8px 12px;
  border: 2px solid #555;
  background: #222;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.style-btn.active {
  border-color: #4caf50;
  background: #2e7d32;
}

#intensity-label {
  font-size: 14px;
}

#source-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

#video-file-label,
#use-camera-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #333;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

#capture-controls {
  display: flex;
  gap: 8px;
}

#capture-controls button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: #333;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

#capture-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#tuning-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 2px solid #555;
  border-radius: 50%;
  background: #222;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 10;
}

#tuning-panel {
  position: fixed;
  top: 60px;
  right: 12px;
  width: min(320px, calc(100vw - 24px));
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: #1a1a1a;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 12px 14px;
  z-index: 10;
}

#tuning-panel h2 {
  margin: 0 0 8px;
  font-size: 15px;
}

.tuning-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.tuning-row label {
  grid-column: 1 / -1;
  opacity: 0.85;
}

.tuning-row input[type='range'] {
  width: 100%;
}

.tuning-value {
  font-variant-numeric: tabular-nums;
  min-width: 3.5em;
  text-align: right;
}

#tuning-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

#tuning-actions button {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 6px;
  background: #333;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

#tuning-copy-output {
  margin-top: 8px;
  padding: 8px;
  background: #000;
  border-radius: 6px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: all;
}

#eye-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

#eye-controls select {
  padding: 4px;
  border-radius: 4px;
}
