/* ========== CSS VARIABLES ========== */
:root {
  --bg-deep: #0a0e17;
  --bg-surface: #111827;
  --bg-card: #1a2234;
  --bg-hover: #1e293b;
  --border: #2a3548;
  --border-light: #374151;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-cyan: #22d3ee;
  --accent-pink: #f472b6;
  --accent-green: #4ade80;
  --accent-orange: #fb923c;
  --accent-purple: #a78bfa;
  --accent-yellow: #fbbf24;
  --accent-red: #f87171;
  --accent-blue: #60a5fa;

  --glow-cyan: 0 0 20px rgba(34, 211, 238, 0.3);
  --glow-pink: 0 0 20px rgba(244, 114, 182, 0.3);
  --glow-green: 0 0 20px rgba(74, 222, 128, 0.3);

  --font-display: 'Playfair Display', serif;
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --sidebar-width: 280px;
  --topbar-height: 60px;
  --info-height: 220px;

  --radius: 12px;
  --radius-sm: 8px;
}

/* ========== RESET ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  display: flex;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ========== SIDEBAR ========== */
#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 100;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-cyan);
  letter-spacing: -0.5px;
}

.sidebar-sections {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.section-group {
  margin-bottom: 8px;
}

.section-title {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 16px 12px 8px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-btn.active {
  background: rgba(34, 211, 238, 0.1);
  color: var(--accent-cyan);
  box-shadow: inset 3px 0 0 var(--accent-cyan);
}

.nav-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
}

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

.hint-text {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

/* ========== MAIN ========== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

/* ========== TOP BAR ========== */
#topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

#module-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-primary);
  white-space: nowrap;
}

#formula-display {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--accent-cyan);
  background: rgba(34, 211, 238, 0.08);
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid rgba(34, 211, 238, 0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
}

/* ========== CANVAS ========== */
#canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg-deep);
  min-height: 0;
}

#geo-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transition: opacity 0.15s;
}

#tooltip.hidden {
  opacity: 0;
}

/* ========== INFO PANEL ========== */
#info-panel {
  height: var(--info-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 1px;
  flex-shrink: 0;
  overflow: hidden;
}

#calculations {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--bg-surface);
}

#calculations h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42, 53, 72, 0.5);
}

.calc-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.calc-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-cyan);
}

.calc-value.pink { color: var(--accent-pink); }
.calc-value.green { color: var(--accent-green); }
.calc-value.orange { color: var(--accent-orange); }
.calc-value.purple { color: var(--accent-purple); }
.calc-value.yellow { color: var(--accent-yellow); }

#theory-box {
  flex: 1.2;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
}

#theory-content h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

#theory-content p {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

#theory-content .formula-block {
  background: rgba(34, 211, 238, 0.06);
  border: 1px solid rgba(34, 211, 238, 0.15);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-cyan);
  margin: 8px 0;
  line-height: 1.6;
}

#controls-panel {
  width: 240px;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
}

#controls-panel h3 {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.control-group {
  margin-bottom: 14px;
}

.control-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.control-group input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  box-shadow: var(--glow-cyan);
}

.control-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  cursor: pointer;
  border: none;
}

.control-group .range-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-cyan);
  float: right;
  margin-top: -18px;
}

.control-group select {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

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

.control-btn {
  padding: 8px 16px;
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  margin-top: 4px;
}

.control-btn:hover {
  background: rgba(34, 211, 238, 0.2);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.checkbox-group input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  width: 14px;
  height: 14px;
}

.checkbox-group label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 0;
  cursor: pointer;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: 20px 0 60px rgba(0,0,0,0.5);
  }

  #menu-toggle {
    display: block;
  }

  #info-panel {
    flex-direction: column;
    height: auto;
    max-height: 300px;
    overflow-y: auto;
  }

  #controls-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  #theory-box {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  #formula-display {
    display: none;
  }
}

@media (max-width: 600px) {
  :root {
    --topbar-height: 50px;
  }
  #module-title {
    font-size: 16px;
  }
}

/* ========== ANIMATIONS ========== */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(34, 211, 238, 0.3); }
  50% { box-shadow: 0 0 20px rgba(34, 211, 238, 0.6); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.calc-row {
  animation: fadeIn 0.3s ease forwards;
}

/* Overlay for mobile sidebar */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

#sidebar-overlay.show {
  display: block;
}
