:root {
  color-scheme: light;
  --page: #edf2f7;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --ink: #172033;
  --muted: #667085;
  --line: #d8e0ea;
  --line-strong: #182230;
  --primary: #3157d5;
  --primary-dark: #2444ad;
  --primary-soft: #e9efff;
  --primary-faint: #f5f7ff;
  --danger: #c93636;
  --danger-soft: #fff1f1;
  --success: #16794b;
  --success-soft: #ecf8f1;
  --warning: #9a6700;
  --warning-soft: #fff8e6;
  --shadow: 0 16px 38px rgba(34, 48, 73, 0.1);
  --shadow-small: 0 5px 16px rgba(34, 48, 73, 0.08);
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1726;
  --panel: #172235;
  --panel-soft: #1d2a40;
  --ink: #eef4ff;
  --muted: #a9b6ca;
  --line: #33445f;
  --line-strong: #dbe6f8;
  --primary: #83a6ff;
  --primary-dark: #a9c0ff;
  --primary-soft: #263b69;
  --primary-faint: #1d315b;
  --danger-soft: #3c2028;
  --success-soft: #17372d;
  --warning-soft: #3b311e;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --shadow-small: 0 7px 18px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  background: var(--page);
  font-family: var(--sans);
  font-size: 16px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(49, 87, 213, 0.28);
  outline-offset: 2px;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  display: block;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 2px 12px rgba(34, 48, 73, 0.05);
  backdrop-filter: blur(12px);
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 3px 7px 3px 3px;
  border: 0;
  border-radius: 13px;
  color: var(--ink);
  background: transparent;
  text-decoration: none;
  text-align: left;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #b8c9f2;
  border-radius: 11px;
  background: #3157d5;
  box-shadow: 0 8px 20px rgba(38, 77, 188, 0.28);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.brand-copy strong {
  font-size: 1.08rem;
  letter-spacing: -0.02em;
}

.brand-copy small {
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-popover {
  position: absolute;
  top: calc(100% + 12px);
  left: 0;
  z-index: 60;
  width: 280px;
  display: grid;
  gap: 4px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 16px 38px rgba(23, 32, 51, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-5px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.brand-popover::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 20px;
  border: 7px solid transparent;
  border-bottom-color: var(--panel);
}

.brand-popover strong {
  font-size: 0.86rem;
}

.brand-popover span {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.brand-popover small {
  margin-top: 2px;
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 750;
}

.brand:hover .brand-popover,
.brand:focus-visible .brand-popover {
  opacity: 1;
  transform: translateY(0);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tool-button {
  position: relative;
  min-width: 76px;
  min-height: 58px;
  display: grid;
  place-items: center;
  gap: 3px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 11px;
  color: #3159bd;
  background: transparent;
  text-decoration: none;
  transition: color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.tool-button::before,
.tool-button::after {
  position: absolute;
  left: 50%;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -5px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.tool-button::before {
  content: "";
  top: calc(100% + 4px);
  border: 6px solid transparent;
  border-bottom-color: #172033;
}

.tool-button::after {
  content: attr(data-tooltip);
  top: calc(100% + 15px);
  width: max-content;
  max-width: 270px;
  padding: 8px 10px;
  border-radius: 9px;
  color: #ffffff;
  background: #172033;
  box-shadow: 0 12px 26px rgba(18, 28, 45, 0.2);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
}

.tool-button:hover::before,
.tool-button:hover::after,
.tool-button:focus-visible::before,
.tool-button:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tool-button:hover {
  color: #2149ad;
  border-color: #c9d8fa;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), #edf3ff);
  box-shadow: 0 7px 18px rgba(49, 87, 213, 0.11);
}

.tool-button svg {
  width: 34px;
  height: 34px;
  padding: 5px;
  border: 1px solid #c9d8fa;
  border-radius: 10px;
  fill: none;
  background: linear-gradient(145deg, #fbfdff 5%, #e6eeff 55%, #d8e5ff);
  box-shadow: inset 0 1px 0 #ffffff, 0 4px 10px rgba(42, 78, 171, 0.12);
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.tool-button:hover svg {
  box-shadow: inset 0 1px 0 #ffffff, 0 6px 14px rgba(42, 78, 171, 0.2);
  transform: translateY(-1px);
}

.tool-button span {
  font-size: 0.76rem;
  font-weight: 700;
}

.app-credit {
  position: fixed;
  right: 16px;
  bottom: 12px;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border: 1px solid rgba(49, 87, 213, 0.18);
  border-radius: 999px;
  color: #536079;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 8px 24px rgba(34, 48, 73, 0.12);
  backdrop-filter: blur(10px);
  font-size: 0.72rem;
  font-weight: 750;
}

.app-credit a {
  color: #3157d5;
  text-decoration: none;
}

.app-credit a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.app-credit span {
  color: #7b8495;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
}

.palette {
  position: relative;
  z-index: 10;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfe;
  overflow-y: auto;
}

.palette-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.palette h1,
.modal h2 {
  margin: 0;
  letter-spacing: -0.025em;
}

.palette h1 {
  font-size: 1.35rem;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #4b5870;
  background: var(--panel);
}

.icon-button:hover {
  color: var(--primary);
  border-color: #becbf3;
  background: var(--primary-faint);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.palette-intro {
  margin: 12px 0 17px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.block-list {
  display: grid;
  gap: 9px;
}

.block-card {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 1px 1px rgba(34, 48, 73, 0.02);
  text-align: left;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.block-card:hover,
.block-card.is-pending {
  border-color: #9cb0ec;
  background: var(--primary-faint);
  box-shadow: var(--shadow-small);
  transform: translateY(-1px);
}

.block-card.is-dragging {
  opacity: 0.48;
  transform: scale(0.98);
}

.block-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid #c8d7fa;
  border-radius: 10px;
  color: #3159bd;
  background:
    radial-gradient(circle at 30% 18%, #ffffff 0 13%, transparent 35%),
    linear-gradient(145deg, #f5f8ff, #dce7ff);
  box-shadow: inset 0 1px 0 #ffffff, 0 4px 10px rgba(49, 87, 213, 0.12);
}

.block-icon svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.block-card-copy {
  min-width: 0;
}

.block-card strong,
.block-card small {
  display: block;
}

.block-card strong {
  margin-bottom: 3px;
  font-size: 0.9rem;
}

.block-card small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drag-grip {
  color: #9ba6b7;
}

.drag-grip svg {
  width: 12px;
  height: 20px;
  fill: currentColor;
  stroke: none;
}

.stage {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.stage-header {
  display: block;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(49, 87, 213, 0.09), rgba(255, 255, 255, 0.82) 52%, rgba(49, 87, 213, 0.04)),
    var(--panel);
}

.title-field {
  width: min(820px, 100%);
  display: grid;
  gap: 9px;
  padding: 14px;
  border: 1px solid #c7d5fb;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 22px rgba(49, 87, 213, 0.08);
}

.title-field label {
  color: #3157d5;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.title-field input {
  width: 100%;
  min-height: 50px;
  padding: 0 15px;
  border: 1px solid #bfcae3;
  border-radius: 12px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
  font-weight: 700;
}

.title-field input:hover,
.title-field input:focus {
  border-color: #9db0e8;
}

.selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 20px;
  border-bottom: 1px solid #cbd6f6;
  background: #f3f6ff;
}

.selection-bar[hidden] {
  display: none;
}

.selection-summary {
  min-width: 0;
}

.selection-summary span {
  display: block;
  color: var(--primary);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.selection-summary strong {
  display: block;
  max-width: 310px;
  overflow: hidden;
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.selection-actions button {
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid #cad4ee;
  border-radius: 7px;
  color: #44516a;
  background: var(--panel);
  font-size: 0.72rem;
  font-weight: 700;
}

.selection-actions button[hidden] {
  display: none;
}

.selection-actions button:hover {
  color: var(--primary-dark);
  border-color: #9eb0e6;
}

.selection-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.selection-actions .danger-action {
  color: var(--danger);
}

.selection-actions .danger-action:hover {
  border-color: #efb7b7;
  background: var(--danger-soft);
}

.selection-actions svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.guidance-bar {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 20px;
  border-bottom: 1px solid var(--line);
  color: #5d6879;
  background: #fbfcfe;
}

.guidance-icon {
  width: 20px;
  height: 20px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 0.72rem;
  font-weight: 800;
}

.guidance-bar p {
  flex: 1;
  margin: 0;
  font-size: 0.78rem;
}

.guidance-bar button {
  padding: 4px 7px;
  border: 0;
  color: var(--primary);
  background: transparent;
  font-size: 0.74rem;
  font-weight: 750;
}

.stage-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background-color: #eef2f7;
  background-image:
    linear-gradient(rgba(117, 134, 161, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(117, 134, 161, 0.12) 1px, transparent 1px);
  background-size: 24px 24px;
}

.paper {
  width: min(1040px, 100%);
  min-height: 680px;
  margin: 0 auto;
  padding: 34px 38px 50px;
  border: 1px solid #d9dee7;
  border-radius: 3px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.diagram-wrap {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 16px;
  border: 1px solid #a8a8a8;
  background: #d6d6d6;
}

.ns-root {
  width: 100%;
  border: 2px solid #111111;
  color: #111111;
  background: #ffffff;
  font-size: 1rem;
}

.ns-title {
  min-height: 56px;
  display: flex;
  align-items: center;
  padding: 11px 15px;
  border-bottom: 2px solid #111111;
  background: #d8d8d8;
  font-size: 1.08rem;
  font-weight: 800;
}

.ns-list {
  min-height: 18px;
}

.ns-element {
  position: relative;
  cursor: grab;
}

.ns-element:active {
  cursor: grabbing;
}

.ns-element.is-moving {
  opacity: 0.45;
}

.ns-element.selected {
  z-index: 2;
  outline: 3px solid rgba(49, 87, 213, 0.52);
  outline-offset: -3px;
}

.ns-element.selected > .ns-simple,
.ns-element.selected > .ns-loop,
.ns-element.selected > .ns-decision,
.ns-element.selected > .ns-switch {
  background-color: #f5f8ff;
}

.ns-simple {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 2px solid #111111;
  background: #ffffff;
}

.ns-list > .ns-element.is-last > .ns-simple,
.ns-list > .ns-element.is-last > .ns-loop,
.ns-list > .ns-element.is-last > .ns-decision,
.ns-list > .ns-element.is-last > .ns-switch {
  border-bottom: 0;
}

.ns-type-subroutine .ns-simple {
  position: relative;
  padding-inline: 22px;
}

.ns-type-subroutine .ns-simple::before,
.ns-type-subroutine .ns-simple::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #111111;
}

.ns-type-subroutine .ns-simple::before {
  left: 9px;
}

.ns-type-subroutine .ns-simple::after {
  right: 9px;
}

.ns-text {
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.ns-text[role="button"] {
  cursor: text;
}

.inline-editor {
  width: 100%;
  min-height: 56px;
  padding: 8px 10px;
  border: 2px solid var(--primary);
  border-radius: 4px;
  color: var(--ink);
  background: #ffffff;
  line-height: 1.4;
  resize: vertical;
}

.branch-label-editor {
  width: calc(100% - 12px);
  height: 32px;
  margin: 5px 6px;
  padding: 4px 7px;
  border: 2px solid var(--primary);
  border-radius: 3px;
  color: var(--ink);
  background: #ffffff;
  text-align: center;
}

.ns-loop {
  border-bottom: 2px solid #111111;
  background: #ffffff;
}

.ns-loop-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border-bottom: 2px solid #111111;
  background: #ffffff;
  font-weight: 750;
}

.ns-loop-body {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  min-height: 78px;
}

.ns-loop-rail {
  border-right: 2px solid #111111;
  background: #d8d8d8;
}

.ns-loop-content {
  min-width: 0;
}

.ns-loop-content > .ns-list > .ns-element > .ns-simple,
.ns-loop-content > .ns-list > .ns-element > .ns-loop,
.ns-loop-content > .ns-list > .ns-element > .ns-decision,
.ns-loop-content > .ns-list > .ns-element > .ns-switch {
  border-bottom: 2px solid #111111;
}

.ns-loop-content > .ns-list > .ns-element.is-last > .ns-simple,
.ns-loop-content > .ns-list > .ns-element.is-last > .ns-loop,
.ns-loop-content > .ns-list > .ns-element.is-last > .ns-decision,
.ns-loop-content > .ns-list > .ns-element.is-last > .ns-switch {
  border-bottom: 0;
}

.ns-decision {
  border-bottom: 2px solid #111111;
  background: #ffffff;
}

.ns-decision-head {
  position: relative;
  min-height: 78px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 13px 58px 25px;
  overflow: hidden;
  border-bottom: 2px solid #111111;
  background: #ffffff;
  text-align: center;
  font-weight: 750;
}

.decision-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.decision-lines line {
  fill: none;
  stroke: #111111;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}

.ns-decision-head > .ns-text,
.ns-decision-head > .inline-editor {
  position: relative;
  z-index: 1;
}

.branch-marker {
  position: absolute;
  bottom: 4px;
  z-index: 1;
  color: #344054;
  font-size: 0.7rem;
  font-weight: 850;
}

.branch-marker.then {
  left: 10px;
}

.branch-marker.else {
  right: 10px;
}

.ns-branches {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 88px;
}

.ns-branch {
  min-width: 0;
}

.ns-branch:first-child {
  border-right: 2px solid #111111;
}

.branch-title {
  padding: 5px 8px;
  border-bottom: 1px solid #aeb7c4;
  color: #5f6b7c;
  background: #ffffff;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-align: center;
  text-transform: uppercase;
}

.ns-branch > .ns-list > .ns-element > .ns-simple,
.ns-branch > .ns-list > .ns-element > .ns-loop,
.ns-branch > .ns-list > .ns-element > .ns-decision,
.ns-branch > .ns-list > .ns-element > .ns-switch {
  border-bottom: 2px solid #111111;
}

.ns-branch > .ns-list > .ns-element.is-last > .ns-simple,
.ns-branch > .ns-list > .ns-element.is-last > .ns-loop,
.ns-branch > .ns-list > .ns-element.is-last > .ns-decision,
.ns-branch > .ns-list > .ns-element.is-last > .ns-switch {
  border-bottom: 0;
}

.empty-list {
  min-height: 62px;
  display: grid;
  place-items: center;
  padding: 12px;
  color: #777777;
  background: #ffffff;
  font-size: 0.76rem;
  font-style: italic;
  text-align: center;
}

.ns-switch {
  border-bottom: 2px solid #111111;
  background: #ffffff;
}

.ns-switch-head {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 11px 14px;
  border-bottom: 2px solid #111111;
  background: #ffffff;
  font-weight: 750;
}

.ns-switch-branches {
  display: grid;
  grid-template-columns: repeat(var(--branch-count), minmax(118px, 1fr));
  min-height: 90px;
  overflow-x: auto;
}

.ns-switch-branch {
  min-width: 0;
  background: #ffffff;
}

.ns-switch-branch + .ns-switch-branch {
  border-left: 2px solid #111111;
}

.ns-switch-label {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 6px 8px;
  border-bottom: 2px solid #111111;
  background: #f2f2f2;
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
}

.ns-switch-branch > .ns-list > .ns-element > .ns-simple,
.ns-switch-branch > .ns-list > .ns-element > .ns-loop,
.ns-switch-branch > .ns-list > .ns-element > .ns-decision,
.ns-switch-branch > .ns-list > .ns-element > .ns-switch {
  border-bottom: 2px solid #111111;
}

.ns-switch-branch > .ns-list > .ns-element.is-last > .ns-simple,
.ns-switch-branch > .ns-list > .ns-element.is-last > .ns-loop,
.ns-switch-branch > .ns-list > .ns-element.is-last > .ns-decision,
.ns-switch-branch > .ns-list > .ns-element.is-last > .ns-switch {
  border-bottom: 0;
}

.drop-zone {
  position: relative;
  height: 10px;
  display: grid;
  place-items: center;
  margin: -5px 0;
  z-index: 5;
  transition: height 0.14s ease, margin 0.14s ease, background 0.14s ease;
}

.drop-zone::before {
  content: "";
  width: calc(100% - 16px);
  height: 2px;
  border-radius: 2px;
  background: transparent;
}

.drop-zone span {
  position: absolute;
  display: none;
  padding: 3px 9px;
  border-radius: 99px;
  color: #ffffff;
  background: var(--primary);
  font-size: 0.68rem;
  font-weight: 750;
  pointer-events: none;
}

body.drag-active .drop-zone,
body.placement-active .drop-zone {
  height: 34px;
  margin: 0;
  background: rgba(49, 87, 213, 0.045);
  cursor: pointer;
}

body.drag-active .drop-zone::before,
body.placement-active .drop-zone::before {
  background: #8ea6ed;
}

body.drag-active .drop-zone span,
body.placement-active .drop-zone span {
  display: block;
  opacity: 0;
}

body.drag-active .drop-zone:hover span,
body.placement-active .drop-zone:hover span,
.drop-zone.drag-over span {
  opacity: 1;
}

.drop-zone.drag-over {
  background: rgba(49, 87, 213, 0.16);
}

.drop-zone.drag-over::before {
  height: 4px;
  background: var(--primary);
}

.print-meta {
  display: none;
}

.modal {
  width: min(680px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(22, 32, 51, 0.24);
}

.modal::backdrop {
  background: rgba(18, 28, 45, 0.52);
  backdrop-filter: blur(2px);
}

.compact-modal {
  width: min(560px, calc(100vw - 28px));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.modal h2 {
  font-size: 1.24rem;
}

.modal-body {
  max-height: calc(min(760px, 100vh - 28px) - 80px);
  padding: 20px;
  overflow-y: auto;
}

.modal-body > p:first-child {
  margin-top: 0;
}

.imprint-content {
  display: grid;
  gap: 14px;
  line-height: 1.55;
}

.imprint-content p {
  margin: 0;
  color: var(--muted);
}

.imprint-content p strong,
.imprint-content .text-link {
  color: var(--ink);
}

.imprint-content .text-link {
  font-weight: 800;
  text-decoration-color: rgba(131, 166, 255, 0.46);
  text-underline-offset: 3px;
}

.imprint-content .text-link:hover {
  color: var(--primary);
}

.copyright-note {
  font-size: 0.82rem;
}

.imprint-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.imprint-brand img {
  width: 54px;
  height: 54px;
  border: 1px solid #b8c9f2;
  border-radius: 13px;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(38, 77, 188, 0.2);
}

.imprint-brand div {
  display: grid;
  gap: 3px;
}

.imprint-brand strong {
  font-size: 1rem;
}

.imprint-brand span {
  color: var(--muted);
  font-size: 0.78rem;
}

.operator-modal {
  width: min(980px, calc(100vw - 28px));
  max-height: min(880px, calc(100vh - 28px));
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.operator-modal::backdrop {
  background:
    radial-gradient(circle at 50% 12%, rgba(131, 166, 255, 0.18), transparent 32%),
    rgba(18, 28, 45, 0.58);
  backdrop-filter: blur(4px);
}

.operator-sheet {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(174, 187, 210, 0.9);
  border-radius: 18px;
  color: #172033;
  background:
    linear-gradient(90deg, rgba(49, 87, 213, 0.05) 0 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(#ffffff, #f9fbff);
  box-shadow: 0 30px 90px rgba(9, 17, 32, 0.34);
  transform-origin: top center;
  animation: sheetIn 0.22s ease-out;
}

.operator-sheet::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7px;
  background: linear-gradient(90deg, #3157d5, #74a7ff, #3157d5);
}

.operator-sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 28px 30px 20px;
  border-bottom: 1px solid #d8e0ea;
  background:
    radial-gradient(circle at 0 0, rgba(49, 87, 213, 0.12), transparent 34%),
    rgba(255, 255, 255, 0.9);
}

.operator-sheet-header h2 {
  margin: 0;
  color: #172033;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.operator-sheet-header p {
  max-width: 680px;
  margin: 7px 0 0;
  color: #667085;
  font-size: 0.86rem;
  line-height: 1.55;
}

.operator-sheet-body {
  max-height: min(650px, calc(100vh - 210px));
  overflow-y: auto;
  padding: 22px 30px 28px;
}

.operator-note {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid #ccdaf8;
  border-radius: 13px;
  color: #2f3c54;
  background: #f4f7ff;
}

.operator-note strong {
  color: #2444ad;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.operator-note span {
  font-size: 0.84rem;
  line-height: 1.5;
}

.operator-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.operator-grid article {
  display: grid;
  gap: 7px;
  padding: 15px 16px;
  border: 1px solid #d8e0ea;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.operator-grid article > span {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  color: #3157d5;
  background: #edf3ff;
  font-size: 0.62rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.operator-grid h3 {
  margin: 0;
  color: #172033;
  font-size: 0.98rem;
}

.operator-grid code {
  display: block;
  padding: 8px 9px;
  border: 1px solid #d8e0ea;
  border-radius: 8px;
  color: #172033;
  background: #f8fafc;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: normal;
}

.operator-grid p {
  margin: 0;
  color: #667085;
  font-size: 0.8rem;
  line-height: 1.5;
}

.operator-sheet-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid #d8e0ea;
}

.operator-sheet-footer span {
  color: #667085;
  font-size: 0.78rem;
}

.operator-sheet-footer a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border: 1px solid #c4d1f4;
  border-radius: 10px;
  color: #2444ad;
  background: linear-gradient(180deg, #ffffff, #f0f5ff);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.operator-sheet-footer a:hover {
  border-color: #9eb0e6;
  background: #edf3ff;
}

@keyframes sheetIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.985) rotateX(4deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotateX(0);
  }
}

.help-content {
  display: grid;
  gap: 20px;
}

.help-content section {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.help-content section:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.help-content h3 {
  margin: 0 0 7px;
  font-size: 0.95rem;
}

.help-content p {
  margin: 0 0 7px;
  color: #566276;
  line-height: 1.55;
}

.help-content a {
  color: var(--primary);
  font-weight: 700;
}

.operator-help-list {
  display: grid;
  gap: 8px;
}

.operator-help-item {
  display: grid;
  gap: 2px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.operator-help-item strong {
  color: var(--ink);
  font-size: 0.82rem;
}

.operator-help-item span {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

kbd {
  min-width: 44px;
  display: inline-block;
  margin-right: 7px;
  padding: 2px 6px;
  border: 1px solid #cbd3df;
  border-bottom-width: 2px;
  border-radius: 5px;
  color: #3d485a;
  background: #f5f7fa;
  font-size: 0.75rem;
  text-align: center;
}

.export-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.export-options button {
  min-height: 112px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--panel-soft);
  text-align: left;
}

.export-options button:hover {
  border-color: #9fb1e7;
  background: var(--primary-faint);
}

.export-options strong {
  color: var(--primary-dark);
  font-size: 1rem;
}

.export-options span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.validation-results {
  display: grid;
  gap: 9px;
}

.validation-item {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 9px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.84rem;
  line-height: 1.45;
}

.validation-item::before {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 900;
}

.validation-item.ok {
  border-color: #bfe2cf;
  background: var(--success-soft);
}

.validation-item.ok::before {
  content: "✓";
  color: var(--success);
  background: #d8f0e3;
}

.validation-item.warning {
  border-color: #ecd79d;
  background: var(--warning-soft);
}

.validation-item.warning::before {
  content: "!";
  color: var(--warning);
  background: #f8e9bd;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 100;
  max-width: min(560px, calc(100vw - 28px));
  padding: 11px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #172033;
  box-shadow: 0 12px 30px rgba(18, 28, 45, 0.24);
  font-size: 0.84rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

html[data-theme="dark"] .topbar {
  background: rgba(15, 23, 38, 0.96);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.26);
}

html[data-theme="dark"] .brand-mark,
html[data-theme="dark"] .imprint-brand img {
  border-color: #5875b5;
}

html[data-theme="dark"] .tool-button {
  color: #a9c0ff;
}

html[data-theme="dark"] .tool-button:hover {
  color: #d6e1ff;
  border-color: #405b91;
  background: linear-gradient(180deg, #1d2b44, #17243a);
}

html[data-theme="dark"] .tool-button svg {
  border-color: #405b91;
  background: linear-gradient(145deg, #253b66, #1b2c4d 58%, #16243d);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 5px 13px rgba(0, 0, 0, 0.24);
}

html[data-theme="dark"] .tool-button::before {
  border-bottom-color: #eef4ff;
}

html[data-theme="dark"] .tool-button::after {
  color: #111827;
  background: #eef4ff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] .app-credit {
  border-color: rgba(131, 166, 255, 0.24);
  color: #a9b6ca;
  background: rgba(17, 27, 45, 0.86);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
}

html[data-theme="dark"] .app-credit a {
  color: #b5c8ff;
}

html[data-theme="dark"] .app-credit span {
  color: #7e8ea8;
}

html[data-theme="dark"] .palette {
  background: #111b2d;
}

html[data-theme="dark"] .block-card {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
}

html[data-theme="dark"] .block-icon {
  border-color: #405b91;
  color: #b5c8ff;
  background:
    radial-gradient(circle at 30% 18%, rgba(255, 255, 255, 0.13) 0 13%, transparent 35%),
    linear-gradient(145deg, #263d69, #1a2b4b);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 10px rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"] .stage-header {
  background:
    linear-gradient(135deg, rgba(131, 166, 255, 0.13), rgba(23, 34, 53, 0.92) 52%, rgba(131, 166, 255, 0.06)),
    var(--panel);
}

html[data-theme="dark"] .title-field {
  border-color: #3f5d9a;
  background: rgba(23, 34, 53, 0.76);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.23);
}

html[data-theme="dark"] .title-field label {
  color: #9db7ff;
}

html[data-theme="dark"] .title-field input {
  border-color: #465b79;
  background: #142034;
}

html[data-theme="dark"] .selection-bar {
  border-color: #3a5080;
  background: #1a2947;
}

html[data-theme="dark"] .guidance-bar {
  color: var(--muted);
  background: #121d30;
}

html[data-theme="dark"] .stage-scroll {
  background-color: #0e1625;
  background-image:
    linear-gradient(rgba(144, 166, 204, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(144, 166, 204, 0.1) 1px, transparent 1px);
}

html[data-theme="dark"] .paper {
  border-color: #34445f;
  background: #172235;
}

html[data-theme="dark"] .diagram-wrap {
  border-color: #738096;
  background: #4a5361;
}

html[data-theme="dark"] .help-content p {
  color: var(--muted);
}

html[data-theme="dark"] kbd {
  border-color: #4a5c77;
  color: var(--ink);
  background: #233149;
}

html[data-theme="dark"] .inline-editor,
html[data-theme="dark"] .branch-label-editor {
  color: #111111;
  background: #ffffff;
}

html[data-theme="dark"] .toast {
  color: #111827;
  background: #eef4ff;
}

html[data-theme="dark"] .operator-sheet {
  color: var(--ink);
  border-color: #40536f;
  background:
    linear-gradient(90deg, rgba(131, 166, 255, 0.05) 0 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(#18253a, #121d30);
}

html[data-theme="dark"] .operator-sheet-header {
  border-color: #33445f;
  background:
    radial-gradient(circle at 0 0, rgba(131, 166, 255, 0.16), transparent 34%),
    rgba(24, 37, 58, 0.94);
}

html[data-theme="dark"] .operator-sheet-header h2,
html[data-theme="dark"] .operator-grid h3,
html[data-theme="dark"] .operator-grid code {
  color: var(--ink);
}

html[data-theme="dark"] .operator-sheet-header p,
html[data-theme="dark"] .operator-grid p,
html[data-theme="dark"] .operator-sheet-footer span {
  color: var(--muted);
}

html[data-theme="dark"] .operator-note {
  border-color: #405b91;
  color: var(--muted);
  background: #1d315b;
}

html[data-theme="dark"] .operator-note strong,
html[data-theme="dark"] .operator-grid article > span {
  color: #d6e1ff;
}

html[data-theme="dark"] .operator-grid article {
  border-color: #33445f;
  background: rgba(23, 34, 53, 0.9);
}

html[data-theme="dark"] .operator-grid article > span {
  background: #263b69;
}

html[data-theme="dark"] .operator-grid code {
  border-color: #33445f;
  background: #111b2d;
}

html[data-theme="dark"] .operator-sheet-footer {
  border-color: #33445f;
}

html[data-theme="dark"] .operator-sheet-footer a {
  border-color: #405b91;
  color: #d6e1ff;
  background: linear-gradient(180deg, #243653, #192842);
}

html[data-theme="dark"] .operator-sheet-footer a:hover {
  background: var(--primary-faint);
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    padding-inline: 16px;
  }

  .brand-copy small {
    display: none;
  }

  .tool-button {
    min-width: 61px;
    padding-inline: 6px;
  }

  .workspace {
    grid-template-columns: 244px minmax(0, 1fr);
  }

  .palette {
    padding-inline: 14px;
  }

  .block-card {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .block-icon {
    width: 38px;
    height: 38px;
  }

  .drag-grip {
    display: none;
  }

  .selection-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .selection-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    align-items: center;
    flex-direction: column;
    gap: 8px;
    padding-block: 12px;
  }

  .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    overflow: visible;
  }

  .tool-button::before,
  .tool-button::after {
    display: none;
  }

  .tool-button {
    min-width: 0;
    padding-inline: 2px;
  }

  .app-credit {
    position: static;
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 10px auto 12px;
  }

  .workspace {
    display: block;
  }

  .palette {
    max-height: none;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .palette-intro {
    display: none;
  }

  .block-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .block-card {
    min-height: 68px;
  }

  .block-card small {
    display: none;
  }

  .stage {
    min-height: 720px;
  }

  .stage-header {
    padding-inline: 14px;
  }

  .selection-bar,
  .guidance-bar {
    padding-inline: 14px;
  }

  .stage-scroll {
    padding: 14px;
  }

  .paper {
    min-height: 600px;
    padding: 20px 14px 36px;
  }

  .ns-root {
    font-size: 0.84rem;
  }

  .export-options {
    grid-template-columns: 1fr;
  }

  .operator-grid,
  .operator-note,
  .operator-sheet-footer {
    grid-template-columns: 1fr;
  }

  .operator-sheet-header,
  .operator-sheet-body {
    padding-inline: 18px;
  }

  .operator-sheet-footer {
    display: grid;
    align-items: stretch;
  }
}

@media (max-width: 430px) {
  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .tool-button {
    min-height: 50px;
  }

  .tool-button svg {
    width: 28px;
    height: 28px;
  }

  .tool-button span {
    font-size: 0.64rem;
    white-space: nowrap;
  }

  .block-list {
    grid-template-columns: 1fr;
  }

  .ns-decision-head {
    padding-inline: 38px;
  }
}

@media print {
  @page {
    margin: 16mm;
  }

  body {
    color: #000000;
    background: #ffffff;
  }

  .topbar,
  .palette,
  .stage-header,
  .selection-bar,
  .guidance-bar,
  .drop-zone,
  .app-credit,
  .toast {
    display: none !important;
  }

  .workspace,
  .stage,
  .stage-scroll,
  .paper,
  .diagram-wrap {
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: #ffffff;
    box-shadow: none;
    overflow: visible;
  }

  .diagram-wrap {
    width: 100%;
  }

  .ns-root {
    break-inside: avoid;
    color: #000000;
    border-color: #000000;
  }

  .ns-title,
  .ns-simple,
  .ns-loop,
  .ns-loop-header,
  .ns-loop-body,
  .ns-loop-rail,
  .ns-decision,
  .ns-decision-head,
  .ns-branch,
  .branch-title,
  .ns-switch,
  .ns-switch-head,
  .ns-switch-branch,
  .ns-switch-label {
    color: #000000 !important;
    border-color: #000000 !important;
    background: #ffffff !important;
  }

  .ns-element.selected {
    outline: 0;
  }

  .print-meta {
    display: block;
    margin-top: 12px;
    color: #555555;
    font-size: 9pt;
    text-align: right;
  }
}
