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

:root {
  --bg: #08090c;
  --bg-panel: rgba(14, 16, 22, 0.85);
  --border: rgba(56, 189, 248, 0.12);
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.3);
  --accent-glow: rgba(56, 189, 248, 0.15);
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-bright: #f8fafc;
  --danger: #f87171;
  --success: #4ade80;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Fira Code', monospace;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ─── Header ─── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: linear-gradient(135deg, #0a0e17 0%, #111827 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}
header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-bright);
}
.subtitle {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-style: italic;
  font-weight: 200;
  margin-top: 1px;
}

.icon-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--accent-glow); border-color: var(--accent); }

/* ─── Info Panel ─── */
#info-panel {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s;
}
#info-panel.hidden { display: none; }
.info-content {
  background: #111827;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 520px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.info-content h3 { color: var(--accent); margin: 16px 0 8px; font-size: 0.95rem; }
.info-content h3:first-child { margin-top: 0; }
.info-content p, .info-content li { font-size: 0.82rem; color: var(--text-dim); line-height: 1.6; }
.info-content ul { padding-left: 18px; }
.info-content li { margin-bottom: 4px; }
.info-content strong { color: var(--text); }
.fun-fact {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--accent-glow);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* ─── Main Layout ─── */
main {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
}
#canvas-wrap:active { cursor: grabbing; }

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

#noise-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(0,0,0,0.82);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  white-space: nowrap;
  z-index: 5;
}
#noise-tooltip.hidden { display: none; }

#fps-counter {
  position: absolute;
  top: 10px; left: 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--success);
  background: rgba(0,0,0,0.6);
  padding: 3px 8px;
  border-radius: 4px;
  z-index: 5;
}
#fps-counter.hidden { display: none; }

#anim-indicator {
  position: absolute;
  top: 10px; right: 10px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--danger);
  background: rgba(0,0,0,0.6);
  padding: 3px 10px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}
#anim-indicator.hidden { display: none; }
.pulse-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ─── Canvas Glow when animating ─── */
#canvas-wrap.animating {
  box-shadow: inset 0 0 40px var(--accent-glow);
}

/* ─── Controls Toggle ─── */
#controls-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  border: none;
  cursor: pointer;
  z-index: 50;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(56, 189, 248, 0.4);
}

/* ─── Controls Panel ─── */
#controls {
  width: 280px;
  flex-shrink: 0;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  padding: 14px 16px;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 20;
  transition: transform 0.3s ease;
}
#controls:not(.open) {
  transform: translateX(100%);
  position: absolute;
  right: 0; top: 0; bottom: 0;
}

.controls-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-bright);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.icon-btn-sm {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
  display: none;
}

.control-group {
  margin-bottom: 14px;
}
.control-group label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.val {
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 400;
}

/* ─── Sliders ─── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-dim);
  transition: box-shadow 0.2s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 0 16px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 8px var(--accent-dim);
}

/* ─── Segmented Buttons ─── */
.seg-buttons {
  display: flex;
  gap: 2px;
  background: #1e293b;
  border-radius: 6px;
  padding: 2px;
  flex-wrap: wrap;
}
.seg-buttons button {
  flex: 1;
  min-width: 0;
  padding: 5px 4px;
  font-size: 0.62rem;
  font-family: var(--font-sans);
  font-weight: 600;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.seg-buttons button.active {
  background: var(--accent);
  color: var(--bg);
}
.seg-buttons button:hover:not(.active) {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

/* ─── Seed Row ─── */
.seed-row {
  display: flex;
  gap: 6px;
}
input[type="number"] {
  flex: 1;
  background: #1e293b;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  outline: none;
}
input[type="number"]:focus {
  border-color: var(--accent);
}

/* ─── Buttons ─── */
.btn-sm {
  padding: 5px 12px;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  font-weight: 600;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm:hover { filter: brightness(1.15); }

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 16px 0 12px;
}
.btn-action {
  padding: 8px 6px;
  font-size: 0.68rem;
  font-family: var(--font-sans);
  font-weight: 600;
  background: #1e293b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-action:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-bright);
}

.toggle-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.toggle-row label { margin-bottom: 0; }
.toggle-btn {
  padding: 4px 12px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 600;
  background: #1e293b;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.on {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

/* ─── Footer ─── */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 20px;
  font-size: 0.68rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
footer a {
  color: var(--accent);
  text-decoration: none;
}
footer a:hover { text-decoration: underline; }

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  header h1 { font-size: 0.95rem; }
  .subtitle { display: none; }

  main { flex-direction: column; }

  #controls {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    max-height: 55vh;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    z-index: 40;
  }
  #controls.open {
    transform: translateY(0);
  }

  .icon-btn-sm { display: block; }
  #controls-toggle { display: flex; }

  .seg-buttons button { font-size: 0.58rem; padding: 4px 2px; }
}

/* Custom scrollbar */
#controls::-webkit-scrollbar { width: 4px; }
#controls::-webkit-scrollbar-track { background: transparent; }
#controls::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }