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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #060a10;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: rgba(255, 255, 255, 0.85);
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
}

/* Loading */
#loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #060a10;
  z-index: 100;
  transition: opacity 0.5s ease;
}

#loading h1 {
  font-size: 2.2rem;
  font-weight: 300;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(200, 160, 140, 0.7);
  margin-bottom: 0.5rem;
}

#loading .subtitle {
  font-size: 0.8rem;
  color: rgba(200, 160, 140, 0.35);
  letter-spacing: 0.15em;
  margin-bottom: 1.5rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 2px solid rgba(200, 160, 140, 0.15);
  border-top-color: rgba(200, 160, 140, 0.6);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* UI */
#ui {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  transition: opacity 0.3s ease;
  z-index: 10;
  pointer-events: none;
}

#ui > * { pointer-events: auto; }

.panel {
  background: rgba(10, 15, 22, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(200, 160, 140, 0.1);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 220px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(200, 160, 140, 0.45);
  min-width: 42px;
}

.btn {
  background: rgba(200, 160, 140, 0.08);
  border: 1px solid rgba(200, 160, 140, 0.18);
  color: rgba(220, 200, 190, 0.85);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  letter-spacing: 0.04em;
  flex: 1;
}

.btn:hover {
  background: rgba(200, 160, 140, 0.16);
  border-color: rgba(200, 160, 140, 0.35);
}

.btn:active { transform: scale(0.96); }

.btn.accent {
  background: rgba(120, 200, 100, 0.1);
  border-color: rgba(120, 200, 100, 0.2);
  color: rgba(160, 230, 140, 0.9);
}

.btn.accent:hover {
  background: rgba(120, 200, 100, 0.2);
  border-color: rgba(120, 200, 100, 0.4);
}

.btn-group { display: flex; gap: 0.35rem; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 100%;
  height: 18px;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-track {
  height: 2px;
  background: rgba(200, 160, 140, 0.15);
  border-radius: 1px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: rgba(200, 160, 140, 0.7);
  border-radius: 50%;
  margin-top: -5px;
  box-shadow: 0 0 6px rgba(200, 160, 140, 0.3);
}

input[type="range"]::-moz-range-track {
  height: 2px;
  background: rgba(200, 160, 140, 0.15);
  border-radius: 1px;
  border: none;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: rgba(200, 160, 140, 0.7);
  border-radius: 50%;
  border: none;
}

/* Legend */
.legend-panel {
  display: flex;
  gap: 0.75rem;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.04em;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.body { background: rgba(220, 160, 140, 0.8); }
.dot.eye { background: rgba(240, 240, 240, 0.9); box-shadow: inset 0 0 3px rgba(60, 120, 60, 0.8); }
.dot.limb { background: rgba(200, 155, 135, 0.8); }
.dot.flagella { background: rgba(180, 200, 160, 0.8); }
.dot.food { background: rgba(120, 220, 100, 0.8); box-shadow: 0 0 4px rgba(120, 220, 100, 0.5); }

/* Stats */
.stats-panel { text-align: right; }

#stats {
  font-size: 0.7rem;
  font-family: 'JetBrains Mono', 'SF Mono', monospace;
  color: rgba(200, 160, 140, 0.4);
  letter-spacing: 0.04em;
}

/* Status toast */
#status {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: rgba(200, 160, 140, 0.85);
  background: rgba(10, 15, 22, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(200, 160, 140, 0.12);
  padding: 0.45rem 1.2rem;
  border-radius: 7px;
  opacity: 0;
  z-index: 20;
  pointer-events: none;
}

#status.fade { animation: fadeToast 2s ease forwards; }
@keyframes fadeToast { 0%,70% { opacity: 1; } 100% { opacity: 0; } }

/* Title */
.title {
  position: fixed;
  top: 1.25rem;
  left: 1.5rem;
  z-index: 10;
}

.title h1 {
  font-size: 0.95rem;
  font-weight: 300;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(200, 160, 140, 0.4);
}

.title p {
  font-size: 0.6rem;
  color: rgba(200, 160, 140, 0.2);
  letter-spacing: 0.1em;
  margin-top: 0.15rem;
}

.help-hint {
  position: fixed;
  top: 1.25rem;
  right: 1.5rem;
  font-size: 0.6rem;
  color: rgba(200, 160, 140, 0.2);
  letter-spacing: 0.04em;
  text-align: right;
  line-height: 1.6;
  z-index: 10;
}

@media (max-width: 768px) {
  #ui {
    padding: 0.75rem;
    flex-wrap: wrap;
  }
  .legend-panel { display: none; }
  .help-hint { display: none; }
  .title h1 { font-size: 0.8rem; }
}
