/* --- Layout --- */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    margin: 0;
}

/* --- Header --- */
.site-header {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
    padding: 15px 0;
    background-color: var(--bg-card);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
    color: var(--primary);
    z-index: 20;
    position: relative;
    text-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

/* --- Feedback Banner --- */
#feedback-banner {
    position: fixed;
    top: 80px;
    left: 0;
    width: 100%;
    padding: 15px;
    text-align: center;
    font-weight: bold;
    font-size: 1.1rem;
    transform: translateY(-100%);
    transition: transform 0.3s ease-in-out;
    z-index: 15;
    color: white;
    font-family: var(--font-body);
}

#feedback-banner.show {
    transform: translateY(0);
}

#feedback-banner.success {
    background-color: var(--success);
}

#feedback-banner.fail {
    background-color: var(--accent);
}

#feedback-banner.warn {
    background-color: var(--warning);
}

/* --- Footer --- */
.footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem 0;
    /* Reduced padding */
    margin-top: 0;
    /* Remove huge margin */
    background: var(--bg-card);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    width: 100%;
    position: relative;
    z-index: 20;
}

/* --- Toolbar (Left Menu) --- */
#toolbar {
    width: 180px;
    background-color: var(--bg-card);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.tool-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 4px;
}

.tool-item {
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 8px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tool-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.1);
}

.tool-item svg {
    width: 32px;
    height: 24px;
    stroke: var(--text-main);
    stroke-width: 2;
    fill: none;
}

.tool-item span {
    margin-top: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

#check-btn {
    margin-top: auto;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: var(--success);
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
    font-family: var(--font-heading);
}

#check-btn:hover {
    background: #059669;
    /* darker emerald */
}

/* --- Canvas --- */
#app-wrapper {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
}

#canvas-viewport {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    /* Changed from auto to hidden to prevent scroll interactions */
    background-color: #1e293b;
    touch-action: none;
    /* darker bg for canvas */
}

#canvas-surface {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 100%;
    min-height: 100%;
    background-image: radial-gradient(rgba(255, 255, 255, 0.1) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
}

/* --- Gates --- */
.gate {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 88px;
    height: 66px;
    background: var(--bg-card);
    border: 2px solid var(--text-muted);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    user-select: none;
    cursor: move;
    z-index: 5;
}

.gate-icon {
    width: 55px;
    height: 44px;
    stroke: var(--text-main);
    stroke-width: 2;
    fill: none;
    pointer-events: none;
}

.gate svg circle {
    stroke: var(--text-main) !important;
    fill: var(--bg-card) !important;
}


/* Switch */
.gate[data-type="switch"] {
    border-color: var(--text-muted);
    width: 54px;
    height: 68px;
    cursor: pointer;
}

.gate[data-type="switch"].on {
    background-color: rgba(22, 163, 74, 0.2);
    border-color: var(--success);
}

.switch-val {
    font-size: 1.3rem;
    font-weight: 800;
    font-family: monospace;
    color: var(--text-main);
}

/* Bulb */
.gate[data-type="bulb"] {
    border-radius: 50%;
    width: 75px;
    height: 75px;
    border-color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.gate[data-type="bulb"] .bulb-guess {
    font-size: 1.5rem;
    font-weight: 800;
    font-family: monospace;
    color: var(--text-muted);
}

.gate[data-type="bulb"].guess-1 {
    border-color: var(--success);
    background-color: rgba(22, 163, 74, 0.1);
}

.gate[data-type="bulb"].guess-1 .bulb-guess {
    color: var(--success);
}

.gate[data-type="bulb"].guess-0 {
    border-color: var(--accent);
    background-color: rgba(244, 63, 94, 0.1);
}

.gate[data-type="bulb"].guess-0 .bulb-guess {
    color: var(--accent);
}

.node-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-top: 2px;
    padding: 0 4px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: text;
}

.node-label:hover {
    border-color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
}

.node-label:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-dark);
    color: var(--text-main);
}

/* --- Wires --- */
#svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

path.wire {
    stroke: var(--accent);
    stroke-width: 4;
    fill: none;
    stroke-dasharray: 5, 5;
    pointer-events: visibleStroke;
    cursor: pointer;
    transition: stroke 0.2s;
}

path.wire:hover {
    stroke-width: 6;
}

path.wire.predict-1 {
    stroke: var(--success);
    stroke-dasharray: 0;
}

/* Ports */
.port {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: var(--bg-card);
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    z-index: 10;
    cursor: crosshair;
    transition: transform 0.1s;
}

.port:hover {
    transform: scale(1.4);
    background-color: var(--primary);
    border-color: var(--primary-light);
}

.port-input {
    left: -6px;
    background-color: var(--bg-dark);
}

.port-output {
    right: -6px;
    background-color: var(--text-muted);
}

.port-in-1 {
    top: calc(50% - 6px);
}

.port-in-top {
    top: 10px;
}

.port-in-bot {
    bottom: 10px;
}

.port-out {
    top: calc(50% - 6px);
}

#drag-line {
    stroke: var(--primary);
    stroke-width: 2;
    stroke-dasharray: 5, 5;
    opacity: 0.6;
}

/* --- Instructions --- */
#instructions {
    position: fixed;
    bottom: 70px;
    right: 20px;
    background: var(--bg-card);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-card);
    font-size: 0.85rem;
    color: var(--text-muted);
    pointer-events: none;
    max-width: 250px;
    backdrop-filter: blur(10px);
}

#instructions b {
    color: var(--primary-light);
}