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

:root {
  --sidebar-width: 320px;
  --sidebar-max-width: 360px;
  --bg: #0a0a0a;
  --bg-light: #fafafa;
  --fg: #e0e0e0;
  --fg-light: #1a1a1a;
  --fg-muted: #666;
  --fg-muted-light: #888;
  --border: #222;
  --border-light: #ddd;
  --surface: #111;
  --surface-light: #f0f0f0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
}

body {
  background: var(--bg);
  color: var(--fg);
}

body.light-mode {
  background: var(--bg-light);
  color: var(--fg-light);
}

#canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  /* White circle outline cursor for dark theme */
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='6' fill='none' stroke='%23ffffff' stroke-width='1.5'/%3E%3C/svg%3E") 8 8, auto;
}

body.light-mode #canvas {
  /* Black circle outline cursor for light theme */
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='6' fill='none' stroke='%23000000' stroke-width='1.5'/%3E%3C/svg%3E") 8 8, auto;
}

#canvas.panning {
  cursor: grabbing;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: var(--sidebar-width);
  max-width: var(--sidebar-max-width);
  background: var(--bg);
  border-right: 1px solid var(--border);
  color: var(--fg);
  z-index: 100;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
}

body.light-mode .sidebar {
  background: var(--bg-light);
  border-right-color: var(--border-light);
  color: var(--fg-light);
}

.sidebar.expanded {
  transform: translateX(0);
}

.sidebar.collapsed .sidebar-content {
  opacity: 0;
  pointer-events: none;
}

.sidebar.expanded .sidebar-content {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.15s ease 0.1s;
}

/* Toggle Button */
.sidebar-toggle {
  position: fixed;
  top: 12px;
  left: 12px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-muted);
  transition: all 0.2s ease;
  z-index: 101;
}

.sidebar-toggle.expanded {
  left: calc(min(var(--sidebar-width), var(--sidebar-max-width)) - 44px);
}

body.light-mode .sidebar-toggle {
  background: var(--bg-light);
  border-color: var(--border-light);
  color: var(--fg-muted-light);
}

.sidebar-toggle:hover {
  color: var(--fg);
  border-color: var(--fg-muted);
}

body.light-mode .sidebar-toggle:hover {
  color: var(--fg-light);
  border-color: var(--fg-muted-light);
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
}

.sidebar-toggle .icon-close {
  display: none;
}

.sidebar-toggle .icon-menu {
  display: block;
}

.sidebar-toggle.expanded .icon-close {
  display: block;
}

.sidebar-toggle.expanded .icon-menu {
  display: none;
}

/* Sidebar Content */
.sidebar-content {
  padding: 48px 16px 16px;
  overflow-y: auto;
  flex: 1;
}

.sidebar-content h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

body.light-mode .sidebar-content h2 {
  color: var(--fg-muted-light);
  border-bottom-color: var(--border-light);
}

/* Setting Groups */
.setting-group {
  margin-bottom: 20px;
}

.setting-group > label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
  margin-bottom: 8px;
}

body.light-mode .setting-group > label {
  color: var(--fg-muted-light);
}

.hint {
  font-size: 10px;
  color: var(--fg-muted);
  margin-bottom: 8px;
}

body.light-mode .hint {
  color: var(--fg-muted-light);
}

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 3px;
  transition: background 0.1s ease;
  font-size: 12px;
  color: var(--fg);
}

body.light-mode .checkbox-label {
  color: var(--fg-light);
}

.checkbox-label:hover {
  background: var(--surface);
}

body.light-mode .checkbox-label:hover {
  background: var(--surface-light);
}

.checkbox-label input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: var(--fg);
}

body.light-mode .checkbox-label input[type="checkbox"] {
  accent-color: var(--fg-light);
}

/* Input Row */
.input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-row input[type="range"] {
  flex: 1;
}

.input-row input[type="number"] {
  width: 60px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

body.light-mode .input-row input[type="number"] {
  border-color: var(--border-light);
}

.input-row input[type="number"]:focus {
  outline: none;
  border-color: var(--fg-muted);
}

/* Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
  cursor: pointer;
}

body.light-mode input[type="range"] {
  background: var(--border-light);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--fg);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s ease;
}

body.light-mode input[type="range"]::-webkit-slider-thumb {
  background: var(--fg-light);
}

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

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--fg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

body.light-mode input[type="range"]::-moz-range-thumb {
  background: var(--fg-light);
}

/* Matrix Container */
.matrix-container {
  display: grid;
  gap: 2px;
  margin-bottom: 10px;
}

.matrix-header {
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  padding: 2px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

.matrix-row-header {
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

.matrix-cell-wrapper {
  position: relative;
}

.matrix-cell {
  width: 100%;
  min-width: 32px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  color: inherit;
  font-size: 10px;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  text-align: center;
  padding: 0 2px;
}

body.light-mode .matrix-cell {
  border-color: var(--border-light);
}

.matrix-cell:focus {
  outline: none;
  border-color: var(--fg-muted);
}

body.light-mode .matrix-cell:focus {
  border-color: var(--fg-muted-light);
}

/* Matrix cell strength indicator dot */
.matrix-cell-dot {
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  pointer-events: none;
}

/* Particle Type Controls */
.particle-types-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.particle-type-dots {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.particle-type-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s ease, opacity 0.1s ease;
  border: none;
  box-sizing: border-box;
}

.particle-type-dot:hover {
  transform: scale(1.2);
}

.particle-type-dot::after {
  content: '×';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: bold;
  color: rgba(0, 0, 0, 0.8);
  opacity: 0;
  transition: opacity 0.1s ease;
  pointer-events: none;
}

.particle-type-dot:hover::after {
  opacity: 1;
}

.particle-type-dot.disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.particle-type-dot.disabled:hover {
  transform: none;
}

.particle-type-dot.disabled::after {
  display: none;
}

.add-type-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--fg-muted);
  background: transparent;
  color: var(--fg-muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  flex-shrink: 0;
}

body.light-mode .add-type-btn {
  border-color: var(--fg-muted-light);
  color: var(--fg-muted-light);
}

.add-type-btn:hover {
  border-color: var(--fg);
  color: var(--fg);
}

body.light-mode .add-type-btn:hover {
  border-color: var(--fg-light);
  color: var(--fg-light);
}

.add-type-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.add-type-btn:disabled:hover {
  border-color: var(--fg-muted);
  color: var(--fg-muted);
}

/* Color Options */
.color-options,
.color-scheme-options {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 3px;
  transition: background 0.1s ease;
  font-size: 12px;
}

.radio-label:hover {
  background: var(--surface);
}

body.light-mode .radio-label:hover {
  background: var(--surface-light);
}

.radio-label input[type="radio"] {
  width: 12px;
  height: 12px;
  accent-color: var(--fg);
}

body.light-mode .radio-label input[type="radio"] {
  accent-color: var(--fg-light);
}

.color-preview {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

body.light-mode .color-preview {
  border-color: var(--border-light);
}

.color-preview.dark {
  background: #000;
}

.color-preview.light {
  background: #fff;
}

/* Scheme Previews */
.scheme-preview {
  width: 32px;
  height: 14px;
  border-radius: 2px;
  border: none;
}

.scheme-preview.neon {
  background: linear-gradient(90deg, #ff006e, #8338ec, #3a86ff, #06ffa5);
}

.scheme-preview.pastel {
  background: linear-gradient(90deg, #ffadad, #ffd6a5, #caffbf, #a0c4ff);
}

.scheme-preview.warm {
  background: linear-gradient(90deg, #ff4d4d, #ff9933, #ffcc00, #ff6666);
}

.scheme-preview.cool {
  background: linear-gradient(90deg, #00b4d8, #0077b6, #90e0ef, #48cae4);
}

.scheme-preview.monochrome {
  background: linear-gradient(90deg, #f8f9fa, #adb5bd, #495057, #212529);
}

/* Buttons */
.btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.1s ease;
  background: transparent;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

body.light-mode .btn {
  border-color: var(--border-light);
  color: var(--fg-muted-light);
}

.btn:hover {
  border-color: var(--fg-muted);
  color: var(--fg);
}

body.light-mode .btn:hover {
  border-color: var(--fg-muted-light);
  color: var(--fg-light);
}

.btn + .btn {
  margin-top: 6px;
}

/* FPS Counter */
.fps-counter {
  position: fixed;
  bottom: 12px;
  right: 12px;
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-muted);
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 10px;
  border-radius: 3px;
  z-index: 50;
  pointer-events: none;
}

body.light-mode .fps-counter {
  background: var(--bg-light);
  border-color: var(--border-light);
  color: var(--fg-muted-light);
}

/* Zoom Controls */
.zoom-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  z-index: 50;
}

body.light-mode .zoom-controls {
  background: var(--bg-light);
  border-color: var(--border-light);
}

.zoom-btn {
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: var(--fg-muted);
  font-size: 14px;
  font-weight: 400;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s ease;
  line-height: 1;
}

body.light-mode .zoom-btn {
  color: var(--fg-muted-light);
}

.zoom-btn:hover {
  color: var(--fg);
}

body.light-mode .zoom-btn:hover {
  color: var(--fg-light);
}

.zoom-controls input[type="range"] {
  width: 60px;
  height: 2px;
}

.zoom-display {
  min-width: 36px;
  text-align: right;
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 10px;
  color: var(--fg-muted);
}

body.light-mode .zoom-display {
  color: var(--fg-muted-light);
}

/* Scrollbar */
.sidebar-content::-webkit-scrollbar {
  width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

body.light-mode .sidebar-content::-webkit-scrollbar-thumb {
  background: var(--border-light);
}

/* Mobile: Full width sidebar */
@media (max-width: 480px) {
  :root {
    --sidebar-width: 100%;
    --sidebar-max-width: 100%;
  }
  
  .sidebar-toggle.expanded {
    left: auto;
    right: 12px;
  }
}
