:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #d8deea;
  --surface: #ffffff;
  --wash: #f3f6fb;
  --blue: #2563eb;
  --teal: #0f9488;
  --red: #d64b4b;
  --amber: #d99a16;
  --violet: #7c3aed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--wash);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 980px;
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.12;
}

h2 {
  margin-bottom: 5px;
  font-size: 18px;
}

h3 {
  margin-bottom: 10px;
  font-size: 14px;
}

.topbar-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.language-tabs,
.mode-tabs,
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--blue);
  outline: none;
}

button.primary,
.lang-button.active,
.tab-button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 32px) 32px;
}

.controls,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.controls {
  align-self: start;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding: 16px;
}

.control-section + .control-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.compare-shared-note {
  margin: 0;
  border: 1px solid #b9cdfc;
  border-radius: 8px;
  background: #eef4ff;
  color: #24427d;
  padding: 10px;
  font-size: 13px;
  line-height: 1.4;
}

.workspace {
  display: grid;
  gap: 18px;
}

.panel {
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px 10px;
}

.panel-heading p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.plot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.plot-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  border-radius: 50%;
}

.dot.small {
  width: 10px;
  height: 10px;
  border: 1px solid #ffffff;
}

.dot.large {
  width: 13px;
  height: 13px;
  border: 2px solid #172033;
}

.dot.red {
  background: var(--red);
}

.dot.blue {
  background: var(--blue);
}

.boundary {
  display: inline-block;
  width: 22px;
  height: 0;
  border-top: 3px dotted rgba(23, 32, 51, 0.55);
}

#stabilityBadge {
  min-width: 112px;
  border-radius: 8px;
  background: #e8f7f3;
  color: #0f6f65;
  padding: 8px 10px;
  text-align: center;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

form,
.control-section {
  display: grid;
  gap: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

select,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
}

label output {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.layer-neuron-controls {
  display: grid;
  gap: 12px;
}

.compare-layer-neuron-controls {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
}

.activation-help {
  position: relative;
  display: inline-flex;
  width: max-content;
  max-width: 100%;
  cursor: help;
  text-decoration: underline dotted rgba(102, 112, 133, 0.65);
  text-underline-offset: 3px;
}

.activation-popover {
  position: absolute;
  z-index: 30;
  left: 0;
  bottom: calc(100% + 10px);
  display: grid;
  gap: 7px;
  width: min(300px, 78vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  padding: 12px;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.activation-popover canvas {
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: #ffffff;
}

.activation-popover strong {
  color: #ffffff;
  font-size: 14px;
}

.activation-popover em {
  color: #dbe7ff;
  font-style: normal;
}

.activation-help:hover .activation-popover,
.activation-help:focus-visible .activation-popover {
  opacity: 1;
  transform: translateY(0);
}

.actions button {
  flex: 1 1 calc(50% - 8px);
}

.step-mode-guide {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.phase-track {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.phase-track span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 5px;
  background: #ffffff;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.phase-track span.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.step-mode-guide p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.status-grid div,
.inspectors div,
.compare-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.status-grid div {
  padding: 10px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-label {
  position: relative;
  cursor: help;
  text-decoration: underline dotted rgba(102, 112, 133, 0.65);
  text-underline-offset: 3px;
}

.metric-label::after {
  content: none;
  position: absolute;
  z-index: 20;
  left: 0;
  bottom: calc(100% + 8px);
  width: min(360px, 78vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  padding: 10px 11px;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.18);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.status-grid div:nth-child(even) .metric-label::after {
  right: 0;
  left: auto;
}

.status-grid div:nth-child(even) .metric-label::before {
  right: 14px;
  left: auto;
}

.metric-label::before {
  content: none;
  position: absolute;
  z-index: 21;
  left: 14px;
  bottom: calc(100% + 2px);
  border: 6px solid transparent;
  border-top-color: #172033;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.metric-label:hover::after,
.metric-label:hover::before,
.metric-label:focus-visible::after,
.metric-label:focus-visible::before {
  opacity: 1;
  transform: translateY(0);
}

.floating-tooltip {
  position: fixed;
  z-index: 1000;
  width: min(360px, 78vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  padding: 10px 11px;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.18);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  pointer-events: none;
}

.status-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 18px;
}

.step-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  padding: 0 14px 14px;
}

.network-wrap {
  position: relative;
  min-width: 0;
}

.weight-tooltip {
  position: absolute;
  z-index: 25;
  max-width: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  padding: 10px 11px;
  box-shadow: 0 10px 22px rgba(23, 32, 51, 0.2);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}

.weight-tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.weight-tooltip dl {
  grid-template-columns: auto auto;
  gap: 4px 12px;
}

.weight-tooltip dt {
  color: #b9c5d8;
}

.weight-tooltip dd {
  color: #ffffff;
}

.inspectors {
  display: grid;
  gap: 12px;
  align-content: start;
}

.inspectors div {
  padding: 12px;
}

dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 10px;
  margin: 0;
  font-size: 13px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  font-weight: 800;
}

.compare-controls,
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 0 14px 14px;
}

.compare-controls fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 12px;
}

.compare-controls legend {
  padding: 0 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.compare-grid > div {
  padding: 12px;
}

@media (max-width: 1120px) {
  .app-shell,
  .step-grid,
  .compare-controls,
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .topbar,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-grid {
    grid-template-columns: 1fr;
  }

  .compare-controls fieldset {
    grid-template-columns: 1fr;
  }
}
