/* ============================================================
   NeuroForge — design system
   A focused "instrument" aesthetic: deep slate, hand-set spacing,
   monospaced telemetry, one molten-amber accent. Cool/warm hues map
   to the two classes everywhere so the whole UI speaks one language.
   ============================================================ */
:root {
  --bg: #05080f;
  --bg-2: #070b15;
  --panel: rgba(146, 167, 200, 0.045);
  --panel-edge: rgba(148, 169, 205, 0.12);
  --panel-edge-strong: rgba(148, 169, 205, 0.22);
  --ink: #eaf0fa;
  --muted: #93a1b8;
  --faint: #5b6678;
  --accent: #f5a524;
  --accent-soft: rgba(245, 165, 36, 0.14);
  --warm: #fb923c;
  --cool: #38bdf8;
  --good: #34d399;
  --r: 14px;
  --r-sm: 9px;
  --r-xs: 6px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --shadow: 0 22px 60px -28px rgba(0, 0, 0, 0.85);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ambient background layers */
.bg-grid {
  position: fixed; inset: 0; z-index: -2;
  background-image:
    linear-gradient(rgba(148, 169, 205, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 169, 205, 0.04) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(ellipse 90% 70% at 50% 0%, #000 30%, transparent 90%);
}
.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 50% at 18% 0%, rgba(245, 165, 36, 0.10), transparent 70%),
    radial-gradient(50% 50% at 88% 12%, rgba(56, 189, 248, 0.10), transparent 70%);
}

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; padding: 14px 22px;
  border-bottom: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, rgba(10, 14, 24, 0.7), rgba(10, 14, 24, 0.2));
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { filter: drop-shadow(0 4px 12px rgba(245, 165, 36, 0.25)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.brand-name span { color: var(--accent); }
.brand-tag { font-family: var(--mono); font-size: 10.5px; color: var(--muted); letter-spacing: 0.02em; }

.header-status { display: flex; align-items: center; gap: 10px; }
.stat {
  display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15;
  padding: 4px 12px; border-left: 1px solid var(--panel-edge);
}
.stat-k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--faint); }
.stat-v { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.stat-v.accent, .accent { color: var(--accent); }
.badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--accent-soft); background: var(--accent-soft);
  padding: 5px 9px; border-radius: 999px; letter-spacing: 0.02em; cursor: default;
}
.ghbtn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  color: var(--muted); border: 1px solid var(--panel-edge); transition: 0.16s; }
.ghbtn:hover { color: var(--ink); border-color: var(--panel-edge-strong); }

.hnav { display: flex; align-items: center; gap: 4px; }
.navlink {
  font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none;
  padding: 6px 11px; border-radius: 8px; border: 1px solid transparent; transition: 0.14s; white-space: nowrap;
}
.navlink:hover { color: var(--ink); border-color: var(--panel-edge-strong); background: rgba(255, 255, 255, 0.03); }

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 312px minmax(0, 1fr) 360px;
  gap: 16px; padding: 16px 22px;
}
.rail, .inspector { display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; padding-right: 4px; }
.inspector { gap: 14px; }
.stage { display: flex; flex-direction: column; min-height: 0; gap: 14px; }

/* custom scrollbars */
.rail::-webkit-scrollbar, .inspector::-webkit-scrollbar { width: 9px; }
.rail::-webkit-scrollbar-thumb, .inspector::-webkit-scrollbar-thumb {
  background: rgba(148, 169, 205, 0.16); border-radius: 9px; border: 2px solid transparent; background-clip: padding-box; }

/* ---------- panels ---------- */
.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--r);
  padding: 15px 15px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.panel.grow { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 220px; }
.panel-title {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 13px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted);
}
.panel-title .idx {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  background: var(--accent-soft); border: 1px solid var(--accent-soft);
  padding: 2px 6px; border-radius: 6px; letter-spacing: 0;
}
.hint { margin: -4px 0 12px; font-size: 11.5px; color: var(--faint); line-height: 1.45; }

/* ---------- dataset tiles ---------- */
.dataset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 9px 4px 8px; border-radius: var(--r-sm);
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.015);
  cursor: pointer; transition: 0.15s; color: var(--muted);
}
.tile canvas { width: 42px; height: 42px; border-radius: 6px; }
.tile span { font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em; }
.tile:hover { border-color: var(--panel-edge-strong); color: var(--ink); transform: translateY(-1px); }
.tile.active { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.tile.active span { color: var(--accent); }

/* ---------- controls ---------- */
.ctl { display: block; margin-bottom: 12px; }
.ctl-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.ctl-row b { color: var(--ink); font-weight: 600; }
.mono { font-family: var(--mono); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; border-radius: 999px;
  background: rgba(148, 169, 205, 0.18); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); border: 2px solid #1a1205; box-shadow: 0 0 0 3px rgba(245, 165, 36, 0.18); transition: 0.12s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent); border: 2px solid #1a1205; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-family: var(--mono); font-size: 12px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.02); color: var(--muted);
  cursor: pointer; transition: 0.14s; user-select: none;
}
.chip:hover { color: var(--ink); border-color: var(--panel-edge-strong); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* segmented control */
.seg { display: flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--panel-edge); border-radius: var(--r-sm); padding: 4px; margin-bottom: 13px; flex-wrap: wrap; }
.seg-label { font-size: 11px; color: var(--faint); padding: 0 8px 0 4px; margin-right: auto; }
.seg button {
  font-family: var(--mono); font-size: 11.5px; color: var(--muted); background: transparent;
  border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer; transition: 0.13s;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--accent); color: #1a1205; font-weight: 600; }

.field { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); }
select {
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--panel-edge);
  border-radius: 7px; padding: 6px 10px; cursor: pointer; min-width: 92px;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* layers editor */
.layers { display: flex; flex-direction: column; gap: 7px; margin-bottom: 11px; }
.layer-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--panel-edge); border-radius: var(--r-sm); background: rgba(255, 255, 255, 0.015);
}
.layer-row .ln { font-size: 11.5px; color: var(--muted); flex: 1; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.03); color: var(--ink); cursor: pointer; font-size: 15px; line-height: 1; transition: 0.12s;
}
.stepper button:hover { border-color: var(--accent); color: var(--accent); }
.stepper .num { font-family: var(--mono); font-size: 13px; width: 22px; text-align: center; }
.layer-actions { display: flex; align-items: center; gap: 8px; }
.paramcount { margin-left: auto; font-size: 11px; color: var(--faint); }

/* buttons */
.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--ink);
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--panel-edge);
  padding: 9px 14px; border-radius: var(--r-sm); cursor: pointer; transition: 0.14s;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn:hover { border-color: var(--panel-edge-strong); background: rgba(255, 255, 255, 0.06); }
.btn:active { transform: translateY(1px); }
.btn.full { width: 100%; }
.btn.ghost { background: transparent; }
.btn.primary {
  background: linear-gradient(180deg, #f8b84e, #f0930f); color: #20160a;
  border-color: #f0930f; box-shadow: 0 8px 22px -10px rgba(245, 165, 36, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.btn.primary:hover { filter: brightness(1.05); }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset {
  text-align: left; font-size: 11.5px; line-height: 1.3; padding: 9px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.02); color: var(--ink); cursor: pointer; transition: 0.14s;
}
.preset:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset b { display: block; font-weight: 700; margin-bottom: 2px; }
.preset small { color: var(--faint); font-family: var(--mono); font-size: 10px; }

/* ---------- stage ---------- */
.stage-toolbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: var(--r);
  padding: 10px 12px;
}
.stage-toolbar .spacer { flex: 1; }
.btn.play { min-width: 116px; }
.ic-pause { display: none; }
.btn.play.running .ic-play { display: none; }
.btn.play.running .ic-pause { display: inline; }
.speed { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--muted); }
.speed input { width: 110px; }
.epochpill { display: flex; align-items: baseline; gap: 6px; padding: 6px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.02); }
.epochpill .mono { font-size: 17px; font-weight: 600; color: var(--accent); }
.epochpill small { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.08em; }

.board {
  position: relative; margin: 0 auto;
  width: min(100%, calc(100vh - 232px)); aspect-ratio: 1 / 1; max-height: 100%;
  border: 1px solid var(--panel-edge-strong); border-radius: var(--r);
  overflow: hidden; background: #070b14; box-shadow: var(--shadow);
}
#boundary { width: 100%; height: 100%; display: block; }
.legend { position: absolute; left: 12px; bottom: 11px; display: flex; gap: 14px;
  font-size: 11px; color: var(--ink); background: rgba(5, 8, 15, 0.62); padding: 6px 11px; border-radius: 999px;
  backdrop-filter: blur(6px); border: 1px solid var(--panel-edge); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.legend .dot.c0 { background: var(--cool); }
.legend .dot.c1 { background: var(--warm); }
.legend .ring { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid #fff; display: inline-block; }
.eps { position: absolute; right: 12px; bottom: 11px; font-size: 10.5px; color: var(--muted);
  background: rgba(5, 8, 15, 0.62); padding: 5px 9px; border-radius: 8px; border: 1px solid var(--panel-edge); }

/* ---------- inspector ---------- */
.netwrap { flex: 1 1 auto; min-height: 160px; position: relative; }
#network { width: 100%; height: 100%; display: block; }
.legend.small { position: static; background: transparent; border: 0; padding: 6px 0 0; backdrop-filter: none; gap: 16px; font-size: 10.5px; color: var(--muted); }
.legend.small .dash { width: 16px; height: 0; border-top: 3px solid; display: inline-block; border-radius: 2px; }
.legend.small .dash.warm { border-color: var(--warm); }
.legend.small .dash.cool { border-color: var(--cool); }
.legend.small .line { width: 16px; height: 0; border-top: 2px solid var(--accent); display: inline-block; }
.legend.small .line.dash { border-top-style: dashed; border-color: var(--cool); }
.legend.small .line.solid { border-color: var(--accent); }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.metric { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, 0.015); }
.m-k { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); }
.m-v { font-size: 19px; font-weight: 600; }

.chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.chart-head h3 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.chartwrap { height: 92px; }
.chartwrap canvas { width: 100%; height: 100%; display: block; }

/* ---------- footer ---------- */
.app-footer {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 22px; border-top: 1px solid var(--panel-edge);
  font-size: 11.5px; color: var(--faint);
}
.kbd-hints { font-family: var(--mono); }
.footer-by { color: var(--faint); }
.footer-by a { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--panel-edge); transition: 0.14s; }
.footer-by a:hover { color: var(--accent); border-color: var(--accent); }
kbd { font-family: var(--mono); font-size: 10.5px; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-edge); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; color: var(--muted); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; }
  .rail, .inspector { overflow: visible; }
  .board { width: min(100%, 560px); }
}
@media (max-width: 820px) {
  .footer-by { display: none; }
}
@media (max-width: 560px) {
  .header-status .stat { display: none; }
  .app-footer .kbd-hints { display: none; }
  .dataset-grid { grid-template-columns: repeat(5, 1fr); }
  .navlink { padding: 6px 8px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
