:root {
  --bg-0: #060814;
  --bg-1: #0b1024;
  --bg-2: #131838;
  --ink-0: #e8ecff;
  --ink-1: #aab1d4;
  --ink-2: #6c739a;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #60e8c0;
  --accent-2: #ff5db1;
  --accent-3: #6f8cff;
  --warn: #ffce5b;
  --panel-bg: rgba(11, 16, 36, 0.72);
  --panel-blur: blur(22px) saturate(140%);
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--bg-0);
  color: var(--ink-0);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(1200px 700px at 78% 10%, rgba(96, 232, 192, 0.07), transparent 60%),
    radial-gradient(900px 600px at 12% 90%, rgba(255, 93, 177, 0.07), transparent 60%),
    linear-gradient(180deg, #07091a 0%, #050610 100%);
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* ───────── Top bar ───────── */
.topbar {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px 20px;
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 5;
  max-width: calc(100vw - 40px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent) 0%, transparent 55%),
    radial-gradient(circle at 70% 70%, var(--accent-2) 0%, transparent 55%),
    linear-gradient(135deg, #1a2150, #061026);
  border: 1px solid var(--line-strong);
  box-shadow: 0 0 24px rgba(96, 232, 192, 0.25), inset 0 0 14px rgba(255, 93, 177, 0.25);
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.brand p {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-stats {
  display: flex;
  gap: 22px;
  padding-left: 22px;
  border-left: 1px solid var(--line);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 56px;
}
.stat-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-2);
  text-transform: uppercase;
}
.stat-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 16px;
  font-weight: 500;
  color: var(--ink-0);
  line-height: 1.2;
  margin-top: 2px;
}
.phase-pill {
  font-family: 'Inter', sans-serif !important;
  font-size: 11px !important;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(96, 232, 192, 0.14);
  color: var(--accent);
  border: 1px solid rgba(96, 232, 192, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
  transition: all 0.3s ease;
}
.phase-pill[data-phase="gas"]     { background: rgba(255, 206, 91, 0.12);  color: var(--warn);     border-color: rgba(255, 206, 91, 0.3); }
.phase-pill[data-phase="flock"]   { background: rgba(96, 232, 192, 0.14);  color: var(--accent);   border-color: rgba(96, 232, 192, 0.3); }
.phase-pill[data-phase="vortex"]  { background: rgba(111, 140, 255, 0.16); color: var(--accent-3); border-color: rgba(111, 140, 255, 0.35); }
.phase-pill[data-phase="crystal"] { background: rgba(255, 93, 177, 0.14);  color: var(--accent-2); border-color: rgba(255, 93, 177, 0.32); }
.phase-pill[data-phase="bands"]   { background: rgba(160, 200, 255, 0.14); color: #a0c8ff;         border-color: rgba(160, 200, 255, 0.3); }

/* ───────── Side panel ───────── */
.panel {
  position: absolute;
  top: 92px;
  left: 18px;
  bottom: 18px;
  width: 308px;
  padding: 18px 20px 12px;
  background: var(--panel-bg);
  backdrop-filter: var(--panel-blur);
  -webkit-backdrop-filter: var(--panel-blur);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  z-index: 4;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 3px; }
.panel.collapsed { transform: translateX(calc(-100% - 24px)); opacity: 0; pointer-events: none; }

.panel-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line-strong);
  color: var(--ink-1);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}
.panel-toggle:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink-0); }
.panel.collapsed + .panel-toggle { transform: rotate(180deg); }

.panel-section { padding-bottom: 18px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.panel-section:last-of-type { border-bottom: none; }
.panel-section h2 {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 0 0 14px;
}

.presets {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.presets button {
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-1);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  text-align: left;
}
.presets button:hover {
  background: rgba(96, 232, 192, 0.08);
  border-color: rgba(96, 232, 192, 0.4);
  color: var(--ink-0);
  transform: translateY(-1px);
}
.presets button.active {
  background: linear-gradient(135deg, rgba(96, 232, 192, 0.18), rgba(111, 140, 255, 0.18));
  border-color: rgba(96, 232, 192, 0.5);
  color: var(--ink-0);
  box-shadow: 0 0 22px rgba(96, 232, 192, 0.18) inset;
}

/* ───────── Sliders ───────── */
.ctrl {
  display: block;
  margin-bottom: 14px;
}
.ctrl span {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--ink-1);
  margin-bottom: 6px;
  font-weight: 500;
}
.ctrl em {
  font-style: normal;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  background: rgba(96, 232, 192, 0.08);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(96, 232, 192, 0.18);
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
  outline: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent) var(--p, 50%), rgba(255, 255, 255, 0.1) var(--p, 50%));
}
input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
}
input[type="range"]::-moz-range-progress {
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  margin-top: -6px;
  cursor: grab;
  box-shadow: 0 0 10px rgba(96, 232, 192, 0.5);
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.1); }
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  cursor: grab;
}

/* ───────── Toggles ───────── */
.toggles { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  color: var(--ink-1);
  cursor: pointer;
  user-select: none;
}
.toggle input { position: absolute; opacity: 0; }
.toggle span {
  position: relative;
  padding-left: 36px;
  font-weight: 500;
}
.toggle span::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line-strong);
  transition: all 0.2s;
}
.toggle span::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink-2);
  transition: all 0.2s;
}
.toggle input:checked + span::before {
  background: rgba(96, 232, 192, 0.25);
  border-color: var(--accent);
}
.toggle input:checked + span::after {
  background: var(--accent);
  transform: translate(12px, -50%);
  box-shadow: 0 0 8px var(--accent);
}

/* ───────── Action buttons ───────── */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  border-bottom: none !important;
}
.actions button {
  padding: 10px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 10px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-1);
  border: 1px solid var(--line);
  transition: all 0.18s;
}
.actions button:hover {
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink-0);
  transform: translateY(-1px);
}
.actions button.primary {
  background: linear-gradient(135deg, var(--accent) 0%, #44caa0 100%);
  color: #052220;
  border-color: transparent;
  box-shadow: 0 0 24px rgba(96, 232, 192, 0.35);
}
.actions button.primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 0 30px rgba(96, 232, 192, 0.5);
}
.actions button.primary.paused {
  background: linear-gradient(135deg, var(--warn) 0%, #ec9b1c 100%);
  color: #251700;
  box-shadow: 0 0 24px rgba(255, 206, 91, 0.35);
}

.panel-foot {
  padding-top: 4px;
}
.muted { color: var(--ink-2); font-size: 11px; line-height: 1.5; }

/* ───────── Hint ───────── */
.hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(11, 16, 36, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 11px;
  letter-spacing: 0.06em;
  z-index: 3;
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 0.6s;
}
.hint.fade { opacity: 0; }

/* ───────── Mobile ───────── */
@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    gap: 10px;
    padding: 10px 14px;
    top: 10px;
    width: calc(100vw - 20px);
  }
  .topbar-stats {
    padding-left: 0;
    border-left: none;
    border-top: 1px solid var(--line);
    padding-top: 10px;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .stat-value { font-size: 13px; }
  .stat-label { font-size: 9px; }
  .panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
  }
  .panel.collapsed { transform: translateY(calc(100% - 0px)); }
  .hint { display: none; }
}
