:root {
        --ui-bg: rgba(12, 18, 28, 0.88);
        --ui-bg-solid: #0c121c;
        --ui-border: rgba(140, 170, 200, 0.22);
        --ui-text: #e8eef5;
        --ui-muted: #8a9bb0;
        --ui-accent: #0077be;
        --ui-accent-soft: rgba(0, 119, 190, 0.25);
        --ui-danger: #c45c5c;
        --ui-radius: 10px;
        --ui-font: "Sora", sans-serif;
        --slot-width: 230px;
        --grid-unit: 100px;
        --canvas-bg: #071018;
      }

      * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
      }

      html,
      body {
        width: 100%;
        height: 100%;
        overflow: hidden;
        background: var(--canvas-bg);
        font-family: var(--ui-font);
        color: var(--ui-text);
      }

      /* Canvas sits alone at the bottom of the stack so boids stay visible */
      #canvas {
        position: fixed;
        inset: 0;
        z-index: 0;
        display: block;
        width: 100%;
        height: 100%;
        cursor: crosshair;
        background: var(--canvas-bg);
      }

      /*
       * UI chrome floats above the canvas. The root never captures hits;
       * only concrete widgets do — empty space always reaches the canvas.
       */
      #ui-root {
        position: fixed;
        inset: 0;
        z-index: 1;
        pointer-events: none;
      }

      #menu-toggle,
      #settings-panel,
      #hud-layer .hud-widget,
      .flock-count,
      .drag-ghost,
      #trash-zone.active {
        pointer-events: auto;
      }

      #title-art {
        position: absolute;
        top: 14px;
        left: 16px;
        z-index: 2;
        pointer-events: none;
        color: var(--ui-accent);
        opacity: 0.9;
        text-shadow: 0 0 18px var(--ui-accent-soft);
        user-select: none;
      }

      #title-art pre {
        margin: 0;
        font-family: "Courier New", Courier, monospace;
        font-size: 9px;
        line-height: 1.05;
        font-weight: 700;
        letter-spacing: 0.02em;
        white-space: pre;
      }

      #title-art .title-sub {
        margin-top: 4px;
        font-family: var(--ui-font);
        font-size: 10px;
        letter-spacing: 0.28em;
        text-transform: uppercase;
        color: var(--ui-muted);
      }

      #menu-toggle {
        position: absolute;
        top: 16px;
        right: 16px;
        border: 1px solid var(--ui-border);
        background: var(--ui-bg);
        color: var(--ui-text);
        font: 500 13px/1 var(--ui-font);
        letter-spacing: 0.04em;
        text-transform: uppercase;
        padding: 10px 14px;
        border-radius: 999px;
        cursor: grab;
        backdrop-filter: blur(10px);
        touch-action: none;
      }

      #menu-toggle:active {
        cursor: grabbing;
      }

      #menu-toggle:hover,
      #menu-toggle[aria-expanded="true"] {
        border-color: var(--ui-accent);
        background: var(--ui-accent-soft);
      }

      #settings-panel {
        position: absolute;
        top: 56px;
        right: 16px;
        width: min(400px, calc(100vw - 32px));
        max-height: min(720px, calc(100vh - 72px));
        background: var(--ui-bg);
        border: 1px solid var(--ui-border);
        border-radius: var(--ui-radius);
        backdrop-filter: blur(14px);
        padding: 0;
        display: none;
        flex-direction: column;
        overflow: hidden;
        z-index: 5;
      }

      #settings-panel.open {
        display: flex;
      }

      .settings-header {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 12px 14px;
        border-bottom: 1px solid var(--ui-border);
        cursor: grab;
        touch-action: none;
        background: rgba(0, 0, 0, 0.18);
      }

      .settings-header:active {
        cursor: grabbing;
      }

      .settings-header h1 {
        font-size: 14px;
        font-weight: 600;
        letter-spacing: 0.06em;
        text-transform: uppercase;
      }

      .settings-header .header-actions {
        display: flex;
        align-items: center;
        gap: 8px;
      }

      .settings-header button {
        border: none;
        background: transparent;
        color: var(--ui-muted);
        font: 500 11px/1 var(--ui-font);
        cursor: pointer;
      }

      .settings-header button:hover {
        color: var(--ui-accent);
      }

      .settings-scroll {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 12px 14px 16px;
        display: flex;
        flex-direction: column;
        gap: 12px;
        scrollbar-width: thin;
        scrollbar-color: var(--ui-accent) transparent;
      }

      .settings-scroll::-webkit-scrollbar {
        width: 8px;
      }

      .settings-scroll::-webkit-scrollbar-thumb {
        background: var(--ui-accent-soft);
        border-radius: 999px;
        border: 2px solid transparent;
        background-clip: padding-box;
      }

      .settings-group {
        border: 1px solid var(--ui-border);
        border-radius: 8px;
        overflow: hidden;
        background: rgba(255, 255, 255, 0.02);
        flex: 0 0 auto;
      }

      .settings-group > summary {
        list-style: none;
        cursor: pointer;
        padding: 12px 14px;
        font-size: 12px;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--ui-muted);
        display: flex;
        justify-content: space-between;
        align-items: center;
        user-select: none;
      }

      .settings-group > summary::-webkit-details-marker {
        display: none;
      }

      .settings-group > summary::after {
        content: "+";
        font-size: 14px;
        color: var(--ui-accent);
      }

      .settings-group[open] > summary::after {
        content: "–";
      }

      .settings-group[open] > summary {
        color: var(--ui-text);
        border-bottom: 1px solid var(--ui-border);
      }

      .group-body {
        padding: 12px 12px 14px;
        display: flex;
        flex-direction: column;
        gap: 14px;
      }

      .setting-row {
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr) auto;
        column-gap: 10px;
        row-gap: 8px;
        align-items: center;
      }

      .setting-row label {
        font-size: 12px;
        color: var(--ui-text);
        line-height: 1.3;
      }

      .setting-meta {
        display: flex;
        align-items: center;
        gap: 6px;
        justify-content: flex-end;
      }

      .setting-value {
        font-size: 11px;
        color: var(--ui-muted);
        font-variant-numeric: tabular-nums;
        min-width: 3.2em;
        text-align: right;
      }

      .drag-handle {
        width: 26px;
        height: 38px;
        border-radius: 6px;
        border: 1px solid var(--ui-border);
        background: rgba(255, 255, 255, 0.04);
        color: var(--ui-muted);
        cursor: grab;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        touch-action: none;
        user-select: none;
        flex-shrink: 0;
      }

      .drag-handle:active {
        cursor: grabbing;
        border-color: var(--ui-accent);
        color: var(--ui-accent);
      }

      .drag-handle span {
        display: block;
        width: 14px;
        height: 2px;
        background: currentColor;
        border-radius: 1px;
      }

      .setting-row.docked .drag-handle,
      .settings-group.docked > summary .drag-handle {
        border-color: var(--ui-accent);
        color: var(--ui-accent);
        background: var(--ui-accent-soft);
      }

      .group-summary-row {
        display: flex;
        align-items: center;
        gap: 10px;
        flex: 1;
        min-width: 0;
        padding-right: 8px;
      }

      .group-summary-row .group-title {
        flex: 1;
      }

      .group-summary-row .group-size {
        font-size: 10px;
        letter-spacing: 0.04em;
        color: var(--ui-muted);
        font-weight: 500;
        text-transform: none;
      }

      .setting-control {
        grid-column: 2 / -1;
        min-width: 0;
      }

      .setting-control input[type="range"] {
        width: 100%;
        accent-color: var(--ui-accent);
      }

      .setting-control input[type="color"] {
        width: 100%;
        height: 28px;
        border: 1px solid var(--ui-border);
        border-radius: 6px;
        background: transparent;
        cursor: pointer;
      }

      .btn-row {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
      }

      .btn-row button {
        flex: 1;
        min-width: 64px;
        border: 1px solid var(--ui-border);
        background: rgba(255, 255, 255, 0.04);
        color: var(--ui-text);
        font: 500 11px/1 var(--ui-font);
        padding: 8px 6px;
        border-radius: 6px;
        cursor: pointer;
      }

      .btn-row button:hover {
        border-color: var(--ui-accent);
        background: var(--ui-accent-soft);
      }

      .btn-row button.danger:hover {
        border-color: var(--ui-danger);
        background: rgba(196, 92, 92, 0.2);
      }

      .hint {
        font-size: 11px;
        color: var(--ui-muted);
        line-height: 1.35;
      }

      .dist-editor {
        border: 1px solid var(--ui-border);
        border-radius: 8px;
        background: rgba(0, 0, 0, 0.28);
        overflow: hidden;
        cursor: ew-resize;
        touch-action: none;
      }

      .dist-editor canvas {
        display: block;
        width: 100%;
        height: 88px;
      }

      .dist-labels {
        display: flex;
        justify-content: space-between;
        padding: 4px 8px 6px;
        font-size: 10px;
        color: var(--ui-muted);
        font-variant-numeric: tabular-nums;
      }

      #hud-layer {
        position: absolute;
        inset: 0;
        pointer-events: none;
      }

      .hud-widget {
        position: absolute;
        box-sizing: border-box;
        background: var(--ui-bg);
        border: 1px solid var(--ui-border);
        border-radius: 10px;
        backdrop-filter: blur(10px);
        padding: 10px 12px;
        z-index: 2;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
        will-change: left, top;
        display: flex;
        flex-direction: column;
        overflow: hidden;
      }

      .hud-widget.dragging {
        opacity: 0.88;
        box-shadow: 0 14px 36px rgba(0, 0, 0, 0.4);
        border-color: var(--ui-accent);
        z-index: 20;
      }

      /* Compact 2×1 strip: label + control share vertical space cleanly */
      .hud-widget.footprint-2x1 {
        padding: 8px 10px;
      }

      .hud-widget.footprint-2x1 .slot-head {
        margin-bottom: 4px;
      }

      .hud-widget.footprint-2x1 .slot-head .title-row > span.label {
        font-size: 11px;
      }

      .hud-widget.footprint-2x1 > .setting-control {
        justify-content: flex-end;
      }

      .hud-widget.footprint-2x1 > .setting-control input[type="color"] {
        height: 36px;
      }

      .hud-widget.footprint-2x1 > .setting-control input[type="range"] {
        margin-top: 2px;
      }

      .hud-widget .slot-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
        gap: 6px;
        flex: 0 0 auto;
      }

      .hud-widget .slot-head .title-row {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
      }

      .hud-widget .slot-head .title-row > span.label {
        font-size: 12px;
        font-weight: 500;
        color: var(--ui-muted);
        letter-spacing: 0.03em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .hud-widget > .setting-control {
        grid-column: auto;
        flex: 1 1 auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
      }

      .hud-widget.group-pane {
        padding: 10px 12px 12px;
      }

      .hud-widget.group-pane .group-pane-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding-right: 4px;
        scrollbar-width: thin;
      }

      .hud-widget.group-pane .group-pane-body .setting-row {
        grid-template-columns: minmax(0, 1fr) auto;
      }

      .hud-widget.group-pane .group-pane-body .setting-control {
        grid-column: 1 / -1;
      }

      .hud-widget .setting-control input[type="color"] {
        height: 40px;
      }

      .hud-widget.footprint-3x2 .dist-editor canvas {
        height: 100px;
      }

      .drag-ghost {
        position: fixed;
        z-index: 100;
        pointer-events: none;
        opacity: 0.92;
        background: var(--ui-bg);
        border: 1px solid var(--ui-accent);
        border-radius: 8px;
        padding: 8px 10px;
        backdrop-filter: blur(10px);
        box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
        box-sizing: border-box;
      }

      .drag-ghost .ghost-label {
        font-size: 12px;
        font-weight: 500;
      }

      .drag-ghost .ghost-size {
        margin-top: 4px;
        font-size: 10px;
        color: var(--ui-muted);
      }

      .snap-ghost {
        position: fixed;
        z-index: 80;
        pointer-events: none;
        border: 1px dashed var(--ui-accent);
        border-radius: 8px;
        background: var(--ui-accent-soft);
        opacity: 0;
        box-sizing: border-box;
        transition:
          opacity 0.12s ease,
          left 0.12s cubic-bezier(0.22, 1.2, 0.36, 1),
          top 0.12s cubic-bezier(0.22, 1.2, 0.36, 1);
      }

      .snap-ghost.visible {
        opacity: 0.55;
      }

      .snap-ghost.blocked {
        border-color: var(--ui-danger);
        background: rgba(196, 92, 92, 0.2);
        opacity: 0.35;
      }

      #trash-zone {
        position: fixed;
        left: 50%;
        bottom: 28px;
        transform: translateX(-50%) translateY(12px) scale(0.92);
        z-index: 95;
        width: 72px;
        height: 72px;
        border-radius: 18px;
        border: 1px dashed var(--ui-border);
        background: var(--ui-bg);
        color: var(--ui-muted);
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
        pointer-events: none;
        transition:
          opacity 0.18s ease,
          transform 0.18s ease,
          border-color 0.15s ease,
          background 0.15s ease,
          color 0.15s ease;
        backdrop-filter: blur(10px);
      }

      #trash-zone.active {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
        pointer-events: auto;
      }

      #trash-zone.hot {
        border-color: var(--ui-danger);
        background: rgba(196, 92, 92, 0.28);
        color: #f0d0d0;
        transform: translateX(-50%) translateY(0) scale(1.08);
      }

      #trash-zone svg {
        width: 28px;
        height: 28px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.8;
        stroke-linecap: round;
        stroke-linejoin: round;
      }

      .flock-count {
        position: absolute;
        left: 16px;
        bottom: 16px;
        background: var(--ui-bg);
        border: 1px solid var(--ui-border);
        border-radius: 999px;
        padding: 8px 14px;
        font-size: 12px;
        color: var(--ui-muted);
        backdrop-filter: blur(10px);
        font-variant-numeric: tabular-nums;
        cursor: grab;
        touch-action: none;
        z-index: 2;
      }

      .flock-count:active {
        cursor: grabbing;
      }

      .flock-count strong {
        color: var(--ui-text);
        font-weight: 600;
      }

      .slot-cap {
        font-size: 10px;
        color: var(--ui-muted);
        padding: 0 4px 4px;
      }
