.pneumatic-layout {
    grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.86fr);
    align-items: stretch;
}

.pneumatic-stage {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    min-height: 560px;
    height: calc(100vh - 210px);
    overflow: hidden;
    background:
        radial-gradient(circle at 18% 0%, rgba(56, 189, 248, 0.08), transparent 32%),
        #0c0c10;
}

.pn-toolbar,
.pn-bench-row,
.pn-coil-row,
.pn-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.pn-toolbar button,
.pn-bench-row button,
.pn-coil-row button,
.pn-actions button,
.pn-palette button,
.pn-warnings button {
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    min-height: 40px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.82rem;
}

.pn-toolbar button:hover,
.pn-bench-row button:hover,
.pn-coil-row button:hover,
.pn-actions button:hover,
.pn-palette button:hover,
.pn-warnings button:hover,
.pn-toolbar button[aria-pressed="true"],
.pn-coil-row button[aria-pressed="true"] {
    color: var(--text-main);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.pn-toolbar button:disabled {
    opacity: 0.45;
    cursor: default;
}

.pn-preset-label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.pn-preset-label select,
.pn-card input[type="text"],
.pn-card input[type="range"] {
    background: rgba(10, 10, 12, 0.9);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}

.pn-preset-label select {
    max-width: 240px;
}

.pn-palette {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.pn-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: max-content;
}

.pn-group h2 {
    margin: 0;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.pn-group-row {
    display: flex;
    gap: 6px;
}

.pn-palette button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: 76px;
    min-height: 64px;
    padding: 4px 4px 6px;
    box-shadow: inset 3px 0 var(--swatch, var(--accent));
    touch-action: none;
}

.pn-palette button svg {
    width: 62px;
    height: 32px;
    color: var(--text-main);
}

.pn-palette button span {
    font-size: 0.68rem;
    line-height: 1.1;
    text-align: center;
}

.pn-palette button[data-type="supply"] { --swatch: #38bdf8; }
.pn-palette button[data-type="exhaust"] { --swatch: #a1a1aa; }
.pn-palette button[data-type="junction"] { --swatch: #e4e4e7; }
.pn-palette button[data-type="v32nc"],
.pn-palette button[data-type="v32no"] { --swatch: #818cf8; }
.pn-palette button[data-type="v42"] { --swatch: #22d3ee; }
.pn-palette button[data-type="v52sr"] { --swatch: #38bdf8; }
.pn-palette button[data-type="v52ds"] { --swatch: #4dff88; }
.pn-palette button[data-type="v53cc"] { --swatch: #a78bfa; }
.pn-palette button[data-type="v53ec"] { --swatch: #fbbf24; }
.pn-palette button[data-type="v53pc"] { --swatch: #fb923c; }
.pn-palette button[data-type="flowctl"] { --swatch: #2dd4bf; }
.pn-palette button[data-type="regulator"] { --swatch: #f472b6; }
.pn-palette button[data-type="gauge"] { --swatch: #e4e4e7; }
.pn-palette button[data-type="cylSA"],
.pn-palette button[data-type="cylDA"] { --swatch: #94a3b8; }

.pn-canvas {
    position: relative;
    flex: 1;
    min-height: 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #0c0c10;
}

#pn-svg {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: grab;
}

#pn-svg:active {
    cursor: grabbing;
}

.pn-labels {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.pn-label {
    position: absolute;
    transform: translate(-50%, -100%);
    color: var(--text-main);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
    background: rgba(12, 12, 16, 0.88);
    border-radius: 4px;
    padding: 1px 5px;
}

.pn-label.side-right {
    transform: translate(0, -50%);
}

.pn-empty,
.pn-hint {
    position: absolute;
    z-index: 2;
    pointer-events: none;
}

.pn-empty {
    left: 50%;
    top: 46%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    background: rgba(12, 12, 16, 0.78);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    padding: 10px 14px;
}

.pn-hint {
    left: 12px;
    bottom: 10px;
    max-width: min(520px, 70%);
    color: var(--text-muted);
    font-size: 0.78rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.pn-ghost {
    position: fixed;
    z-index: 40;
    pointer-events: none;
    opacity: 0.9;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
}

.pneumatic-panel {
    max-height: calc(100vh - 180px);
    overflow: auto;
    padding: 16px;
    min-width: 0;
}

.pneumatic-panel h2 {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 16px 0 8px;
}

.pn-message {
    color: var(--text-main);
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.28);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    line-height: 1.45;
    font-size: 0.88rem;
}

.pn-card {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.pn-card p,
.pn-blurb p {
    color: var(--text-main);
    line-height: 1.45;
    font-size: 0.9rem;
}

.pn-kicker {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.pn-readout {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    font-size: 0.86rem;
}

.pn-readout span {
    color: var(--text-muted);
}

.pn-card input[type="text"] {
    width: 100%;
}

.pn-card input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    padding: 0;
}

.pneumatic-panel .control {
    display: grid;
    gap: 4px;
}

.pneumatic-panel .control-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: baseline;
}

.pneumatic-panel .control-head label {
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
}

.pn-blurb {
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.pn-note {
    color: #fde68a;
}

.pn-table-wrap {
    overflow-x: auto;
}

.pn-compare {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    line-height: 1.35;
}

.pn-compare th,
.pn-compare td {
    border-bottom: 1px solid var(--border-color);
    padding: 6px 5px;
    text-align: left;
    vertical-align: top;
}

.pn-compare th {
    color: var(--text-muted);
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.pn-compare tr.is-selected {
    background: rgba(99, 102, 241, 0.16);
}

.pn-compare .strong {
    color: var(--text-main);
    font-weight: 700;
}

.pn-warnings {
    list-style: none;
    display: grid;
    gap: 6px;
}

.pn-warnings button {
    width: 100%;
    text-align: left;
    line-height: 1.35;
    color: #fdba74;
    border-color: rgba(249, 115, 22, 0.45);
    background: rgba(124, 45, 18, 0.28);
}

.pn-warnings .quiet {
    color: var(--text-muted);
    font-size: 0.86rem;
}

.pn-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    list-style: none;
    margin: 0;
    color: var(--text-main);
    font-size: 0.8rem;
    font-weight: 600;
}

.pn-legend li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pn-legend .swatch,
.swatch {
    width: 14px;
    height: 8px;
    border-radius: 99px;
    display: inline-block;
}

.swatch-pressure { background: #38bdf8; }
.swatch-vent { background: #52525b; }
.swatch-trap { background: #a78bfa; }
.swatch-short { background: #f97316; }
.swatch-idle { background: #3f3f46; }
.swatch-coil { background: #4dff88; }

.pn-symbol,
.pn-part {
    color: var(--text-main);
}

.pn-body,
.pn-square,
.pn-passage,
.pn-spring,
.pn-coil-box,
.pn-coil-slash,
.pn-manual,
.pn-port,
.pn-piston,
.pn-rod,
.pn-pilot,
.pn-adjust,
.pn-tick,
.pn-needle line,
.pn-silencer,
.pn-silencer-slot,
.pn-detent,
.pn-barrel {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6px;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
}

.pn-square {
    fill: rgba(255, 255, 255, 0.03);
}

.pn-square-active > .pn-square,
.pn-square-wrap.pn-square-active .pn-square {
    fill: rgba(56, 189, 248, 0.07);
}

.pn-head,
.pn-junction {
    fill: currentColor;
    stroke: none;
}

.pn-pilot {
    stroke-dasharray: 3 2;
}

.pn-coil.on .pn-coil-box {
    fill: #4dff88;
    stroke: #4dff88;
}

.pn-coil.on .pn-coil-slash {
    stroke: #052e16;
}

.pn-manual {
    fill: rgba(255, 255, 255, 0.05);
    cursor: pointer;
}

.pn-port-label {
    fill: var(--text-muted);
    stroke: none;
    font-family: Inter, "Segoe UI", sans-serif;
    font-weight: 600;
    text-anchor: middle;
}

.pn-port-hit {
    fill: transparent;
    stroke: transparent;
    pointer-events: all;
    cursor: crosshair;
}

.pn-port-hit.armed {
    fill: rgba(251, 191, 36, 0.35);
    stroke: #fbbf24;
    stroke-width: 1.5px;
    vector-effect: non-scaling-stroke;
}

.pn-outline {
    fill: transparent;
    stroke: transparent;
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
    pointer-events: all;
    cursor: grab;
}

.pn-part.selected .pn-outline {
    stroke: #fbbf24;
}

.pn-part {
    cursor: grab;
}

.pn-coil,
.pn-manual {
    cursor: pointer;
}

.pn-line-vis {
    fill: none;
    stroke: #3f3f46;
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}

.pn-line-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 12px;
    vector-effect: non-scaling-stroke;
    pointer-events: stroke;
    cursor: pointer;
}

.pn-line[data-state="pressurized"] .pn-line-vis { stroke: #38bdf8; }
.pn-line[data-state="vented"] .pn-line-vis { stroke: #52525b; }
.pn-line[data-state="trapped"] .pn-line-vis {
    stroke: #a78bfa;
    stroke-dasharray: 7 5;
}
.pn-line[data-state="short"] .pn-line-vis {
    stroke: #f97316;
    stroke-dasharray: 8 5;
    animation: pn-dash 0.55s linear infinite;
}
.pn-line[data-state="idle"] .pn-line-vis { stroke: #3f3f46; }
.pn-line.selected .pn-line-vis { stroke: #fbbf24; }

.pn-line.flowing .pn-line-vis {
    stroke-dasharray: 7 6;
    animation: pn-dash 0.7s linear infinite;
}

.pn-line.flowing[data-toward="a"] .pn-line-vis {
    animation-direction: reverse;
}

.pn-port[data-state="pressurized"] { stroke: #38bdf8; }
.pn-port[data-state="vented"] { stroke: #71717a; }
.pn-port[data-state="trapped"] { stroke: #a78bfa; }
.pn-port[data-state="short"] { stroke: #f97316; }
.pn-junction[data-state="pressurized"] { fill: #38bdf8; }
.pn-junction[data-state="trapped"] { fill: #a78bfa; }
.pn-junction[data-state="short"] { fill: #f97316; }
.pn-junction[data-state="vented"] { fill: #71717a; }

.pn-rubber {
    fill: none;
    stroke: #fbbf24;
    stroke-width: 2px;
    stroke-dasharray: 6 4;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}

@keyframes pn-dash {
    to { stroke-dashoffset: -26; }
}

@media (max-width: 900px) {
    .pneumatic-layout {
        grid-template-columns: 1fr;
    }

    .pneumatic-stage {
        height: 58vh;
        min-height: 320px;
    }

    .pneumatic-panel {
        max-height: none;
    }

    .pn-palette {
        flex-wrap: nowrap;
    }

    .pn-hint {
        display: none;
    }

    .pn-toolbar button,
    .pn-bench-row button,
    .pn-coil-row button,
    .pn-palette button,
    .pn-preset-label select {
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pn-line[data-state="short"] .pn-line-vis,
    .pn-line.flowing .pn-line-vis {
        animation: none;
    }
}
