:root {
  color-scheme: dark;
  font-family: Inter, system-ui, sans-serif;
  --bg: #0b1020;
  --panel: #121a2f;
  --panel2: #17213b;
  --text: #eef3ff;
  --muted: #94a3c8;
  --line: #263451;
  --a: #73a7ff;
  --b: #67e8b3;
  --start: #ff657a;
  --end: #73a7ff;
  --bad: #ff8a9b;
  --warn: #ffd47a;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-width: 320px; color: var(--text); background:
  radial-gradient(circle at 20% -10%, #73a7ff25, transparent 34rem), var(--bg);
}
a { color: var(--a); }
button, select, textarea, input { font: inherit; }
.hero, main, footer { width: calc(100% - 32px); max-width: none; margin-inline: auto; }
.hero { padding: 38px 0 22px; display: flex; justify-content: space-between; gap: 24px; align-items: end; }
.hero h1 { margin: 3px 0 5px; font-size: clamp(2.3rem, 5vw, 4.2rem); letter-spacing: -.05em; }
.hero p, .hint { color: var(--muted); }
.hero-note { max-width: 370px; padding: 14px 16px; border: 1px solid #ffd47a55; background: #ffd47a10; border-radius: 15px; display: grid; gap: 5px; }
.hero-note strong { color: var(--warn); }
.hero-note span { color: var(--muted); font-size: .9rem; }
.eyebrow { margin: 0; color: var(--b) !important; font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
main { display: grid; gap: 15px; padding-bottom: 28px; }
.panel { padding: 17px; background: var(--panel); border: 1px solid var(--line); border-radius: 17px; box-shadow: 0 18px 45px #0003; }
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.field { display: grid; gap: 5px; }
.field.wide, .status { grid-column: 1 / -1; }
label { color: var(--muted); font-size: .83rem; font-weight: 700; }
select, textarea, button { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 10px; }
select, button { min-height: 41px; padding: 0 11px; }
textarea { width: 100%; min-height: 145px; padding: 14px; resize: vertical; font: 1rem/1.5 ui-monospace, monospace; }
button { cursor: pointer; font-weight: 750; }
button:hover { border-color: var(--a); }
button.primary { background: var(--a); color: #081221; border-color: transparent; }
.check { grid-column: span 2; display: flex; align-items: center; gap: 8px; }
.actions { display: flex; justify-content: end; gap: 8px; }
.status { font-family: ui-monospace, monospace; }
.status.ok { color: var(--b); }
.status.error { color: var(--bad); }
.section-title { display: flex; justify-content: space-between; align-items: end; gap: 15px; margin-bottom: 11px; }
.section-title h2, .rep h3 { margin: 2px 0 0; }
.hint, .legend { font-size: .82rem; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.metric { padding: 10px 11px; background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; min-width: 0; }
.metric span { display: block; color: var(--muted); font-size: .73rem; margin-bottom: 4px; }
.metric strong { display: block; overflow-wrap: anywhere; }
.representation-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.rep { min-width: 0; }
pre { margin: 9px 0 0; padding: 11px; max-height: 330px; overflow: auto; color: #cfe0ff; background: #09101e; border: 1px solid #ffffff0e; border-radius: 11px; font: .81rem/1.43 ui-monospace, monospace; }
.machine-workspace {
  display: grid;
  grid-template-columns: minmax(420px, .88fr) minmax(560px, 1.35fr);
  gap: 15px;
  align-items: stretch;
}
.debugger-panel, .graph-panel { min-width: 0; }
.debugger-panel { display: flex; flex-direction: column; }
.debug-controls {
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) auto auto auto;
  gap: 7px;
  align-items: center;
  margin-bottom: 9px;
}
.debug-controls button { min-width: 38px; padding-inline: 9px; }
#debugRange { width: 100%; min-width: 90px; }
#debugStep { white-space: nowrap; font: .83rem ui-monospace, monospace; }
.debug-source {
  min-height: 42px;
  margin-bottom: 12px;
  padding: 8px 10px;
  overflow-x: auto;
  white-space: nowrap;
  background: #09101e;
  border: 1px solid #ffffff0e;
  border-radius: 10px;
  font: .9rem/1.4 ui-monospace, monospace;
}
.debug-char { display: inline-block; min-width: 1.2em; padding: 2px 3px; text-align: center; border-radius: 5px; }
.debug-char.active { background: var(--warn); color: #111827; font-weight: 800; }
.debug-caret { display: inline-block; width: 2px; height: 1.35em; margin-left: 3px; vertical-align: middle; background: var(--warn); }
.debug-grid { display: grid; grid-template-columns: 1fr; gap: 10px; min-height: 0; }
.debug-card { min-width: 0; }
.debug-card h3 { margin: 0 0 5px; font-size: 1rem; }
.debug-card pre { max-height: 250px; }
.debug-stack { display: grid; gap: 7px; }
.stack-frame { padding: 9px 10px; background: #09101e; border: 1px solid #ffffff0e; border-radius: 10px; font: .79rem/1.45 ui-monospace, monospace; }
.stack-frame.top { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.stack-values { color: #cfe0ff; overflow-wrap: anywhere; }
.graph-panel { display: flex; flex-direction: column; }
.graph-heading { align-items: center; }
.graph-toolbar { display: flex; align-items: center; justify-content: end; gap: 7px; flex-wrap: wrap; }
.graph-toolbar label { margin-right: 2px; }
.graph-toolbar select { min-width: 150px; }
.graph-toolbar button { min-height: 36px; padding-inline: 10px; }
.graph-toolbar .graph-zoom { width: 38px; padding: 0; font-size: 1.25rem; line-height: 1; }
.graph-meta { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin: -2px 0 9px; }
.graph-physics-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #09101e;
  border-radius: 11px;
}
.graph-physics-controls[hidden] { display: none; }
.physics-range { display: grid; gap: 6px; min-width: 0; }
.physics-range > span { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.physics-range output { color: var(--b); font: .78rem ui-monospace, monospace; }
.physics-range input { width: 100%; }
.physics-actions { display: flex; gap: 7px; align-items: end; }
.physics-actions button { min-height: 36px; white-space: nowrap; }
#graph {
  width: 100%;
  height: min(68vh, 720px);
  min-height: 560px;
  background: #08101d;
  border: 1px solid #ffffff0d;
  border-radius: 13px;
  overflow: hidden;
  touch-action: none;
}
#graph > canvas { width: 100%; height: 100%; }
.machine-workspace #graph { flex: 1 1 520px; height: auto; min-height: 520px; }
#graph:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }
.start-line, .end-line {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 13px;
  margin-inline: 2px;
  vertical-align: middle;
  transform: translateY(-1px);
}
.start-line::after, .end-line::before {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: 6px;
  height: 2px;
  border-radius: 999px;
}
.start-line::before {
  content: "×";
  position: absolute;
  left: -2px;
  top: -6px;
  z-index: 1;
  color: var(--start);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}
/* RGB-путь связи: начало красное -> центр зелёный -> конец синий. */
.start-line::after { background: linear-gradient(90deg, var(--start), var(--b)); }
.end-line::before { background: linear-gradient(90deg, var(--b), var(--end)); }
.end-line::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 2px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--end);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 9px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .75rem; }
td:last-child { min-width: 330px; font-family: ui-monospace, monospace; }
#trace tr[data-step] { cursor: pointer; }
#trace tr[data-step]:hover { background: #ffffff08; }
#trace tr[data-step].active { background: #ffd47a12; box-shadow: inset 3px 0 0 var(--warn); }
.export-controls { display: flex; gap: 8px; margin-bottom: 11px; }
details summary { cursor: pointer; color: var(--a); }
footer { display: flex; gap: 15px; padding: 18px 0 30px; border-top: 1px solid var(--line); color: var(--muted); font-size: .84rem; align-items: center; }
footer > span:first-child { margin-right: auto; }
.app-version { padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); font: .75rem ui-monospace, monospace; }
@media (max-width: 1150px) {
  .machine-workspace { grid-template-columns: 1fr; }
  .machine-workspace #graph { height: 620px; min-height: 500px; }
}
@media (max-width: 900px) {
  .hero { display: grid; }
  .controls, .representation-grid { grid-template-columns: 1fr 1fr; }
  .graph-heading, .graph-meta { align-items: stretch; flex-direction: column; }
  .graph-toolbar { justify-content: start; }
  .graph-physics-controls { grid-template-columns: 1fr 1fr; }
  .physics-actions { grid-column: 1 / -1; }
  #graph { height: 600px; min-height: 480px; }
}
@media (max-width: 620px) {
  .hero, main, footer { width: calc(100% - 18px); }
  .controls, .representation-grid { grid-template-columns: 1fr; }
  .check { grid-column: span 1; }
  .actions, .section-title, footer, .export-controls { flex-direction: column; align-items: stretch; }
  .debug-controls { grid-template-columns: auto auto 1fr auto auto; }
  #debugStep { grid-column: 1 / -1; text-align: right; }
  footer > span:first-child { margin-right: 0; }
  .graph-toolbar { display: grid; grid-template-columns: 1fr auto auto; }
  .graph-toolbar label { grid-column: 1 / -1; }
  .graph-toolbar select { grid-column: span 2; min-width: 0; }
  .graph-physics-controls { grid-template-columns: 1fr; }
  .physics-actions { grid-column: auto; display: grid; grid-template-columns: 1fr 1fr; }
  .machine-workspace #graph, #graph { height: 520px; min-height: 420px; }
}

body.graph-fullscreen-active { overflow: hidden; }
.graph-panel:fullscreen,
.graph-panel.graph-fullscreen-fallback {
  width: 100vw;
  height: 100vh;
  max-width: none;
  margin: 0;
  padding: 12px;
  border-radius: 0;
  background: var(--panel);
  overflow: hidden;
}
.graph-panel.graph-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 1000;
}
.graph-panel:fullscreen #graph,
.graph-panel.graph-fullscreen-fallback #graph,
.machine-workspace .graph-panel:fullscreen #graph,
.machine-workspace .graph-panel.graph-fullscreen-fallback #graph {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 0;
}
.graph-panel:fullscreen .graph-heading,
.graph-panel.graph-fullscreen-fallback .graph-heading {
  flex: 0 0 auto;
}
.graph-panel:fullscreen .graph-meta,
.graph-panel.graph-fullscreen-fallback .graph-meta,
.graph-panel:fullscreen .graph-physics-controls,
.graph-panel.graph-fullscreen-fallback .graph-physics-controls {
  flex: 0 0 auto;
}

/* Blueprint — цельная SVG-связь start -> center -> end; semantic RGB остаётся общим. */
.blueprint-svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  user-select: none;
  background:
    linear-gradient(#ffffff08 1px, transparent 1px),
    linear-gradient(90deg, #ffffff08 1px, transparent 1px);
  background-size: 32px 32px;
}
.blueprint-svg:active { cursor: grabbing; }
.blueprint-curve {
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  opacity: .9;
  transition: opacity .12s ease, filter .12s ease;
}
.blueprint-center-group { cursor: move; outline: none; }
.blueprint-center-halo {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.blueprint-center-dot {
  stroke: #07101c;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.blueprint-center-dot.root { stroke: var(--warn); stroke-width: 2.5; }
.blueprint-label {
  fill: var(--text);
  paint-order: stroke;
  stroke: #08101d;
  stroke-width: 4;
  stroke-linejoin: round;
  font: 700 13px ui-monospace, monospace;
  pointer-events: none;
}
.blueprint-selected.blueprint-center-group .blueprint-center-halo {
  stroke: var(--warn);
  fill: #ffd47a18;
}
.blueprint-selected.blueprint-curve,
.blueprint-selected .blueprint-curve { filter: drop-shadow(0 0 5px #ffd47a88); opacity: 1; }
.blueprint-debug-hidden { opacity: .12 !important; }
.blueprint-debug-produced.blueprint-center-group .blueprint-center-halo { stroke: var(--b); }
.blueprint-debug-reused.blueprint-center-group .blueprint-center-halo { stroke: var(--a); stroke-dasharray: 4 3; }
.blueprint-center-group:focus-visible .blueprint-center-halo { stroke: var(--a); }
