:root {
  --bg-color: #07090e;
  --surface-panel: rgba(13, 17, 26, 0.82);
  --surface-panel-border: rgba(255, 255, 255, 0.1);
  --surface-card: rgba(255, 255, 255, 0.04);
  --surface-card-hover: rgba(255, 255, 255, 0.08);
  --text-main: #f0f4fc;
  --text-muted: #8b9bb4;
  --text-sub: #5c6c84;
  --accent-cyan: #00f0ff;
  --accent-violet: #a855f7;
  --accent-crimson: #ff3366;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-panel: 0 16px 36px -4px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
}

#app-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#sim-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  cursor: crosshair;
}

#sim-canvas.panning {
  cursor: grab;
}

#sim-canvas.panning:active {
  cursor: grabbing;
}

/* Glass panel shared styling */
.glass-panel {
  background: var(--surface-panel);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--surface-panel-border);
  box-shadow: var(--shadow-panel);
  border-radius: var(--radius-lg);
}

/* Top Telemetry Header Bar */
#top-bar {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
  background: rgba(11, 15, 23, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-panel-border);
  border-radius: 999px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-glyph {
  color: var(--accent-cyan);
  font-size: 18px;
  filter: drop-shadow(0 0 10px rgba(0, 240, 255, 0.7));
  animation: pulse-glow 3s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 2.5px;
  background: linear-gradient(135deg, #ffffff 30%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
  padding-left: 10px;
}

.quick-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.8px;
  color: var(--text-sub);
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-cyan);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  padding: 6px 13px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.icon-btn.active {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Floating Controls Panel */
#controls-panel {
  position: absolute;
  top: 80px;
  right: 20px;
  width: 370px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  z-index: 10;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

#controls-panel.hidden {
  transform: translateX(400px);
  opacity: 0;
  pointer-events: none;
}

#controls-panel::-webkit-scrollbar {
  width: 4px;
}
#controls-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.panel-sub {
  display: block;
  font-size: 10px;
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.panel-hint {
  font-size: 11px;
  color: var(--text-sub);
}

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

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.badge-btn {
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.3);
  color: #c084fc;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.badge-btn:hover {
  background: rgba(168, 85, 247, 0.3);
  border-color: #c084fc;
}

/* Preset Cards */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-chip {
  background: var(--surface-card);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  background: var(--surface-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
}

.preset-chip.active {
  background: rgba(0, 240, 255, 0.12);
  border-color: rgba(0, 240, 255, 0.5);
}

.preset-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  display: block;
}

.preset-desc {
  font-size: 10px;
  color: var(--text-sub);
  margin-top: 2px;
  display: block;
  line-height: 1.3;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.segment-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.segment-btn:hover {
  color: var(--text-main);
}

.segment-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent-cyan);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Force Matrix Grid */
.matrix-wrapper {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.matrix-legend {
  display: flex;
  gap: 10px;
  font-size: 10px;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-sub);
}

.leg-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.leg-item .dot.attract { background: var(--accent-emerald); }
.leg-item .dot.repel { background: var(--accent-crimson); }

.matrix-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.matrix-header-cell, .matrix-cell {
  width: 38px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
}

.matrix-header-cell {
  color: var(--text-muted);
  font-weight: 700;
}

.matrix-cell {
  cursor: ew-resize;
  transition: transform 0.1s ease;
  user-select: none;
}

.matrix-cell:hover {
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.2);
  z-index: 2;
}

.matrix-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.action-btn-sm {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 10px;
  padding: 5px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn-sm:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Physics Controls Sliders */
.control-row {
  margin-bottom: 12px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.control-num {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Footer / Actions */
.button-row {
  display: flex;
  gap: 8px;
}

.btn-primary, .btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.btn-primary {
  flex: 1.4;
  background: linear-gradient(135deg, #00d2ff, #0077ff);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 119, 255, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(0, 119, 255, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

/* Bottom status hints */
#status-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  background: rgba(11, 15, 23, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  color: var(--text-sub);
  z-index: 5;
  pointer-events: none;
}

.key-hint {
  display: flex;
  align-items: center;
  gap: 5px;
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

@media (max-width: 820px) {
  #top-bar {
    left: 10px;
    right: 10px;
    padding: 0 12px;
  }
  .brand-subtitle, #stat-interactions, #stat-zoom {
    display: none;
  }
  #controls-panel {
    width: calc(100vw - 20px);
    right: 10px;
  }
}
