/* ============================================================
   ESP.AI — design system
   ============================================================ */

:root {
  --bg: #07080a;
  --panel: rgba(19, 21, 26, 0.74);
  --panel-solid: #101217;
  --hair: rgba(255, 255, 255, 0.07);
  --hair-strong: rgba(255, 255, 255, 0.13);

  --text: #f2ede2;
  --text-2: #a9a394;
  --text-3: #716c60;

  --amber: #e9b072;
  --amber-deep: #c4813c;
  --mint: #7fd1b9;
  --coral: #e0745f;

  --r-lg: 16px;
  --r-md: 11px;
  --r-sm: 8px;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --t: 160ms var(--ease);

  --shadow-panel: 0 20px 50px rgba(0, 0, 0, 0.45);
  --shadow-pop: 0 14px 34px rgba(0, 0, 0, 0.55);
  --inset-top: inset 0 1px 0 rgba(255, 255, 255, 0.05);

  --font: "Instrument Sans", -apple-system, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --topbar: 56px;
  --statusbar: 26px;
  --rail-l: 296px;
  --rail-r: 324px;
  --gap: 10px;
}

*,
*::before,
*::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 6% -10%, rgba(233, 176, 114, 0.12), transparent 62%),
    radial-gradient(720px 460px at 104% 2%, rgba(127, 209, 185, 0.06), transparent 58%);
}
.noise {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.026;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
img { display: block; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.012em; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid rgba(233, 176, 114, 0.6); outline-offset: 2px; }

/* ---------- shell ---------- */

.app {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar);
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--hair);
  background: rgba(8, 9, 11, 0.72);
  backdrop-filter: blur(20px) saturate(140%);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { justify-content: flex-end; }

.brand { display: inline-flex; align-items: center; gap: 9px; flex: none; }
.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: linear-gradient(150deg, #f8d9ad, var(--amber) 45%, #985e26);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 5px 14px rgba(196, 129, 60, 0.32), var(--inset-top);
  display: grid;
  place-items: center;
}
.brand-mark::after {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  border: 1.5px solid rgba(28, 18, 8, 0.8);
}
.brand-text { font-weight: 700; font-size: 14.5px; letter-spacing: 0.015em; }
.brand-text i { color: var(--amber); font-style: normal; }

.divider-v { width: 1px; height: 20px; background: var(--hair); flex: none; }

.project-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  min-width: 0;
}
.project-chip input {
  border: 0;
  background: transparent;
  outline: none;
  width: 140px;
  min-width: 60px;
  font-size: 12.5px;
  font-weight: 500;
}
.project-chip input::placeholder { color: var(--text-3); }
.save-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}
.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 8px rgba(127, 209, 185, 0.7);
  transition: var(--t);
}
.save-state[data-state="dirty"] .save-dot { background: var(--amber); box-shadow: 0 0 8px rgba(233, 176, 114, 0.6); }
.save-state[data-state="error"] .save-dot { background: var(--coral); box-shadow: 0 0 8px rgba(224, 116, 95, 0.7); }

.segnav {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow: var(--inset-top);
}
.segnav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-2);
  white-space: nowrap;
  transition: var(--t);
}
.segnav a:hover { color: var(--text); }
.segnav a.is-active {
  color: #201607;
  background: linear-gradient(180deg, #f6d0a2, var(--amber-deep));
  box-shadow: 0 3px 12px rgba(196, 129, 60, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.segnav svg { width: 14px; height: 14px; flex: none; }

.iconbtn.panel-toggle { display: none; }

/* ---------- controls ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--t);
}
.btn svg { width: 14px; height: 14px; flex: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-accent {
  color: #201607;
  background: linear-gradient(180deg, #f6d0a2, var(--amber-deep));
  box-shadow: 0 5px 16px rgba(196, 129, 60, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.btn-accent:hover:not(:disabled) { filter: brightness(1.06); }
.btn-outline { border-color: var(--hair-strong); background: rgba(255, 255, 255, 0.03); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: rgba(233, 176, 114, 0.45); background: rgba(233, 176, 114, 0.08); }
.btn-ghost { color: var(--text-2); background: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn-danger { color: #f0b9ad; border-color: rgba(224, 116, 95, 0.32); background: rgba(224, 116, 95, 0.1); }
.btn-danger:hover { background: rgba(224, 116, 95, 0.18); }
.btn-block { width: 100%; }

.iconbtn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: var(--t);
}
.iconbtn svg { width: 15px; height: 15px; }
.iconbtn:hover { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.iconbtn.is-bordered { border-color: var(--hair); background: rgba(255, 255, 255, 0.03); }

.field {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.3);
  outline: none;
  font-size: 12.5px;
  transition: var(--t);
}
select.field { cursor: pointer; }
textarea.field { height: auto; padding: 9px 10px; resize: vertical; }
.field:focus { border-color: rgba(233, 176, 114, 0.5); box-shadow: 0 0 0 3px rgba(233, 176, 114, 0.1); }
.field-label { display: grid; gap: 6px; font-size: 11px; color: var(--text-2); }
.field-label .row { display: flex; align-items: center; justify-content: space-between; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.num { font-family: var(--mono); font-size: 11px; color: var(--amber); }
.hint { color: var(--text-3); font-size: 11px; line-height: 1.5; margin: 0; }
.eyebrow {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-3);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f6d0a2, var(--amber-deep));
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%;
  background: linear-gradient(180deg, #f6d0a2, var(--amber-deep));
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 5px 10px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 550;
  cursor: pointer;
  transition: var(--t);
}
.chip:hover { color: var(--text); border-color: var(--hair-strong); }
.chip.is-active { color: #201607; background: linear-gradient(180deg, #f2c795, var(--amber-deep)); border-color: transparent; }

kbd {
  font-family: var(--mono);
  font-size: 9.5px;
  padding: 2px 5px;
  border-radius: 5px;
  border: 1px solid var(--hair-strong);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-2);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
  transition: var(--t);
}
.toggle:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.toggle input { display: none; }
.toggle .box {
  width: 14px; height: 14px; flex: none;
  border-radius: 4px;
  border: 1px solid var(--hair-strong);
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  transition: var(--t);
}
.toggle .box::after { content: ""; width: 6px; height: 6px; border-radius: 2px; background: transparent; transition: var(--t); }
.toggle input:checked + .box { border-color: rgba(233, 176, 114, 0.6); background: rgba(233, 176, 114, 0.16); }
.toggle input:checked + .box::after { background: var(--amber); }

/* ---------- layout ---------- */

.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-l) minmax(0, 1fr) var(--rail-r);
  gap: var(--gap);
  padding: var(--gap);
}
.layout-studio { --rail-l: 274px; --rail-r: 320px; }

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  background: var(--panel);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-panel), var(--inset-top);
  overflow: hidden;
}

.scrim {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(4, 5, 7, 0.6);
  backdrop-filter: blur(2px);
  transition: opacity 200ms var(--ease);
}

.rail-head {
  padding: 13px 14px 11px;
  border-bottom: 1px solid var(--hair);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.rail-head h2 { font-size: 14.5px; margin-top: 6px; }
.rail-head p { margin: 4px 0 0; color: var(--text-3); font-size: 11.5px; line-height: 1.45; }
.rail-tools { padding: 11px 12px; display: grid; gap: 9px; border-bottom: 1px solid var(--hair); }
.rail-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rail-foot { padding: 11px; border-top: 1px solid var(--hair); }
.rail-close { display: none; }

.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 10px; width: 13px; height: 13px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%;
  height: 32px;
  padding: 0 11px 0 31px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.3);
  outline: none;
  font-size: 12.5px;
  transition: var(--t);
}
.search input:focus { border-color: rgba(233, 176, 114, 0.5); box-shadow: 0 0 0 3px rgba(233, 176, 114, 0.1); }

/* ---------- cards ---------- */

.card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 8px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.022);
  cursor: grab;
  text-align: left;
  transition: var(--t);
}
.card:hover {
  border-color: rgba(233, 176, 114, 0.4);
  background: rgba(233, 176, 114, 0.07);
  box-shadow: var(--shadow-pop);
}
.card.is-active { border-color: rgba(233, 176, 114, 0.6); background: rgba(233, 176, 114, 0.1); }
.card-thumb {
  width: 46px;
  height: 46px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  padding: 4px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01)),
    repeating-conic-gradient(#15171c 0 25%, #1b1e24 0 50%) 0 0 / 9px 9px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 1px 6px rgba(0, 0, 0, 0.5);
}
.card-thumb img { max-width: 100%; max-height: 38px; width: auto; object-fit: contain; }
.card-title { display: block; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-3);
}
.pin-dots { display: inline-flex; gap: 3px; }
.pin-dots i { width: 5px; height: 5px; border-radius: 50%; display: block; }

.empty {
  display: grid;
  gap: 7px;
  justify-items: center;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.55;
}
.empty .empty-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hair);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-3);
}

/* ---------- stage ---------- */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  overflow: hidden;
  background:
    radial-gradient(900px 520px at 50% -6%, rgba(255, 255, 255, 0.045), transparent 62%),
    radial-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px) 0 0 / 24px 24px,
    #090a0c;
  box-shadow: var(--shadow-panel), var(--inset-top);
}
.stage-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.stage-viewport.is-panning { cursor: grabbing; }
.stage-viewport.can-pan { cursor: grab; }
.stage-viewport.is-wiring { cursor: crosshair; }
.stage-viewport.is-wiring .part-node { cursor: crosshair; }

.stage-world {
  position: absolute;
  left: 0;
  top: 0;
  width: 1536px;
  height: 1024px;
  transform-origin: 0 0;
  will-change: transform;
}
.table-bg {
  width: 1536px;
  height: 1024px;
  max-width: none;
  aspect-ratio: 1536 / 1024;
  object-fit: contain;
  border-radius: 4px;
  user-select: none;
  pointer-events: none;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.placements { position: absolute; inset: 0; }
.stage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(130% 95% at 50% 45%, transparent 58%, rgba(0, 0, 0, 0.5) 100%);
}

.part-node {
  position: absolute;
  transform-origin: 50% 50%;
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 9px 14px rgba(0, 0, 0, 0.55));
  transition: filter var(--t);
}
.part-node img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.part-node.is-selected {
  filter: drop-shadow(0 0 6px rgba(233, 176, 114, 0.5)) drop-shadow(0 11px 18px rgba(0, 0, 0, 0.6));
  z-index: 6;
}
.part-node.is-selected::before {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1px solid rgba(233, 176, 114, 0.7);
  border-radius: 5px;
  pointer-events: none;
}
.part-node.is-dragging { cursor: grabbing; }
.part-label {
  position: absolute;
  left: 50%;
  top: -21px;
  transform: translateX(-50%);
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(9, 10, 12, 0.9);
  border: 1px solid var(--hair);
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text-2);
  white-space: nowrap;
  opacity: 0;
  transition: var(--t);
  pointer-events: none;
}
.part-node:hover .part-label,
.part-node.is-selected .part-label { opacity: 1; }

.part-pins { position: absolute; inset: 0; pointer-events: none; }
.pin {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: var(--amber);
  border: 1.5px solid rgba(10, 8, 4, 0.85);
  box-shadow: 0 0 0 2px rgba(233, 176, 114, 0.2);
  pointer-events: auto;
  cursor: crosshair;
  transition: box-shadow var(--t);
}
.pin::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; }
.pin:hover, .pin.is-target { box-shadow: 0 0 0 5px rgba(233, 176, 114, 0.45); z-index: 2; }
.pin.is-origin { box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.5); }

.wires {
  position: absolute;
  inset: 0;
  width: 1536px;
  height: 1024px;
  overflow: visible;
  pointer-events: none;
  z-index: 7;
}
.wire { pointer-events: stroke; cursor: pointer; }
.wire-hit { stroke: transparent; stroke-width: 16; fill: none; }
.wire-shadow { fill: none; stroke: rgba(0, 0, 0, 0.55); stroke-linecap: round; }
.wire-core { fill: none; stroke-linecap: round; }
.wire-gloss { fill: none; stroke: rgba(255, 255, 255, 0.28); stroke-linecap: round; }
.wire.is-selected .wire-core { filter: drop-shadow(0 0 6px rgba(233, 176, 114, 0.9)); }
.wire.is-selected .wire-gloss { stroke: rgba(255, 255, 255, 0.55); }
.wire:hover .wire-core { filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.45)); }
.wire-temp {
  fill: none;
  stroke: rgba(233, 176, 114, 0.9);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 7 6;
  pointer-events: none;
}
.solder { stroke: rgba(0, 0, 0, 0.6); stroke-width: 1; }

.dock {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: rgba(13, 15, 19, 0.85);
  backdrop-filter: blur(16px) saturate(150%);
  box-shadow: var(--shadow-pop), var(--inset-top);
  z-index: 8;
  max-width: calc(100% - 24px);
}
.dock .divider-v { height: 16px; margin: 0 2px; }
.zoom-value { min-width: 42px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--text-2); }

.stage-caption {
  position: absolute;
  left: 14px;
  bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  max-width: 30%;
  font-size: 11px;
  color: var(--text-3);
  pointer-events: none;
  z-index: 3;
}

/* ---------- inspector ---------- */

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  margin: 10px 11px 0;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
}
.tab {
  flex: 1;
  height: 27px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--t);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: #201607; background: linear-gradient(180deg, #f2c795, var(--amber-deep)); }
.tab .count {
  font-family: var(--mono);
  font-size: 9.5px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}
.tab.is-active .count { background: rgba(0, 0, 0, 0.18); }

.insp-title { display: flex; align-items: center; gap: 9px; }
.insp-title h3 { font-size: 14px; }

.kv-grid {
  display: grid;
  gap: 1px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--hair);
}
.kv {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 8px;
  padding: 8px 10px;
  background: rgba(13, 15, 19, 0.92);
  font-size: 11.5px;
}
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 11px; color: var(--text-2); word-break: break-word; }

.section-sep { height: 1px; background: var(--hair); }

.conn-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 26px;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.022);
  cursor: pointer;
  transition: var(--t);
}
.conn-row:hover { border-color: var(--hair-strong); background: rgba(255, 255, 255, 0.05); }
.conn-row.is-selected { border-color: rgba(233, 176, 114, 0.55); background: rgba(233, 176, 114, 0.08); }
.conn-swatch { width: 10px; height: 10px; border-radius: 50%; }
.conn-text {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conn-sub { display: block; font-size: 10px; color: var(--text-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ai-card {
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  padding: 11px;
  background: linear-gradient(180deg, rgba(233, 176, 114, 0.06), rgba(255, 255, 255, 0.012));
  display: grid;
  gap: 8px;
}
.ai-card header { display: flex; align-items: center; justify-content: space-between; }
.ai-card h3 { font-size: 12.5px; }
.badge-soon {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--amber);
  border: 1px solid rgba(233, 176, 114, 0.35);
  border-radius: 999px;
  padding: 3px 7px;
}

/* ---------- studio ---------- */

.dropzone {
  display: grid;
  gap: 7px;
  padding: 14px 11px;
  border: 1px dashed var(--hair-strong);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
  transition: var(--t);
}
.dropzone.is-over { border-color: rgba(233, 176, 114, 0.6); background: rgba(233, 176, 114, 0.08); }
.dropzone p { margin: 0; font-size: 11px; color: var(--text-3); }

.studio-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--hair);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: #0a0b0e;
  box-shadow: var(--shadow-panel), var(--inset-top);
  display: flex;
  flex-direction: column;
}
.studio-bar {
  flex: none;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--hair);
  background: rgba(13, 15, 19, 0.72);
  flex-wrap: wrap;
}
.mode-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--hair); border-radius: 999px; background: rgba(0, 0, 0, 0.3); }
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--t);
}
.mode-btn svg { width: 13px; height: 13px; }
.mode-btn:hover { color: var(--text); }
.mode-btn.is-active { color: #201607; background: linear-gradient(180deg, #f6d0a2, var(--amber-deep)); }
.bar-hint { margin-left: auto; font-size: 11px; color: var(--text-3); }

.studio-canvas-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; --gutter: 24px; }
.ruler { position: absolute; background: #0f1116; z-index: 3; }
.ruler-h { top: 0; left: var(--gutter); right: 0; height: var(--gutter); border-bottom: 1px solid var(--hair); }
.ruler-v { left: 0; top: var(--gutter); bottom: 0; width: var(--gutter); border-right: 1px solid var(--hair); }
.ruler-corner {
  position: absolute;
  left: 0; top: 0;
  width: var(--gutter); height: var(--gutter);
  background: #0f1116;
  border-right: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  z-index: 4;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 8px;
  color: var(--text-3);
}
.plane { position: absolute; left: var(--gutter); top: var(--gutter); right: 0; bottom: 0; overflow: hidden; touch-action: none; }
.plane-grid { position: absolute; inset: 0; pointer-events: none; }
.plane.is-panning { cursor: grabbing; }
.plane.mode-pin { cursor: crosshair; }

.part { position: absolute; transform-origin: 50% 50%; cursor: move; }
.part img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.6));
  user-select: none;
}
.part-outline { position: absolute; inset: 0; border: 1px solid rgba(233, 176, 114, 0.55); pointer-events: none; }
.handle {
  position: absolute;
  width: 11px; height: 11px;
  border-radius: 3px;
  background: linear-gradient(180deg, #f6d0a2, var(--amber-deep));
  border: 1px solid rgba(10, 8, 4, 0.8);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  z-index: 5;
}
.handle[data-h="nw"] { left: -6px; top: -6px; cursor: nwse-resize; }
.handle[data-h="ne"] { right: -6px; top: -6px; cursor: nesw-resize; }
.handle[data-h="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle[data-h="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.handle-rot {
  position: absolute;
  left: 50%; top: -28px;
  width: 12px; height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: #0f1116;
  border: 1.5px solid var(--amber);
  cursor: grab;
  z-index: 5;
}
.handle-rot::after { content: ""; position: absolute; left: 50%; top: 11px; width: 1px; height: 17px; background: rgba(233, 176, 114, 0.5); }
.part.mode-pin .handle, .part.mode-pin .handle-rot { display: none; }

.studio-pin {
  position: absolute;
  width: 13px; height: 13px;
  margin: -6.5px 0 0 -6.5px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid rgba(8, 7, 5, 0.9);
  box-shadow: 0 0 0 3px rgba(233, 176, 114, 0.22);
  cursor: grab;
  z-index: 6;
}
.studio-pin.is-selected { box-shadow: 0 0 0 4px rgba(233, 176, 114, 0.4); z-index: 7; }
.studio-pin .tag-name {
  position: absolute;
  left: 14px; top: -4px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(8, 9, 11, 0.92);
  border: 1px solid var(--hair);
  font-family: var(--mono);
  font-size: 9.5px;
  color: var(--text);
  white-space: nowrap;
  pointer-events: none;
}
.size-chip {
  position: absolute;
  left: 50%; bottom: -28px;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(8, 9, 11, 0.9);
  border: 1px solid rgba(233, 176, 114, 0.3);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--amber);
  white-space: nowrap;
  pointer-events: none;
}
.plane-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding: 28px;
  gap: 9px;
}
.plane-empty .icon {
  width: 42px; height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hair);
  background: rgba(255, 255, 255, 0.03);
  color: var(--amber);
}
.plane-empty h3 { font-size: 16px; }
.plane-empty p { margin: 0; max-width: 400px; color: var(--text-3); font-size: 12px; line-height: 1.6; }

.pin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 26px;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--hair);
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.022);
  transition: var(--t);
}
.pin-row.is-selected { border-color: rgba(233, 176, 114, 0.5); background: rgba(233, 176, 114, 0.07); }
.pin-row .field { height: 27px; font-size: 11.5px; padding: 0 7px; }
.pin-row .coords { grid-column: 1 / -1; font-family: var(--mono); font-size: 9px; color: var(--text-3); }

/* ---------- status bar ---------- */

.statusbar {
  height: var(--statusbar);
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  border-top: 1px solid var(--hair);
  background: rgba(8, 9, 11, 0.72);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
}
.statusbar b { color: var(--text-2); font-weight: 500; }
.statusbar .spacer { margin-left: auto; }
.statusbar .st-item { display: inline-flex; align-items: center; gap: 5px; }
.st-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--amber); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border: 1px solid var(--hair-strong);
  border-radius: var(--r-md);
  background: rgba(15, 17, 22, 0.96);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-pop);
  font-size: 12.5px;
  font-weight: 500;
  animation: toast-in 200ms var(--ease);
}
.toast .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); }
.toast[data-kind="error"] .dot { background: var(--coral); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   responsive
   ============================================================ */

@media (max-width: 1500px) {
  :root { --rail-l: 274px; --rail-r: 300px; }
}

@media (max-width: 1320px) {
  :root { --rail-l: 250px; --rail-r: 276px; }
  .stage-caption { max-width: 42%; }
}

@media (max-width: 1140px) {
  /* rails become overlay drawers */
  .layout,
  .layout-studio {
    grid-template-columns: minmax(0, 1fr);
    overflow: hidden;
  }
  .iconbtn.panel-toggle { display: inline-grid; }
  .rail {
    position: absolute;
    top: var(--gap);
    bottom: var(--gap);
    z-index: 30;
    width: min(330px, 86vw);
    box-shadow: 0 30px 70px rgba(0, 0, 0, 0.65);
    transition: transform 220ms var(--ease);
  }
  .rail-left { left: var(--gap); transform: translateX(calc(-100% - var(--gap) - 12px)); }
  .rail-right { right: var(--gap); transform: translateX(calc(100% + var(--gap) + 12px)); }
  body.drawer-left .rail-left,
  body.drawer-right .rail-right { transform: none; }
  .scrim { display: block; opacity: 0; pointer-events: none; }
  body.drawer-left .scrim,
  body.drawer-right .scrim { opacity: 1; pointer-events: auto; }
  .rail-close { display: inline-grid; }
  .stage-caption { display: none; }
}

@media (max-width: 860px) {
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
  .segnav { justify-self: center; }
  .segnav a { padding: 6px 11px; }
  .project-chip { display: none; }
  .save-state-mobile { display: inline-flex; }
  .btn-label { display: none; }
  .btn { padding: 0 10px; }
  .bar-hint { display: none; }
}

@media (max-width: 700px) {
  :root { --gap: 8px; --topbar: 52px; }
  .statusbar { display: none; }
  .segnav a span { display: none; }
  .segnav a { padding: 6px 12px; }
  .brand-text { display: none; }
  .dock { gap: 2px; padding: 5px 6px; bottom: 10px; }
  .zoom-value { min-width: 36px; }
  .toggle span:not(.box) { display: none; }
  .rail { width: min(340px, 92vw); }
  .studio-bar { min-height: 42px; }
  .mode-btn { padding: 0 9px; font-size: 11.5px; }
}

@media (max-height: 620px) {
  .rail-head { padding: 10px 12px 9px; }
  .rail-head p { display: none; }
  .statusbar { display: none; }
}
