/* Import Modern Fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=Outfit:wght@400;500;700;800&display=swap');

/* Color Variables */
:root {
  --bg-primary: #0a0813;
  --bg-gradient: radial-gradient(circle at 50% 50%, #15102a 0%, #07050f 100%);
  --glass-bg: rgba(18, 14, 36, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.15);

  --accent-white: #ffffff;
  --accent-glow: rgba(255, 255, 255, 0.4);
  --neon-cyan: #00f0ff;
  --neon-cyan-glow: rgba(0, 240, 255, 0.35);
  --neon-pink: #ff007f;
  --neon-pink-glow: rgba(255, 0, 127, 0.35);
  --text-primary: #f3f1f9;
  --text-muted: #9f9baa;

  --transition-smooth: all 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  background-image: var(--bg-gradient);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  padding: 0;
}

/* Starfield grid background overlay */
body::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: center center;
  z-index: 0;
  pointer-events: none;
}

/* HUD visibility and transitions */
.hud {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.5s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.5s step-start;
  z-index: 10;
}

.hud-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.5s step-end;
}

/* Start Play Overlay screen - Dimming mask, no blur */
.start-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(7, 5, 15, 0.55);
  z-index: 500;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: opacity 0.5s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.5s step-start;
  opacity: 1;
  visibility: visible;
}

.start-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.25, 0.8, 0.25, 1), visibility 0.5s step-end;
}

.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.start-btn {
  background: rgba(18, 14, 36, 0.65);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  width: 100px;
  height: 100px;
  cursor: pointer;
  color: var(--accent-white);
  transition: var(--transition-smooth);
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.4),
    inset 0 0 15px rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
}

.play-svg {
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.2));
  transition: var(--transition-smooth);
}

.start-btn:hover {
  transform: scale(1.08);
  background: rgba(20, 16, 40, 0.8);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow:
    0 0 25px var(--neon-cyan-glow),
    0 10px 40px rgba(0, 240, 255, 0.15),
    inset 0 0 15px rgba(0, 240, 255, 0.08);
}

.start-btn:hover .play-svg {
  filter: drop-shadow(0 0 12px var(--neon-cyan-glow));
}

.start-btn:active {
  transform: scale(0.95);
}

/* Central Workspace */
.main-workspace {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: crosshair;
}

#lifeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Floating Settings Button */
.floating-settings-btn {
  position: fixed;
  right: 2rem;
  top: 2rem;
  z-index: 100;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  transition: var(--transition-smooth);
}

.floating-settings-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px var(--neon-cyan-glow);
  transform: rotate(45deg);
}

.floating-settings-btn:active {
  transform: scale(0.95) rotate(45deg);
}

/* Slide-out Settings Drawer */
.settings-drawer {
  position: fixed;
  right: -360px;
  /* Hidden offscreen by default */
  top: 0;
  width: 350px;
  height: 100vh;
  z-index: 200;
  background: rgba(12, 9, 24, 0.85);
  border-left: 1px solid var(--glass-border);
  border-radius: 24px 0 0 24px;
  backdrop-filter: blur(30px);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding: 1.5rem 1.5rem;
  transition: right 0.45s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.settings-drawer.open {
  right: 0;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.8rem;
}

.drawer-header h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-white);
  letter-spacing: 0.5px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: var(--transition-smooth);
}

.close-btn:hover {
  color: var(--neon-pink);
  background: rgba(255, 255, 255, 0.05);
  transform: scale(1.05);
}

/* Statistics inside Drawer */
.drawer-stats {
  display: flex;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.2rem;
}

.drawer-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.drawer-stat-item:not(:last-child) {
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.drawer-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.15rem;
}

.drawer-stat-val {
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-white);
}

.drawer-content {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  padding-right: 0.3rem;
}

/* Custom Scrollbar for drawer */
.drawer-content::-webkit-scrollbar {
  width: 4px;
}

.drawer-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.control-group h4 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-left: 3px solid var(--neon-cyan);
  padding-left: 0.5rem;
  margin-bottom: 0.2rem;
}

/* Buttons inside Drawer */
.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.btn-full {
  grid-column: span 2;
}

button {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: var(--transition-smooth);

}

button:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--glass-border-hover);
}

button.btn-primary {
  background: var(--accent-white);
  color: var(--bg-primary);
  border: none;
  box-shadow: 0 0 12px var(--accent-glow);
}

button.btn-primary:hover {
  background: #e0e0e0;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.6);
}

button.btn-active {
  background: rgba(0, 240, 255, 0.15);
  border-color: var(--neon-cyan);
  color: var(--neon-cyan);
  box-shadow: 0 0 10px var(--neon-cyan-glow);
}

.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.presets-grid button {
  font-size: 0.72rem;
  padding: 0.45rem 0.2rem;
}

/* Sliders & Dropdown selectors inside drawer */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.slider-val {
  color: var(--neon-cyan);
  font-weight: 600;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-white);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
  transition: var(--transition-smooth);
}

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

select {
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: rgba(18, 14, 36, 0.9);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
}

.piano-labels {
  position: absolute;
  left: 10px;
  top: 33.333%;
  height: 33.333%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1.5% 0;
  pointer-events: none;
  font-family: 'Outfit', sans-serif;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.22);
  font-weight: 700;
  z-index: 2;
}

.piano-labels span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.piano-labels span::after {
  content: '';
  width: 6px;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}