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

:root {
  --bg-deep: #0a0a0f;
  --bg-panel: rgba(13, 17, 23, 0.88);
  --bg-editor: #0d1117;
  --accent-cyan: #00f0ff;
  --accent-magenta: #ff00aa;
  --accent-green: #00ff88;
  --accent-yellow: #ffd700;
  --text-primary: #e6edf3;
  --text-dim: #7d8590;
  --border-color: rgba(0, 240, 255, 0.15);
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --glow-cyan: 0 0 10px rgba(0, 240, 255, 0.4);
  --glow-magenta: 0 0 10px rgba(255, 0, 170, 0.4);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: var(--font-mono);
  color: var(--text-primary);
}

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

/* Nav Bar */
#nav-bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 48px; z-index: 100;
  display: flex; align-items: center;
  padding: 0 12px; gap: 12px;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
}

#nav-left { display: flex; align-items: center; flex-shrink: 0; }

#app-title {
  font-size: 14px; font-weight: 700;
  color: var(--accent-cyan);
  text-shadow: var(--glow-cyan);
  white-space: nowrap;
}

#demo-select {
  flex: 1;
  max-width: 220px;
  min-width: 120px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: rgba(255,255,255,0.04);
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2300f0ff' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
#demo-select:hover {
  background-color: rgba(0, 240, 255, 0.08);
  border-color: rgba(0, 240, 255, 0.4);
}
#demo-select:focus {
  border-color: var(--accent-cyan);
  box-shadow: var(--glow-cyan);
}
#demo-select option {
  background: #0d1117;
  color: var(--text-primary);
  font-family: var(--font-mono);
  padding: 6px;
}

#nav-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

#fps-counter {
  font-size: 11px; color: var(--accent-green);
  text-shadow: 0 0 6px rgba(0, 255, 136, 0.3);
  min-width: 52px;
}

#nav-right button, #editor-actions button {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
#nav-right button:hover, #editor-actions button:hover {
  background: rgba(0, 240, 255, 0.12);
  border-color: var(--accent-cyan);
}

/* Editor Panel */
#editor-panel {
  position: fixed;
  top: 48px; left: 0;
  width: 440px;
  bottom: 32px;
  z-index: 50;
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
#editor-panel.collapsed { transform: translateX(-100%); }

#editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
#editor-title { font-size: 12px; color: var(--accent-magenta); font-weight: 500; }
#editor-actions { display: flex; gap: 4px; }
#editor-actions button { font-size: 11px; padding: 3px 8px; }

#editor-wrap {
  flex: 1; position: relative;
  overflow: hidden;
  background: var(--bg-editor);
}

#line-numbers {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 42px;
  overflow: hidden;
  z-index: 3;
}

#line-numbers-inner {
  padding: 10px 6px 10px 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px; line-height: 1.5;
  color: var(--text-dim);
  white-space: pre;
  user-select: none; pointer-events: none;
  will-change: transform;
}

#code-editor {
  display: block;
  width: 100%;
  height: 100%;
  padding: 10px 12px 10px 48px;
  background: transparent;
  border: none; outline: none; resize: none;
  font-family: var(--font-mono);
  font-size: 12px; line-height: 1.5;
  color: transparent;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  z-index: 2;
  position: relative;
  caret-color: var(--accent-cyan);
  -webkit-text-fill-color: transparent;
}

#code-editor::selection {
  background: rgba(0, 240, 255, 0.2);
  -webkit-text-fill-color: transparent;
}

#syntax-overlay {
  position: absolute; left: 0; top: 0;
  width: 100%;
  padding: 10px 12px 10px 48px;
  font-family: var(--font-mono);
  font-size: 12px; line-height: 1.5;
  white-space: pre;
  overflow-wrap: normal;
  pointer-events: none;
  z-index: 1;
}

.syn-keyword { color: #ff7b72; }
.syn-type { color: #79c0ff; }
.syn-func { color: #d2a8ff; }
.syn-number { color: #a5d6ff; }
.syn-comment { color: #484f58; font-style: italic; }
.syn-define { color: #ffa657; }
.syn-string { color: var(--accent-green); }

#error-bar {
  flex-shrink: 0;
  max-height: 80px;
  overflow-y: auto;
  background: rgba(255, 50, 50, 0.12);
  border-top: 1px solid rgba(255, 50, 50, 0.3);
  color: #ff6b6b;
  font-size: 11px;
  padding: 0;
  display: none;
  line-height: 1.4;
}
#error-bar.visible { display: block; padding: 6px 10px; }

#uniform-controls {
  flex-shrink: 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border-color);
  max-height: 180px;
  overflow-y: auto;
}

#builtin-uniforms {
  display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-dim);
  margin-bottom: 6px;
}
.uniform-label span { color: var(--accent-yellow); }

#time-controls {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; flex-wrap: wrap;
}
#time-controls button {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 14px; padding: 2px 8px;
  border-radius: 4px; cursor: pointer;
}
#time-controls label { display: flex; align-items: center; gap: 4px; color: var(--text-dim); }
#time-controls input[type="range"] {
  width: 70px; accent-color: var(--accent-cyan);
}

#custom-sliders { margin-top: 6px; }
.slider-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; color: var(--text-dim); margin: 3px 0;
}
.slider-row input[type="range"] { flex: 1; accent-color: var(--accent-magenta); }
.slider-row .slider-val { color: var(--accent-yellow); min-width: 40px; text-align: right; }

#editor-resize-handle {
  position: absolute; right: -3px; top: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 60;
}

/* Help Modal */
#help-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.25s;
}
#help-modal.modal-hidden { display: none; }

#help-content {
  background: var(--bg-editor);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  max-width: 620px; width: 90%; max-height: 80vh;
  overflow-y: auto; padding: 24px;
  position: relative;
}
#help-content h2 { font-size: 16px; color: var(--accent-cyan); margin-bottom: 16px; }
#help-content h3 { font-size: 13px; color: var(--accent-magenta); margin: 14px 0 6px; }
#help-content p, #help-content li { font-size: 12px; line-height: 1.6; color: var(--text-dim); }
#help-content code { background: rgba(255,255,255,0.06); padding: 1px 5px; border-radius: 3px; color: var(--accent-green); font-size: 11px; }
#help-content ul { padding-left: 18px; }
#close-help {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--text-dim);
  font-size: 18px; cursor: pointer;
}

/* Footer */
#app-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 32px; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-color);
  font-size: 11px; color: var(--text-dim);
}
#app-footer a { color: var(--accent-cyan); text-decoration: none; }
#app-footer a:hover { text-decoration: underline; }

/* Toast */
#toast {
  position: fixed; bottom: 48px; left: 50%; transform: translateX(-50%);
  z-index: 300;
  background: var(--bg-editor);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
  padding: 6px 18px; border-radius: 8px;
  font-size: 12px;
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Mobile */
@media (max-width: 700px) {
  #app-title { display: none; }
  #editor-panel {
    top: auto; bottom: 32px; left: 0; right: 0;
    width: 100% !important;
    height: 50vh;
    border-right: none;
    border-top: 1px solid var(--border-color);
  }
  #editor-panel.collapsed { transform: translateY(100%); }
  #editor-resize-handle { display: none; }
}