:root {
  --bg: #03060c;
  --cyan: #00e5ff;
  --cyan-dim: rgba(0, 229, 255, 0.35);
  --red: #ff3355;
  --red-dim: rgba(255, 51, 85, 0.4);
  --glass: rgba(4, 20, 40, 0.45);
  --text: #e8f4ff;
  --muted: #7aa0c4;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", monospace;
  --gold: #c9a227;
  --dwell: 0;
  /* Right column: Jarvis panel + gap to workshop “BAY ENV” box */
  --hud-right-col-w: min(360px, 40vw);
  --hud-edge-inset: 1rem;
  --hud-col-gap: 0.75rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

.app {
  position: relative;
  width: 100%;
  height: 100%;
}

.start-gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(ellipse at 50% 40%, rgba(0, 40, 80, 0.55), rgba(2, 6, 14, 0.92));
  backdrop-filter: blur(6px);
}

.start-gate[hidden] {
  display: none !important;
}

.start-gate-panel {
  max-width: 420px;
  width: 100%;
  padding: 1.5rem 1.75rem;
  border: 1px solid var(--cyan-dim);
  box-shadow: 0 0 40px rgba(0, 229, 255, 0.15), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  text-align: center;
}

.start-gate-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
  font-weight: 700;
}

.start-gate-copy {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--muted);
}

.start-gate-copy strong {
  color: var(--text);
}

.btn-start {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.start-gate-error {
  margin: 1rem 0 0;
  font-size: 0.8rem;
  color: var(--red);
  line-height: 1.4;
}

.camera-pip {
  position: absolute;
  right: var(--hud-edge-inset);
  bottom: 5rem;
  width: min(320px, 38vw);
  aspect-ratio: 4 / 3;
  z-index: 6;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--cyan-dim);
  box-shadow: 0 0 24px var(--cyan-dim), inset 0 0 40px rgba(0, 229, 255, 0.06);
  pointer-events: none;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.45s ease;
}

.app.tracking-active .camera-pip {
  opacity: 1;
}

.webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  filter: saturate(0.85) contrast(1.05) brightness(0.55);
  z-index: 0;
}

.app.tracking-active .webcam {
  filter: saturate(0.9) contrast(1.05) brightness(0.78);
}

/* —— Center 3D model (model-viewer) —— */
.model-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4.5rem min(1rem, env(safe-area-inset-right)) 5.5rem min(1rem, env(safe-area-inset-left));
  pointer-events: none;
  background: radial-gradient(ellipse 90% 70% at 50% 45%, rgba(0, 45, 85, 0.35), transparent 62%),
    radial-gradient(ellipse 70% 50% at 50% 100%, rgba(0, 30, 60, 0.5), transparent 55%),
    linear-gradient(180deg, rgba(5, 10, 20, 0.97) 0%, rgba(3, 6, 14, 0.98) 100%);
}

.model-stage model-viewer {
  display: block;
  width: min(92vw, 920px);
  height: min(72vh, 640px);
  max-height: calc(100vh - 10rem);
  pointer-events: none;
  --poster-color: transparent;
  border-radius: 12px;
  border: 1px solid rgba(0, 229, 255, 0.22);
  box-shadow: 0 0 40px rgba(0, 229, 255, 0.1), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  background: rgba(0, 8, 20, 0.4);
}

.model-chrome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
  pointer-events: none;
}

.model-caption {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--cyan);
  text-shadow: 0 0 12px var(--cyan-dim);
}

.model-dots {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.model-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(0, 229, 255, 0.25);
  border: 1px solid rgba(0, 229, 255, 0.35);
}

.model-dot--active {
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan-dim);
}

.hand-pointer {
  position: fixed;
  z-index: 26;
  width: 0;
  height: 0;
  pointer-events: none;
  margin: 0;
  --dwell: 0;
}

.hand-dwell-arc {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 0;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: conic-gradient(
    from -90deg,
    var(--cyan) 0%,
    var(--cyan) calc(var(--dwell) * 100%),
    transparent 0%
  );
  opacity: 0.85;
  mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #fff calc(100% - 3px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #fff calc(100% - 3px));
}

.hand-pointer-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border: 2px solid rgba(0, 229, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.5);
  opacity: 0.9;
}

.hand-pointer-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--cyan);
}

.camera-pip .overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  z-index: 1;
  transform: scaleX(-1);
  background: transparent;
}

.scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 3;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 229, 255, 0.03) 2px,
    rgba(0, 229, 255, 0.03) 4px
  );
  mix-blend-mode: screen;
  opacity: 0.5;
}

.vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 4;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.65) 100%);
}

.hud-top,
.hud-right,
.hud-bottom {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.hud-top * ,
.hud-right * ,
.hud-bottom * {
  pointer-events: auto;
}

.hud-top {
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  gap: 1rem;
}

.brand-mark {
  display: block;
  font-size: 1.35rem;
  letter-spacing: 0.35em;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 12px var(--cyan-dim);
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.pill {
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.35rem 0.65rem;
  border-radius: 4px;
  border: 1px solid var(--cyan-dim);
  background: var(--glass);
  color: var(--cyan);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.15);
}

.pill.alert {
  border-color: var(--red-dim);
  color: var(--red);
  box-shadow: 0 0 14px var(--red-dim);
}

.hud-right {
  right: var(--hud-edge-inset);
  top: 5.5rem;
  width: var(--hud-right-col-w);
  max-height: calc(100% - 7rem);
  display: flex;
  flex-direction: column;
}

.hud-bottom {
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: center;
}

.panel {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--cyan-dim);
  backdrop-filter: blur(10px);
  background: var(--glass);
  box-shadow: 0 0 30px rgba(0, 229, 255, 0.08), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.panel h2 {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cyan);
  font-weight: 600;
}

.telemetry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.telemetry dt {
  color: var(--muted);
}

.telemetry dd {
  margin: 0;
  text-align: right;
  color: var(--text);
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0 0 0.5rem;
  line-height: 1.4;
}

.log {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--cyan);
  max-height: 4.5rem;
  overflow-y: auto;
  line-height: 1.35;
}

.jarvis-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  max-height: calc(100vh - 8rem);
}

.api-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.api-row select,
.api-row input[type="password"],
.api-row input[type="text"] {
  flex: 1;
  min-width: 0;
  background: rgba(0, 20, 40, 0.6);
  border: 1px solid var(--cyan-dim);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.chat {
  flex: 1;
  min-height: 120px;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 229, 255, 0.12);
  font-size: 0.82rem;
  line-height: 1.45;
}

.chat .msg {
  margin-bottom: 0.5rem;
}

.chat .msg.user {
  color: var(--muted);
}

.chat .msg.jarvis {
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan-dim);
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.chat-input-row input {
  flex: 1;
  background: rgba(0, 20, 40, 0.6);
  border: 1px solid var(--cyan-dim);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
}

.voice-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 1rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.78rem;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--cyan-dim);
  background: rgba(0, 40, 80, 0.5);
  color: var(--cyan);
  cursor: pointer;
  transition: box-shadow 0.2s, background 0.2s;
}

.btn:hover {
  box-shadow: 0 0 14px var(--cyan-dim);
  background: rgba(0, 60, 100, 0.55);
}

.btn.primary {
  background: linear-gradient(135deg, rgba(0, 120, 180, 0.5), rgba(0, 60, 100, 0.6));
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.mono {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.hud-hint {
  max-width: 220px;
  line-height: 1.25;
  text-align: left;
  opacity: 0.9;
}

@media (max-width: 1100px) {
  .hud-hint {
    display: none;
  }
}

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  z-index: 32;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--cyan-dim);
  background: rgba(4, 20, 40, 0.92);
  color: var(--cyan);
  font-size: 0.85rem;
  box-shadow: 0 0 24px var(--cyan-dim);
  transition: transform 0.35s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app.fullscreen-ui .hud-right {
  opacity: 0.92;
}

@media (max-width: 900px) {
  .hud-right {
    width: auto;
    left: var(--hud-edge-inset);
    right: var(--hud-edge-inset);
    top: 5.5rem;
    max-height: 40vh;
  }

  .camera-pip {
    width: min(200px, 45vw);
    bottom: 4.5rem;
  }

  .model-stage model-viewer {
    width: min(94vw, 100%);
    height: min(52vh, 480px);
  }
}

@media (max-width: 640px) {
  .model-stage model-viewer {
    height: min(48vh, 420px);
  }
}

