:root {
  --bg: #0a0f0d;
  --surface: #101713;
  --surface-2: #161f1a;
  --border: #24322b;
  --text: #e8f3ec;
  --muted: #7f9488;
  --accent: #4dffb0;
  --accent-dim: #1f6b4c;
  --danger: #ff6b6b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(77, 255, 176, 0.05), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

.app { max-width: 1280px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }

.topbar { margin-bottom: 1.5rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 2px color-mix(in srgb, var(--accent) 70%, transparent);
}
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.tagline { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.95rem; max-width: 70ch; }

.layout { display: grid; grid-template-columns: 1fr 340px; gap: 1.25rem; align-items: start; }

.stage {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  line-height: 0;
}
#world { display: block; width: 100%; height: auto; cursor: crosshair; background: #060a08; }

.stage-overlay {
  position: absolute; inset: 0;
  background: rgba(6, 10, 8, 0.82);
  align-items: center; justify-content: center;
  text-align: center;
  color: var(--text);
}
.stage-overlay[hidden] { display: none; }
.stage-overlay:not([hidden]) { display: flex; }
.stage-overlay strong { color: var(--danger); font-size: 1.1rem; }
.stage-overlay p { color: var(--muted); margin: 0.4rem 0 0; }

.panel { display: flex; flex-direction: column; gap: 1rem; }
.panel-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.panel-block h2 {
  margin: 0 0 0.8rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.row { display: flex; gap: 0.6rem; margin-bottom: 0.9rem; }
button {
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
button.primary { background: var(--accent); color: #05130c; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

.slider-label {
  display: flex; flex-direction: column; gap: 0.4rem;
  font-size: 0.82rem; color: var(--muted);
  margin-bottom: 0.9rem;
}
.slider-label:last-child { margin-bottom: 0; }
.slider-label span { color: var(--text); font-weight: 600; }
input[type="range"] {
  -webkit-appearance: none;
  width: 100%; height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.stat-row {
  display: flex; justify-content: space-between;
  font-size: 0.86rem; padding: 0.3rem 0;
  border-bottom: 1px dashed var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--muted); }
.stat-row.highlight {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.3rem;
  border-bottom: none;
}
.stat-row.highlight span:first-child { color: var(--text); font-weight: 600; }
.stat-row.highlight span:last-child { color: var(--accent); font-size: 1.05rem; font-weight: 700; }

.leaderboard { display: flex; flex-direction: column; gap: 0.4rem; }
.leaderboard-row {
  display: flex; align-items: center; gap: 0.55rem;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
}
.leaderboard-row .rank { color: var(--muted); font-weight: 700; width: 1.2rem; }
.leaderboard-row .swatch-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.leaderboard-row .lb-value { margin-left: auto; color: var(--accent); font-weight: 600; }
.leaderboard-empty { color: var(--muted); font-size: 0.82rem; }

#chart { width: 100%; height: auto; display: block; margin-top: 0.4rem; }
.legend { display: flex; gap: 0.9rem; margin-top: 0.6rem; font-size: 0.75rem; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.swatch.speed { background: #4dffb0; }
.swatch.size { background: #ffcf4d; }
.swatch.sense { background: #6ab8ff; }

.help { color: var(--muted); font-size: 0.82rem; margin: 0; }
.brain-viz { margin-top: 0.9rem; }
#brain-canvas { width: 100%; height: auto; margin-top: 0.5rem; background: var(--surface-2); border-radius: var(--radius-sm); }

.why-block {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow);
  max-width: 90ch;
}
.why-block h2 {
  margin: 0 0 0.6rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
}
.why-block p { margin: 0; font-size: 0.92rem; line-height: 1.6; color: var(--text); }
.why-block strong { color: var(--accent); }

footer { margin-top: 1.75rem; color: var(--muted); font-size: 0.82rem; line-height: 1.6; max-width: 90ch; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}
