:root {
    --bg: #0f172a;
    --panel-bg: #1e293b;
    --line: #e2e8f0;
    --accent: #38bdf8;
    --danger: #f87171;
    --on: #4ade80;
    --text: #e2e8f0;
    --grid: #1e293b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--panel-bg);
    border-bottom: 1px solid #334155;
}

.topbar h1 {
    font-size: 16px;
    margin: 0;
}

.topbar-actions button {
    margin-left: 8px;
    padding: 6px 12px;
    background: #334155;
    color: var(--text);
    border: 1px solid #475569;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.topbar-actions button:hover {
    background: #475569;
}

.topbar-actions button.danger {
    background: #7f1d1d;
    border-color: #991b1b;
}

.app {
    flex: 1;
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 0;
}

.panel {
    background: var(--panel-bg);
    padding: 12px;
    overflow-y: auto;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel h2 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin: 0 0 10px;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.palette-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    background: #334155;
    border-radius: 8px;
    cursor: grab;
    text-align: center;
}

.palette-item:hover {
    background: #475569;
}

.palette-symbol {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
}

.palette-symbol svg {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

.palette-label {
    font-size: 9px;
    color: #94a3b8;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.hint {
    font-size: 12px;
    color: #94a3b8;
    margin-top: 16px;
    line-height: 1.4;
}

.canvas-wrap {
    position: relative;
    overflow: hidden;
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 24px 24px;
    cursor: grab;
}

.canvas-layer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
}

#device-layer {
    z-index: 2;
}

.wire-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

.wire-svg .wire-group {
    pointer-events: auto;
}

.wire {
    fill: none;
    stroke: #475569;
    stroke-width: 2;
}

.wire-group.on .wire {
    stroke: var(--wire-color, var(--on));
    filter: drop-shadow(0 0 2px var(--wire-color, transparent));
}

.wire.wire-pending {
    stroke-dasharray: 4 3;
    stroke: var(--accent);
}

.wire-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 12;
    cursor: pointer;
}

.wire-group.selected .wire {
    stroke: var(--danger);
    stroke-width: 3;
}

.device-node {
    position: absolute;
    cursor: grab;
}

.device-node.selected .symbol .gate-body {
    stroke: var(--danger);
}

.device-body {
    color: var(--text);
}

.symbol {
    overflow: visible;
}

.symbol .gate-body {
    fill: #1e293b;
    stroke: var(--line);
    stroke-width: 2;
}

.symbol .gate-label {
    fill: var(--text);
    font-size: 11px;
    font-weight: 600;
}

.symbol .switch-track {
    fill: #1e293b;
    stroke: var(--line);
    stroke-width: 1.5;
}

.symbol .switch-knob {
    stroke: #0f172a;
    stroke-width: 1.5;
}

.symbol .switch-knob.off {
    fill: #64748b;
    filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.6));
}

.symbol .switch-knob.on {
    fill: var(--on);
    filter: drop-shadow(0 0 4px var(--on));
}

.symbol .bulb {
    stroke: var(--line);
    stroke-width: 2;
}

.symbol .bulb.off {
    fill: #334155;
}

.symbol .bulb.on {
    fill: #fbbf24;
    filter: drop-shadow(0 0 8px #fbbf24);
}

.symbol .bulb-filament {
    stroke: #94a3b8;
    stroke-width: 1;
    fill: none;
}

.symbol .bulb-base {
    fill: #334155;
    stroke: var(--line);
    stroke-width: 1.5;
}

.symbol .bulb-base-line {
    stroke: #0f172a;
    stroke-width: 1;
}

.symbol .bulb-rays {
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
}

.symbol .bulb-rays.off {
    stroke: transparent;
}

.symbol .bulb-rays.on {
    stroke: #fbbf24;
    filter: drop-shadow(0 0 3px #fbbf24);
}

.symbol .segment {
    stroke: #0f172a;
    stroke-width: 1;
}

.symbol .segment.off {
    fill: #334155;
}

.symbol .segment.on {
    fill: #ef4444;
    filter: drop-shadow(0 0 4px #ef4444);
}

.device-label {
    position: absolute;
    top: -16px;
    left: 0;
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
}

.ports-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.port-group {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.port {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #475569;
    border: 2px solid #0f172a;
    cursor: crosshair;
    pointer-events: auto;
}

.port.on {
    background: var(--on);
}

.port:hover {
    background: #7dd3fc;
}

.port-label {
    position: absolute;
    font-size: 9px;
    color: #94a3b8;
    white-space: nowrap;
    background: var(--bg);
    padding: 1px 4px;
    border-radius: 3px;
    line-height: 1.3;
}

.side-left .port-label {
    right: 100%;
    margin-right: 6px;
    top: 50%;
    transform: translateY(-50%);
    text-align: right;
}

.side-right .port-label {
    left: 100%;
    margin-left: 6px;
    top: 50%;
    transform: translateY(-50%);
    text-align: left;
}

.side-top .port-label {
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
}

.side-bottom .port-label {
    left: 50%;
    top: 12px;
    transform: translateX(-50%);
}

.device-seven-segment .port-label {
    right: auto;
    left: 12px;
    text-align: left;
}

.inspector-empty {
    font-size: 12px;
    color: #64748b;
}

.inspector-hint {
    font-size: 11px;
    color: #64748b;
    line-height: 1.4;
}

.inspector-field {
    display: block;
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 12px;
}

.inspector-field input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 6px 8px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 4px;
    color: var(--text);
    font-size: 13px;
}

.inspector-delete {
    width: 100%;
    padding: 8px;
    background: #7f1d1d;
    border: 1px solid #991b1b;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
}
