:root {
  /* Color Palette. */
  --color-rosewater: #dc8a78;
  --color-flamingo: #dd7878;
  --color-pink: #ea76cb;
  --color-mauve: #8839ef;
  --color-red: #d20f39;
  --color-maroon: #e64553;
  --color-peach: #fe640b;
  --color-orange: #9e760c;
  --color-yellow: #df8e1d;
  --color-green: #348523;
  --color-teal: #179299;
  --color-sky: #04a5e5;
  --color-sapphire: #209fb5;
  --color-blue: #1e66f5;
  --color-lavender: #7287fd;
  --color-text: #4c4f69;
  --color-subtext1: #5c5f77;
  --color-subtext0: #6c6f85;
  --color-overlay2: #7c7f93;
  --color-overlay1: #8c8fa1;
  --color-overlay0: #9ca0b0;
  --color-surface2: #acb0be;
  --color-surface1: #bcc0cc;
  --color-surface0: #ccd0da;
  --color-base: #eff1f5;
  --color-mantle: #e6e9ef;
  --color-crust: #dce0e8;

  /* Semantic Mapping. */
  --bg-color: var(--color-mantle);
  --arena-bg: var(--color-crust);
  --border-radius: 8px;
  --node-bg: var(--color-base);
  --node-border: var(--color-surface0);
  --node-header-bg: var(--color-surface0);
  --pod-bg: var(--color-blue);
  --pod-text: var(--color-base);
  --text-main: var(--color-text);
  --text-muted: var(--color-subtext0);
  --shadow-color: var(--color-text);
  --btn-bg: var(--color-mantle);
  --btn-border: var(--color-surface1);
  --btn-hover: var(--color-surface0);

  /* Ghost Slots Semantic Mapping. */
  --rail-bg: var(--color-surface0);
  --ghost-dark-bg: color-mix(in srgb, var(--color-text) 15%, transparent);
  --ghost-dark-shadow: inset 0 2px 4px color-mix(in srgb, var(--shadow-color) 25%, transparent);

  --ghost-queued-bg: linear-gradient(to bottom, var(--color-surface1), var(--color-surface2));
  --ghost-queued-shadow:
    inset 0 2px 4px color-mix(in srgb, var(--shadow-color) 40%, transparent),
    0 0 16px 6px color-mix(in srgb, var(--shadow-color) 35%, transparent);

  /* Track Anchor Semantic Mapping. */
  --track-anchor-fill: var(--arena-bg);
  --track-anchor-stroke: color-mix(in srgb, var(--color-surface2) 90%, black);
}

[data-theme='dark'] {
  /* Color Palette. */
  --color-rosewater: #f5e0dc;
  --color-flamingo: #f2cdcd;
  --color-pink: #f5c2e7;
  --color-mauve: #cba6f7;
  --color-red: #f38ba8;
  --color-maroon: #eba0ac;
  --color-peach: #fab387;
  --color-orange: #e5b46a;
  --color-yellow: #f9e2af;
  --color-green: #a6e3a1;
  --color-teal: #94e2d5;
  --color-sky: #89dceb;
  --color-sapphire: #74c7ec;
  --color-blue: #89b4fa;
  --color-lavender: #b4befe;
  --color-text: #cdd6f4;
  --color-subtext1: #bac2de;
  --color-subtext0: #a6adc8;
  --color-overlay2: #9399b2;
  --color-overlay1: #7f849c;
  --color-overlay0: #6c7086;
  --color-surface2: #585b70;
  --color-surface1: #45475a;
  --color-surface0: #313244;
  --color-base: #1e1e2e;
  --color-mantle: #181825;
  --color-crust: #11111b;

  /* Semantic Mapping. */
  --node-bg: var(--color-surface0);
  --node-header-bg: var(--color-surface1);
  --shadow-color: #000000;
  --rail-bg: color-mix(in srgb, var(--color-surface0) 50%, var(--color-base));
  --btn-bg: var(--color-surface1);
  --btn-border: var(--color-surface2);
  --btn-hover: var(--color-surface2);

  --ghost-dark-bg: var(--color-mantle);
  --ghost-dark-shadow: inset 0 0 0 1px var(--color-surface1), inset 0 4px 8px rgba(0, 0, 0, 0.8);

  --ghost-queued-bg: var(--color-crust);
  --ghost-queued-shadow:
    inset 0 0 0 1px var(--color-surface1), inset 0 4px 8px rgba(0, 0, 0, 0.8),
    0 0 12px 4px rgba(0, 0, 0, 0.5);

  --track-anchor-fill: transparent;
  --track-anchor-stroke: var(--color-text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  margin: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
}

.sim-wrapper {
  width: 100%;
  /* 40px*2 nodes + 34px gap + 16px arena padding + 24px wrapper padding + 2px arena border */
  min-width: 156px;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--node-bg);
  padding: 12px;
  border-radius: calc(var(--border-radius) + 12px);
  box-shadow:
    0 8px 32px -8px color-mix(in srgb, var(--shadow-color) 15%, transparent),
    0 0 0 1px var(--node-border);
  box-sizing: border-box;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0;
  flex-wrap: wrap;
  gap: 10px;
  position: relative;
  z-index: 10;
}

.status-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  flex: 1;
  gap: 16px;
  min-width: 0;
}

.toolbar-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--node-bg);
  border: 1px solid var(--color-surface1);
  border-radius: 10px;
  padding: 8px 16px;
  min-height: 56px;
  min-width: 170px;
  box-sizing: border-box;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--shadow-color) 4%, transparent);
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.toolbar-card:focus-within {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-blue) 25%, transparent);
}

.toolbar-card:has(select:disabled) {
  opacity: 0.6;
  cursor: not-allowed;
}

.card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.card-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.cost-value-text {
  white-space: nowrap;
}

.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.select-wrapper select {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.95rem;
  padding-right: 24px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  width: 100%;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.select-wrapper select option {
  background: var(--node-bg);
  color: var(--text-main);
}

.select-wrapper select:disabled {
  cursor: not-allowed;
}

.select-wrapper .select-arrow {
  position: absolute;
  right: 0;
  pointer-events: none;
  color: var(--text-muted);
  width: 16px;
  height: 16px;
}

.info-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.toolbar-center {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
}

.queue-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.queue-status {
  height: 30px;
  display: flex;
  align-items: center;
  padding: 0 5px;
}

.queue-bar {
  width: 10px;
  height: 24px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}

.queue-bar-fill {
  width: 100%;
  background: var(--color-green);
  height: 0%;
  transition: height 0.2s ease;
}

.queue-count {
  margin-right: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  min-width: 12px;
  text-align: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 14px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text-main);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 400;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--shadow-color) 4%, transparent);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--btn-hover);
}

.btn-primary {
  background: var(--color-green);
  color: var(--color-base);
  border-color: var(--color-green);
}

.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--color-green) 85%, black);
  border-color: color-mix(in srgb, var(--color-green) 85%, black);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--color-green) 30%, transparent);
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
  transition-duration: 0.05s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.arena {
  position: relative;
  width: 100%;
  min-height: 600px;
  height: auto;
  background: var(--arena-bg);
  border-radius: var(--border-radius);
  border: 1px solid var(--node-border);
  box-shadow: inset 0 2px 8px color-mix(in srgb, var(--shadow-color) 8%, transparent);
  box-sizing: border-box;
}

.rail-line {
  position: absolute;
  left: 20px;
  width: calc(100% - 40px);
  height: 10px;
  background-color: var(--rail-bg);
  border-radius: 5px;
  z-index: 0;
  transform: translateY(-50%);
}

.rail-line-vertical {
  position: absolute;
  width: 10px;
  background-color: var(--rail-bg);
  border-radius: 5px;
  z-index: 0;
  transform: translateX(-50%);
}

.svg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

.node {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--node-bg);
  border: 2px solid var(--node-border);
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  will-change: transform, height;
  overflow: hidden;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    box-shadow 0.2s;
}

.node:hover,
.node.node-hovered {
  border-color: var(--color-surface2);
  box-shadow:
    0 12px 24px -6px rgba(0, 0, 0, 0.15),
    0 8px 10px -6px rgba(0, 0, 0, 0.08);
}

.node-header {
  position: relative;
  background: var(--node-header-bg);
  padding: 3.5px 5px;
  min-height: 27px;
  font-weight: bold;
  font-size: 0.85rem;
  color: var(--text-main);
  user-select: none;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  transition:
    background-color 0.2s,
    color 0.2s;
}

.node-header.node-header-narrow {
  cursor: pointer;
}

.collapse-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: -1px;
  margin-right: 4px;
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  color: var(--text-main);
  opacity: 0.65;
  transition:
    transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1),
    opacity 0.2s;
  position: relative;
  cursor: pointer;
}

.collapse-icon::before {
  content: '';
  position: absolute;
  top: -10px;
  bottom: -10px;
  left: -10px;
  right: -10px;
}

.collapse-icon svg {
  width: 100%;
  height: 100%;
}

.node-header:hover .collapse-icon {
  opacity: 1;
}

.node-name-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 1 auto;
  min-width: 0;
  margin-right: 0;
}

.pod-indicators {
  position: absolute;
  top: 0;
  left: 0;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.4s ease;
}

.indicator-col {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
}

.node-stats {
  display: flex;
  gap: 3px;
  margin-left: auto;
  flex-shrink: 0;
  margin-right: -5px;
  position: relative;
}

.node-stats::before {
  content: '';
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 50%;
  width: 1px;
  background-color: var(--color-surface2);
  transform: translateX(-50%);
}

.stat-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
}

.stat-label {
  font-size: 0.55rem;
  color: var(--text-muted);
  font-weight: normal;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 0.84rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--color-subtext1);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.indicators-hidden {
  opacity: 0;
}

.indicator-composite {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  width: 12px;
  height: 12px;
  gap: 2px;
  position: relative;
  box-sizing: border-box;
  flex-shrink: 0;
}

.sub-square {
  border-radius: 1px;
  box-sizing: border-box;
  background: color-mix(in srgb, var(--color-text) 15%, transparent);
  transition:
    background-color 0.2s ease,
    box-shadow 0.2s ease;
}

.indicator-composite.indicator-green .sub-square.visible {
  background: var(--color-green);
  box-shadow: 0 0 6px color-mix(in srgb, var(--color-green) 50%, transparent);
}

.indicator-composite.indicator-orange .sub-square.visible {
  background: var(--color-peach);
  box-shadow: 0 0 6px color-mix(in srgb, var(--color-peach) 50%, transparent);
}

/* Outer layout wrapper (Managed by JS Physics). */
.pod {
  position: absolute;
  top: 0;
  left: 0;
  height: 28px;
  cursor: grab;
  user-select: none;
  will-change: transform;
  touch-action: none;
  z-index: 10;
  box-sizing: border-box;
}

/* Inner visual wrapper (Managed by CSS Presentation). */
.pod-inner {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--pod-bg);
  color: var(--pod-text);
  border-radius: 14px;
  display: flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: bold;
  box-shadow: 0 2px 4px color-mix(in srgb, var(--shadow-color) 20%, transparent);
  justify-content: flex-start;
  text-align: left;
  padding: 0 10px;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform-origin: center center;
  transition:
    transform 0.1s cubic-bezier(0.25, 0.8, 0.25, 1),
    box-shadow 0.1s,
    border-radius 0.2s,
    color 0.1s,
    filter 0.2s;
}

.pod.row-hovered:not(.pod-dragged) .pod-inner {
  transform: scale(1.02);
  filter: brightness(1.03);
}

.pod-hidden {
  pointer-events: none;
}

.pod.pod-hidden .pod-inner {
  box-shadow: none;
  border: none;
}

.pod.pod-hidden .pod-border-svg {
  display: none;
}

.absolute-header {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  box-sizing: border-box;
  border-top-left-radius: calc(var(--border-radius) - 2px);
  border-top-right-radius: calc(var(--border-radius) - 2px);
}

.absolute-header.collapsed .collapse-icon {
  transform: rotate(-90deg);
}

.absolute-header.collapsed {
  border-bottom-left-radius: calc(var(--border-radius) - 2px);
  border-bottom-right-radius: calc(var(--border-radius) - 2px);
}

.pod-circle {
  width: 28px !important;
  min-width: 28px !important;
}

.pod.pod-circle .pod-inner {
  padding: 0;
  border-radius: 50%;
  color: transparent;
  transform: scale(0.95);
  background: linear-gradient(180deg, #ffffff 0%, #f0f4f8 100%) !important;
  border: 2.5px solid var(--pod-base-color, var(--pod-bg));
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--pod-base-color, var(--pod-bg)) 20%, transparent),
    0 8px 16px -2px color-mix(in srgb, var(--shadow-color) 45%, transparent),
    0 3px 6px -1px color-mix(in srgb, var(--shadow-color) 25%, transparent);
}

.pod:active {
  cursor: grabbing;
}

.pod-active {
  z-index: 100;
}

.pod-active .pod-inner {
  filter: brightness(1.1);
}

.pod.pod-active.pod-dragged:not(.pod-hidden) .pod-inner {
  box-shadow: 8px 12px 20px -5px color-mix(in srgb, var(--shadow-color) 60%, transparent);
  transform: scale(0.97, 1.01);
}

.pod.pod-queued:not(.pod-hidden) .pod-inner {
  box-shadow: 4px 8px 16px -4px color-mix(in srgb, var(--shadow-color) 45%, transparent);
}

.pod.ghost {
  pointer-events: none;
  z-index: 2;
}

.pod.ghost .pod-inner {
  transition: none;
}

.pod.ghost-dark .pod-inner {
  background: var(--ghost-dark-bg);
  color: transparent;
}

.pod.ghost-dark:not(.pod-hidden) .pod-inner {
  box-shadow: var(--ghost-dark-shadow);
}

.pod.ghost-gray-gradient .pod-inner {
  background: var(--ghost-queued-bg);
  color: transparent;
  border: none;
}

.pod.ghost-gray-gradient:not(.pod-hidden) .pod-inner {
  box-shadow: var(--ghost-queued-shadow);
}

.pod.ghost-shade .pod-inner {
  background: color-mix(in srgb, var(--pod-base-color, #3b82f6) 15%, transparent);
  border: none;
  color: transparent;
  box-shadow: none;
}

.pod-border-svg {
  position: absolute;
  top: 1px;
  left: 1px;
  width: calc(100% - 2px);
  height: calc(100% - 2px);
  pointer-events: none;
  display: none;
  z-index: 2;
  overflow: visible;
}
.pod-queued:not(.pod-hidden) .pod-border-svg,
.ghost-shade:not(.pod-hidden) .pod-border-svg {
  display: block;
}
.pod-border-svg rect {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: color-mix(in srgb, var(--pod-base-color, var(--pod-bg)) 33%, var(--color-base));
  stroke-width: 2px;
  stroke-linecap: round;

  stroke-dasharray: 0.333 0.667;
  animation: dash-march 0.6s linear infinite;
}

@keyframes dash-march {
  /* Shifts the dash array backwards by exactly 1 normalized period. */
  from {
    stroke-dashoffset: 1;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.path-bg-flow {
  stroke-dasharray: 8 6;
}
.pod-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  pointer-events: none;
}

.tooltip {
  position: fixed;
  background: var(--color-surface0);
  color: var(--color-text);
  padding: 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 6px color-mix(in srgb, var(--shadow-color) 15%, transparent);
  border: 1px solid var(--color-surface1);
  max-width: 200px;
  line-height: 1.4;
}
.tooltip.hidden {
  display: none;
}
