/** @format */

:root {
  --bg: #11161d;
  --bg-top: #1a2430;
  --bg-bottom: #0f141b;
  --flare-1: rgba(89, 139, 176, 0.2);
  --flare-2: rgba(74, 110, 91, 0.18);
  --panel: #1a222c;
  --ink: #e4ebf3;
  --muted: #9eb0c3;
  --line: #2a3745;
  --accent: #67a8d4;
  --accent-strong: #4a8bb6;
  --control-bg: #141c26;
  --json-bg: #131b25;
  --json-line: #273545;
  --thead-bg: #18222d;
  --thead-ink: #bdcddd;
  --thead-line: #2f3f50;
  --row-line: #263443;
  --shadow: 0 16px 30px rgba(5, 10, 16, 0.35);
  --layout-line: rgba(214, 225, 235, 0.2);
  --layout-bg: #101822;
}

body[data-theme='sand'] {
  --bg: #efe7da;
  --bg-top: #f5efe6;
  --bg-bottom: #efe7da;
  --flare-1: rgba(159, 91, 31, 0.14);
  --flare-2: rgba(52, 86, 68, 0.14);
  --panel: #fff9ef;
  --ink: #2b2218;
  --muted: #6b5d4e;
  --line: #d8c8b0;
  --accent: #9f5b1f;
  --accent-strong: #c27a37;
  --control-bg: #fffdf7;
  --json-bg: #f8f1e5;
  --json-line: #eadbc6;
  --thead-bg: #f2e4d1;
  --thead-ink: #5d4a35;
  --thead-line: #dfc7aa;
  --row-line: #ecdcc6;
  --shadow: 0 18px 40px rgba(62, 40, 19, 0.12);
  --layout-line: rgba(107, 93, 78, 0.22);
  --layout-bg: #f3eadb;
}

body[data-theme='night'] {
  --bg: #090d12;
  --bg-top: #121923;
  --bg-bottom: #070b10;
  --flare-1: rgba(57, 94, 129, 0.22);
  --flare-2: rgba(57, 94, 129, 0.1);
  --panel: #111922;
  --ink: #dfe8f2;
  --muted: #90a4b8;
  --line: #223041;
  --accent: #5ea5d9;
  --accent-strong: #3c7ba8;
  --control-bg: #0b1219;
  --json-bg: #0c131b;
  --json-line: #1f2d3d;
  --thead-bg: #101a24;
  --thead-ink: #adbece;
  --thead-line: #2a3a4b;
  --row-line: #1d2b3a;
  --shadow: 0 16px 34px rgba(3, 6, 10, 0.46);
  --layout-line: rgba(196, 211, 227, 0.18);
  --layout-bg: #0a1119;
}

body[data-theme='dawn'] {
  --bg: #f7eee4;
  --bg-top: #fcf5ed;
  --bg-bottom: #f2e4d5;
  --flare-1: rgba(217, 115, 62, 0.18);
  --flare-2: rgba(228, 163, 95, 0.14);
  --panel: #fff8f0;
  --ink: #332419;
  --muted: #7a5d49;
  --line: #e5cdb8;
  --accent: #d67e3d;
  --accent-strong: #c3652f;
  --control-bg: #fff4e8;
  --json-bg: #fdf2e5;
  --json-line: #efd7c2;
  --thead-bg: #f6e4d1;
  --thead-ink: #6f513d;
  --thead-line: #e7c8ad;
  --row-line: #efd8c4;
  --shadow: 0 18px 36px rgba(89, 54, 23, 0.14);
  --layout-line: rgba(122, 93, 73, 0.2);
  --layout-bg: #f8ebde;
}

body[data-theme='forest'] {
  --bg: #0f1b16;
  --bg-top: #1a2a23;
  --bg-bottom: #0d1713;
  --flare-1: rgba(91, 166, 122, 0.18);
  --flare-2: rgba(151, 195, 121, 0.12);
  --panel: #17251f;
  --ink: #e3efe8;
  --muted: #a6bcaf;
  --line: #2a4035;
  --accent: #5aaa7e;
  --accent-strong: #3f8d67;
  --control-bg: #122019;
  --json-bg: #111d18;
  --json-line: #274236;
  --thead-bg: #15261f;
  --thead-ink: #bbd3c5;
  --thead-line: #315243;
  --row-line: #22392f;
  --shadow: 0 16px 34px rgba(4, 10, 8, 0.42);
  --layout-line: rgba(199, 220, 206, 0.18);
  --layout-bg: #101b16;
}

body[data-theme='ember'] {
  --bg: #1a1211;
  --bg-top: #2a1916;
  --bg-bottom: #130d0c;
  --flare-1: rgba(213, 92, 58, 0.2);
  --flare-2: rgba(211, 144, 71, 0.14);
  --panel: #241816;
  --ink: #f0e6df;
  --muted: #c3aca1;
  --line: #4a2d28;
  --accent: #d5683e;
  --accent-strong: #b94a30;
  --control-bg: #1a1210;
  --json-bg: #1c1311;
  --json-line: #3f2924;
  --thead-bg: #231613;
  --thead-ink: #d7bdb2;
  --thead-line: #4f342d;
  --row-line: #34211d;
  --shadow: 0 16px 34px rgba(12, 5, 4, 0.5);
  --layout-line: rgba(223, 198, 187, 0.18);
  --layout-bg: #17100f;
}

body[data-theme='ice'] {
  --bg: #eaf3f8;
  --bg-top: #f2f8fc;
  --bg-bottom: #e4eef5;
  --flare-1: rgba(109, 168, 206, 0.16);
  --flare-2: rgba(135, 187, 203, 0.14);
  --panel: #f9fcff;
  --ink: #1f2e3b;
  --muted: #5e7489;
  --line: #c7dae7;
  --accent: #4d8eb8;
  --accent-strong: #3d779d;
  --control-bg: #f0f7fc;
  --json-bg: #eef6fb;
  --json-line: #d8e7f2;
  --thead-bg: #e5f1f9;
  --thead-ink: #49657b;
  --thead-line: #c6dceb;
  --row-line: #d8e8f3;
  --shadow: 0 18px 34px rgba(35, 69, 99, 0.12);
  --layout-line: rgba(94, 116, 137, 0.2);
  --layout-bg: #edf5fb;
}

* {
  box-sizing: border-box;
}

body {
  --rotating-bg-image: none;
  margin: 0;
  background:
    radial-gradient(circle at top left, var(--flare-1), transparent 28%), radial-gradient(circle at top right, var(--flare-2), transparent 24%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--ink);
  font-family: 'Inter', 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  position: relative;
  isolation: isolate;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: var(--rotating-bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.2;
  z-index: -1;
  pointer-events: none;
  transition: opacity 700ms ease;
}

.page {
  width: calc(100% - 32px);
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  position: relative;
  margin-left: auto;
  padding: 0 0 12px;
  text-align: right;
  max-width: min(520px, 100%);
}

.menu-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 40;
  min-width: 0;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  padding: 0;
  font-size: 1.2rem;
}

.side-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, 86vw);
  height: 100vh;
  z-index: 50;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 45;
}

.side-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.menu-close {
  min-width: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  line-height: 0.94;
}

.intro,
.muted {
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 16px;
  align-items: end;
  margin: 16px 0 24px;
}

.item-selection h2 {
  margin-bottom: 0;
}

.item-selection-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.selected-target-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
}

.selected-target-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.82rem;
  line-height: 1;
  padding: 8px 10px;
  animation: target-chip-enter 180ms ease-out;
}

.bubble-selected-style,
.selected-target-chip,
.item-cell.active,
.choice-option-bubble.active,
.layout-version-bubble.active,
.option-bubble.active,
.layout-fit-bubble.active {
  background: color-mix(in srgb, var(--accent) 28%, var(--layout-bg) 72%);
  border-color: color-mix(in srgb, var(--accent) 82%, #000 18%);
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--accent) 78%, transparent),
    0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
  color: #f5f9ff;
}

.selected-target-label {
  display: inline-block;
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-target-remove {
  border: none;
  background: color-mix(in srgb, #000 25%, transparent);
  color: #f5f9ff;
  border-radius: 999px;
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

@keyframes target-chip-enter {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.item-table {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 8px;
  padding: 4px;
}

.item-cell {
  min-width: 0;
  width: 100%;
  text-align: center;
  padding: 6px 8px;
  font-size: 0.8rem;
  line-height: 1.15;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--control-bg) 68%, var(--ink) 32%);
  color: var(--ink);
  height: 44px;
  min-height: 44px;
  max-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.field {
  display: grid;
  gap: 8px;
  flex: 1;
}

.field-theme {
  flex: 0 0 180px;
}

.field-toggle {
  flex: 0 0 220px;
}

.field span {
  font-size: 0.9rem;
  color: var(--muted);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--control-bg);
}

.toggle input {
  margin: 0;
}

select,
input,
button {
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
}

select {
  background: var(--control-bg);
}

input {
  background: var(--control-bg);
}

button {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #f4f8fc;
  cursor: pointer;
  min-width: 150px;
}

.results-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 4fr 1fr;
  gap: 18px;
}

.json-output {
  margin: 12px 0 0;
  padding: 16px;
  border-radius: 14px;
  background: var(--json-bg);
  border: 1px solid var(--json-line);
  overflow: auto;
  white-space: pre-wrap;
  font-family: 'SFMono-Regular', ui-monospace, Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
}

.tree-table-wrap {
  margin: 12px 0 0;
  border-radius: 14px;
  background: var(--json-bg);
  border: 1px solid var(--json-line);
  overflow: auto;
}

.tree-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tree-table thead th {
  text-align: left;
  background: var(--thead-bg);
  color: var(--thead-ink);
  padding: 10px 12px;
  border-bottom: 1px solid var(--thead-line);
  position: sticky;
  top: 0;
}

.tree-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--row-line);
  vertical-align: top;
}

.tree-table tbody tr:last-child td {
  border-bottom: none;
}

.tree-item {
  font-family: 'SFMono-Regular', ui-monospace, Menlo, monospace;
}

.tree-kind {
  color: var(--muted);
}

.choice-fields {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.choice-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(760px, 92vw);
  width: 92vw;
}

.choice-dialog::backdrop {
  background: rgba(0, 0, 0, 0.46);
}

.choice-dialog-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  color: var(--ink);
  max-height: 84vh;
  overflow: auto;
}

.choice-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.choice-item-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 90%, var(--bg) 10%);
}

.choice-item-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--ink);
}

.choice-options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.choice-option-bubble {
  min-width: 0;
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--control-bg) 72%, var(--ink) 28%);
  color: var(--ink);
  padding: 8px 10px;
  font-size: 0.82rem;
  line-height: 1.2;
  text-align: center;
}

.stats-subcards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

.stats-subcard {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: color-mix(in srgb, var(--panel) 86%, var(--bg) 14%);
}

.stats-subcard h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

.stats-subcard .json-output {
  margin-top: 10px;
}

.hidden {
  display: none;
}

.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 180px;
  background: color-mix(in srgb, var(--panel) 94%, #000 6%);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 10px;
  min-width: 0;
}

.context-menu button:hover {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.context-menu button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.layout-workspace {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(260px, 1fr);
  gap: 14px;
}

.layout-panel {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.options-panel h2 {
  margin-bottom: 10px;
}

.options-panel {
  min-width: 260px;
}

.option-bubble,
.layout-version-bubble {
  min-width: 0;
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--control-bg) 72%, var(--ink) 28%);
  color: var(--ink);
  padding: 8px 10px;
  font-size: 0.82rem;
  line-height: 1.2;
  text-align: center;
}

.manual-mode-bubble {
  margin-top: 10px;
  margin-bottom: 8px;
  width: 100%;
  justify-self: start;
}

.lock-ports-bubble {
  width: calc((100% - 16px) / 3);
  justify-self: start;
}

.layout-version-bubbles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.options-three-buttons {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.layout-version-bubble.bad {
  background: color-mix(in srgb, #ff425d 52%, var(--layout-bg) 48%);
  border-color: #ff425d;
  color: #fff7f9;
  box-shadow: inset 0 0 0 1px rgba(255, 210, 216, 0.35);
}

.layout-version-bubble.bad.active {
  background: color-mix(in srgb, #ff2f4d 64%, var(--layout-bg) 36%);
  border-color: #ff2f4d;
  color: #fff;
  box-shadow:
    inset 0 0 0 2px rgba(255, 220, 226, 0.5),
    0 0 0 1px rgba(255, 71, 99, 0.55);
}

.layout-version-bubble.best-source {
  border-color: #f59e0b;
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.45);
}

.option-bubble:disabled,
.layout-version-bubble:disabled {
  opacity: 0.52;
  cursor: not-allowed;
}

.options-divider {
  margin: 10px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.worker-cards {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.manual-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.manual-debug-head h3 {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.manual-debug-head .option-bubble {
  width: auto;
  min-width: 88px;
  padding: 6px 12px;
}

.manual-debug-output {
  margin-top: 8px;
  width: 100%;
  min-height: 220px;
  max-height: 220px;
  font-size: 0.76rem;
  line-height: 1.35;
  resize: vertical;
  color: white;
}

.worker-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg) 8%);
}

.worker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.worker-versions-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  align-items: stretch;
}

.worker-versions-row .layout-version-bubble {
  padding: 5px 6px;
  font-size: 0.68rem;
  line-height: 1;
  height: 30px;
  min-height: 30px;
  max-height: 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.owner-row {
  justify-content: center;
  margin-bottom: 8px;
}

.worker-bubble {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--control-bg) 72%, var(--ink) 28%);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 0.78rem;
}

.owner-bubble {
  font-size: 0.86rem;
  font-weight: 700;
  padding: 8px 12px;
}

.worker-bubble .remove {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: none;
  padding: 0;
  min-width: 16px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.22);
  color: inherit;
}

.worker-forget-wrap {
  margin-top: 10px;
  display: flex;
  justify-content: center;
}

.worker-start-button {
  margin-top: 12px;
  width: 100%;
  border-radius: 999px;
  font-weight: 700;
}

.worker-config h3 {
  margin: 10px 0 6px;
  font-size: 0.9rem;
}

.worker-config-card input[type='text'] {
  width: 100%;
}

.worker-config-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg) 12%);
}

.choice-options-grid.compact-five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.choice-options-grid.compact-five .choice-option-bubble {
  padding: 5px 6px;
  font-size: 0.72rem;
  line-height: 1;
  min-height: 28px;
}

.lane-profile-sections {
  display: grid;
  gap: 8px;
}

.lane-profile-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--bg) 12%);
}

.lane-profile-card h4 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.lane-profile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.lane-profile-subcard {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg) 8%);
}

.lane-profile-subcard h5 {
  margin: 0 0 6px;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
}

.pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.pulse.green {
  background: #24d17f;
  box-shadow: rgba(36, 209, 127, 0.2) 0 0 0 6px;
  animation: 1.8s ease 0s infinite pulse;
}

.pulse.red {
  background: #ef4444;
  box-shadow: rgba(239, 68, 68, 0.2) 0 0 0 6px;
  animation: none;
}

.engine-debug {
  margin-top: 10px;
}

.engine-debug summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
}

.layout-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.layout-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout-fit-bubble {
  min-width: 0;
  width: auto;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--control-bg) 72%, var(--ink) 28%);
  color: var(--ink);
  padding: 7px 14px;
  font-size: 0.82rem;
  line-height: 1;
}

.layout-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.field-grid-size {
  flex: 0 0 120px;
}

.field-version-select {
  flex: 0 0 170px;
}

.field-grid-size input {
  width: 100%;
}

.layout-controls button {
  min-width: auto;
  padding: 10px 12px;
}

.layout-controls input[type='range'] {
  width: 160px;
  padding: 0;
}

.zoom-label {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 48px;
  text-align: right;
}

.layout-engine-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--control-bg) 76%, transparent);
}

.layout-engine-status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f59e0b;
}

.layout-engine-status.busy .dot {
  background: #f59e0b;
  animation: layoutPulse 1s infinite ease-in-out;
}

.layout-engine-status.idle .dot {
  background: #6b7280;
  animation: none;
}

.layout-version-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--control-bg) 76%, transparent);
}

.layout-version-indicator .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f87171;
}

.layout-version-indicator.valid .dot {
  background: #22c55e;
}

.layout-version-indicator.invalid .dot {
  background: #ef4444;
}

.layout-version-indicator.pulse .dot {
  animation: layoutPulse 1.2s infinite ease-in-out;
}

@keyframes layoutPulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.72;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.16);
    opacity: 0.76;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.layout-viewport {
  margin: 14px auto 0;
  width: 100%;
  max-width: 100%;
  height: clamp(680px, 84vh, 980px);
  min-height: 680px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--layout-bg);
  overflow: hidden;
  overflow: clip;
  position: relative;
  cursor: grab;
  isolation: isolate;
  clip-path: inset(0 round 14px);
}

.layout-viewport.dragging {
  cursor: grabbing;
}

.layout-grid {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  user-select: none;
  overflow: hidden;
  contain: paint;
  clip-path: inset(0);
}

.layout-core-grid {
  position: absolute;
  background-image: linear-gradient(to right, var(--layout-line) 1px, transparent 1px), linear-gradient(to bottom, var(--layout-line) 1px, transparent 1px);
  background-repeat: repeat;
  border-right: 1px solid var(--layout-line);
  border-bottom: 1px solid var(--layout-line);
}

.layout-connections {
  position: absolute;
  pointer-events: auto;
  overflow: hidden;
  clip-path: inset(0);
}

.layout-bridges {
  position: absolute;
  pointer-events: none;
  overflow: hidden;
  clip-path: inset(0);
}

.layout-connection-path {
  stroke: #d7c84e;
  stroke-width: 6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.25));
  pointer-events: stroke;
}

.layout-connection-path.bad {
  stroke: #ff6c7a;
  stroke-dasharray: 8 6;
}

.layout-connection-path.draft {
  stroke: color-mix(in srgb, var(--accent) 74%, #ffffff 26%);
  stroke-dasharray: 7 5;
  opacity: 0.95;
}

.layout-bridge-marker {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #111827;
  background: #fef3c7;
  border: 2px solid #0f172a;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.45),
    0 1px 2px rgba(0, 0, 0, 0.45);
  text-shadow: none;
  z-index: 1;
}

.layout-marker-band {
  position: absolute;
  display: grid;
  pointer-events: none;
}

.layout-marker-band.horizontal {
  grid-auto-flow: column;
}

.layout-marker-band.vertical {
  grid-auto-flow: row;
}

.layout-marker-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--control-bg) 78%, var(--bg) 22%);
  color: color-mix(in srgb, var(--muted) 82%, var(--ink) 18%);
  border: 1px solid color-mix(in srgb, var(--layout-line) 82%, transparent);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.layout-building {
  position: absolute;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  border: 2px solid color-mix(in srgb, var(--ink) 46%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--panel) 35%, transparent);
  background: color-mix(in srgb, var(--panel) 80%, transparent);
  z-index: 2;
  touch-action: none;
  cursor: move;
}

.layout-building.selected {
  border-color: color-mix(in srgb, var(--accent) 72%, #ffffff 28%);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent),
    inset 0 0 0 1px color-mix(in srgb, var(--panel) 35%, transparent);
}

.layout-building.drag-invalid {
  border-color: color-mix(in srgb, #ff6c7a 72%, #ffffff 28%);
  box-shadow:
    0 0 0 1px color-mix(in srgb, #ff6c7a 45%, transparent),
    inset 0 0 0 1px color-mix(in srgb, var(--panel) 35%, transparent);
  opacity: 0.88;
}

.layout-building-cell {
  position: relative;
  border: 1px solid color-mix(in srgb, var(--layout-line) 80%, transparent);
}

.layout-building-cell.input {
  background: color-mix(in srgb, #ff8f9a 22%, transparent);
}

.layout-building-cell.output {
  background: color-mix(in srgb, #dbe86f 24%, transparent);
}

.layout-building-cell.liquid-in {
  background: color-mix(in srgb, #8ec7ff 40%, transparent);
}

.layout-building-cell.liquid-out {
  background: color-mix(in srgb, #2f65c7 55%, transparent);
}

.layout-building-cell.center-input {
  background: color-mix(in srgb, #ff8f9a 22%, transparent);
}

.layout-building-cell.center-output {
  background: color-mix(in srgb, #dbe86f 24%, transparent);
}

.layout-port-marker {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  opacity: 0.94;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.layout-port-marker.in {
  color: color-mix(in srgb, var(--ink) 78%, #4f5f73 22%);
}

.layout-port-marker.out {
  color: color-mix(in srgb, var(--ink) 78%, #3f5020 22%);
}

.layout-building-label {
  position: absolute;
  inset: 4% 4%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 2px;
  color: var(--ink);
  font-weight: 600;
  line-height: 1.1;
  pointer-events: none;
  overflow: hidden;
  z-index: 3;
}

.layout-building-name,
.layout-building-product {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  transform-origin: center center;
}

.layout-building-name {
  font-weight: 650;
}

.layout-building-product {
  font-weight: 500;
  color: var(--muted);
}

.engine-stop-button {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--control-bg);
  color: var(--ink);
  border: 1px solid var(--line);
}

.engine-stop-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}

@media (max-width: 860px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .layout-header {
    flex-direction: column;
    align-items: stretch;
  }
}
