@import url('./reentry-specimens.css');

/* Reentry · tissue bench. Same language as the Hyphae culture bench (components in hyphae.css):
   bench on the black stage, numbered rail, one neutral primary action.
   Bench = what runs next (media library, field, start) and a monitor of what runs now.
   Stage = the running tissue. Rail = live instruments: Excite, Dynamics, Image.
   Accent = the running palette; the tab keeps PHOSPHOR, the identity of the process.
   The stage stays black in both themes, so stage text uses fixed stage colours. */
body:not([data-process=barkley]) :is(#reentry-hud, #reentry-overlay, #reentry-live-name, #reentry-stage-meta, #reentry-next-flag) { display: none !important; }

/* ---------- Accent from the running palette ----------
   --accent-stage: the bright stop, used on the black stage in both themes.
   --accent-light: darker step for light surfaces, at least 4.6:1 on --bg. */
body[data-process=barkley] {
  --st-text: #ededf0; --st-muted: #a1a1aa; --st-faint: #8a8a94; --st-dim: #787882; --st-hair: #ffffff17;
  --hud-w: clamp(196px, 21cqw, 252px);
  --ease: cubic-bezier(.2,.8,.2,1);
  --accent-stage: #3ce296; --accent-light: #0b7a4f;
}
body[data-process=barkley][data-palette=PHOSPHOR] { --accent-stage: #3ce296; --accent-light: #0b7a4f; --accent-ink: #03120b; }
body[data-process=barkley][data-palette=CIRCUIT] { --accent-stage: #ff5e00; --accent-light: #c24400; --accent-ink: #160600; }
body[data-process=barkley][data-palette=ARGON] { --accent-stage: #ee1c80; --accent-light: #d7006c; --accent-ink: #18020c; }
body[data-process=barkley][data-palette=OXIDE] { --accent-stage: #f0a234; --accent-light: #a25d1f; --accent-ink: #180f02; }
body[data-process=barkley][data-palette=NEON] { --accent-stage: #60e8f0; --accent-light: #d5007c; --accent-ink: #021416; }
body[data-process=barkley][data-palette=ICE] { --accent-stage: #3092ff; --accent-light: #0068e4; --accent-ink: #020a18; }
body[data-process=barkley][data-palette=RUBY] { --accent-stage: #f0343a; --accent-light: #de000d; --accent-ink: #180204; }
body[data-process=barkley][data-palette=MERCURY] { --accent-stage: #a0aaba; --accent-light: #606f85; --accent-ink: #0b0c0e; }
body[data-process=barkley][data-palette=CITRON] { --accent-stage: #aace14; --accent-light: #617601; --accent-ink: #0b1000; }
body[data-process=barkley][data-palette=DRIVE] { --accent-stage: #ff5c26; --accent-light: #c24400; --accent-ink: #180600; }
body[data-process=barkley][data-palette] { --accent: var(--accent-stage); }
:root[data-theme=light] body[data-process=barkley][data-palette] { --accent: var(--accent-light); --accent-ink: #ffffff; }
body[data-process=barkley] #process-barkley[aria-pressed=true] { border-bottom-color: #3ce296; box-shadow: inset 0 -1px 0 #3ce296; }
:root[data-theme=light] body[data-process=barkley] #process-barkley[aria-pressed=true] { border-bottom-color: #0b7a4f; box-shadow: inset 0 -1px 0 #0b7a4f; }

/* ---------- Stage ---------- */
body[data-process=barkley] .live-dot { background: var(--accent-stage); box-shadow: 0 0 10px var(--accent-stage); }
body[data-process=barkley] .live-dot::after { border-color: var(--accent-stage); }
body[data-process=barkley].is-paused .live-dot { background: var(--hud); box-shadow: none; }
.live-name { margin-left: 6px; color: var(--hud-strong); }
#reentry-stage-meta { color: var(--hud); }
.next-flag { display: inline-flex; align-items: center; gap: 8px; color: var(--hud-strong); }
.next-flag::before { content: ""; width: 22px; height: 1px; background: #ffffff38; }
.next-flag i { width: 6px; height: 6px; border-radius: 50%; border: 1px dashed #f4f4f6; }
body[data-process=barkley] .canvas-wrap { inset: 0 0 0 var(--hud-w); --side: min(calc(100cqw - var(--hud-w) - 64px), calc(100cqh - 120px)); outline: 0; }
body[data-process=barkley] .canvas-wrap::before { top: -9px; }

/* Overlay in field units (viewBox 256): rim ticks, the Ring hole, pacemaker sites. */
.stage-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.stage-overlay .tick { stroke: #ffffff2e; stroke-width: .45; }
.stage-overlay .tick.major { stroke: #ffffff5c; }
.stage-overlay .hole { fill: none; stroke: #ffffff52; stroke-width: .45; stroke-dasharray: 1.6 1.6; }
.stage-overlay text { font: 4.2px var(--mono); letter-spacing: .04em; fill: #f4f4f6; paint-order: stroke; stroke: #000000c0; stroke-width: 1.1px; }
.stage-overlay .hole-label { fill: #a1a1aa; text-anchor: middle; }
.stage-overlay .site circle, .stage-overlay .site path { fill: none; stroke: #f4f4f6; stroke-width: .55; }
.stage-overlay .site .pulse { stroke: var(--accent-stage); stroke-width: .6; }
.stage-overlay .site text.period { fill: #a1a1aa; }
body[data-tool=cut] .cursor-ring { border-style: dashed; }
body[data-tool=scar] .cursor-ring { box-shadow: 0 0 0 2px #00000080, inset 0 0 0 1px #ffffff80; }
body[data-tool=pacemaker] .cursor-ring { border-style: dotted; }

/* ---------- Bench ---------- */
body[data-process=barkley] #reentry-hud { position: absolute; z-index: 2; left: 24px; top: 56px; bottom: 52px; width: calc(var(--hud-w) - 30px); display: block; overflow-y: auto; scrollbar-width: none; color: var(--st-text); }
#reentry-hud::-webkit-scrollbar { display: none; }
#reentry-hud .hud-next, #reentry-hud .hud-monitor { display: none; }
body[data-preview] #reentry-hud .hud-next { display: block; }
body:not([data-preview]) #reentry-hud .hud-monitor { display: block; }

/* Next medium: a living specimen (loop) over its still, the way the tissue opens after Run. */
#reentry-hud .specimen { width: min(100%, 152px); background: var(--loop, none) center / 100% 100% no-repeat, #000 var(--still, none) center / 100% 100% no-repeat; }
#reentry-hud .specimen-name small { color: var(--st-muted); }
.specimen-tag { display: inline-flex; align-items: center; gap: 6px; }
.specimen-tag i { width: 22px; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--r0), var(--r1), var(--r2), var(--r3), var(--r4), var(--r5)); }
.rule-key i { flex: none; width: 9px; height: 9px; border-radius: 50%; border: 1px solid #ffffff73; }
body:is([data-preview=TURBULENCE]) .rule-key i { border-style: dashed; }
#reentry-hud .strip-scale span:first-child { overflow: hidden; text-overflow: ellipsis; }
#reentry-hud .growth { margin-top: 10px; }
#reentry-hud .specimen-caption { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

/* Media library. White ring: chosen for the next run. Dot: running now. Dashed: the second rule. */
#reentry-media.wells { gap: 8px; }
#reentry-media .well img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
#reentry-media .well[data-rule=be]::before { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 1px dashed #ffffff42; pointer-events: none; }
#reentry-media .well[aria-pressed=true] { box-shadow: inset 0 0 0 1px #ffffff33, 0 0 0 3px #000, 0 0 0 4.5px #f4f4f6, 0 0 22px -6px #f4f4f6; }
#reentry-media .well[data-running] { filter: none; }
#reentry-media .well[data-running]::after { content: ""; position: absolute; top: 0; right: 0; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-stage); box-shadow: 0 0 0 2px #000, 0 0 10px var(--accent-stage); }
#reentry-hud .library-label { margin-top: 14px; padding-top: 12px; }
.recipe-label { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--st-hair); }
.stage-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; margin: 0 0 6px; border: 1px solid #ffffff1c; border-radius: 7px; }
.stage-seg button { display: flex; align-items: center; justify-content: center; gap: 7px; height: 28px; padding: 0 6px; border: 1px solid transparent; border-radius: 4.5px; background: transparent; color: var(--st-faint); font-size: 12px; }
.stage-seg button:hover { color: var(--st-text); }
.stage-seg button[aria-pressed=true] { background: #ffffff12; border-color: #ffffff2e; color: #f4f4f6; }
.stage-seg button[data-next] { border-style: dashed; border-color: #ffffff6b; }
.ico.ring { position: relative; width: 12px; height: 12px; border-radius: 50%; }
.ico.ring::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 1px solid currentColor; }
body[data-armed] .recipe-label b { color: #f4f4f6; }

/* Monitor: the running tissue in numbers. The trace is the measured rotor count, never decoration. */
.vital { display: grid; grid-template-columns: auto 1fr; align-items: end; gap: 4px 14px; }
.vital-num { margin: 0; }
.vital-num dt { font: 10.5px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--st-faint); }
.vital-num dd { margin: 2px 0 0; min-width: 1ch; font: 200 52px/.92 var(--display); letter-spacing: -.04em; color: #f4f4f6; font-variant-numeric: tabular-nums; }
.trace { display: block; width: 100%; height: 50px; overflow: visible; }
.trace .grid { stroke: #ffffff12; stroke-width: 1; }
.trace .line { fill: none; stroke: var(--accent-stage); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; filter: drop-shadow(0 0 3px color-mix(in srgb, var(--accent-stage) 70%, transparent)); }
.trace .area { fill: url(#reentry-trace-fill); }
.trace-scale { grid-column: 2; display: flex; justify-content: space-between; font: 10.5px var(--mono); color: var(--st-dim); }
#reentry-hud .metrics { display: grid; grid-template-columns: auto 1fr; gap: 14px 24px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--st-hair); }
#reentry-hud .metrics dd small { margin-left: 3px; font: 10.5px var(--mono); letter-spacing: .04em; color: var(--st-faint); }
#reentry-hud .metrics .sub { display: block; margin-top: 5px; font: 10.5px var(--mono); letter-spacing: .04em; color: var(--st-dim); }
#reentry-hud .readout:not([hidden]) { display: block; position: static; width: auto; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--st-hair); font: 10.5px/1.6 var(--mono); }
#reentry-hud .readout div { display: flex; justify-content: space-between; gap: 8px; padding: 0; border: 0; }
#reentry-hud .readout dt { color: var(--st-faint); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; }
#reentry-hud .readout dd { margin: 0; color: var(--st-muted); text-align: right; }

/* ---------- Rail ----------
   One flex column: the shared Brush and Speed controls slot into Excite and Dynamics by order. */
body[data-process=barkley] .controls { padding-top: 20px; }
body[data-process=barkley] .panel-heading { margin-bottom: 12px; }
body[data-process=barkley] .process-section { display: flex; flex-direction: column; border: 0; padding: 0; margin: 0; }
body[data-process=barkley] .process-section > .section-label { display: none; }
body[data-process=barkley] #barkley-controls, body[data-process=barkley] #reentry-tool-panel:not([hidden]) { display: contents; }
body[data-process=barkley] .reentry-excite-label { order: 1; }
body[data-process=barkley] #reentry-tools { order: 2; }
body[data-process=barkley] :is(#reentry-tool-param-row, #reentry-tool-param, label[for=brush], #brush) { order: 3; }
body[data-process=barkley] .tool-actions { order: 4; }
body[data-process=barkley] #reentry-tool-sites { order: 5; }
body[data-process=barkley] #reentry-tool-help { order: 6; }
body[data-process=barkley] .reentry-dynamics-label { order: 10; }
body[data-process=barkley] :is(label[for=excitability], #excitability, #reentry-excitability-help) { order: 11; }
body[data-process=barkley] :is(label[for=speed], #speed) { order: 12; }
body[data-process=barkley] :is(.reentry-excite-label, .reentry-dynamics-label) { padding-top: 14px; border-top: 1px solid var(--line); }
body[data-process=barkley] .reentry-dynamics-label { margin-top: 18px; }
body[data-process=barkley] #barkley-image { margin-top: 18px; padding-top: 14px; }
body[data-process=barkley] :is(.process-section, #barkley-image) label { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 0 6px; font-size: 12.5px; }
body[data-process=barkley] :is(.process-section, #barkley-image) label output { margin-left: auto; color: var(--text); font: 12px var(--mono); }
body[data-process=barkley] .reentry-dynamics-label + label { margin-top: 2px; }
/* The stage hint already carries the tool help; the excitability note matters only where the slider does little. */
body[data-process=barkley] #reentry-tool-help, body[data-process=barkley]:not([data-medium=TURBULENCE]) #reentry-excitability-help { display: none; }
body[data-process=barkley] input[type=range]::-webkit-slider-thumb { width: 12px; height: 12px; margin-top: -5px; border-width: 1.5px; }

.tool-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool-grid .tool { height: 52px; flex-direction: column; gap: 5px; padding: 0 4px; font-size: 11.5px; color: var(--muted); }
.tool-grid .tool:hover { color: var(--text); }
:is(.tool-grid .tool, #reentry-tool-erase)[aria-pressed=true] { background: var(--text); border-color: var(--text); color: var(--bg); }
.tool-ico { width: 16px; height: 16px; background: currentColor; -webkit-mask: var(--icon) center / 16px 16px no-repeat; mask: var(--icon) center / 16px 16px no-repeat; }
[data-reentry-tool=stimulus] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='1.6' fill='%23000' stroke='none'/%3E%3Ccircle cx='8' cy='8' r='4.2'/%3E%3Cpath d='M8 1.2v1.6M8 13.2v1.6M1.2 8h1.6M13.2 8h1.6'/%3E%3C/svg%3E"); }
[data-reentry-tool=beat] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 9h3.2l1.6-4.6 2.6 8.6 1.7-5.2 1 1.2H15'/%3E%3C/svg%3E"); }
[data-reentry-tool=cut] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 13.5 13.5 2.5' stroke-dasharray='2.2 1.8'/%3E%3Cpath d='M10.5 2.5h3v3'/%3E%3C/svg%3E"); }
[data-reentry-tool=scar] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Cpath d='M2.5 13.5 13.5 2.5' stroke-width='1.7'/%3E%3Cpath d='M4.4 9.4l2.2 2.2M6.9 6.9l2.2 2.2M9.4 4.4l2.2 2.2'/%3E%3C/svg%3E"); }
[data-reentry-tool=pacemaker] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3'%3E%3Ccircle cx='8' cy='8' r='1.4' fill='%23000' stroke='none'/%3E%3Ccircle cx='8' cy='8' r='3.8'/%3E%3Ccircle cx='8' cy='8' r='6.6' stroke-dasharray='1.6 1.6'/%3E%3C/svg%3E"); }
[data-reentry-tool=pulse] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23000' stroke-width='1.3' stroke-linejoin='round'%3E%3Cpath d='M9.2 1.5 4 9h3.6l-1 5.5L12 7H8.3z'/%3E%3C/svg%3E"); }
.tool-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tool-actions:not(:has(> :not([hidden]))) { display: none; }
.tool-actions .tool { margin-top: 10px; }
.tool-actions .tool:only-child, .tool-actions .tool:has(+ [hidden]), .tool-actions [hidden] + .tool { grid-column: 1 / -1; }
.sites { margin-top: 12px; }
.sites .pin { position: relative; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--text); }
.sites .pin::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--text); }
.sites .coord { font: 10.5px var(--mono); color: var(--muted); white-space: nowrap; }

.rotor-count { margin-left: auto; color: var(--faint); }
.rotor-count b { margin-left: 4px; font-weight: 400; color: var(--text); font-variant-numeric: tabular-nums; }
.switch { position: relative; flex: none; width: 26px; height: 15px; padding: 0; border: 0; border-radius: 8px; background: var(--line-strong); }
.switch::after { content: ""; position: absolute; top: 2.5px; left: 2.5px; width: 10px; height: 10px; border-radius: 50%; background: var(--text); transition: transform .2s var(--ease); }
.switch[aria-pressed=true] { background: var(--accent); }
.switch[aria-pressed=true]::after { transform: translateX(11px); background: var(--accent-ink); }
.seg-pair { display: grid; grid-template-columns: 1.25fr 1fr; gap: 6px; }
.seg-pair .segments button { padding: 7px 2px; font-size: 12px; }
.palette-channels { display: grid; grid-template-columns: repeat(9, 1fr); gap: 7px; margin: 14px 0 0; }
.palette-channels .channel { width: 100%; background: radial-gradient(circle closest-side, var(--r0) 0, var(--r1) 30%, var(--r2) 52%, var(--r3) 70%, var(--r4) 86%, var(--r5) 100%); }
.palette-channels .channel[aria-pressed=true] { box-shadow: inset 0 0 0 1px #ffffff33, 0 0 0 2.5px var(--panel), 0 0 0 4px var(--text); }
.palette-channels .channel:disabled { opacity: .28; transform: none; }
.palette-name { display: flex; justify-content: space-between; margin: 10px 0 0; font: 10.5px var(--mono); letter-spacing: .06em; color: var(--faint); }
.palette-name b { font-weight: 400; color: var(--text); letter-spacing: .1em; }
body[data-process=barkley] #barkley-image .legend { margin-top: 10px; }
body[data-process=barkley] #barkley-image .gradient { height: 4px; border-radius: 2px; }
:root[data-theme=light] body[data-process=barkley] #barkley-image .gradient { box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- Actions: Run when a tissue is armed; pause, reset and Save image in one row ---------- */
body[data-process=barkley] .actions { grid-template-columns: 40px 40px minmax(0,1fr); }
body[data-process=barkley] #reentry-run { grid-column: 1 / -1; }
body[data-process=barkley] #reentry-keep { grid-column: 1 / -1; justify-self: start; margin-top: -2px; }
body[data-process=barkley] .cta .cta-sub, #reentry-run small { text-transform: none; letter-spacing: .02em; }
body[data-process=barkley] .transport button { height: 40px; padding: 0; font-size: 14px; }
body[data-process=barkley] #pause span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
body[data-process=barkley] #reset { font-size: 0; }
body[data-process=barkley] #reset::before { content: "↺"; font-size: 15px; }
body[data-process=barkley] .export { grid-column: auto; align-items: center; height: 40px; padding: 0 14px; }
body[data-process=barkley] #save-session { grid-column: 1 / 3; }
body[data-process=barkley] #load-session { grid-column: 3; }
body[data-process=barkley] #reentry-save-help { grid-column: 1 / -1; margin: 0; }

/* ---------- Short windows ---------- */
@media (max-height: 860px) {
  body[data-process=barkley] .panel-heading { margin-bottom: 6px; }
  body[data-process=barkley] .panel-heading h2 { font-size: 22px; }
  body[data-process=barkley] :is(#reentry-excitability-help, #barkley-image .rail-help:last-child) { display: none; }
}
@container (max-height: 700px) {
  body[data-process=barkley] #reentry-hud { top: 50px; bottom: 46px; }
  #reentry-hud .specimen { width: 112px; margin-bottom: 8px; }
  #reentry-hud .specimen-name { font-size: 22px; }
  #reentry-hud :is(.growth, .wells-key) { display: none; }
  .vital-num dd { font-size: 40px; }
  #reentry-hud .readout:not([hidden]) { display: none; }
}
@container (max-width: 780px) {
  body[data-process=barkley] { --hud-w: 176px; }
  #reentry-hud :is(.specimen, .growth) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #reentry-hud .specimen { background: #000 var(--still, none) center / 100% 100% no-repeat; }
  .switch::after { transition: none; }
}
