:root {
  --bg: #f3f6fb;
  --ink: #172433;
  --panel: #ffffff;
  --border: #d6deea;
  --accent: #0c6e8e;
  --accent-dark: #084f66;
  --line: #1f77b4;
  --class0: #2ca02c;
  --class1: #d62728;
  --trained-bg: #a3b8cc;
  --highlight-bg: #e8a430;
  --highlight-border: #c68a1a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Trebuchet MS", "Candara", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 0%, rgba(12,110,142,0.14), transparent 42%),
    radial-gradient(circle at 88% 22%, rgba(214,39,40,0.08), transparent 38%),
    linear-gradient(160deg, #ffffff 0%, var(--bg) 100%);
}

.app {
  max-width: 1600px;
  width: 98vw;
  margin: 14px auto;
  display: grid;
  gap: 14px;
}

/* ── Hero ── */
.hero {
  background: linear-gradient(135deg, #0b1d2e 0%, #163a5f 50%, #1a4a6e 100%);
  border: none;
  border-radius: 14px;
  box-shadow: 0 10px 32px rgba(10,28,50,0.25);
  padding: 18px 22px;
  color: #fff;
}

.hero h1 {
  margin: 0 0 12px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Flow steps */
.flow-steps {
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
}

.flow-step {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.2px;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  font-size: 0.78rem;
  font-weight: 700;
}

.step-linear {
  background: linear-gradient(135deg, #e8563a, #d44325);
  color: #fff;
}

.step-bridge {
  background: linear-gradient(135deg, #7c3aed, #6026c9);
  color: #fff;
}

.step-logistic {
  background: linear-gradient(135deg, #0891b2, #0e7490);
  color: #fff;
}

.flow-chevron {
  display: inline-block;
  width: 28px;
  height: 28px;
  position: relative;
  flex-shrink: 0;
}

.flow-chevron::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 4px;
  width: 16px;
  height: 2px;
  background: rgba(255,255,255,0.5);
  transform: translateY(-50%);
}

.flow-chevron::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 14px;
  width: 8px;
  height: 8px;
  border-right: 2.5px solid rgba(255,255,255,0.65);
  border-top: 2.5px solid rgba(255,255,255,0.65);
  transform: translateY(-50%) rotate(45deg);
}

/* ── Three-panel grid ── */
.three-panels {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}

/* ── Lab card (each panel) ── */
.lab-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(17,34,51,0.07);
  padding: 14px;
  display: grid;
  gap: 10px;
  align-content: start;
  transition: box-shadow 0.2s;
}

.lab-card:hover {
  box-shadow: 0 10px 36px rgba(17,34,51,0.12);
}

.lab-card h2 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 700;
  color: #0f2744;
  letter-spacing: 0.2px;
}

/* ── Canvas ── */
canvas {
  width: 100%;
  height: min(360px, 44vw);
  border: 1.5px solid #dce4f0;
  border-radius: 12px;
  display: block;
  background: linear-gradient(180deg, #fefefe 0%, #f8faff 100%);
  cursor: crosshair;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.04);
}

/* ── Controls area (below each graph) ── */
.controls-area {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.control-group {
  background: linear-gradient(180deg, #f8fbff 0%, #f1f6fd 100%);
  border: 1px solid #d8e1ee;
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 6px;
  align-content: start;
}

.control-group.full-width {
  grid-column: 1 / -1;
}

.control-group h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--accent-dark);
}

.control-group label {
  font-size: 0.85rem;
}

.control-group select {
  width: 100%;
  border: 1px solid #c7d3e2;
  border-radius: 7px;
  padding: 5px;
  background: #fff;
  font-size: 0.85rem;
}

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

/* ── Buttons ── */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 1px solid #0a5972;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: transform 0.12s ease, background 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  background: #f3f6fb;
  color: #21334c;
  border-color: #c4d1e2;
}

button.secondary:hover {
  background: #e0eaf5;
}

/* Trained state: grey out the train button */
button.trained-done {
  background: var(--trained-bg) !important;
  border-color: #8fa4b8 !important;
  cursor: default !important;
  transform: none !important;
  opacity: 0.7;
}

/* Highlighted reset button after training */
button.highlight {
  background: var(--highlight-bg) !important;
  border-color: var(--highlight-border) !important;
  color: #fff !important;
  font-weight: 600;
}

button.highlight:hover {
  background: #d4941e !important;
}

/* ── Metrics table ── */
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.metrics-table th, .metrics-table td {
  border: 1px solid #d8e1ee;
  padding: 5px 8px;
  text-align: left;
}

.metrics-table th {
  background: #eaf0f8;
  font-weight: 600;
  color: #1f3350;
}

.metrics-table td {
  background: #fff;
}

/* ── Formula block ── */
.formula-block {
  margin: 0;
  border: 1px solid #c9d8eb;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #f8fcff 0%, #f1f8ff 100%);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.82rem;
  line-height: 1.4;
}

.formula-block div + div { margin-top: 2px; }

/* ── Annotation ── */
.annotation {
  margin: 0;
  font-size: 0.85rem;
}

.section-note {
  margin: 0;
  font-size: 0.9rem;
  color: #32465c;
}

/* ── Mini-table ── */
.mini-table {
  border: 1px solid #d8e1ee;
  border-radius: 8px;
  padding: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  font-size: 0.8rem;
  line-height: 1.35;
}

/* ── Data points info ── */
.data-points-info {
  font-size: 0.82rem;
  color: #3e5268;
}

/* ── Guide text ── */
.guide-text {
  margin: 0;
  font-size: 0.78rem;
  color: #506a82;
  line-height: 1.4;
  padding: 6px 8px;
  background: #fffaf0;
  border: 1px solid #eedfc0;
  border-radius: 6px;
}

.guide-text strong {
  color: #9b6e1a;
}

/* ── Hover info highlight box ── */
.hover-info {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 10px;
  border: 1.5px solid #c4d8f0;
  border-radius: 8px;
  background: linear-gradient(180deg, #eef5ff 0%, #e4eefa 100%);
  font-size: 0.82rem;
  min-height: 34px;
  transition: border-color 0.2s, background 0.2s;
}

.hover-info.active {
  border-color: #5a9fd4;
  background: linear-gradient(180deg, #dbeeff 0%, #cfe3fa 100%);
}

.hover-info-label {
  font-weight: 600;
  color: var(--accent-dark);
  white-space: nowrap;
}

.hover-info-content {
  color: #2a3e54;
}

/* ── Comparison table ── */
.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.comparison-table th,
.comparison-table td {
  border: 1px solid #d8e1ee;
  padding: 5px 7px;
  text-align: left;
}

.comparison-table th {
  background: #eaf0f8;
  font-weight: 600;
  color: #1f3350;
}

.comparison-table td:first-child {
  font-weight: 600;
  color: var(--accent-dark);
  white-space: nowrap;
}

.comparison-table tr:nth-child(even) td {
  background: #f7faff;
}

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 20;
  display: none;
  min-width: 160px;
  max-width: 280px;
  border: 1px solid #233d61;
  border-radius: 8px;
  background: rgba(12,23,40,0.95);
  color: #fff;
  padding: 8px;
  font-size: 0.78rem;
  line-height: 1.35;
}

.hidden { display: none; }

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

@media (max-width: 780px) {
  .three-panels {
    grid-template-columns: 1fr;
  }
  canvas {
    height: min(320px, 60vw);
  }
}
