:root {
  color-scheme: dark;
  --bg: #05060b;
  --panel: rgba(12, 14, 24, 0.72);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8eaf2;
  --muted: #8a90a6;
  --faint: #5a6078;
  --accent: #7cf5d0;
  --accent-2: #b38cff;
  --pos: 46, 230, 166;
  --neg: 255, 77, 109;
  --radius: 14px;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- panel ---------- */
.panel {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 304px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 18px 18px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  transition: transform 0.35s cubic-bezier(.2, .8, .2, 1), opacity 0.35s;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.panel.hidden { transform: translateX(calc(100% + 32px)); opacity: 0; pointer-events: none; }

.panel-toggle {
  position: fixed;
  top: 16px;
  right: 336px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: right 0.35s cubic-bezier(.2, .8, .2, 1);
}
.panel-toggle.collapsed { right: 16px; }

.brand h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  background: linear-gradient(92deg, #ff6b8b 0%, #ffc15e 28%, #7cf5d0 58%, #8fa2ff 82%, #d58cff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

section { margin-top: 16px; }
h2 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.row-title { display: flex; align-items: baseline; justify-content: space-between; }

.hint { color: var(--faint); font-size: 11px; }
.small { margin: 8px 0 0; }
.hint b { color: var(--muted); font-weight: 500; }
kbd {
  font: 10px var(--mono);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--panel-border);
  color: var(--muted);
}

/* ---------- stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stats div {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.stats span { display: block; font: 500 17px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.stats label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint); }

/* ---------- presets ---------- */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
}
.presets button[aria-pressed="true"] {
  color: #06110d;
  background: var(--accent);
  border-color: transparent;
}
.blurb { margin: 8px 0 0; min-height: 2.9em; color: var(--muted); font-size: 12px; }

/* ---------- matrix ---------- */
.matrix {
  display: grid;
  max-width: 300px;
  gap: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.matrix .dot {
  display: grid;
  place-items: center;
}
.matrix .dot i {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
  background: currentColor;
}
.matrix .cell {
  aspect-ratio: 1;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font: 500 9px var(--mono);
  color: rgba(255, 255, 255, 0.0);
  cursor: ns-resize;
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: color 0.15s, transform 0.1s;
}
.matrix .cell:hover { color: rgba(255, 255, 255, 0.92); transform: scale(1.08); border-color: rgba(255,255,255,0.35); }
.matrix .cell.active { color: #fff; border-color: #fff; }

/* ---------- buttons ---------- */
button {
  font: 500 12px var(--sans);
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
button:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.2); }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  background: linear-gradient(135deg, rgba(124, 245, 208, 0.22), rgba(179, 140, 255, 0.22));
  border-color: rgba(124, 245, 208, 0.35);
}
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.actions button { padding: 8px 4px; }

/* ---------- sliders ---------- */
.sliders { display: grid; gap: 10px; }
.slider span { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.slider output { font: 12px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 2px 0 0;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent) var(--fill, 50%), rgba(255, 255, 255, 0.1) var(--fill, 50%));
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(124, 245, 208, 0.25), 0 2px 6px rgba(0, 0, 0, 0.4);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%; background: #fff;
}

/* ---------- seed ---------- */
.seed { display: flex; align-items: center; gap: 10px; }
.seed label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.seed input {
  flex: 1;
  min-width: 0;
  font: 13px var(--mono);
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 7px 10px;
}

footer { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--panel-border); }
footer a { color: var(--accent); text-decoration: none; font-size: 12px; }
footer a:hover { text-decoration: underline; }

/* ---------- toast / error ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 24, 38, 0.92);
  border: 1px solid var(--panel-border);
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.error {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.error[hidden], .toast[hidden] { display: none; }

/* ---------- small screens: bottom sheet ---------- */
@media (max-width: 640px) {
  .panel {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
    max-height: 58dvh;
  }
  .panel.hidden { transform: translateY(calc(100% + 32px)); }
  .panel-toggle, .panel-toggle.collapsed { top: 16px; right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .panel-toggle, button, .matrix .cell { transition: none; }
}
