:root {
  color-scheme: dark;
  --bg: #0c1114;
  --surface: #131b20;
  --surface-2: #182228;
  --surface-3: #202c33;
  --line: #2b3941;
  --line-bright: #41545f;
  --text: #f2f5f6;
  --muted: #91a1aa;
  --quiet: #687a84;
  --accent: #ffb547;
  --accent-strong: #ffc466;
  --accent-ink: #211505;
  --valid: #5ad7a0;
  --invalid: #ff6f68;
  --blue: #5a9fe8;
  --teal: #53c8c3;
  --violet: #a985f4;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.cb-theme-light .canvas-frame { background-color: #e9ebec; }
.cb-theme-light .canopy-svg { color: #252829; }

body {
  min-width: 320px;
  font-size: 16px;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
[tabindex]:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 100;
  transform: translateY(-160%);
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  display: grid;
  grid-template-rows: 72px 76px minmax(0, 1fr) 42px;
  width: 100%;
  height: 100vh;
  min-height: 0;
  background:
    radial-gradient(circle at 76% 16%, rgba(255, 181, 71, 0.06), transparent 24rem),
    var(--bg);
}

.topbar,
.active-bar,
.statusbar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-color: var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
}

.topbar {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line));
  border-radius: 12px;
  background: rgba(255, 181, 71, 0.09);
}

.brand-mark svg {
  width: 28px;
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.eyebrow,
.active-kicker {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  line-height: 1;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.18rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.toolbar,
.toolbar-group,
.active-actions,
.layout-meta,
.modal-actions,
.segmented-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layout-navigation {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0f161a;
}

.layout-navigation > .eyebrow {
  margin: 0 2px 0 7px;
}

.side-switcher {
  display: flex;
  gap: 3px;
}

.side-tab {
  display: inline-flex;
  min-width: 88px;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 9px 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 650;
}

.side-tab span {
  display: grid;
  min-width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--quiet);
  font-size: 0.68rem;
}

.side-tab.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.side-tab.is-active span {
  background: rgba(33, 21, 5, 0.16);
  color: var(--accent-ink);
}

.toolbar-group {
  margin-right: 6px;
  padding-right: 12px;
  border-right: 1px solid var(--line);
}

.icon-button,
.text-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 620;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.icon-button {
  width: 38px;
  padding: 0;
}

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

.text-button {
  gap: 8px;
  padding: 0 14px;
}

.icon-button:hover:not(:disabled),
.text-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--line-bright);
  background: var(--surface-3);
}

.text-button.accent {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.text-button.accent:hover {
  background: var(--accent-strong);
}

.danger-quiet {
  color: #ffaaa5;
}

.text-button.danger {
  border-color: var(--invalid);
  background: var(--invalid);
  color: #220606;
}

button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.active-bar {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.active-component {
  min-width: 0;
}

.active-empty,
.active-details {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 26px;
  color: var(--muted);
  font-size: 0.9rem;
}

.active-details strong {
  color: var(--text);
  font-size: 1rem;
}

.active-details > span:not(.active-type) {
  color: var(--muted);
}

.active-details small {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--quiet);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
}

.selection-mark {
  width: 11px;
  height: 11px;
  border: 2px solid var(--quiet);
  border-radius: 3px;
}

.active-type {
  width: 8px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
}

.tone-dot-blue { background: var(--blue); }
.tone-dot-teal { background: var(--teal); }
.tone-dot-violet { background: var(--violet); }
.tone-dot-amber { background: var(--accent); }

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

.workspace:has(.debug-panel:not([hidden])) {
  grid-template-columns: 292px minmax(0, 1fr) 278px;
}

.library-panel,
.debug-panel {
  min-height: 0;
  background: var(--surface);
}

.library-panel {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  border-right: 1px solid var(--line);
}

.debug-panel {
  overflow-y: auto;
  border-left: 1px solid var(--line);
  padding-bottom: 20px;
}

.panel-heading,
.editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
}

.panel-heading {
  position: sticky;
  z-index: 2;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px);
}

.panel-heading.compact {
  position: static;
}

.library-hint {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 620;
  text-transform: uppercase;
}

.component-library {
  padding: 6px 10px 18px;
}

.library-group {
  padding: 10px 0 3px;
}

.library-group + .library-group {
  border-top: 1px solid var(--line);
}

.library-group-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 7px;
}

.library-group-heading h3 {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.library-group-heading span {
  color: var(--quiet);
  font-size: 0.72rem;
}

.library-items {
  display: grid;
  gap: 6px;
}

.library-card {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 68px;
  grid-template-columns: 62px 1fr 14px;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  cursor: grab;
  text-align: left;
  touch-action: none;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.library-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  content: "";
  opacity: 0;
  transition: opacity 160ms ease;
}

.library-card:hover {
  z-index: 1;
  transform: translateX(2px);
  border-color: var(--line-bright);
  background: var(--surface-3);
  box-shadow: 0 9px 24px rgba(0, 0, 0, 0.2);
}

.library-card:hover::before {
  opacity: 1;
}

.miniature {
  width: 62px;
  height: 44px;
  overflow: visible;
  fill: rgba(255, 255, 255, 0.015);
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.miniature .mini-shell {
  fill: rgba(255, 255, 255, 0.025);
  stroke-width: 4;
}

.miniature .mini-accent {
  stroke: var(--accent);
  stroke-width: 5;
}

.miniature .mini-open-shelf {
  fill: rgba(5, 10, 13, 0.28);
  stroke: rgba(233, 242, 246, 0.72);
  stroke-width: 4;
}

.miniature.tone-blue .mini-accent { stroke: var(--blue); }
.miniature.tone-teal .mini-accent { stroke: var(--teal); }
.miniature.tone-violet .mini-accent { stroke: var(--violet); }

.library-card-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.library-card-copy strong {
  font-size: 0.8rem;
  font-weight: 620;
  line-height: 1.15;
}

.library-card-copy small {
  color: var(--muted);
  font-size: 0.63rem;
  line-height: 1.35;
}

.drag-grip {
  color: var(--quiet);
  font-size: 1rem;
  letter-spacing: -5px;
  transform: rotate(90deg);
}

.editor-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 74px minmax(0, 1fr);
  padding: 0 22px 20px;
}

.editor-heading {
  padding-inline: 4px;
}

.layout-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.elevation-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.elevation-actions .text-button {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 0.72rem;
}

.layout-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font-weight: 600;
}

.layout-status > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--valid);
  box-shadow: 0 0 0 3px rgba(90, 215, 160, 0.12);
}

.layout-status.is-invalid {
  color: #ffaaa5;
}

.layout-status.is-invalid > span {
  background: var(--invalid);
  box-shadow: 0 0 0 3px rgba(255, 111, 104, 0.12);
}

.canvas-frame {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    #0e1519;
  background-size: 28px 28px;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.2), var(--shadow);
}

.canvas-frame::before {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 54%, rgba(89, 130, 151, 0.07), transparent 56%);
  content: "";
  pointer-events: none;
}

.canopy-svg {
  display: block;
  width: calc(100% - 54px);
  height: calc(100% - 76px);
  min-height: 360px;
  overflow: visible;
  touch-action: none;
  user-select: none;
}

.svg-backdrop {
  fill: rgba(5, 9, 11, 0.24);
}

.canopy-fill {
  fill: #111b20;
}

.canopy-grid {
  opacity: 0.56;
}

.grid-line {
  fill: none;
  stroke: #43525a;
  stroke-width: 1;
  opacity: 0.28;
  vector-effect: non-scaling-stroke;
}

.canopy-boundary {
  fill: none;
  stroke: #778a94;
  stroke-width: 5;
  vector-effect: non-scaling-stroke;
}

.canopy-dimensions {
  fill: none;
  stroke: #59666c;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.canopy-dimensions text {
  fill: #7c8b92;
  stroke: none;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.layout-module {
  cursor: grab;
  filter: url(#module-shadow);
  transition: opacity 120ms ease;
}

.layout-module:active,
.is-dragging .layout-module {
  cursor: grabbing;
}

.is-dragging .module-label {
  display: none;
}

.module-shell {
  fill: #666;
  stroke: #888;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.tone-amber .module-shell,
.tone-blue .module-shell,
.tone-teal .module-shell,
.tone-violet .module-shell,
.tone-neutral .module-shell { fill: #666; stroke: #888; }

.module-managed-icon { pointer-events: none; }

.canopy-tray-reference,
.canopy-reference-layer { transition: none; }

@media (prefers-reduced-motion: reduce) {
  .canopy-tray-reference,
  .canopy-reference-layer { transition: none; }
}

.layout-module.is-selected .module-shell { fill: #999; }

.module-panel,
.module-screen {
  fill: rgba(5, 10, 13, 0.22);
  stroke: rgba(233, 242, 246, 0.48);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.module-screen {
  fill: rgba(80, 177, 208, 0.15);
  stroke: #63b6d2;
}

.module-detail,
.module-vents path,
.module-handle {
  fill: none;
  stroke: rgba(236, 243, 246, 0.5);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.module-handle {
  stroke: var(--accent-strong);
  stroke-width: 3.5;
}

.tone-blue .module-handle { stroke: #82b9ef; }
.module-knob { fill: var(--accent-strong); }
.tone-blue .module-knob { fill: #82b9ef; }
.tone-teal .module-knob { fill: #76ddd8; }

.module-power {
  fill: #d3bdfd;
  opacity: 0.9;
}

.module-electrical-mark {
  fill: var(--cb-accent);
  font-family: var(--cb-font-ui);
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 2px;
  pointer-events: none;
}

.mini-electrical-mark {
  fill: currentColor;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1px;
}

.module-tray {
  fill: rgba(5, 10, 13, 0.18);
  stroke: #76ddd8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.module-label rect {
  fill: rgba(8, 13, 16, 0.82);
  stroke: rgba(255, 255, 255, 0.09);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.module-label text {
  fill: #f6f8f9;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.module-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.module-dimensions {
  fill: #a9b6bc !important;
  font-size: 11px;
  font-weight: 520;
}

.module-delete {
  cursor: pointer;
  opacity: 0.86;
  transition: opacity 140ms ease, transform 140ms ease;
}

.module-delete:hover,
.module-delete:focus {
  opacity: 1;
}

.module-delete rect {
  fill: rgba(17, 10, 10, 0.9);
  stroke: rgba(255, 136, 128, 0.85);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.module-delete path {
  fill: none;
  stroke: #ff9f99;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.selection-border {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.2;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  animation: selection-border-pulse .9s ease-in-out infinite;
}

@keyframes selection-border-pulse {
  0%, 100% {
    opacity: .45;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .selection-border {
    animation: none;
    opacity: 1;
  }
}

.layout-module.is-ghost {
  opacity: 0.62;
}

.opposite-side-layer {
  opacity: 0.2;
  pointer-events: none;
  filter: saturate(0.45) brightness(1.12);
}

.opposite-side-layer .module-shell,
.opposite-side-layer [class^="module-"] {
  stroke-dasharray: 9 8;
}

.opposite-side-layer .module-shell {
  fill-opacity: 0.36;
}

.shared-partition-layer {
  opacity: .9;
}

.shared-partition-module {
  cursor: pointer;
  filter: none;
}

.shared-partition-module .module-shell {
  fill: #666;
  stroke: var(--accent);
  stroke-width: 2;
}

.shared-partition-module:hover .module-shell,
.shared-partition-module:focus .module-shell {
  fill: #777;
  stroke: var(--accent-strong);
  stroke-width: 3;
}

.rear-profile-layer {
  opacity: 0.34;
  pointer-events: none;
}

.rear-profile-module .module-shell {
  fill: #666;
  fill-opacity: 0.48;
  stroke: var(--accent);
  stroke-dasharray: 8 7;
  stroke-width: 2;
}

.rear-profile-detail {
  fill: none;
  stroke: #aeb4b7;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.rear-profile-module text {
  fill: #e5e8e9;
  font: 700 22px/1 Inter, ui-sans-serif, system-ui, sans-serif;
  pointer-events: none;
}

.layout-module.is-ghost .module-shell {
  stroke: var(--valid);
  stroke-dasharray: 14 10;
  stroke-width: 3.5;
}

.layout-module.is-ghost.is-floating .module-shell {
  stroke: var(--accent);
}

.layout-module.is-ghost.is-invalid .module-shell {
  stroke: var(--invalid);
}

.layout-stack.is-moving {
  opacity: 0.7;
}

.layout-stack.is-moving .debug-collision-box,
.layout-stack.is-invalid .debug-collision-box {
  stroke: var(--invalid);
}

.insertion-indicator {
  fill: var(--valid);
  stroke: var(--valid);
  stroke-width: 8;
  vector-effect: non-scaling-stroke;
}

.insertion-indicator.is-invalid {
  fill: var(--invalid);
  stroke: var(--invalid);
}

.empty-canopy {
  fill: none;
  stroke: #60727b;
  stroke-width: 4;
  opacity: 0.76;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.empty-canopy path {
  stroke: var(--accent);
  stroke-width: 7;
}

.empty-canopy text {
  fill: #ccd5d9;
  stroke: none;
  font-size: 48px;
  font-weight: 750;
}

.empty-canopy .empty-canopy-sub {
  fill: #84969f;
  font-size: 30px;
  font-weight: 600;
}

.debug-collision-box {
  fill: none;
  stroke: #56dba2;
  stroke-dasharray: 12 9;
  stroke-width: 3;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.debug-stack-label,
.debug-instance,
.debug-vertex text {
  fill: #c8f7e1;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 24px;
  font-weight: 700;
  paint-order: stroke;
  pointer-events: none;
  stroke: #0b1114;
  stroke-width: 7;
}

.debug-instance {
  fill: #fff1cb;
  font-size: 21px;
}

.debug-vertex circle {
  fill: var(--accent);
  stroke: #0b1114;
  stroke-width: 4;
}

.debug-vertex text {
  fill: var(--accent-strong);
}

.canvas-help {
  position: absolute;
  right: 15px;
  bottom: 12px;
  left: 15px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  color: var(--quiet);
  font-size: 0.72rem;
  pointer-events: auto;
}

.canvas-help-panel {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
}

.canvas-help-panel[hidden] { display: none; }

.canvas-help b,
.canvas-help-toggle {
  color: var(--muted);
}

.canvas-help-toggle {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  font: inherit;
}

.canvas-help-toggle > span {
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-weight: 800;
  line-height: 1;
}

.mouse-help { display: inline-flex; align-items: center; gap: 5px; }
.mouse-help svg { width: 14px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.mouse-help .mouse-control { stroke: var(--accent); fill: color-mix(in srgb, var(--accent) 26%, transparent); }

.statusbar {
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--quiet);
  font-size: 0.72rem;
}

.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}

.switch-control input {
  position: absolute;
  opacity: 0;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 19px;
  border: 1px solid var(--line-bright);
  border-radius: 999px;
  background: var(--surface-3);
}

.switch-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.switch-control input:checked + .switch-track {
  border-color: var(--accent);
  background: rgba(255, 181, 71, 0.12);
}

.switch-control input:checked + .switch-track span {
  transform: translateX(15px);
  background: var(--accent);
}

.switch-control input:focus-visible + .switch-track {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 3px;
}

.debug-summary,
.debug-stack-card {
  margin: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.debug-summary {
  display: grid;
  gap: 5px;
  border-left: 3px solid var(--valid);
}

.debug-summary.is-invalid {
  border-left-color: var(--invalid);
}

.debug-summary span,
.debug-summary small {
  color: var(--muted);
  font-size: 0.73rem;
}

.debug-summary strong {
  color: var(--valid);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
}

.debug-summary.is-invalid strong {
  color: var(--invalid);
}

.debug-stack-card > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
}

.debug-stack-card > div span {
  color: var(--muted);
}

.debug-stack-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 14px 0 0;
}

.debug-stack-card dl div {
  padding: 8px;
  border-radius: 6px;
  background: #11191d;
}

.debug-stack-card dt {
  color: var(--quiet);
  font-size: 0.64rem;
  text-transform: uppercase;
}

.debug-stack-card dd {
  margin: 3px 0 0;
  color: #dce4e7;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
}

.debug-empty {
  padding: 16px;
  color: var(--quiet);
  font-size: 0.78rem;
}

.toast {
  position: absolute;
  z-index: 90;
  right: auto;
  bottom: 30px;
  left: 50%;
  max-width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, 16px);
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 680;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.toast.error {
  border-color: color-mix(in srgb, var(--invalid) 50%, var(--line));
  background: #2a1919;
  color: #ffd5d2;
}

.toast.neutral {
  border-color: var(--line-bright);
  background: var(--surface-2);
  color: var(--text);
}

.modal {
  width: min(92vw, 700px);
  padding: 0;
  border: 1px solid var(--line-bright);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.52);
  color: var(--text);
}

.modal::backdrop {
  background: rgba(2, 6, 8, 0.75);
  backdrop-filter: blur(5px);
}

.small-modal {
  width: min(92vw, 430px);
  padding: 28px;
  text-align: center;
}

.small-modal form {
  display: grid;
  justify-items: center;
  gap: 14px;
}

.small-modal p {
  max-width: 36ch;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.modal-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  font-size: 1.25rem;
  font-weight: 850;
}

.modal-icon.danger {
  background: rgba(255, 111, 104, 0.12);
  color: var(--invalid);
}

.modal-icon.settings {
  background: rgba(255, 181, 71, 0.12);
  color: var(--accent);
}

.dimensions-modal {
  width: min(92vw, 500px);
}

.dimensions-modal h2 {
  margin-top: 4px;
}

.dimension-fields {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.dimension-fields label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 620;
}

.settings-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.018);
  text-align: left;
}

.settings-row > div {
  display: grid;
  gap: 4px;
}

.settings-row strong {
  font-size: 0.82rem;
  font-weight: 620;
}

.settings-row small {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

.settings-switch {
  flex: 0 0 auto;
}

.dimension-input {
  display: flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b1114;
}

.dimension-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 181, 71, 0.12);
}

.dimension-input input {
  width: 100%;
  min-width: 0;
  padding: 12px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.dimension-input b {
  padding-right: 12px;
  color: var(--muted);
  font-size: 0.72rem;
}

.dimensions-modal .form-error {
  width: 100%;
  margin: 0;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--invalid) 45%, var(--line));
  border-radius: 8px;
  background: rgba(255, 111, 104, 0.08);
  color: #ffd5d2;
  text-align: left;
}

@media (max-width: 480px) {
  .dimension-fields {
    grid-template-columns: 1fr;
  }
}

.small-modal .modal-actions {
  margin-top: 8px;
}

.json-modal {
  padding: 22px;
}

.json-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
}

.json-modal-head .icon-button {
  font-size: 1.4rem;
}

.segmented-control {
  width: max-content;
  margin-bottom: 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #10171b;
}

.segmented-control button {
  padding: 7px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 750;
}

.segmented-control button.is-active {
  background: var(--surface-3);
  color: var(--text);
}

#json-output {
  width: 100%;
  height: min(50vh, 460px);
  resize: vertical;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b1114;
  color: #d5e4dc;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
}

.json-modal .modal-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

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

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .workspace:has(.debug-panel:not([hidden])) {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .debug-panel:not([hidden]) {
    position: fixed;
    z-index: 20;
    top: 148px;
    right: 0;
    bottom: 42px;
    width: 278px;
    box-shadow: -18px 0 42px rgba(0, 0, 0, 0.3);
  }

  .library-card {
    grid-template-columns: 56px 1fr 12px;
  }

  .miniature {
    width: 56px;
  }

  .layout-navigation > .eyebrow {
    display: none;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto auto auto;
  }

  .topbar,
  .active-bar {
    align-items: flex-start;
    gap: 16px;
    padding: 14px 16px;
  }

  .topbar {
    flex-direction: column;
  }

  .layout-navigation {
    width: 100%;
    justify-content: center;
  }

  .toolbar {
    width: 100%;
    overflow-x: auto;
  }

  .active-bar {
    flex-direction: column;
  }

  .active-details {
    flex-wrap: wrap;
  }

  .workspace,
  .workspace:has(.debug-panel:not([hidden])) {
    display: grid;
    grid-template-columns: 1fr;
  }

  .library-panel {
    max-height: 420px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .editor-panel {
    min-height: 650px;
    padding: 0 12px 16px;
  }

  .editor-heading {
    align-items: flex-start;
    gap: 10px;
  }

  .layout-meta {
    align-items: flex-end;
    flex-direction: column;
  }

  .elevation-actions {
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .canopy-svg {
    width: calc(100% - 24px);
    height: calc(100% - 68px);
    min-height: 440px;
  }

  .canvas-help {
    align-items: center;
    flex-direction: column;
    gap: 3px;
  }

  .statusbar {
    gap: 12px;
    padding-block: 12px;
  }

  .debug-panel:not([hidden]) {
    position: static;
    width: auto;
    max-height: 420px;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: none;
  }
}

@media (max-width: 560px) {
  .library-items {
    grid-template-columns: 1fr;
  }

  .toolbar .text-button {
    padding-inline: 10px;
  }

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

  .editor-heading {
    flex-direction: column;
  }

  .layout-meta {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
