body {
    margin: 0;

    --theme-color: #161616;
}

#toolbar {
    position: absolute;
    padding: 10px;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
}

#toolbar button {
    margin: 0;
    padding: 8px 12px;
    border: none;
    background: #242424;
    color: white;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.15s ease;
}

#toolbar button:hover {
    background: #3a3a3a;
    transform: translateY(-1px);
}

.root {
    background: var(--theme-color);
    width: 100vw;
    height: 100vh;

    font-family: sans-serif;
}

.context-menu {
    position: fixed;
    z-index: 999;
    background: #222;
    border: 1px solid #444;
    padding: 6px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.4);
    display: none;
}

.context-menu button {
    width: 100%;
    border: none;
    background: transparent;
    color: white;
    padding: 8px 12px;
    text-align: left;
    cursor: pointer;
}

.context-menu button:hover {
    background: rgba(255,255,255,0.08);
}

.connections {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

.connection-line {
    pointer-events: stroke;
    stroke: rgb(100 100 100);
    stroke-width: 4;
    stroke-linecap: round;
    opacity: 0.9;
}

.connection-line.powered {
    stroke: rgb(255, 0, 0);
}

.bend-point {
    fill: rgb(0, 0, 0, 0.5);
    stroke-width: 1;
    cursor: move;
    pointer-events: auto;
}

.bend-point:hover {
    fill: rgb(150, 150, 150);
}

.component {
    --component-primary-color: rgb(50, 50, 50);
    --power-color: rgb(255, 0, 0);
    --component-outline-color: color-mix(in srgb, var(--component-primary-color) 75%,rgb(0, 0, 0));
    --component-text-color: white;

    position: absolute;
    left: 100px;
    top: 100px;
    width: 150px;

    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 12px;
    align-items: center;
    justify-items: center;
    padding: 12px 0;
    overflow: visible;
    z-index: 1;

    user-select: none;

    outline: 2px solid var(--component-outline-color);
    border-bottom: 5px solid var(--component-outline-color);
    background: var(--component-primary-color);
}

.component.powered {
    outline: 2px solid var(--power-color);
}

.component:hover {
    filter: brightness(1.1);
}

.input-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    cursor: pointer;
    user-select: none;
    margin: 5px;
}

.switch-track {
    position: relative;
    width: 40px;
    height: 18px;
    background: rgba(255,255,255,0.28);
    margin-right: 8px;
}

.switch-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: rgb(160, 160, 160);
    transition: transform 0.2s ease;
}

.input-switch.on .switch-knob {
    transform: translateX(22px);
    background: white;
}

.switch-label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.ports {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    z-index: 1;
}

.ports.left {
    grid-column: 1;
    margin-left: -5px;
}

.ports.right {
    grid-column: 3;
    margin-right: -5px;
}

.component-content {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
}

.port {
    width: 10px;
    height: 10px;
    background: rgb(100, 100, 100);
    border-radius: 50%;
    cursor: pointer;
}

.port.powered {
    background-color: var(--power-color);
}

.port:hover {
    filter: brightness(1.5);
}

.component-label {
    text-transform: uppercase;
    font-weight: 600;
    color: var(--component-text-color);
    grid-column: 2;
    justify-self: center;
}

.component-label.digit {
    background-color: rgba(0, 0, 0, 0.5);
    padding: 10px;
    outline: none;
    scale: 2;
}