/* --- Scenario Bar --- */
#scenario-bar {
    background: var(--bg-card);
    padding: 20px 30px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: var(--shadow-card);
    z-index: 15;
    min-height: 90px;
}

.top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.scenario-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Level Selector Dropdown */
#level-select {
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--text-main);
    background-color: var(--bg-dark);
    cursor: pointer;
}

#level-select:hover, #level-select:focus {
    border-color: var(--primary);
    outline: none;
}

.scenario-text {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.5;
    max-width: 950px;
}

.highlight-inputs {
    color: var(--warning);
    font-weight: 700;
}

.highlight-output {
    color: var(--success);
    font-weight: 700;
}

/* --- Layout --- */
#app-wrapper {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    /* ensure it takes up remaining height minus header/footer */
    min-height: 600px; 
}

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

.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: 8px;
    padding: 10px;
    transition: all 0.2s;
}

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

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

.tool-item span {
    margin-top: 5px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* --- Canvas --- */
#canvas-viewport {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background-color: #1e293b; /* darker bg specifically for canvas to see wires */
}

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

/* --- Inputs/Outputs --- */
.io-container {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
    cursor: move;
}

.io-node {
    position: relative;
    width: 50px;
    height: 50px;
    background: var(--bg-card);
    border: 2px solid var(--text-muted);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: monospace;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-main);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.io-input .io-node {
    background: rgba(14, 165, 233, 0.2); /* light blue tint */
    border-color: var(--secondary);
}

.io-output .io-node {
    background: rgba(22, 163, 74, 0.2); /* light green tint */
    border-color: var(--success);
}

.io-label {
    background: var(--bg-card);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px solid rgba(255,255,255,0.1);
    max-width: 120px;
    text-align: center;
    pointer-events: none;
}

/* --- 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.2);
    user-select: none;
    cursor: move;
    z-index: 5;
}

.gate svg path {
    stroke: var(--text-main) !important;
}

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

.gate.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* --- Ports --- */
.port {
    position: absolute;
    width: 14px;
    height: 14px;
    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: -7px;
    background-color: var(--bg-dark);
}

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

.port-mid { top: calc(50% - 7px); }
.port-top { top: 10px; }
.port-bot { bottom: 10px; }

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

path.wire {
    stroke: var(--text-muted);
    stroke-width: 3;
    fill: none;
    cursor: pointer;
    pointer-events: visibleStroke;
}

path.wire:hover {
    stroke: var(--accent);
    stroke-width: 5;
}

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

/* --- Feedback --- */
#feedback-overlay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 25px;
    border-radius: 30px;
    font-weight: 700;
    color: white;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    z-index: 30;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
}

.success {
    background: var(--success);
    opacity: 1 !important;
    top: 50px !important;
}

.fail {
    background: var(--accent); /* Red/Pink for error */
    opacity: 1 !important;
    top: 50px !important;
}

/* --- Buttons --- */
.action-btn {
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    margin-top: auto;
    text-transform: uppercase;
    font-size: 0.8rem;
    font-family: var(--font-heading);
}

.btn-check {
    background: var(--success);
    color: #fff;
    margin-bottom: 10px;
}

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

.btn-next {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-next:hover {
    background: rgba(255, 255, 255, 0.2);
}
