@layer components {
  /* The journey canvas. Card internals use px so saved positions survive root font changes. */
  .journey { position: absolute; inset: 0; overflow: hidden; background: var(--surface-2); }
  .journey-float { position: absolute; left: var(--gap, 1.2rem); right: var(--gap, 1.2rem); z-index: 4; display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; pointer-events: none; }
  .journey-float > * { pointer-events: auto; }
  .journey-float.is-bottom { bottom: var(--gap, 1.2rem); justify-content: flex-end; }
  .journey-search { position: absolute; left: calc(100% + .6rem); top: auto; bottom: .2rem; display: flex; align-items: center; gap: .6rem; height: 4rem; padding: 0 .6rem 0 1rem; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow-float); }
  .journey-search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(var(--focus-rgb) / .15), var(--shadow-float); }
  .journey-search > .icon { width: 1.5rem; height: 1.5rem; color: var(--ink-3); }
  .search-field { width: 18rem; border: 0; outline: 0; background: transparent; font: inherit; font-size: 1.35rem; color: var(--ink); }
  .search-field::-webkit-search-cancel-button { display: none; }
  .journey-search kbd { margin-left: auto; }
  .search-results { left: 0; right: auto;  position: absolute; top: calc(100% + .4rem); width: min(36rem, 80vw); margin: 0; padding: .4rem; list-style: none; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow-float); }
  .search-result { display: grid; grid-template-columns: auto auto minmax(0, 1fr); align-items: center; gap: .7rem; width: 100%; padding: .6rem .8rem; border: 0; border-radius: var(--r-control); background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
  .search-result .kind-icon { width: 15px; height: 15px; }
  .search-result:hover, .search-result.is-active { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
  .search-id { font-family: var(--mono); font-size: 1.25rem; font-weight: 600; }
  .search-copy { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.25rem; color: var(--ink-3); }
  .search-empty { padding: .6rem .8rem; font-size: 1.3rem; color: var(--ink-3); }
  .journey.is-searching .node:not(.is-match), .journey.is-searching .journey-edges { opacity: .25; }
  .node.is-found { animation: node-found 1.6s ease-out; }
  @keyframes node-found { 0%, 30% { box-shadow: 0 0 0 6px rgb(var(--focus-rgb) / .35), var(--shadow-float); border-color: var(--focus); } 100% { box-shadow: 0 1px 2px rgb(var(--shade) / .05); } }
  @media (prefers-reduced-motion: reduce) { .node.is-found { animation: none; outline: 2px solid var(--focus); outline-offset: 3px; } }
  .palette { display: grid; gap: .2rem; }
  .zoom { display: flex; align-items: center; gap: .1rem; padding: .3rem; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--island); box-shadow: var(--shadow-float); backdrop-filter: blur(10px); }
  .zoom form { display: inline; }
  .zoom-level { min-width: 4.8rem; text-align: center; font-family: var(--mono); font-size: 1.2rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
  .journey-help { position: relative; }
  .journey-help > summary .icon { width: 18px; height: 18px; }
  .journey-help > summary { display: grid; place-items: center; list-style: none; cursor: pointer; }
  .journey-help > summary::-webkit-details-marker { display: none; }
  .journey-help[open] > summary { color: var(--ink); border-color: var(--line-strong); }
  .journey-help > p { bottom: 4.4rem; top: auto;  position: absolute; right: 0; width: min(34rem, 70vw); margin: 0; padding: 1.1rem 1.3rem; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--surface); color: var(--ink-2); font-size: 1.35rem; box-shadow: var(--shadow-float); }
  .chip { position: relative; display: grid; place-items: center; width: 4rem; height: 4rem; border: 0; border-radius: var(--r-control); background: transparent; color: var(--ink); text-decoration: none; cursor: grab; user-select: none; }
  /* Each chip names its kind and how to use it beside the rail. */
  .chip-label { position: absolute; left: calc(100% + 1.2rem); top: 50%; z-index: 20; display: grid; gap: .1rem; padding: .6rem 1rem; border-radius: var(--r-control); background: var(--inverse); color: var(--on-inverse); font-size: 1.2rem; font-weight: 450; white-space: nowrap; box-shadow: var(--shadow-float); pointer-events: none; opacity: 0; transform: translate(-.4rem, -50%); transition: opacity .12s ease, transform .12s ease; }
  .chip-label strong { font-size: 1.35rem; font-weight: 650; }
  .chip:hover .chip-label, .chip:focus-visible .chip-label { opacity: 1; transform: translate(0, -50%); transition-delay: .15s; }
  @media (max-width: 879px) { .chip-label { display: none; } }
  /* Right-click menu, opened at the pointer. */
  .context-menu { position: fixed; inset: auto; margin: 0; z-index: 30; min-width: 22rem; color: var(--ink); }
  .context-menu:not([open]) { display: none; }
  .context-group { display: grid; }
  .context-group[hidden], .context-menu .menu-item[hidden] { display: none; }
  .context-menu .menu-item kbd { margin-left: auto; }
  .chip .kind-icon { width: 3rem; height: 3rem; padding: .6rem; border-radius: var(--r-control); }
  .chip .kind-icon.is-menu { background: var(--menu-soft); }
  .chip .kind-icon.is-input { background: var(--input-soft); }
  .chip .kind-icon.is-router { background: var(--router-soft); }
  .chip .kind-icon.is-end { background: var(--end-soft); }
  .chip:hover { background: var(--surface-2); }
  .chip:active { cursor: grabbing; }
  .journey-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; background-color: var(--surface-2); background-image: radial-gradient(rgb(var(--ink-rgb) / .13) 1px, transparent 1.2px); background-size: 20px 20px; }
  .journey-viewport.is-panning { cursor: grabbing; }
  .journey-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
  .journey-canvas.is-zooming { will-change: transform; }
  .journey-canvas.is-unplaced { opacity: 0; pointer-events: none; }
  .journey-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
  .journey-edges:not(.is-lit-layer) { will-change: opacity; }
  /* Out of reach of the viewport: the card or link keeps its place and its size, and is not painted. */
  .node.is-culled, .cord.is-culled { visibility: hidden; }
  /* Unless it is being watched, held or walked to, in which case it stays drawn wherever it sits. */
  .node.is-culled:is(.is-selected, .is-dragging, .is-drop-target, .is-current, .is-found) { visibility: visible; }

  /* Links, in the colour of the screen they leave. */
  .cord-sheath { display: none; }
  .cord-core { fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; }
  .plug { fill: var(--ink-3); }
  .plug.is-faded { fill-opacity: .5; }
  .plug.is-menu { fill: var(--menu); }
  .plug.is-input { fill: var(--input); }
  .plug.is-router { fill: var(--router); }
  .plug.is-end { fill: var(--end); }
  .cord.is-menu .cord-core { stroke: var(--menu); }
  .cord.is-input .cord-core { stroke: var(--input); }
  .cord.is-router .cord-core { stroke: var(--router); }
  .cord.is-end .cord-core { stroke: var(--end); }
  /* Faded by the stroke rather than by the group: a group's half-opacity costs an offscreen layer for every link. */
  .cord.is-back .cord-core { stroke-opacity: .5; stroke-dasharray: 4 4; }
  .is-focusing .journey-edges:not(.is-lit-layer) { opacity: .15; }
  .cord.is-lit .cord-core { stroke-width: 2.4; stroke-opacity: 1; stroke-dasharray: none; }
  .cord-core.is-wire { stroke: var(--focus); stroke-width: 2; stroke-dasharray: 6 4; }

  /* A card is the screen itself: the message a caller reads, the options they press, and where each one goes. */
  .node { position: absolute; left: 0; top: 0; contain: layout style; width: 232px; border: 1px solid var(--line-strong); border-radius: var(--r-card); background: var(--surface); font-size: 12.5px; line-height: 1.4; box-shadow: 0 1px 2px rgb(var(--shade) / .05); cursor: grab; user-select: none; transition: box-shadow .12s ease, border-color .12s ease; }
  .node:hover { border-color: var(--ink-3); box-shadow: var(--shadow-float); }
  .node:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
  .node.is-dragging { z-index: 3; cursor: grabbing; box-shadow: 0 14px 34px rgb(var(--shade) / .2); transition: none; }
  .node.is-drop-target { border-color: var(--focus); box-shadow: 0 0 0 3px rgb(var(--focus-rgb) / .25); }
  .node.has-warning { border-color: var(--warning-line); }
  .node.has-error { border-color: var(--error-line); }
  .node-head { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; padding: 10px 10px 7px; border-radius: 0; background: var(--kind-soft, var(--surface-2)); box-shadow: inset 0 3px 0 var(--kind, var(--line-strong)); }
  .node.is-menu { --kind: var(--menu); --kind-soft: var(--menu-soft); }
  .node.is-input { --kind: var(--input); --kind-soft: var(--input-soft); }
  .node.is-router { --kind: var(--router); --kind-soft: var(--router-soft); }
  .node.is-end { --kind: var(--end); --kind-soft: var(--end-soft); }
  .node.is-unknown { --kind: var(--error); --kind-soft: var(--error-soft); }
  .node-head .kind-icon { width: 15px; height: 15px; }
  .kind-icon { flex: 0 0 auto; }
  .kind-icon.is-menu { color: var(--menu); }
  .kind-icon.is-input { color: var(--input); }
  .kind-icon.is-router { color: var(--router); }
  .kind-icon.is-end { color: var(--end); }
  .kind-icon.is-unknown { color: var(--error); }
  .node-id { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; font-weight: 600; }
  .node-flag { display: grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--warning); color: var(--on-accent); font-size: 11px; font-weight: 700; }
  .node-flag.is-error { background: var(--error); }

  .node-screen { margin: 0 7px 7px; padding: 8px 10px 9px; border: 1px solid var(--screen-line); border-radius: var(--r-control); background: var(--screen-bg); color: var(--screen-ink); font-family: var(--mono); font-size: 11.5px; line-height: 1.45; transition: background-color .15s ease, border-color .15s ease; }
  .node-copy { margin: 0; white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
  .copy-var { padding: 0 3px; border-radius: 3px; background: var(--input-soft); color: var(--input-ink); }
  .copy-var.is-sample { border-bottom: 1px dashed currentColor; cursor: help; }
  .node-options { list-style: none; margin: 7px 0 0; padding: 6px 0 0; border-top: 1px dashed var(--screen-rule); }
  .node-copy:empty + .node-options, .node-options:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
  .port { position: relative; }
  .port.is-option { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 7px; padding: 2px 0; }
  .node-key { display: grid; place-items: center; min-width: 17px; height: 17px; padding: 0 3px; border: 1px solid var(--keycap-line); border-bottom-width: 2px; border-radius: var(--r-control); background: var(--keycap); font-size: 10.5px; font-weight: 600; line-height: 1; }
  .port.is-option .port-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .node-answer { display: flex; align-items: center; gap: 6px; margin: 7px 0 0; padding-top: 6px; border-top: 1px dashed var(--screen-rule); color: var(--screen-muted); }
  .node-answer code { padding: 0 3px; border: 0; background: var(--input-soft); color: var(--input-ink); font-size: 11px; }
  .node-caret { width: 8px; height: 14px; border-radius: 1px; background: var(--input); opacity: .75; }

  .node-routes { margin: 0; padding: 0 0 6px; list-style: none; }
  .node.is-router .node-routes { padding-bottom: 5px; }
  .port.is-route { display: flex; justify-content: flex-end; align-items: center; min-height: 22px; padding: 1px 16px 1px 12px; color: var(--ink-2); font-family: var(--mono); font-size: 11px; line-height: 1.4; text-align: right; }
  .port.is-route .port-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .node-end { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0 10px 9px; font-size: 11.5px; color: var(--ink-3); }
  .node-end::before { content: ""; width: 14px; height: 2px; border-radius: 2px; background: var(--end); }

  /* Connectors sit on the right edge of an option line, or under a route chip. */
  .port-dot { position: absolute; top: 50%; width: 11px; height: 11px; margin-top: -5.5px; border: 2px solid var(--surface); border-radius: 50%; background: var(--ink-3); box-shadow: 0 0 0 1px var(--ink-3); cursor: crosshair; touch-action: none; transition: transform .1s ease; }
  .port.is-option .port-dot { right: -24px; }
  .port.is-route .port-dot { right: -6.5px; }
  .node.is-menu .port-dot { background: var(--menu); box-shadow: 0 0 0 1px var(--menu); }
  .node.is-input .port-dot { background: var(--input); box-shadow: 0 0 0 1px var(--input); }
  .node.is-router .port-dot { background: var(--router); box-shadow: 0 0 0 1px var(--router); }
  .port-dot:hover, .port.is-wiring .port-dot { transform: scale(1.4); }
  .port.is-unlinked .port-label { color: var(--ink-3); font-style: italic; }
  .node .port.is-unlinked .port-dot { background: var(--surface); box-shadow: 0 0 0 1px var(--ink-3); }
  .port.is-missing .port-label { color: var(--error); }
  .node .port.is-missing .port-dot { background: var(--error); box-shadow: 0 0 0 1px var(--error); }

  /* Routers are silent: no screen, a lighter dashed outline. */
  .node.is-router { width: auto; min-width: 150px; max-width: 250px; border-style: dashed; background: color-mix(in srgb, var(--surface) 70%, transparent); }
  /* The screen the phone is on lights up. */
  .node.is-current { border-color: var(--live); box-shadow: 0 0 0 3px var(--live-glow), var(--shadow-float); }
  .node.is-current .node-screen { background: var(--live-soft); border-color: var(--live-line); }
  .journey-trigger { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 7px; padding: 5px 12px 5px 9px; border-radius: 999px; background: var(--trigger-bg); color: var(--trigger-ink); box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-float); font-size: 12px; font-weight: 550; white-space: nowrap; box-shadow: var(--shadow-float); pointer-events: none; }
  .trigger-icon { width: 14px; height: 14px; color: var(--trigger-icon); }
  .trigger-line { fill: none; stroke: var(--ink-3); stroke-width: 1.6; stroke-dasharray: 3 4; }
  @media (max-width: 879px) {
    .journey-search { position: fixed; left: var(--gap); right: var(--gap); bottom: auto; top: 7.2rem; }
  }
}
