:root {
  --deepest: #050A0F;
  --deep: #0A1219;
  --space: #0F1924;
  --teal: #79BBC3;
  --teal-soft: #5EA8B1;
  --cyan: #A5D8E0;
  --blue: #3F7994;
  --ghost: #2A5674;
  --text: #E2EEF3;
  --text-dim: #9FB8C3;
  --border: rgba(121, 188, 195, 0.25);
  --panel-bg: rgba(10, 18, 25, 0.92);
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--deepest);
  color: var(--text);
  font-family: 'Inter', system_ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  touch-action: none; /* Important for 3D controls */
}

/* Canvas */
#three-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

/* Loading Screen */
.loading {
  position: fixed;
  inset: 0;
  background: var(--deepest);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s;
}

.loading.hidden {
  opacity: 0;
  visibility: hidden;
}

.loading-content {
  text-align: center;
}

.loading-subtitle {
  font-size: 14px;
  letter-spacing: 3px;
  color: var(--teal);
  margin-top: 8px;
  opacity: 0.9;
}

.loading-bar {
  width: 180px;
  height: 2px;
  background: rgba(121, 188, 195, 0.15);
  margin: 32px auto 0;
  border-radius: 2px;
  overflow: hidden;
}

.loading-progress {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--teal), var(--cyan));
  animation: load-progress 2.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes load-progress {
  to { width: 100%; }
}

.loading-text {
  font-size: 10px;
  letter-spacing: 2px;
  margin-top: 14px;
  color: var(--text-dim);
  opacity: 0.7;
}

/* HUD */
.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: 24px;
  font-size: 13px;
}

.hud > * {
  pointer-events: auto;
}

/* Top Left Brand */
.hud-top-left {
  position: absolute;
  top: 24px;
  left: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 10px 18px 10px 14px;
  border-radius: 12px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ═══ WORDMARK LOGO (enso-based) ═══ */
.wordmark {
  display: flex;
  align-items: center;
  font-weight: 200;
  font-size: 26px;
  letter-spacing: .06em;
  color: var(--text);
  opacity: 0.72;
  transition: opacity 0.6s ease;
  text-decoration: none;
}
.wordmark:hover { opacity: 1; }
.wordmark .enso-o {
  width: .92em;
  height: .92em;
  margin: 0 .03em;
  transform: translateY(.06em);
}
.spin {
  transform-origin: 50% 50%;
  animation: spin 110s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Loading screen wordmark */
.load-wordmark {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
.load-wordmark .wordmark {
  font-size: 48px;
  opacity: 1;
  color: var(--text);
}
.load-wordmark .enso-o {
  width: .95em;
  height: .95em;
}

/* HUD wordmark */
.hud-wordmark {
  font-size: 24px;
}
.hud-wordmark + div .brand-tag {
  font-size: 10px;
  color: var(--teal-soft);
  letter-spacing: 1px;
}

.brand-name {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-weight: 600;
  letter-spacing: 2.5px;
  font-size: 15px;
}

.brand-tag {
  font-size: 10px;
  color: var(--teal-soft);
  letter-spacing: 1px;
  margin-top: 1px;
}

/* Top Right Stats */
.hud-top-right {
  position: absolute;
  top: 24px;
  right: 24px;
}

.stats {
  display: flex;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px 6px 6px 14px;
  backdrop-filter: blur(12px);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0 10px;
  border-right: 1px solid rgba(121, 188, 195, 0.15);
}

.stat:last-child {
  border-right: none;
  padding-right: 6px;
}

.stat-value {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
}

.stat-label {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-top: 3px;
}

.stat.status {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 8px #4ade80;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Bottom Left Legend */
.hud-bottom-left {
  position: absolute;
  bottom: 24px;
  left: 24px;
}

.legend {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  backdrop-filter: blur(12px);
  font-size: 11px;
}

.legend-title {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
  color: var(--text-dim);
}

.legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px currentColor;
}

.legend-swatch.active { background: var(--teal); color: var(--teal); }
.legend-swatch.bootstrap { background: var(--blue); color: var(--blue); }
.legend-swatch.planned { background: #4A6A7F; color: #4A6A7F; }
.legend-swatch.ghost { background: var(--ghost); color: var(--ghost); box-shadow: none; }

/* Bottom Center Timeline */
.hud-bottom-center {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 620px;
  padding: 0 24px;
}

.timeline-container {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px 16px;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.timeline-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.timeline-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--teal);
  flex: 1;
}

.play-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(121, 188, 195, 0.15);
  border: 1px solid var(--border);
  color: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.15s ease;
}

.play-btn:hover {
  background: rgba(121, 188, 195, 0.25);
  border-color: var(--teal);
}

.play-btn.playing {
  background: var(--teal);
  color: var(--deepest);
}

.current-time {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  min-width: 84px;
  text-align: right;
}

.timeline-slider-wrap {
  position: relative;
  padding: 4px 0 8px;
}

#timeline-slider {
  width: 100%;
  accent-color: var(--teal);
  height: 3px;
  background: rgba(121, 188, 195, 0.2);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}

#timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--teal);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(121, 188, 195, 0.2);
  cursor: pointer;
  transition: all 0.1s;
}

#timeline-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 6px rgba(121, 188, 195, 0.3);
}

.timeline-markers {
  position: relative;
  height: 14px;
  margin-top: -2px;
  font-size: 9px;
  color: var(--text-dim);
  opacity: 0.6;
}

.marker {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
  font-size: 9px;
}

.timeline-scrub-hint {
  font-size: 9px;
  color: var(--text-dim);
  opacity: 0.5;
  text-align: center;
  margin-top: 4px;
  letter-spacing: 0.3px;
}

/* Bottom Right Controls Hint */
.hud-bottom-right {
  position: absolute;
  bottom: 24px;
  right: 24px;
}

.controls-hint {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key {
  font-family: monospace;
  font-size: 10px;
  opacity: 0.85;
}

/* Info Panel */
.info-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(20px);
  z-index: 100;
  padding: 24px;
  overflow-y: auto;
  transform: translateX(0);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
}

.info-panel.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.panel-title {
  font-family: 'Space Grotesk', Inter, sans-serif;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.3px;
  line-height: 1.1;
}

.panel-host {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 3px;
}

.panel-close {
  font-size: 28px;
  line-height: 1;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.panel-close:hover {
  color: var(--teal);
}

.panel-section {
  margin-bottom: 22px;
}

.section-label {
  font-size: 10px;
  letter-spacing: 1.8px;
  color: var(--teal);
  margin-bottom: 9px;
  text-transform: uppercase;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 13px 4px 7px;
  border-radius: 999px;
  font-weight: 500;
}

.status-badge.active { background: rgba(121, 188, 195, 0.15); color: var(--teal); }
.status-badge.bootstrap { background: rgba(63, 121, 148, 0.25); color: #8EC1D9; }
.status-badge.planned { background: rgba(74, 106, 127, 0.25); color: #9AB5C7; }
.status-badge.ghost { background: rgba(42, 86, 116, 0.2); color: #6C8CA1; }

.instances-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.instance-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(121, 188, 195, 0.1);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 13px;
}

.instance-item:hover {
  background: rgba(121, 188, 195, 0.1);
  border-color: var(--border);
}

.instance-item .name {
  font-weight: 500;
}

.instance-item .meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.instance-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
}

.instance-status.stopped { background: #f87171; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--text-dim);
}

.history-item {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.history-item .date {
  font-family: monospace;
  color: var(--teal-soft);
}

.resources {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.resource {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.res-label {
  width: 36px;
  color: var(--text-dim);
  font-size: 11px;
}

.res-bar {
  flex: 1;
  height: 3px;
  background: rgba(121, 188, 195, 0.15);
  border-radius: 2px;
  overflow: hidden;
}

.res-fill {
  height: 100%;
  background: linear-gradient(to right, var(--teal), var(--cyan));
  transition: width 0.4s ease;
}

.res-val {
  font-family: 'Space Grotesk', Inter, sans-serif;
  width: 38px;
  text-align: right;
  font-size: 12px;
  font-weight: 500;
}

.panel-footer {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.focus-btn {
  width: 100%;
  padding: 12px;
  background: rgba(121, 188, 195, 0.1);
  border: 1px solid var(--border);
  color: var(--teal);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.focus-btn:hover {
  background: var(--teal);
  color: var(--deepest);
  border-color: var(--teal);
}

/* Instance Tooltip */
.instance-tooltip {
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12px;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: 210px;
  backdrop-filter: blur(14px);
}

.instance-tooltip.hidden {
  display: none;
}

/* Mobile Hint */
.mobile-hint {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 18, 25, 0.8);
  color: var(--text-dim);
  font-size: 11px;
  padding: 5px 14px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 50;
  display: none;
  backdrop-filter: blur(10px);
}

/* Responsive */
@media (max-width: 780px) {
  .hud-top-right .stats {
    padding: 5px 4px;
  }
  .stat {
    padding: 0 6px;
  }
  .stat-value { font-size: 15px; }
  
  .hud-bottom-left {
    left: 12px;
    bottom: 12px;
  }
  .hud-bottom-right {
    display: none;
  }
  
  .hud-bottom-center {
    bottom: 12px;
    max-width: calc(100% - 24px);
    padding: 0 12px;
  }
  
  .info-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    top: auto;
    bottom: 0;
    height: 62vh;
    border-radius: 16px 16px 0 0;
  }
  
  .mobile-hint {
    display: block;
  }
}

@media (max-width: 520px) {
  .brand {
    padding: 8px 12px 8px 10px;
  }
  .brand-name { font-size: 13px; }
  .hud-top-left { left: 12px; top: 12px; }
  .hud-top-right { right: 12px; top: 12px; }
}

/* Selection highlight styles */
.selected-node {
  /* Handled in JS via Three.js */
}

#timeline-slider {
  position: relative;
  z-index: 1;
}

/* Scrollbar for panel */
.info-panel::-webkit-scrollbar {
  width: 4px;
}
.info-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}