:root {
  --bg: #f5f1e8;
  --panel: #fffdf8;
  --ink: #202020;
  --muted: #6c675d;
  --line: #d6cfbf;
  --accent: #204d48;
  --claim: #e7efe3;
  --blueprint: #e2eef5;
  --iteration: #f7e8cf;
  --task: #f3dfd5;
  --result: #dfead7;
  --childrun: #e9e2f2;
  --childstep: #efe7f7;
  --query: #e8f0dc;
  --select: #dde9f7;
  --retrieval: #f6efe2;
  --retrieval_irrelevant: #ece9e3;
  --event: #f0ece4;
  --shadow: 0 10px 30px rgba(32, 32, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 35%),
    linear-gradient(180deg, #f8f5ee 0%, var(--bg) 100%);
}

.app {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) 12px minmax(480px, 560px);
  height: 100vh;
}

.main {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow-y: auto;
}

#canvasWrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.divider {
  position: relative;
  cursor: col-resize;
  background: linear-gradient(
    180deg,
    rgba(214, 207, 191, 0) 0%,
    rgba(214, 207, 191, 0.9) 18%,
    rgba(214, 207, 191, 0.9) 82%,
    rgba(214, 207, 191, 0) 100%
  );
}

.divider::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 72px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: #c0b7a6;
  box-shadow: 0 0 0 3px rgba(255, 253, 248, 0.9);
}

.divider:hover::before,
.divider.dragging::before {
  background: var(--accent);
}

.sidebar {
  background: rgba(255, 253, 248, 0.88);
  backdrop-filter: blur(12px);
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
}

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

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.hero h1 {
  font-size: 32px;
  margin-bottom: 8px;
}

.subtle {
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.controls select.bp-select {
  flex: 1 1 100%;
}

.upload,
.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.upload input {
  display: none;
}

.summary-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 12px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.stat .label {
  color: var(--muted);
  font-size: 11px;
}

.stat .value {
  font-size: 12px;
  font-weight: 600;
}

#canvasWrap {
  background: rgba(255, 255, 255, 0.5);
  overflow: hidden;
}

#graph {
  width: 100%;
  height: 100%;
  min-height: 640px;
}

.pillbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 22px;
}

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: var(--event);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f6f1e8;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
  overflow: auto;
}

.empty {
  padding: 28px;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.85);
  border: 1px solid var(--line);
  font-size: 12px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(32, 32, 32, 0.1);
}

.sidebar-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 4px 0 18px;
}

.detail-section {
  margin-bottom: 18px;
}

.detail-section ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

details {
  margin-top: 12px;
}

details summary {
  cursor: pointer;
  font-weight: 600;
}

.evidence-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.evidence-card {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(32, 32, 32, 0.06);
}

.evidence-card .evidence-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.evidence-card .evidence-index {
  flex-shrink: 0;
  font-size: 11px;
  font-family: monospace;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
}

.evidence-card .evidence-source {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.evidence-card .evidence-preview {
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  margin: 0 0 4px;
}

.evidence-card details {
  margin-top: 8px;
}

.evidence-card details summary {
  font-size: 13px;
}

/* ── Claim detail ──────────────────────────────────────────── */

.claim-text {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 14px;
  color: var(--ink);
}

.media-ref-badge {
  display: inline-block;
  font-size: 11px;
  font-family: monospace;
  background: var(--claim);
  border: 1px solid #b4c9ac;
  border-radius: 999px;
  padding: 1px 8px;
  color: #2a5a30;
  white-space: nowrap;
  vertical-align: middle;
}

.claim-media-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.claim-media-img {
  max-width: 100%;
  max-height: 260px;
  border-radius: 10px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #f0ece4;
  cursor: zoom-in;
}

.claim-media-video {
  max-width: 100%;
  max-height: 260px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #1a1a1a;
}

.claim-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.claim-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--ink);
}

.claim-meta-label {
  font-weight: 600;
  color: var(--muted);
  margin-right: 2px;
}

/* ── Blueprint viewer ──────────────────────────────────────── */

.bp-section {
  margin-bottom: 20px;
}
.bp-section h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.check-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.check-list li {
  font-size: 13px;
  line-height: 1.4;
}
.check-id {
  font-family: monospace;
  font-size: 11px;
  background: var(--event);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  margin-right: 6px;
  white-space: nowrap;
}
.condition-row {
  font-family: monospace;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 4px;
}
.condition-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.node-actions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.node-action-card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel);
  font-size: 13px;
}
.node-action-name {
  font-family: monospace;
  font-weight: 700;
  font-size: 12px;
  margin-bottom: 4px;
}
.node-action-field {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}
.node-action-field strong {
  color: var(--ink);
}
.gate-conditions {
  margin-top: 6px;
}
.gate-conditions p {
  font-size: 13px;
  margin-bottom: 4px;
}
.condition-chip {
  display: inline-block;
  font-family: monospace;
  font-size: 11px;
  background: var(--result);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  margin: 2px 2px 0 0;
}
.condition-chip.refute {
  background: var(--task);
}
.bp-description {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
  color: var(--ink);
}
select.bp-select {
  appearance: none;
  width: 100%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 32px 10px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236c675d' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.node-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.node-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.85);
  border: 1px solid var(--line);
  font-size: 12px;
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
  }

  .divider {
    display: none;
  }

  .sidebar {
    border-top: 1px solid var(--line);
  }
}

.graph-hint {
  position: absolute;
  bottom: 14px;
  right: 16px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  box-shadow: var(--shadow);
  pointer-events: none;
  user-select: none;
}

.media-unavailable {
  display: inline-block;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 4px;
  color: var(--subtle);
  font-size: 12px;
}
