* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --holo: #00d9ff;
  --holo-bright: #7cf3ff;
  --holo-dim: rgba(0, 217, 255, 0.35);
  --holo-faint: rgba(0, 217, 255, 0.12);
  --bg: #03060a;
  --text: #d8f6ff;
  --text-dim: #6f8b96;
  --warn: #ffb454;
  --ok: #6ee7a8;
  --font-hud: 'Roboto Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-hud);
  color: var(--text);
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

/* --- Mirrored stage (video + 3D canvas) --- */

#stage {
  position: absolute;
  inset: 0;
  transform: scaleX(-1);
  overflow: hidden;
  background: #000;
  z-index: 0;
}

#webcam,
#scene-canvas,
#cursor-canvas,
#hud-grid {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Topmost layer, above #ui-layer, so the cursor is never occluded by a
   panel. It applies the same mirror the stage does, which keeps the
   overlay drawing in stage-normalized coordinates exactly as before. */
#cursor-canvas {
  transform: scaleX(-1);
  z-index: 2;
}

#webcam {
  object-fit: cover;
  filter: saturate(0.85) brightness(0.92) contrast(1.05);
  transition: opacity 0.2s ease;
}

/* Workbench mode: hide the camera feed behind a plain dark surface. The
   video element keeps decoding frames in the background (CSS visibility
   doesn't pause it), so hand tracking is unaffected. */
body.workbench #webcam {
  opacity: 0;
}

#scene-canvas,
#cursor-canvas,
#hud-grid {
  pointer-events: none;
}

#hud-grid {
  background-image:
    linear-gradient(rgba(0, 217, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 217, 255, 0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  mix-blend-mode: screen;
  animation: grid-drift 14s linear infinite;
}

@keyframes grid-drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 42px, 42px 0; }
}

/* --- Unmirrored UI layer --- */

/* Children are positioned individually rather than flowed, because the
   control deck is now centered over the stage instead of pinned to an
   edge. */
#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

#ui-layer > * {
  pointer-events: auto;
}

/* --- HUD panel chrome: angular corners + glow + scanning top edge --- */

.hud-panel {
  position: relative;
  background: rgba(3, 10, 14, 0.62);
  backdrop-filter: blur(10px);
  border: 1px solid var(--holo-dim);
  box-shadow: 0 0 18px rgba(0, 217, 255, 0.12), inset 0 0 24px rgba(0, 217, 255, 0.04);
  clip-path: polygon(
    12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%,
    0 100%, 0 12px
  );
  padding: 12px 16px;
}

.hud-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-top: 1px solid rgba(124, 243, 255, 0.5);
  clip-path: polygon(12px 0, 100% 0, 100% 1px, 0 1px);
  pointer-events: none;
}

/* --- Status bar --- */

#left-stack {
  position: absolute;
  top: 22px;
  left: 22px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  max-width: 280px;
}

#status-bar {
  display: flex;
  gap: 10px;
  padding: 8px 14px;
}

/* --- Active model info (name, size, provenance) --- */

#info-panel {
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-dim);
  pointer-events: none;
  width: 100%;
}

#info-panel.hidden {
  display: none;
}

.info-title {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--holo-bright);
  opacity: 0.85;
  margin-bottom: 4px;
}

.info-name {
  font-size: 13px;
  color: var(--text);
  letter-spacing: 0.02em;
  margin-bottom: 3px;
}

.info-row {
  word-break: break-word;
}

.info-license {
  margin-top: 3px;
  font-size: 10px;
  opacity: 0.75;
}

.pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
}

.pill + .pill {
  border-left: 1px solid var(--holo-dim);
  padding-left: 10px;
}

#hand-status.active {
  color: var(--ok);
  text-shadow: 0 0 8px rgba(110, 231, 168, 0.6);
}

#camera-status.active {
  color: var(--holo-bright);
}

/* --- Right stack (legend + debug readout, in flow so one can't overlap
       the other as its content grows) --- */

#right-stack {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 230px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

/* --- Legend --- */

#legend {
  font-size: 11.5px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-title {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--holo-bright);
  text-transform: uppercase;
  margin-bottom: 2px;
  opacity: 0.85;
}

#legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.dot.pinch { background: var(--warn); color: var(--warn); }
.dot.two-hand { background: var(--ok); color: var(--ok); }
.dot.point { background: var(--holo); color: var(--holo); }
.dot.fist { background: #c58bff; color: #c58bff; }
.dot.xray { background: #ff9d5c; color: #ff9d5c; }

.legend-hint {
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-dim);
}

/* --- Debug readout --- */

#debug-readout {
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--ok);
  white-space: pre;
}

#debug-readout:empty {
  display: none;
}

#debug-readout.hidden {
  display: none;
}

/* --- Fist-to-open hint (shown only while the menu is closed) --- */

#menu-hint {
  position: absolute;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.fist-glyph {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid var(--holo);
  box-shadow: 0 0 10px var(--holo-dim);
  animation: fist-pulse 2s ease-in-out infinite;
}

@keyframes fist-pulse {
  0%, 100% { transform: scale(1); opacity: 0.55; }
  50% { transform: scale(0.82); opacity: 1; }
}

body.menu-open #menu-hint {
  opacity: 0;
}

/* --- Control deck (category tabs + model grid + actions), centered --- */

#control-deck {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px 16px;
  min-width: 620px;
  max-width: min(900px, calc(100vw - 60px));
  transform: translate(-50%, -50%) scale(0.92);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
}

body.menu-open #control-deck {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  visibility: visible;
}

#category-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

#model-grid {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 56px;
}

#action-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  border-top: 1px solid var(--holo-faint);
  padding-top: 10px;
}

#action-row-2 {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* An active toggle (spin on) reads as lit rather than just relabelled, so
   state is visible at a glance from across the room. */
.hud-btn.toggled {
  border-color: var(--holo-bright);
  background: rgba(0, 217, 255, 0.18);
  color: var(--holo-bright);
  box-shadow: 0 0 12px rgba(0, 217, 255, 0.35);
}

/* --- HUD buttons (all dwell targets share this look) --- */

.hud-btn {
  position: relative;
  overflow: hidden;
  background: rgba(0, 217, 255, 0.06);
  border: 1px solid var(--holo-dim);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  color: var(--text);
  font-family: var(--font-hud);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  padding: 9px 14px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hud-btn-label {
  position: relative;
  z-index: 2;
}

.dwell-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 217, 255, 0.5), rgba(124, 243, 255, 0.75));
  transform: scaleX(var(--dwell, 0));
  transform-origin: left center;
  transition: transform 0.05s linear;
  z-index: 1;
}

.hud-btn:hover {
  border-color: var(--holo-bright);
}

.hud-btn.dwelling {
  border-color: var(--holo-bright);
  color: #04222a;
  box-shadow: 0 0 14px rgba(0, 217, 255, 0.45);
}

.hud-btn.dwelling .hud-btn-label {
  color: #04222a;
  font-weight: 700;
}

.hud-btn.selected {
  border-color: var(--warn);
  box-shadow: 0 0 14px rgba(255, 180, 84, 0.4);
}

#category-tabs .hud-btn {
  padding: 7px 16px;
  font-size: 10.5px;
}

#category-tabs .hud-btn.active {
  border-color: var(--holo-bright);
  background: rgba(0, 217, 255, 0.16);
  color: var(--holo-bright);
}

#model-grid .hud-btn {
  min-width: 92px;
  text-align: center;
}

.hud-btn-wide {
  flex: 1;
  text-align: center;
}

.hud-btn-clear {
  border-color: rgba(224, 122, 122, 0.4);
}

.hud-btn-clear:hover {
  border-color: #e07a7a;
}

.hud-btn.hidden {
  display: none;
}
