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

.logic-stage {
    position: relative;
    padding: 0;
    overflow: hidden;
    min-height: 560px;
    height: calc(100vh - 210px);
    background:
        radial-gradient(circle at 20% 0%, rgba(74, 222, 128, 0.08), transparent 32%),
        #0c0c10;
}

.logic-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.logic-status,
.logic-badge,
.logic-legend,
.logic-hint,
.logic-live,
.logic-empty {
    position: absolute;
    z-index: 2;
    pointer-events: none;
}

.logic-status,
.logic-badge,
.logic-legend {
    top: 14px;
    color: var(--text-main);
    background: rgba(12, 12, 16, 0.8);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    font-size: 0.85rem;
}

.logic-status,
.logic-badge {
    left: 16px;
}

.logic-badge {
    top: 58px;
}

.logic-status[hidden] ~ .logic-badge {
    top: 14px;
}

.logic-status[hidden] + .logic-badge,
.logic-badge {
    font-weight: 600;
}

.logic-badge.warn {
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.55);
    background: rgba(69, 10, 10, 0.88);
}

.logic-badge.loop {
    color: #fde68a;
    border-color: rgba(251, 191, 36, 0.55);
    background: rgba(62, 42, 8, 0.82);
}

.logic-legend {
    right: 16px;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px 12px;
    margin: 0;
    list-style: none;
    font-size: 0.78rem;
    font-weight: 600;
}

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

.swatch-high { background: #4dff88; }
.swatch-low { background: #6a2e32; }

.logic-hint,
.logic-live {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
    bottom: 14px;
}

.logic-hint {
    left: 16px;
    max-width: min(440px, 68%);
}

.logic-live {
    right: 16px;
    text-align: right;
    max-width: 42%;
}

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

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

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

.logic-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;
}

.palette,
.preset-row,
.logic-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.palette button,
.preset-row button,
.logic-actions button,
.pin-actions button,
.wire-chip {
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-muted);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    min-height: 44px;
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.82rem;
}

.palette button {
    flex: 1 1 72px;
    box-shadow: inset 3px 0 var(--swatch, var(--accent));
}

.palette button[data-type="switch"] { --swatch: #a1a1aa; }
.palette button[data-type="clock"] { --swatch: #38bdf8; }
.palette button[data-type="and"] { --swatch: #3b82f6; }
.palette button[data-type="or"] { --swatch: #2dd4bf; }
.palette button[data-type="not"] { --swatch: #a78bfa; }
.palette button[data-type="nand"] { --swatch: #60a5fa; }
.palette button[data-type="nor"] { --swatch: #5eead4; }
.palette button[data-type="xor"] { --swatch: #fb923c; }
.palette button[data-type="dff"] { --swatch: #fb7185; }
.palette button[data-type="seg7"] { --swatch: #f87171; }

.palette button:hover,
.preset-row button:hover,
.logic-actions button:hover,
.pin-actions button:hover,
.wire-chip:hover,
.preset-row button.active {
    color: var(--text-main);
    border-color: var(--accent);
    background: var(--accent-soft);
}

.logic-panel .control {
    display: grid;
    gap: 4px;
    margin-top: 8px;
}

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

.logic-panel .control-head span,
.logic-panel .control-head label {
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

.logic-panel .control input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.logic-panel .result-list {
    grid-template-columns: 1fr;
    margin-top: 0;
}

.logic-panel .result-list div {
    padding-bottom: 6px;
    gap: 8px;
}

.logic-panel .result-list dt,
.logic-panel .result-list dd {
    font-size: 0.84rem;
}

.logic-panel .result-list dd {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
    align-items: center;
}

.wire-chip,
.pin-actions button {
    min-height: 32px;
    padding: 4px 8px;
    font-size: 0.75rem;
}

.truth {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 0.84rem;
    margin-top: 8px;
}

.truth th,
.truth td {
    border-bottom: 1px solid var(--border-color);
    padding: 5px 6px;
    text-align: center;
}

.truth th {
    color: var(--text-muted);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.truth tr.hot {
    background: rgba(77, 255, 136, 0.12);
    color: #c8ffd8;
}

.digit {
    position: relative;
    width: 72px;
    height: 120px;
    margin: 8px 0 4px;
}

.digit i {
    position: absolute;
    background: #3f1d1d;
    border-radius: 4px;
}

.digit i.on {
    background: #ff3b30;
    box-shadow: 0 0 12px rgba(255, 59, 48, 0.85);
}

.digit [data-seg="a"] { left: 16px; top: 0; width: 40px; height: 10px; }
.digit [data-seg="b"] { right: 0; top: 12px; width: 10px; height: 40px; }
.digit [data-seg="c"] { right: 0; bottom: 12px; width: 10px; height: 40px; }
.digit [data-seg="d"] { left: 16px; bottom: 0; width: 40px; height: 10px; }
.digit [data-seg="e"] { left: 0; bottom: 12px; width: 10px; height: 40px; }
.digit [data-seg="f"] { left: 0; top: 12px; width: 10px; height: 40px; }
.digit [data-seg="g"] { left: 16px; top: 54px; width: 40px; height: 10px; }

.digit-caption {
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.logic-fault,
.logic-note {
    margin-top: 12px;
    border-radius: var(--radius-md);
    padding: 8px 10px;
    line-height: 1.45;
    font-size: 0.88rem;
}

.logic-fault {
    color: #fecaca;
    background: rgba(127, 29, 29, 0.45);
    border: 1px solid rgba(248, 113, 113, 0.5);
}

.logic-note {
    color: #fde68a;
    background: rgba(62, 42, 8, 0.55);
    border: 1px solid rgba(251, 191, 36, 0.4);
}

.level-high { color: #86efac; }
.level-low { color: #fca5a5; }

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

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

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

    .logic-hint,
    .logic-live {
        max-width: 70%;
    }

    .palette button,
    .preset-row button,
    .logic-actions button {
        flex: 1 1 104px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .digit i.on {
        box-shadow: none;
    }
}
