:root {
  --font-display: 'Tomorrow', sans-serif;
  --font-mono: 'Share Tech Mono', monospace;
}

body.theme-blueprint-dark {
  --bg-dark: #07162c;
  --bg-panel: rgba(11, 29, 58, 0.88);
  --cyan-bright: #38bdf8;
  --cyan-dim: #0284c7;
  --emerald-bright: #34d399;
  --orange-warn: #fbbf24;
  --red-danger: #f87171;
  --purple-accent: #c084fc;
  --text-main: #f0f9ff;
  --text-muted: #7dd3fc;
  --border-cyan: rgba(56, 189, 248, 0.45);
}

body.theme-blueprint-light {
  --bg-dark: #cbd5e1;
  --bg-panel: rgba(241, 245, 249, 0.92);
  --cyan-bright: #0284c7;
  --cyan-dim: #0369a1;
  --emerald-bright: #059669;
  --orange-warn: #d97706;
  --red-danger: #dc2626;
  --purple-accent: #7c3aed;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-cyan: rgba(2, 132, 199, 0.4);
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-display);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* CRT Scanlines Overlay */
.hud-scanlines {
  position: fixed;
  inset: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
  background-size: 100% 4px;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.02;
}

.simulation-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-dark);
  transition: background-color 0.3s ease;
}

.theme-blueprint-dark .simulation-container {
  background-image: 
    linear-gradient(rgba(56, 189, 248, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
}

.theme-blueprint-light .simulation-container {
  background-image: 
    linear-gradient(rgba(2, 132, 199, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(2, 132, 199, 0.08) 1px, transparent 1px);
  background-size: 24px 24px;
}

/* Top Nav */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.5rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-cyan);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
  height: 72px; /* enlarged for astronaut headshots */
  z-index: 10;
  transition: all 0.3s ease;
  overflow: hidden;
}

.top-nav.collapsed {
  height: 0;
  padding: 0;
  border-bottom: none;
  box-shadow: none;
  pointer-events: none;
}

/* Floating Restore Handle */
.header-toggle-tab {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-cyan);
  border-top: none;
  border-radius: 0 0 6px 6px;
  padding: 4px 16px;
  color: var(--cyan-bright);
  font-size: 0.8rem;
  cursor: pointer;
  z-index: 1001;
  display: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
}

.header-toggle-tab:hover {
  background: var(--border-cyan);
  color: #fff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.top-nav.collapsed + .header-toggle-tab {
  display: block;
}

/* Crew Astronaut Banner Strip */
.header-crew-banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 auto;
}

.header-crew-member {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.header-crew-member:hover {
  background: rgba(56, 189, 248, 0.08);
  border-color: var(--cyan-bright);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.2);
}

.header-crew-photo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--cyan-bright);
  object-fit: cover;
  background: #02070b;
}

.header-crew-details {
  display: flex;
  flex-direction: column;
  font-family: var(--font-mono);
}

.header-crew-details .name {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
}

.header-crew-details .status {
  font-size: 0.6rem;
  color: var(--text-muted);
}

.header-crew-details .status b {
  color: var(--cyan-bright);
}

.btn-theme-toggle {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-cyan);
  color: var(--cyan-bright);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s ease;
}

.btn-theme-toggle:hover {
  background: var(--border-cyan);
  color: #fff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.logo-box {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--cyan-bright);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 2px;
}

.logo-bracket { color: var(--emerald-bright); }
.mission-tag {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 1rem;
  display: inline-block;
}

.btn-fps-mode {
  background: linear-gradient(135deg, rgba(0, 255, 170, 0.2), rgba(0, 240, 255, 0.3));
  border: 1px solid var(--emerald-bright);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  padding: 6px 14px;
  cursor: pointer;
  border-radius: 3px;
  box-shadow: 0 0 10px rgba(0, 255, 170, 0.3);
  transition: all 0.2s;
  margin-right: 0.75rem;
}

.btn-fps-mode:hover, .btn-fps-mode.active-fps {
  background: var(--emerald-bright);
  color: #000;
  box-shadow: 0 0 16px var(--emerald-bright);
}

.sim-speed-controls {
  display: inline-flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.4);
  padding: 2px;
  border-radius: 4px;
  border: 1px solid rgba(0, 240, 255, 0.2);
}

.btn-ctrl {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.btn-ctrl:hover, .btn-ctrl.active {
  background: var(--cyan-dim);
  color: #fff;
  box-shadow: 0 0 8px var(--cyan-bright);
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--emerald-bright);
  margin-right: 1rem;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald-bright);
  box-shadow: 0 0 10px var(--emerald-bright);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.btn-warning {
  background: rgba(255, 170, 0, 0.15);
  border: 1px solid var(--orange-warn);
  color: var(--orange-warn);
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 1px;
  padding: 6px 12px;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s;
}

.btn-warning:hover {
  background: var(--orange-warn);
  color: #000;
  box-shadow: 0 0 12px var(--orange-warn);
}

/* Main Layout Grid */
.main-layout {
  display: grid;
  grid-template-columns: 320px 1fr 380px;
  height: calc(100vh - 54px);
  overflow: hidden;
}

/* Panels */
.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(10px);
  border-right: 1px solid var(--border-cyan);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1rem;
  gap: 0.75rem;
}

.right-panel {
  border-right: none;
  border-left: 1px solid var(--border-cyan);
}

.panel-header {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--cyan-bright);
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(0, 240, 255, 0.2);
}

.header-icon { color: var(--emerald-bright); }

/* Telemetry Cards */
.telemetry-card {
  background: rgba(0, 25, 35, 0.65);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 4px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-title {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 1px;
}

.gauge-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.gauge-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gauge-item .label {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.gauge-item .value {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
}

.progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.progress-bar .fill {
  height: 100%;
  transition: width 0.3s ease;
}

.fill.ok { background: var(--emerald-bright); box-shadow: 0 0 6px var(--emerald-bright); }
.fill.warn { background: var(--orange-warn); box-shadow: 0 0 6px var(--orange-warn); }
.fill.danger { background: var(--red-danger); box-shadow: 0 0 6px var(--red-danger); }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.stat-row b { color: var(--text-main); }
.stat-row b.highlight { color: var(--emerald-bright); }

.sub-stats {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
}

.subsystem-list {
  list-style: none;
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
}

.subsystem-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.subsystem-list li i {
  color: var(--cyan-bright);
  font-style: normal;
  margin-left: auto;
}

.sub-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.sub-dot.ok { background: var(--emerald-bright); }

/* Center Stage Viewport */
.center-stage {
  position: relative;
  background: transparent;
  overflow: hidden;
}

#three-container {
  width: 100%;
  height: 100%;
}

.room-toolbar {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  background: rgba(2, 12, 18, 0.9);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-cyan);
  backdrop-filter: blur(8px);
  z-index: 5;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
}

.btn-room {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 4px 9px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.btn-room:hover, .btn-room.active {
  background: rgba(0, 240, 255, 0.2);
  border-color: var(--cyan-bright);
  color: #fff;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.viewport-overlay {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.camera-info {
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.65);
  padding: 4px 8px;
  border-radius: 3px;
}

.active-activity-pill {
  color: var(--emerald-bright);
  background: rgba(0, 255, 170, 0.12);
  border: 1px solid rgba(0, 255, 170, 0.35);
  padding: 4px 12px;
  border-radius: 12px;
}

/* First Person Helmet Visor HUD */
.visor-hud-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2rem;
}

.visor-glass-edge {
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 80px rgba(0, 240, 255, 0.25), inset 0 0 140px rgba(0, 0, 0, 0.6);
  border-radius: 35px;
  border: 2px solid rgba(0, 240, 255, 0.25);
  pointer-events: none;
}

.visor-top-bar {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--cyan-bright);
  text-shadow: 0 0 8px var(--cyan-bright);
  z-index: 21;
}

.crosshair-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border: 2px solid rgba(0, 255, 170, 0.7);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(0, 255, 170, 0.8);
  pointer-events: none;
  z-index: 21;
}

.interact-prompt {
  position: absolute;
  top: 58%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(2, 20, 28, 0.85);
  border: 1px solid var(--emerald-bright);
  color: var(--emerald-bright);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 6px 14px;
  border-radius: 4px;
  box-shadow: 0 0 14px rgba(0, 255, 170, 0.4);
  z-index: 21;
}

.visor-bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-main);
  z-index: 21;
}

.visor-vital-box {
  display: flex;
  gap: 12px;
  background: rgba(0, 20, 30, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.3);
  padding: 6px 12px;
  border-radius: 4px;
}

.visor-nav-help {
  color: var(--text-muted);
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.6);
  padding: 4px 10px;
  border-radius: 3px;
}

/* Crew Cards */
.crew-roster-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crew-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 25, 35, 0.65);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 4px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.crew-card:hover {
  background: rgba(0, 240, 255, 0.12);
  border-color: var(--cyan-bright);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.25);
}

.btn-mini-possess {
  background: rgba(0, 255, 170, 0.15);
  border: 1px solid var(--emerald-bright);
  color: var(--emerald-bright);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-mini-possess:hover {
  background: var(--emerald-bright);
  color: #000;
}

.crew-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  border: 2px solid var(--cyan-bright);
}

.vance-avatar { background: #0a3d62; color: #60a5fa; }
.tanaka-avatar { background: #064e3b; color: #34d399; }
.rostova-avatar { background: #581c87; color: #c084fc; }

.crew-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1;
}

.crew-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.crew-activity {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--emerald-bright);
}

.vitals-mini {
  display: flex;
  gap: 8px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.vitals-mini b { color: var(--text-main); }

/* CAPCOM Section */
.capcom-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border-cyan);
  border-radius: 4px;
  overflow: hidden;
}

.capcom-delay-selector {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.4);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(0, 240, 255, 0.15);
}

.capcom-delay-selector label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
}

.terminal-feed {
  flex-grow: 1;
  min-height: 180px;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
}

.msg {
  padding: 4px 8px;
  border-radius: 3px;
  line-height: 1.4;
  word-break: break-word;
}

.msg.sys {
  background: rgba(0, 240, 255, 0.05);
  color: var(--cyan-dim);
  border-left: 2px solid var(--cyan-dim);
}

.msg.uplink {
  background: rgba(0, 255, 170, 0.1);
  color: var(--emerald-bright);
  border-left: 2px solid var(--emerald-bright);
}

.msg.downlink {
  background: rgba(192, 68, 255, 0.1);
  color: #e9d5ff;
  border-left: 2px solid var(--purple-accent);
}

.capcom-input-bar {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-cyan);
}

.recipient-select {
  background: var(--bg-dark);
  border: 1px solid var(--border-cyan);
  color: var(--cyan-bright);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 4px;
  border-radius: 2px;
}

#capcom-text-input {
  flex-grow: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border-cyan);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 6px 8px;
  border-radius: 2px;
}

#capcom-text-input:focus {
  outline: none;
  border-color: var(--cyan-bright);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}

.btn-send {
  background: var(--cyan-dim);
  border: 1px solid var(--cyan-bright);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0 12px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s;
}

.btn-send:hover {
  background: var(--cyan-bright);
  color: #000;
  box-shadow: 0 0 10px var(--cyan-bright);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-backdrop.hidden { display: none; }

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--cyan-bright);
  box-shadow: 0 0 35px rgba(0, 240, 255, 0.35);
  border-radius: 6px;
  width: 90vw;
  max-width: 680px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: rgba(0, 240, 255, 0.1);
  border-bottom: 1px solid var(--border-cyan);
}

.modal-header h2 {
  font-size: 0.95rem;
  letter-spacing: 1.5px;
  color: var(--cyan-bright);
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.btn-close:hover { color: #fff; }

.modal-body {
  padding: 1.25rem;
  display: flex;
  gap: 1.5rem;
}

.inspect-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  min-width: 160px;
}

.profile-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #0a3d62;
  border: 3px solid var(--cyan-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--cyan-bright);
}

.profile-details {
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inspect-right {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.inspect-right h3 {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--cyan-bright);
}

.memory-stream-box {
  background: rgba(0, 10, 15, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 4px;
  padding: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.malfunction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.malfunction-card {
  background: rgba(40, 10, 15, 0.6);
  border: 1px solid rgba(255, 51, 68, 0.4);
  border-radius: 4px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.malfunction-card h4 {
  color: var(--red-danger);
  font-size: 0.85rem;
}

.malfunction-card p {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.btn-danger {
  background: rgba(255, 51, 68, 0.2);
  border: 1px solid var(--red-danger);
  color: var(--red-danger);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 2px;
  margin-top: auto;
  transition: all 0.2s;
}

.btn-danger:hover {
  background: var(--red-danger);
  color: #fff;
  box-shadow: 0 0 10px var(--red-danger);
}
