:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface-2: #252533;
  --text: #e8e8f0;
  --text-muted: #9898b0;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --border: #33334a;
  --success: #66bb6a;
  --danger: #ef5350;
  --shadow: rgba(0, 0, 0, 0.4);
}

body.light-theme {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #e8eaed;
  --text: #1a1a2e;
  --text-muted: #5f6368;
  --accent: #0288d1;
  --accent-hover: #0277bd;
  --border: #dadce0;
  --shadow: rgba(0, 0, 0, 0.1);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Righteous', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s, color 0.3s;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
  z-index: 10;
}

header h1 {
  font-size: 1.5rem;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--accent), #ab47bc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

.header-controls button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: background 0.2s, transform 0.15s;
}

.header-controls button:hover {
  background: var(--accent);
  transform: scale(1.05);
}

main {
  display: flex;
  height: calc(100vh - 110px);
  gap: 0;
}

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

#world {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#stats {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(0,0,0,0.35);
  padding: 6px 12px;
  border-radius: 6px;
  pointer-events: none;
  font-family: system-ui, monospace;
}

#instructions {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(0,0,0,0.4);
  padding: 6px 14px;
  border-radius: 20px;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0.85;
}

#controls {
  width: 300px;
  min-width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.panel {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.9rem;
  border: 1px solid var(--border);
}

.panel h2 {
  font-size: 1rem;
  margin-bottom: 0.7rem;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
}

.btn-row.presets {
  margin-bottom: 0;
}

button, .shape-btn, .preset-btn {
  font-family: 'Righteous', system-ui, sans-serif;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  flex: 1;
  min-width: 70px;
}

button:hover, .shape-btn:hover, .preset-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button:active {
  transform: scale(0.97);
}

.shape-btn.active, .preset-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#add-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#add-btn:hover {
  background: var(--accent-hover);
}

#clear-btn, #reset-btn {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

#clear-btn:hover, #reset-btn:hover {
  background: var(--danger);
  color: #fff;
}

#pause-btn.paused {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.control-group {
  margin-bottom: 0.65rem;
}

.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

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

.control-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.control-group input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  padding: 2px;
}

footer {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* Mobile responsive */
@media (max-width: 768px) {
  main {
    flex-direction: column;
    height: calc(100vh - 100px);
  }

  #canvas-container {
    height: 55%;
    min-height: 280px;
  }

  #controls {
    width: 100%;
    min-width: unset;
    height: 45%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 0.6rem;
  }

  header h1 {
    font-size: 1.2rem;
  }

  #instructions {
    font-size: 0.7rem;
    white-space: normal;
    text-align: center;
    max-width: 90%;
  }

  .panel {
    padding: 0.7rem;
  }
}

@media (max-width: 480px) {
  .btn-row button {
    font-size: 0.75rem;
    padding: 0.4rem 0.5rem;
  }
}
