/* Design Tokens & Variables */
:root {
  --bg-color: #060813;
  --bg-gradient: radial-gradient(circle at center, #0f1635 0%, #050710 100%);
  --panel-bg: rgba(10, 15, 35, 0.65);
  --panel-border: rgba(0, 240, 255, 0.15);
  --panel-border-focus: rgba(0, 240, 255, 0.4);
  --text-primary: #f0f3ff;
  --text-secondary: #8c9bb4;
  --text-muted: #52637f;
  
  /* Theme Accents (Default: Sapphire) */
  --accent-primary: #00f0ff;
  --accent-secondary: #0064dc;
  --accent-dark: #0a1450;
  --accent-glow: rgba(0, 240, 255, 0.35);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --sidebar-width: 380px;
  --header-height: 70px;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  
  --shadow-glow: 0 0 20px var(--accent-glow);
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-color);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

/* App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Header */
.app-header {
  height: var(--header-height);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(6, 8, 19, 0.8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 24px;
  color: var(--accent-primary);
  filter: drop-shadow(0 0 8px var(--accent-glow));
  animation: logo-spin 10s linear infinite;
}

@keyframes logo-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.logo-text h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.1;
  background: linear-gradient(90deg, var(--text-primary) 0%, var(--accent-primary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-text span {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.header-status {
  display: flex;
  gap: 20px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.green {
  background-color: #00e676;
  box-shadow: 0 0 8px #00e676;
}

.status-dot.blue {
  background-color: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-primary);
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  gap: 10px;
}

/* Main Body */
.app-body {
  display: flex;
  flex: 1;
  position: relative;
  height: calc(100vh - var(--header-height));
}

/* Sidebar Panel */
.sidebar-panel {
  width: var(--sidebar-width);
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  z-index: 5;
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
  transition: var(--transition-smooth);
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px;
  gap: 2px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 12px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition-smooth);
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.tab-btn.active {
  background: rgba(0, 240, 255, 0.1);
  color: var(--accent-primary);
  border: 1px solid rgba(0, 240, 255, 0.2);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

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

/* Control Groups */
.control-group {
  margin-bottom: 24px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 16px;
}

.control-group h3 {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-primary);
  margin-bottom: 16px;
  border-left: 3px solid var(--accent-primary);
  padding-left: 8px;
}

.control-row {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.num-display {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-primary);
  font-weight: bold;
}

/* Range Inputs */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
  transition: var(--transition-smooth);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-primary);
  cursor: pointer;
  transition: var(--transition-smooth);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 12px var(--accent-primary), 0 0 20px var(--accent-primary);
}

/* Checkbox and Select styling */
.checkbox-row {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.checkbox-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 40px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  position: relative;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.checkbox-row input[type="checkbox"]:checked {
  background: var(--accent-secondary);
  box-shadow: 0 0 10px rgba(0, 100, 220, 0.5);
}

.checkbox-row input[type="checkbox"]::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-primary);
  top: 3px;
  left: 3px;
  transition: var(--transition-smooth);
}

.checkbox-row input[type="checkbox"]:checked::before {
  left: 23px;
  background: var(--accent-primary);
}

select {
  width: 100%;
  padding: 10px;
  background: rgba(10, 15, 30, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}

/* Button & Button Grid */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-smooth);
  text-decoration: none;
  white-space: nowrap;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-secondary) 0%, #00a2ff 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0, 100, 220, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 100, 220, 0.5), 0 0 10px var(--accent-primary);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
}

.btn-danger {
  background: rgba(220, 20, 60, 0.15);
  border: 1px solid rgba(220, 20, 60, 0.3);
  color: #ff5e7e;
}

.btn-danger:hover {
  background: rgba(220, 20, 60, 0.3);
  border-color: #ff5e7e;
  box-shadow: 0 0 15px rgba(220, 20, 60, 0.2);
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Theme Selector Grid */
.theme-selector-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.theme-btn {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-smooth);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.theme-btn:hover {
  transform: scale(1.15);
}

.theme-btn.active {
  border-color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

/* Telemetry Table */
.telemetry-table {
  width: 100%;
  border-collapse: collapse;
}

.telemetry-table td {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 13px;
}

.telemetry-table tr:last-child td {
  border-bottom: none;
}

.telemetry-table .lbl {
  color: var(--text-secondary);
  font-weight: 500;
}

.telemetry-table .val {
  text-align: right;
  font-weight: 600;
  color: var(--text-primary);
}

.telemetry-table .val.num {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Energy Bars */
.energy-bar-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.energy-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.energy-bar-row .lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  width: 65px;
}

.energy-bar-row .bar-outer {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
}

.energy-bar-row .bar-inner {
  height: 100%;
  border-radius: 4px;
  width: 0%;
  transition: width 0.1s linear;
}

.energy-bar-row .bar-inner.kinetic {
  background: #00f0ff;
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.7);
}

.energy-bar-row .bar-inner.potential {
  background: #ffc107;
  box-shadow: 0 0 8px rgba(255, 193, 7, 0.7);
}

.energy-bar-row .bar-inner.total {
  background: #ff2a85;
  box-shadow: 0 0 8px rgba(255, 42, 133, 0.7);
}

.energy-bar-row .val {
  width: 75px;
  text-align: right;
  font-size: 12px;
}

/* Simulation Space */
.simulation-space {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 20px;
  overflow: hidden;
  height: 100%;
}

.canvas-container {
  flex: 1;
  position: relative;
  background: rgba(5, 7, 18, 0.9);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 240, 255, 0.05), 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

#sim-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.canvas-overlay {
  position: absolute;
  pointer-events: none;
  background: rgba(6, 8, 19, 0.75);
  backdrop-filter: blur(4px);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.instruction-overlay {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  animation: fade-in-out 6s forwards;
}

@keyframes fade-in-out {
  0% { opacity: 0; transform: translate(-50%, -10px); }
  10% { opacity: 1; transform: translate(-50%, 0); }
  90% { opacity: 1; }
  100% { opacity: 0.2; transform: translate(-50%, 0); }
}

.canvas-container:hover .instruction-overlay {
  opacity: 1;
  animation: none;
}

.quick-action-bar {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

/* Graph Panel */
.graph-panel {
  height: 200px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

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

.panel-header h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.graph-legend {
  display: flex;
  gap: 15px;
  font-size: 11px;
  font-weight: 600;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.legend-color {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.legend-color.kinetic { background-color: #00f0ff; }
.legend-color.potential { background-color: #ffc107; }
.legend-color.total { background-color: #ff2a85; }

.graph-body {
  flex: 1;
  position: relative;
  width: 100%;
}

#graph-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(3, 4, 10, 0.85);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: rgba(10, 15, 35, 0.95);
  border: 1px solid var(--accent-primary);
  box-shadow: 0 0 30px rgba(0, 240, 255, 0.25), 0 20px 50px rgba(0,0,0,0.8);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  transform: translateY(30px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-primary);
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-close:hover {
  color: #ff5e7e;
  transform: scale(1.1);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text-secondary);
}

.theory-section {
  margin-bottom: 24px;
}

.theory-section:last-child {
  margin-bottom: 0;
}

.theory-section h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 6px;
}

.theory-section p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.theory-section ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.theory-section li {
  margin-bottom: 8px;
  line-height: 1.5;
}

.theory-section strong {
  color: var(--accent-primary);
}

/* Scrollbars styling */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* Responsiveness */
@media (max-width: 1024px) {
  .app-body {
    flex-direction: column;
    overflow-y: auto;
  }
  
  body {
    overflow-y: auto;
  }

  .sidebar-panel {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }
  
  .simulation-space {
    height: auto;
    min-height: 600px;
    padding: 10px;
  }
  
  .canvas-container {
    height: 400px;
  }
}
