/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0e13;
  --surface: #12151d;
  --surface2: #1a1f2e;
  --border: #252b3b;
  --accent: #00e5a0;
  --accent2: #ff6b6b;
  --accent3: #ffd166;
  --accent4: #4cc9f0;
  --text: #e8eaf0;
  --text-muted: #8e9bbf;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Inter', sans-serif;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--accent);
}

.header__logo svg { width: 22px; height: 22px; stroke: var(--accent); }

.header__badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  color: var(--accent);
  letter-spacing: 0.05em;
}

/* ── Main Layout ── */
.main {
  display: grid;
  grid-template-columns: 1fr 280px 280px;
  gap: 1rem;
  padding: 1rem;
  min-height: calc(100vh - 56px);
  align-items: start;
}

/* ── Panel ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.panel__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel__header svg { width: 15px; height: 15px; }
.panel__header h2 { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.panel__sub {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  margin-left: auto;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

/* ── Network Canvas ── */
#network-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: block;
}

/* ── Activation Pills ── */
.activations-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.activation-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.7rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.72rem;
  transition: border-color 0.3s;
}

.activation-pill.correct { border-color: var(--accent); }
.activation-pill.wrong   { border-color: var(--accent2); }

.act-label { font-family: var(--font-mono); color: var(--text-muted); }
.act-output { font-family: var(--font-mono); font-weight: 700; color: var(--accent4); }

/* ── Controls ── */
.controls-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.control-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mono { font-family: var(--font-mono); color: var(--text); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: var(--surface2);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px var(--accent);
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.25); }

select {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  outline: none;
  cursor: pointer;
}

select:focus { border-color: var(--accent); }

/* ── Buttons ── */
.btn-row {
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: none;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  flex: 1;
  justify-content: center;
}

.btn svg { width: 13px; height: 13px; }

.btn--primary {
  background: var(--accent);
  color: #0c0e13;
}

.btn--primary:hover { filter: brightness(1.15); box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 50%, transparent); }
.btn--primary.running { background: var(--accent3); }

.btn--ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost:hover { border-color: var(--accent4); color: var(--accent4); }

.btn--danger {
  background: var(--surface2);
  color: var(--accent2);
  border: 1px solid color-mix(in srgb, var(--accent2) 30%, transparent);
}

.btn--danger:hover { background: color-mix(in srgb, var(--accent2) 15%, transparent); }

/* ── Stats Bar ── */
.stats-bar {
  display: flex;
  gap: 0.5rem;
}

.stat {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  text-align: center;
}

.stat__label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.2rem;
}

.stat__value {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Decision Boundary ── */
#boundary-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  image-rendering: pixelated;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 0.5rem;
}

.legend-dot--zero { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }
.legend-dot--one  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }

/* ── Loss Chart ── */
.chart-wrap {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  height: 180px;
  position: relative;
}

.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ── Truth Table ── */
.truth-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  font-family: var(--font-mono);
}

.truth-table th {
  text-align: center;
  padding: 0.4rem 0.3rem;
  color: var(--text-muted);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.truth-table td {
  text-align: center;
  padding: 0.45rem 0.3rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
  transition: color 0.3s;
}

.truth-table tr:last-child td { border-bottom: none; }

.truth-table .pred { font-weight: 700; color: var(--accent4); }

.verdict {
  font-size: 1rem;
}

.verdict.ok::after  { content: '✓'; color: var(--accent); }
.verdict.bad::after { content: '✗'; color: var(--accent2); }

/* ── Speed Control ── */
.speed-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.speed-control svg { width: 13px; height: 13px; stroke: var(--accent3); }
.speed-control label { display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.speed-control input { flex: 1; }
.speed-control .mono { font-size: 0.72rem; min-width: 2.5rem; text-align: right; }

/* ── Animations ── */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 6px var(--accent); }
  50% { box-shadow: 0 0 18px var(--accent); }
}

.stat__value.animated { animation: pulse-glow 0.6s ease; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel { animation: fadeSlideIn 0.4s ease both; }
.panel--controls { animation-delay: 0.05s; }
.panel--chart    { animation-delay: 0.1s; }

/* ── Responsive ── */
@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
}
