:root {
  --ink: #172026;
  --muted: #62717f;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --line: #d9e0dc;
  --teal: #087f8c;
  --teal-soft: #d8f1ef;
  --coral: #ef6f61;
  --gold: #f3bc3c;
  --green: #5e9f57;
  --blue: #4d73b9;
  --shadow: 0 18px 48px rgba(21, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(8, 127, 140, 0.08), transparent 34%),
    linear-gradient(320deg, rgba(239, 111, 97, 0.1), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(440px, 1fr) minmax(300px, 380px);
  gap: 16px;
  min-height: calc(100vh - 36px);
}

.panel,
.stage {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 224, 220, 0.9);
  box-shadow: var(--shadow);
}

.panel {
  border-radius: 8px;
  padding: 18px;
  overflow: auto;
}

.stage {
  border-radius: 8px;
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  overflow: hidden;
}

.brand-block h1,
.stage-header h2,
.selected-sample h2 {
  margin: 0;
  line-height: 1.05;
}

.brand-block h1 {
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.brand-block p:last-child,
#sampleName {
  color: var(--muted);
  line-height: 1.45;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-group,
.control-grid,
.action-row,
.training-summary,
.parameter-panel {
  margin-top: 18px;
}

.group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 7px;
  color: #32424c;
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
  min-height: 42px;
  padding: 9px 11px;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.14);
}

input[type="range"] {
  accent-color: var(--teal);
  min-height: auto;
  padding: 0;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.quick-row,
.action-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.quick-row button,
.icon-button {
  min-height: 36px;
  border-radius: 8px;
  background: var(--teal-soft);
  color: #0b5660;
  font-weight: 800;
}

.icon-button {
  width: 36px;
  min-height: 36px;
}

.meter-line {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 3px;
}

.action-row {
  grid-template-columns: 1fr 1fr;
}

.primary,
.accent {
  min-height: 46px;
  border-radius: 8px;
  color: white;
  font-weight: 900;
}

.primary {
  background: var(--teal);
}

.accent {
  background: var(--coral);
}

.status-line {
  min-height: 44px;
  color: var(--muted);
  line-height: 1.4;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.prediction-chip {
  display: grid;
  gap: 2px;
  min-width: 112px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #172026;
  color: white;
  text-align: center;
}

.prediction-chip span {
  color: #b9c7cc;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.prediction-chip strong {
  font-size: 2rem;
  line-height: 1;
}

.visual-band {
  min-height: 360px;
  background:
    linear-gradient(90deg, rgba(23, 32, 38, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 32, 38, 0.035) 1px, transparent 1px),
    #fbfcfa;
  background-size: 34px 34px;
}

#networkSvg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
}

.link-line {
  stroke: rgba(98, 113, 127, 0.28);
  stroke-width: 1.1;
}

.link-line.active {
  stroke: var(--coral);
  stroke-width: 2.6;
  filter: drop-shadow(0 0 6px rgba(239, 111, 97, 0.55));
}

.neuron {
  stroke: #ffffff;
  stroke-width: 2;
  fill: #9aa7ad;
  transition: r 240ms ease, fill 240ms ease, opacity 240ms ease;
}

.neuron.active {
  fill: var(--gold);
  r: 7.5;
}

.layer-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-anchor: middle;
}

.sample-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
  max-height: 184px;
  overflow: auto;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #eef3ef;
}

.sample-card {
  display: grid;
  gap: 5px;
  justify-items: center;
  border: 2px solid transparent;
  border-radius: 8px;
  background: white;
  padding: 7px 5px;
  color: var(--ink);
  font-weight: 900;
}

.sample-card.selected {
  border-color: var(--coral);
  box-shadow: 0 8px 18px rgba(239, 111, 97, 0.16);
}

.sample-card img {
  width: 42px;
  height: 42px;
  image-rendering: pixelated;
}

.selected-sample {
  display: grid;
  grid-template-columns: 92px 1fr;
  align-items: center;
  gap: 14px;
}

.sample-preview-wrap {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  border-radius: 8px;
  background: #101820;
}

#selectedPreview {
  width: 76px;
  height: 76px;
  image-rendering: pixelated;
}

.probability-list {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.prob-row {
  display: grid;
  grid-template-columns: 24px 1fr 48px;
  align-items: center;
  gap: 9px;
  font-size: 0.84rem;
  font-weight: 800;
}

.prob-track {
  height: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: #e6ece8;
}

.prob-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 360ms ease;
}

.training-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.training-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.training-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.training-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.1rem;
}

#historyChart {
  width: 100%;
  height: 160px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.parameter-panel small {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.param-row {
  display: grid;
  grid-template-columns: 54px 1fr 64px;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-size: 0.8rem;
  font-weight: 800;
}

.param-track {
  height: 12px;
  border-radius: 99px;
  background: #e6ece8;
  overflow: hidden;
}

.param-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--coral));
  transition: width 400ms ease;
}

.is-busy {
  opacity: 0.72;
  pointer-events: none;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 320px 1fr;
  }

  .insight-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 10px;
  }

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

  .stage-header,
  .selected-sample {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .stage-header {
    flex-direction: column;
  }

  .control-grid,
  .training-summary {
    grid-template-columns: 1fr;
  }
}
