:root {
  --bg-dark: #0a0e17;
  --bg-panel: #141926;
  --bg-card: #1a2035;
  --border-color: #2a3050;
  --text-primary: #e8edf5;
  --text-secondary: #8892a8;
  --accent-blue: #4a9eff;
  --accent-cyan: #00d4ff;
  --accent-purple: #8b5cf6;
  --accent-green: #10b981;
  --accent-orange: #f59e0b;
  --accent-red: #ef4444;
  --highlight: rgba(74, 158, 255, 0.15);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

.site-header {
  text-align: center;
  padding: 1.5rem 2rem;
  background: linear-gradient(135deg, var(--bg-panel), var(--bg-card));
  border-bottom: 1px solid var(--border-color);
}

.site-header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-top: 0.5rem;
}

.app-container {
  display: grid;
  grid-template-columns: 220px 1fr;
  height: calc(100vh - 80px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.sidebar h2 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.component-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.component-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius);
  transition: background var(--transition);
}

.component-item:hover {
  background: var(--highlight);
}

.component-item input[type="checkbox"] {
  accent-color: var(--accent-blue);
  width: 18px;
  height: 18px;
}

.component-item label {
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.sidebar-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.control-group select {
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.control-group select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.btn {
  padding: 0.6rem 1.2rem;
  background: var(--accent-blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition);
}

.btn:hover {
  background: #3a8eef;
}

.btn-secondary {
  background: var(--accent-purple);
}

.btn-secondary:hover {
  background: #7b4cf6;
}

/* Viewport */
.viewport {
  position: relative;
  background: var(--bg-dark);
  overflow: hidden;
}

#scene-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#scene-canvas:active {
  cursor: grabbing;
}

.viewport-hints {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-secondary);
  font-size: 0.85rem;
  pointer-events: none;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay p {
  color: var(--text-secondary);
}

/* Info Panel */
.info-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-color);
  transition: right 0.3s ease;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.info-panel.open {
  right: 0;
}

.close-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  line-height: 1;
}

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

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.tab-btn:hover {
  background: var(--highlight);
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Spec Cards */
.component-info {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.component-info h2 {
  font-size: 1.3rem;
  color: var(--accent-cyan);
}

.component-description {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

.spec-card {
  background: var(--bg-card);
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.spec-card h3 {
  font-size: 0.75rem;
  color: var(--accent-blue);
  margin-bottom: 0.25rem;
}

.spec-card p {
  font-size: 0.9rem;
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.timeline-item {
  display: flex;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent-blue);
}

.timeline-year {
  font-weight: 700;
  color: var(--accent-cyan);
  min-width: 50px;
}

.timeline-content h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.timeline-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Comparison Charts */
.comparison-chart {
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.comparison-chart h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--accent-purple);
}

.chart-container {
  width: 100%;
  overflow-x: auto;
}

.chart-container canvas {
  max-width: 100%;
  height: auto !important;
}

/* Simulator */
.simulator-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.simulator-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.simulator-controls label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.simulator-controls select {
  padding: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
}

.simulate-btn {
  padding: 0.75rem;
  background: var(--accent-green);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

.simulate-btn:hover {
  background: #0ea072;
}

.simulate-btn:disabled {
  background: var(--text-secondary);
  cursor: not-allowed;
}

.benchmark-display {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.progress-bar-container {
  width: 100%;
  height: 24px;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
  transition: width 0.1s linear;
}

.progress-bar.running {
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan), var(--accent-green));
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.benchmark-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.result-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.result-item strong {
  color: var(--accent-cyan);
}

/* Latency Visualization */
.latency-visualization h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--accent-orange);
}

.latency-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.latency-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 80px;
}

.latency-track {
  flex: 1;
  height: 12px;
  background: var(--bg-card);
  border-radius: 6px;
  overflow: hidden;
}

.latency-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.3s ease;
}

.latency-value {
  font-size: 0.8rem;
  color: var(--accent-cyan);
  min-width: 50px;
  text-align: right;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 800px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.close-modal {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
}

.research-editor {
  margin: 1.5rem 0;
}

.research-textarea {
  width: 100%;
  min-height: 500px;
  padding: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  resize: vertical;
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    z-index: 50;
    width: 280px;
  }

  .sidebar.open {
    left: 0;
  }

  .info-panel {
    width: 100%;
    right: -100%;
  }
}

/* Utility */
.hidden {
  display: none !important;
}
