/* gate_maker.css */

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

/* --- Question Bar --- */
#question-bar {
    background: var(--bg-panel);
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
    z-index: 15;
    flex-shrink: 0;
}

.q-label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.q-text {
    font-family: 'Fira Code', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-left: 15px;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.1);
}

.difficulty-badge {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 6px 14px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

.diff-1 {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid #10b981;
}

.diff-2 {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    border: 1px solid #6366f1;
}

.diff-3 {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid #f59e0b;
}

.diff-4 {
    background: rgba(249, 115, 22, 0.2);
    color: #fdba74;
    border: 1px solid #f97316;
}

.diff-5 {
    background: rgba(244, 63, 94, 0.2);
    color: #fda4af;
    border: 1px solid #f43f5e;
}

/* --- Layout --- */
#app-wrapper {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    position: relative;
    background-color: var(--bg-main);
}

/* --- Toolbar --- */
#toolbar {
    width: 200px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    z-index: 10;
    overflow-y: auto; /* Allow scrolling on short screens */
}

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

.tool-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    background: var(--bg-hover);
}

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

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

/* --- Canvas --- */
#canvas-viewport {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-dark);
    touch-action: none; /* Prevent browser scrolling while dragging */
    /* Fallback */
    /* Fallback */
    background-image: radial-gradient(rgba(255, 255, 255, 0.1) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
}

#canvas-surface {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* --- Fixed Inputs/Outputs --- */
.io-node {
    position: absolute;
    width: 50px;
    height: 50px;
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Fira Code', monospace;
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    z-index: 5;
    cursor: move;
    color: var(--text-main);
}

.io-input {
    border-color: var(--secondary);
    box-shadow: 0 0 15px rgba(6, 182, 212, 0.2);
}

.io-output {
    border-color: var(--warning);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.2);
}

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

.gate:hover {
    border-color: var(--text-muted);
}

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

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

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

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

#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;
    transition: stroke 0.2s;
}

path.wire:hover {
    stroke: var(--accent);
    stroke-width: 5;
    filter: drop-shadow(0 0 5px var(--accent));
}

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

/* --- Feedback Overlay --- */
#feedback-overlay {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 700;
    color: white;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    z-index: 30;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    font-size: 1rem;
    backdrop-filter: blur(5px);
}

#feedback-overlay.success {
    background: rgba(16, 185, 129, 0.9);
    opacity: 1;
    top: 40px;
    border: 1px solid #34d399;
}

#feedback-overlay.fail {
    background: rgba(220, 38, 38, 0.9);
    opacity: 1;
    top: 40px;
    border: 1px solid #f87171;
}

/* --- Controls --- */
.action-btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    margin-top: auto;
    transition: all 0.2s;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.btn-check {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.btn-check:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-next {
    background: var(--bg-card);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.btn-next:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}