.folia-recipe-graph {
  --rg-soil: var(--soil, #171916);
  --rg-panel: var(--panel, #222520);
  --rg-inset: var(--inset, #191c18);
  --rg-line: var(--line, #3b4038);
  --rg-ink: var(--ink, #e8e8de);
  --rg-fog: var(--fog, #a5a99e);
  --rg-sage: var(--sage, #a3bd8c);
  --rg-rust: var(--rust, #d38b69);
  color: var(--rg-ink);
  background: var(--rg-soil);
  border: 1px solid var(--rg-line);
  border-radius: 8px;
  font: 13px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

.folia-recipe-graph * { box-sizing: border-box; }

.folia-recipe-graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--rg-line);
  background: var(--rg-panel);
}

.folia-recipe-graph-zoom { display: inline-flex; align-items: center; gap: 4px; }
.folia-recipe-graph-zoom button {
  min-width: 27px;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid var(--rg-line);
  border-radius: 4px;
  color: var(--rg-ink);
  background: var(--rg-inset);
  font: inherit;
  cursor: pointer;
}
.folia-recipe-graph-zoom button:last-child { padding-inline: 8px; font-size: 11px; }
.folia-recipe-graph-zoom-label { min-width: 38px; color: var(--rg-fog); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }

.folia-recipe-graph-count { color: var(--rg-fog); font-size: 12px; }
.folia-recipe-graph-expand { display: inline-flex; align-items: center; gap: 7px; color: var(--rg-ink); cursor: pointer; font-size: 12px; }
.folia-recipe-graph-expand input { accent-color: var(--rg-sage); margin: 0; }

.folia-recipe-graph-viewport {
  position: relative;
  max-width: 100%;
  max-height: 520px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--rg-line) var(--rg-soil);
}

.folia-recipe-graph-surface { position: relative; }
.folia-recipe-graph-canvas { position: relative; min-width: 100%; }
.folia-recipe-graph-canvas { transform-origin: top left; }
.folia-recipe-graph-edges { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.folia-recipe-graph-edge { fill: none; stroke: var(--rg-line); stroke-width: 1.5; }
.folia-recipe-graph-arrowhead { fill: var(--rg-sage); }

.folia-recipe-graph-node {
  position: absolute;
  width: 190px;
  min-height: 102px;
  padding: 8px;
  border: 1px solid var(--rg-line);
  border-radius: 7px;
  background: var(--rg-panel);
  z-index: 1;
}

.folia-recipe-graph-node.folia-recipe-graph-group { border-color: color-mix(in srgb, var(--rg-sage) 45%, var(--rg-line)); }
.folia-recipe-graph-select {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 3px;
  padding: 3px 4px 6px;
  border: 0;
  border-radius: 4px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.folia-recipe-graph-title { overflow: hidden; color: var(--rg-ink); font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }
.folia-recipe-graph-meta { overflow: hidden; color: var(--rg-fog); font: 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.folia-recipe-graph-select[aria-pressed="true"] { background: color-mix(in srgb, var(--rg-sage) 13%, transparent); }
.folia-recipe-graph-select:focus-visible,
.folia-recipe-graph-preview-link:focus-visible,
.folia-recipe-graph-expand input:focus-visible { outline: 2px solid var(--rg-sage); outline-offset: 2px; }
.folia-recipe-graph-outputs {
  overflow: hidden;
  padding: 5px 4px 0;
  border-top: 1px solid var(--rg-line);
  color: var(--rg-fog);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.folia-recipe-graph-preview { max-height: 142px; overflow: hidden; margin-top: 6px; padding: 5px; border-radius: 4px; background: var(--rg-inset); }
.folia-recipe-graph-preview .folia-nb-output { max-height: 112px; overflow: hidden; }
.folia-recipe-graph-preview .folia-nb-thumb { display: block; max-width: 100%; max-height: 78px; object-fit: contain; }
.folia-recipe-graph-preview .folia-nb-table { width: 100%; font-size: 9px; }
.folia-recipe-graph-preview .folia-nb-table th,
.folia-recipe-graph-preview .folia-nb-table td { max-width: 76px; overflow: hidden; padding: 2px 3px; text-overflow: ellipsis; white-space: nowrap; }
.folia-recipe-graph-preview .folia-nb-stat { font-size: 17px; }
.folia-recipe-graph-preview-link { margin-top: 4px; padding: 2px 0; border: 0; color: var(--rg-rust); background: transparent; font: inherit; font-size: 10px; cursor: pointer; }

@media (max-width: 600px) {
  .folia-recipe-graph-toolbar { align-items: flex-start; flex-direction: column; }
}

.folia-recipe-graph-thumbnail {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.folia-recipe-graph-thumbnail:focus-visible {
  outline: 2px solid var(--accent, #9ac9b4);
  outline-offset: 3px;
}

/* Connections and cards share fixed geometry with layoutRecipeGraph. */
.folia-recipe-graph-toolbar { flex-wrap: wrap; justify-content: flex-start; }
.folia-recipe-graph-count { margin-right: auto; }
.folia-recipe-graph-zoom button { min-height: 32px; min-width: 32px; }
.folia-recipe-graph-zoom button:disabled { opacity: .4; cursor: default; }
.folia-recipe-graph-edges { pointer-events: none; }
.folia-recipe-graph-connection { cursor: pointer; outline: none; }
.folia-recipe-graph-edge-halo { fill: none; stroke: var(--rg-soil); stroke-width: 6; pointer-events: none; }
.folia-recipe-graph-edge { stroke: color-mix(in srgb, var(--rg-fog) 70%, var(--rg-line)); stroke-width: 1.8; pointer-events: none; }
.folia-recipe-graph-edge-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; }
.folia-recipe-graph-arrowhead { fill: var(--rg-fog); }
.folia-recipe-graph-connection.is-on-path .folia-recipe-graph-edge,
.folia-recipe-graph-connection:focus-visible .folia-recipe-graph-edge { stroke: var(--rg-sage); stroke-width: 3; }
.folia-recipe-graph-connection:focus-visible .folia-recipe-graph-edge-halo { stroke: color-mix(in srgb, var(--rg-sage) 30%, var(--rg-soil)); stroke-width: 9; }
.folia-recipe-graph-connection.is-dimmed { opacity: .16; }
.folia-recipe-graph-node { padding: 0; min-height: 0; overflow: visible; }
.folia-recipe-graph-node.is-dimmed { opacity: .46; }
.folia-recipe-graph-node.is-on-path { border-color: color-mix(in srgb, var(--rg-sage) 65%, var(--rg-line)); }
.folia-recipe-graph-node.is-selected { border-color: var(--rg-sage); }
.folia-recipe-graph-select { position: absolute; top: 10px; left: 10px; width: calc(100% - 20px); height: 82px; padding: 4px 6px; justify-content: flex-start; gap: 4px; }
.folia-recipe-graph-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; white-space: normal; line-height: 18px; max-height: 54px; font-size: 14px; }
.folia-recipe-graph-meta { font-size: 10px; line-height: 15px; max-width: 100%; }
.folia-recipe-graph-inputs { position: absolute; left: 0; right: 0; }
.folia-recipe-graph-input { display: block; position: relative; width: 100%; padding: 2px 16px; border: 0; border-radius: 0; color: var(--rg-fog); background: transparent; text-align: left; font: 11px/20px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: visible; cursor: pointer; }
.folia-recipe-graph-input:hover,
.folia-recipe-graph-input:focus-visible { color: var(--rg-ink); background: color-mix(in srgb, var(--rg-sage) 10%, var(--rg-panel)); }
.folia-recipe-graph-input:focus-visible { outline: 2px solid var(--rg-sage); outline-offset: -2px; }
.folia-recipe-graph-port,
.folia-recipe-graph-output-port { position: absolute; width: 8px; height: 8px; border: 1px solid var(--rg-fog); background: var(--rg-panel); border-radius: 50%; }
.folia-recipe-graph-port { left: -4px; top: calc(50% - 4px); }
.folia-recipe-graph-output-port { right: -4px; top: 61px; }
.folia-recipe-graph-node-footer { position: absolute; left: 16px; right: 16px; }
.folia-recipe-graph-outputs { padding: 0; border: 0; font-size: 10px; line-height: 18px; }
.folia-recipe-graph-open-group,
.folia-recipe-graph-collapse { padding: 3px 6px; min-height: 28px; margin-top: 4px; border: 1px solid var(--rg-line); border-radius: 4px; background: var(--rg-inset); color: var(--rg-sage); font: inherit; font-size: 11px; cursor: pointer; }
.folia-recipe-graph-collapse { margin-top: 0; }
.folia-recipe-graph-trace { min-height: 52px; padding: 10px 14px; border-top: 1px solid var(--rg-line); color: var(--rg-fog); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.folia-recipe-graph-open-group:focus-visible,
.folia-recipe-graph-collapse:focus-visible,
.folia-recipe-graph-zoom button:focus-visible { outline: 2px solid var(--rg-sage); outline-offset: 2px; }
.folia-recipe-graph [hidden] { display: none; }
@media (max-width: 600px) {
  .folia-recipe-graph-toolbar { flex-direction: row; align-items: center; }
  .folia-recipe-graph-count { flex-basis: 100%; }
  .folia-recipe-graph-zoom button { min-height: 40px; min-width: 36px; }
}


/* Data labels wrap; exact operation input paths remain available on focus/inspect. */
.folia-recipe-graph-input { display: flex; align-items: center; padding: 4px 16px; font: 12px/16px system-ui, -apple-system, sans-serif; }
.folia-recipe-graph-input-label { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; max-height: 32px; overflow: hidden; white-space: normal; overflow-wrap: anywhere; }
.folia-recipe-graph-settings { margin: 0; }
.folia-recipe-graph-setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 32px; margin: 0; border-top: 1px solid var(--rg-line); }
.folia-recipe-graph-setting dt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rg-fog); font-size: 11px; }
.folia-recipe-graph-setting dd { margin: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--rg-ink); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.folia-recipe-graph-context-more { display: block; height: 20px; color: var(--rg-fog); font-size: 10px; }
.folia-recipe-graph-legend-heading { height: 24px; display: flex; align-items: center; color: var(--rg-fog); font-size: 10px; }
.folia-recipe-graph-class { height: 22px; display: flex; align-items: center; gap: 8px; font-size: 11px; }
.folia-recipe-graph-swatch { display: block; flex: 0 0 12px; height: 12px; border-radius: 2px; border: 1px solid var(--rg-line); }
.folia-recipe-graph-class-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.folia-recipe-graph-class-code { margin-left: auto; color: var(--rg-fog); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }

/* A bounded host can opt into fitting both dimensions. Contain the unscaled
   layout box so it cannot create phantom scrollbars beyond the scaled graph. */
.folia-recipe-graph[data-fit-mode="viewport"] .folia-recipe-graph-surface { overflow: hidden; margin-inline: auto; }
