/* Design tokens — palette, density, typography, motion. */
:root {
  /* Surfaces — slightly cooler, with a faint blue undertone. */
  --bg:           #0a0c10;
  --bg-grad:      radial-gradient(1200px 700px at 12% -10%, #131722 0%, #0a0c10 55%, #07080b 100%);
  --bg-elev:      #11141b;
  --bg-elev-2:    #161a23;
  --bg-elev-3:    #1c2130;
  --bg-glass:     rgba(17, 20, 27, 0.72);

  /* Borders — translucent so they feel etched, not drawn. */
  --border:        rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --border-accent: rgba(120, 162, 255, 0.42);

  /* Text. */
  --text:        #eef0f5;
  --text-dim:    #aab2c0;
  --text-muted:  #6f7888;
  --text-faint:  #4d5564;

  /* Accents. */
  --accent:      #7aa3ff;
  --accent-soft: rgba(122, 163, 255, 0.16);
  --accent-glow: rgba(122, 163, 255, 0.28);
  --good:        #4ade80;
  --bad:         #f87171;
  --warn:        #fbbf24;
  --partial:     #c084fc;
  --pending:     #94a3b8;

  /* Concept colours — stable across the app. Slightly muted from raw values. */
  --c-Hypothesizing: #c084fc;
  --c-Modifying:     #fbbf24;
  --c-Experimenting: #7aa3ff;
  --c-Evaluating:    #34d399;
  --c-Logging:       #60a5fa;
  --c-Communicating: #a78bfa;
  --c-Requesting:    #94a3b8;
  --c-Profiling:     #f59e0b;
  --c-Discovering:   #22d3ee;
  --c-Committing:    #facc15;
  --c-Freestyling:   #ef4444;

  /* Radii. */
  --r-xs: 3px;
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  /* Spacing scale. */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;

  /* Elevation. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px -4px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  --shadow-lg: 0 18px 40px -16px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  --shadow-glow: 0 0 0 3px var(--accent-soft);

  /* Motion. */
  --ease: cubic-bezier(0.4, 0.0, 0.2, 1);
  --t-fast: 120ms;
  --t-med:  200ms;

  /* Type. */
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-sans:    "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.14); background-clip: padding-box; }

button {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.005em;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 5px 11px;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
button:hover {
  background: var(--bg-elev);
  border-color: var(--border-strong);
  color: var(--text);
}
button:active { transform: translateY(0.5px); }
button.active {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--text);
}
button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
  border-color: var(--border-accent);
}

input, select {
  font-family: var(--font-sans);
  font-size: 12.5px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 6px 9px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input::placeholder { color: var(--text-faint); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus {
  outline: none;
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}
select { appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

#app {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(380px, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "left   right";
  height: 100vh;
}

/* ─────────── Header ─────────── */
.app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--s-5);
  border-bottom: 1px solid var(--border);
  gap: var(--s-4);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.018), rgba(255,255,255,0)),
    var(--bg-glass);
  backdrop-filter: blur(8px);
  position: relative;
}
.app-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-strong) 30%, var(--border-strong) 70%, transparent);
  pointer-events: none;
}
.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.app-header h1::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.18);
  align-self: center;
  flex-shrink: 0;
}
.app-header h1 small {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0;
  margin-left: 0;
}
.app-header .controls { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.app-header .controls label {
  color: var(--text-faint);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}

/* ─────────── Left pane ─────────── */
.left-pane {
  grid-area: left;
  display: grid;
  grid-template-rows: minmax(200px, 38%) 1fr;
  border-right: 1px solid var(--border);
  min-height: 0;
}

/* ─────────── Metric section ─────────── */
.metric-section {
  border-bottom: 1px solid var(--border);
  padding: var(--s-4) var(--s-5);
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: var(--s-2);
}
.metric-section h2 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.metric-meta {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.metric-meta span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
}
.metric-meta b {
  color: var(--text);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.metric-chart-container { flex: 1; min-height: 130px; position: relative; }
.metric-chart-container svg { width: 100%; height: 100%; display: block; }

/* ─────────── Event stream ─────────── */
.event-stream {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.event-stream .toolbar {
  display: flex;
  gap: var(--s-2);
  padding: 10px var(--s-5);
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
  background: linear-gradient(180deg, rgba(255,255,255,0.012), transparent);
}
.event-stream .toolbar input[type="search"] { flex: 1; min-width: 140px; }
.event-stream .toolbar label {
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.event-stream .toolbar input[type="checkbox"] { accent-color: var(--accent); }
.event-stream .stream-list {
  flex: 1;
  overflow: auto;
  padding: 4px 0;
  margin: 0;
  list-style: none;
  font-family: var(--font-mono);
  font-size: 12px;
}
.event-row {
  display: grid;
  grid-template-columns: 50px 118px 1fr;
  gap: var(--s-3);
  align-items: center;
  padding: 6px var(--s-5);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease);
  position: relative;
}
.event-row:hover { background: rgba(255, 255, 255, 0.025); }
.event-row.selected {
  background: linear-gradient(90deg, var(--accent-soft) 0%, rgba(122, 163, 255, 0.04) 100%);
  border-left-color: var(--accent);
}
.event-row.freestyle { border-left-color: var(--c-Freestyling); }
.event-row.freestyle.selected { border-left-color: var(--c-Freestyling); }
.event-row .id {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-align: right;
}
.event-row.selected .id { color: var(--text-dim); }
.event-row .pill {
  display: inline-block;
  padding: 1.5px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c, var(--text-muted)) 18%, transparent);
  color: var(--c, var(--text-muted));
  font-weight: 500;
  font-size: 10.5px;
  font-family: var(--font-sans);
  white-space: nowrap;
  letter-spacing: 0.02em;
  border: 1px solid color-mix(in srgb, var(--c, var(--text-muted)) 30%, transparent);
  text-align: center;
}
.event-row .summary {
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}
.event-row.selected .summary { color: var(--text); }
.event-row .summary .verb {
  color: var(--text-faint);
  margin-right: 6px;
  font-style: italic;
}
.event-row .summary .badge-fs {
  background: var(--c-Freestyling);
  color: #1a1c1f;
  padding: 1px 6px;
  border-radius: var(--r-xs);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin-right: 6px;
  font-family: var(--font-sans);
  text-transform: uppercase;
  vertical-align: 1px;
}

/* ─────────── Right pane ─────────── */
.right-pane {
  grid-area: right;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.012), transparent);
  padding: 0 var(--s-3);
}
.tabs button {
  flex: 1;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 12px 8px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: transparent;
  color: var(--text-muted);
  transition: color var(--t-fast) var(--ease), border-color var(--t-med) var(--ease);
}
.tabs button:hover { color: var(--text); background: transparent; }
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: transparent;
  box-shadow: none;
}
.tabs button:focus-visible { outline: none; box-shadow: inset 0 -2px 0 var(--accent); }

.tab-body {
  flex: 1;
  overflow: auto;
  padding: var(--s-5);
}

/* ─────────── Inspector ─────────── */
.inspector h3 {
  margin: 0 0 var(--s-3);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--s-2);
}
.inspector h3 .status-pill { font-size: 10.5px; }
.inspector .placeholder {
  color: var(--text-muted);
  font-style: italic;
  padding: var(--s-6) var(--s-4);
  text-align: center;
  font-family: var(--font-display);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.012);
}
.inspector section + section { margin-top: var(--s-3); }
.inspector .panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.018), rgba(255,255,255,0)) , var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  box-shadow: var(--shadow-sm);
}
.inspector .panel h4 {
  margin: 0 0 var(--s-3);
  font-size: 10.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-weight: 600;
}
.inspector .panel-prose {
  margin: var(--s-3) 0 0;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.55;
}
.inspector .panel-prose:first-child { margin-top: 0; margin-bottom: var(--s-3); }
.inspector .panel-footer { margin-top: var(--s-3); }
.inspector .json {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  overflow: auto;
  max-height: 280px;
  white-space: pre;
  color: var(--text-dim);
  line-height: 1.55;
}
.inspector .reaction {
  font-family: var(--font-mono);
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: var(--s-3);
  border-radius: var(--r-sm);
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.55;
}
.inspector .reaction .label {
  color: var(--accent);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.inspector .chain {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.inspector .chain-link {
  display: grid;
  grid-template-columns: 18px 70px 1fr;
  align-items: baseline;
  gap: var(--s-2);
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
  padding: 5px var(--s-2);
  border-radius: var(--r-sm);
  color: var(--text-dim);
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.inspector .chain-link:hover { background: rgba(255,255,255,0.03); color: var(--text); }
.inspector .chain-link.current {
  background: var(--accent-soft);
  color: var(--text);
}
.inspector .chain-link .arrow { color: var(--text-faint); }
.inspector .chain-link.current .arrow { color: var(--accent); }

/* ─────────── Hypotheses tab ─────────── */
.hyp-list { display: grid; gap: var(--s-3); }
.hyp-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0)) , var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.hyp-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}
.hyp-card.selected {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--border-accent);
}
.hyp-card-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  align-items: flex-start;
  margin-bottom: var(--s-2);
}
.hyp-card .desc {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.005em;
  color: var(--text);
}
.hyp-card .reasoning {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.55;
  margin: 6px 0 0;
}
.hyp-card .reasoning.outcome {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px dashed var(--border);
  color: var(--text-dim);
}
.pred-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: var(--s-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.pred-grid > div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
}
.pred-grid label {
  color: var(--text-faint);
  display: block;
  font-size: 9.5px;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  margin-bottom: 2px;
}
.pred-grid span { color: var(--text-dim); }
.status-pill {
  font-size: 9.5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.status-confirmed { background: rgba(74, 222, 128, 0.12); color: var(--good); border-color: rgba(74, 222, 128, 0.28); }
.status-violated  { background: rgba(248, 113, 113, 0.12); color: var(--bad);  border-color: rgba(248, 113, 113, 0.28); }
.status-partial   { background: rgba(192, 132, 252, 0.12); color: var(--partial); border-color: rgba(192, 132, 252, 0.28); }
.status-pending   { background: rgba(148, 163, 184, 0.12); color: var(--pending); border-color: rgba(148, 163, 184, 0.24); }
.status-discarded { background: rgba(107, 114, 128, 0.14); color: var(--text-muted); border-color: rgba(107, 114, 128, 0.22); }

/* ─────────── Insights tab ─────────── */
.insights-grid { display: grid; gap: var(--s-3); }
.insight-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.018), rgba(255,255,255,0)) , var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-4) var(--s-3);
  box-shadow: var(--shadow-sm);
}
.insight-card h4 {
  margin: 0 0 var(--s-3);
  font-size: 10.5px;
  text-transform: uppercase;
  color: var(--text-faint);
  letter-spacing: 0.16em;
  font-weight: 600;
}
.insight-card .stats {
  display: flex;
  gap: var(--s-5);
  flex-wrap: wrap;
}
.insight-card .stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 60px;
}
.insight-card .stat b {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1;
}
.insight-card .stat span {
  font-size: 9.5px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
}
.insight-card p { margin: 0 0 var(--s-2); font-size: 12.5px; color: var(--text-dim); line-height: 1.55; }
.insight-card ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }
.insight-card li { margin-bottom: 4px; }
.insight-card li b { color: var(--text); font-weight: 600; }
.insight-card .empty { color: var(--text-faint); font-style: italic; font-family: var(--font-display); }

/* ─────────── Metric chart ─────────── */
.metric-dot {
  stroke: var(--bg);
  stroke-width: 1.5;
  cursor: pointer;
  transition: r 120ms var(--ease), stroke-width 120ms var(--ease);
}
.metric-dot:hover { stroke: var(--text); stroke-width: 2; }
.metric-dot.selected { stroke: var(--accent); stroke-width: 2.5; }
.metric-dot.kept       { fill: var(--good); }
.metric-dot.discarded  { fill: var(--bad); }
.metric-dot.crashed    { fill: #5a6374; }
.metric-dot.below_noise { fill: var(--warn); }
.metric-dot.running    { fill: var(--text-muted); }
.metric-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  opacity: 0.85;
  filter: drop-shadow(0 0 6px var(--accent-glow));
  stroke-linecap: round;
  stroke-linejoin: round;
}
.metric-area { fill: url(#metric-area-grad); opacity: 0.55; pointer-events: none; }
.metric-axis text {
  fill: var(--text-faint);
  font-size: 9.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.metric-axis line {
  stroke: var(--border);
  stroke-dasharray: 2 4;
}
.metric-axis .axis-label {
  font-family: var(--font-sans);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  fill: var(--text-faint);
}
.metric-pred-band { fill: var(--accent); opacity: 0.07; }
.metric-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-elev-3);
  border: 1px solid var(--border-strong);
  padding: 7px 10px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text);
  white-space: pre;
  z-index: 10;
  box-shadow: var(--shadow-md);
  line-height: 1.5;
}

/* ─────────── Notices, empty states ─────────── */
.notice {
  padding: var(--s-3) var(--s-5);
  color: var(--text-dim);
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.notice.warn  { color: var(--warn); }
.notice.error { color: var(--bad); border-left: 3px solid var(--bad); }

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  font-style: italic;
  font-family: var(--font-display);
  font-size: 13.5px;
  letter-spacing: 0;
}

/* ─────────── Responsive ─────────── */
@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr 1fr;
    grid-template-areas:
      "header"
      "left"
      "right";
  }
  .left-pane { border-right: none; border-bottom: 1px solid var(--border); }
}
