/* ─── Design Tokens ───────────────────────────────────────── */
:root {
  --bg0: #f2efe8;
  --bg1: #d9e6df;
  --bg2: #f8c37a;
  --panel: #fffef8;
  --ink: #1e2b2c;
  --accent: #136f63;
  --accent-2: #ff8f5a;
  --accent-3: #7c4dff;
  --muted: #6a6f72;
  --danger: #ac2a18;
  --success: #1a7a4a;
  --radius: 18px;

  /* Step colors */
  --step1: #136f63;
  --step2: #7c4dff;
  --step3: #d97009;
  --step4: #1a7a4a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Space Grotesk", "Trebuchet MS", "Gill Sans", sans-serif;
  background:
    radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--bg2) 60%, transparent), transparent 38%),
    radial-gradient(circle at 82% 4%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 36%),
    linear-gradient(155deg, var(--bg0), var(--bg1));
  overflow-x: hidden;
}

/* ─── Ambient blobs ───────────────────────────────────────── */
.ambient {
  position: fixed;
  pointer-events: none;
  filter: blur(32px);
  opacity: 0.35;
  animation: drift 18s ease-in-out infinite;
}
.ambient-a {
  width: 340px; height: 340px;
  left: -80px; top: 42vh;
  background: color-mix(in srgb, var(--accent-2) 58%, transparent);
}
.ambient-b {
  width: 280px; height: 280px;
  right: -70px; top: 16vh;
  background: color-mix(in srgb, var(--accent) 48%, transparent);
  animation-delay: -6s;
}

/* ─── Sticky Pipeline Bar ─────────────────────────────────── */
#pipeline-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(18px) saturate(1.4);
  background: color-mix(in srgb, var(--ink) 88%, transparent);
  border-bottom: 1px solid color-mix(in srgb, white 14%, transparent);
  box-shadow: 0 4px 24px color-mix(in srgb, var(--ink) 28%, transparent);
}
.pipeline-bar-inner {
  width: min(1200px, 95vw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  flex-wrap: wrap;
}
.bar-title {
  font-weight: 700;
  font-size: 0.93rem;
  color: #fff;
  letter-spacing: 0.03em;
  margin-right: 6px;
  white-space: nowrap;
}
.bar-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  flex: 1;
}
.bar-btn {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, white 25%, transparent);
  background: color-mix(in srgb, white 12%, transparent);
  color: #fff;
  cursor: pointer;
  transition: background 130ms, opacity 130ms;
  white-space: nowrap;
}
.bar-btn:hover:not(:disabled) {
  background: color-mix(in srgb, white 22%, transparent);
}
.bar-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
.bar-file-label {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  min-height: 30px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, white 25%, transparent);
  background: color-mix(in srgb, white 12%, transparent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 130ms;
  white-space: nowrap;
}
.bar-file-label:hover {
  background: color-mix(in srgb, white 22%, transparent);
}
.bar-file-label input[type="file"] {
  display: none;
}
.pipeline-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
  color: #fff;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ─── Layout ──────────────────────────────────────────────── */
.layout {
  width: min(1200px, 95vw);
  margin: 22px auto 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ─── Cards ───────────────────────────────────────────────── */
.card {
  background: color-mix(in srgb, var(--panel) 88%, white);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  box-shadow: 0 9px 34px color-mix(in srgb, var(--ink) 13%, transparent);
  animation: rise 360ms ease both;
}

/* ─── Intro ───────────────────────────────────────────────── */
.intro h1 { margin: 0 0 6px; }
.intro p { color: var(--muted); margin: 0; }

/* ─── Pipeline Section ────────────────────────────────────── */
.pipeline-section {
  position: relative;
  border-left: 5px solid transparent;
  transition: opacity 300ms, filter 300ms;
}
.step-1 { border-left-color: var(--step1); }
.step-2 { border-left-color: var(--step2); }
.step-3 { border-left-color: var(--step3); }
.step-4 { border-left-color: var(--step4); }

.section-locked {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}
.section-locked::after {
  content: "🔒 Complete the previous step to unlock";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 50%, transparent);
  border-radius: var(--radius);
  pointer-events: none;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.section-header h2 { margin: 0; flex: 1; }

.step-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  color: #fff;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.step-1 .step-badge { background: var(--step1); }
.step-2 .step-badge { background: var(--step2); }
.step-3 .step-badge { background: var(--step3); }
.step-4 .step-badge { background: var(--step4); }

.section-badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  background: color-mix(in srgb, var(--bg1) 60%, white);
  color: var(--muted);
  white-space: nowrap;
}
.section-badge.badge-ok { color: var(--success); border-color: var(--success); background: color-mix(in srgb, var(--success) 10%, white); }
.section-badge.badge-running { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, white); }
.section-badge.badge-warn { color: var(--danger); border-color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, white); }

/* ─── Two-column section body ─────────────────────────────── */
.section-body {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}

.collect-controls h3 { margin: 0 0 10px; }
.collect-vis { display: flex; flex-direction: column; gap: 8px; }

/* ─── Typography ──────────────────────────────────────────── */
h1, h2, h3 {
  margin: 0 0 10px;
  letter-spacing: 0.02em;
}
h1 { font-size: clamp(1.32rem, 1.9vw, 1.9rem); }
h2 { font-size: clamp(1.03rem, 1.3vw, 1.32rem); }
h3 { font-size: 0.95rem; color: var(--muted); }
p  { margin: 0; color: var(--muted); }

/* ─── Form controls ───────────────────────────────────────── */
.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.tight-grid {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

input, select, button { font: inherit; }

input, select {
  min-height: 36px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  padding: 7px 10px;
  background: #fff;
}

.checkbox {
  flex-direction: row;
  align-items: center;
  margin-top: 22px;
  gap: 9px;
}
.checkbox input { min-height: 16px; }

/* ─── Buttons ─────────────────────────────────────────────── */
.btn-row {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: none;
  border-radius: 10px;
  min-height: 36px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, black));
  transition: transform 130ms ease, filter 130ms ease, opacity 130ms;
}
button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}
button:active:not(:disabled) { transform: translateY(0); }
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
}

.btn-secondary {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--ink) 60%, var(--muted)),
    color-mix(in srgb, var(--ink) 80%, black)
  );
}
.btn-danger {
  background: linear-gradient(135deg, var(--danger), color-mix(in srgb, var(--danger) 60%, black));
}

/* ─── Status text ─────────────────────────────────────────── */
.status {
  margin-top: 8px;
  font-size: 0.84rem;
  color: var(--muted);
}
.status.warn { color: var(--danger); }
.status.ok   { color: var(--success); }

/* ─── Canvases ────────────────────────────────────────────── */
#envCanvas, #testCanvas {
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  background: linear-gradient(to top, #d7e4dd, #f8efe1);
}

.caption {
  margin-top: 4px;
  font-size: 0.83rem;
}

#heatmapCanvas {
  width: min(300px, 100%);
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  background: #fefdf8;
}

/* ─── Metrics panels ──────────────────────────────────────── */
.metrics-panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 15%, transparent);
}
.metrics-panel h3 { margin-bottom: 8px; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.metrics-grid div {
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: 11px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 52px;
  background: color-mix(in srgb, #fff 85%, var(--bg0));
}
.metrics-grid span   { color: var(--muted); font-size: 0.73rem; }
.metrics-grid strong { font-size: 0.89rem; }

/* ─── Progress bars ───────────────────────────────────────── */
.progress-group {
  margin-bottom: 12px;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
  flex-direction: row;
  gap: 0;
}
progress {
  width: 100%;
  height: 10px;
  border-radius: 10px;
  border: none;
  appearance: none;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  overflow: hidden;
}
progress::-webkit-progress-bar {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  border-radius: 10px;
}
progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--step3), var(--accent-2));
  border-radius: 10px;
  transition: width 200ms ease;
}
progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--step3), var(--accent-2));
  border-radius: 10px;
}

/* ─── Training log ────────────────────────────────────────── */
.train-log {
  width: 100%;
  height: 120px;
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  padding: 8px 10px;
  resize: vertical;
  background: color-mix(in srgb, var(--ink) 5%, #fff);
  color: var(--ink);
  margin-top: 12px;
}

/* ─── Animations ──────────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%       { transform: translate(24px, -18px) scale(1.05); }
}

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 920px) {
  .section-body {
    grid-template-columns: 1fr;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ─── Q-Value Visualization Panel ────────────────────────── */
.q-viz-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 15%, transparent);
  animation: rise 400ms ease both;
}
.q-viz-panel h3 { margin-bottom: 12px; }

.q-viz-canvases {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.q-viz-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 300px;
}

.q-viz-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

#qValueCanvas,
#greedyMapCanvas {
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, transparent);
  background: #0d1117;
}
