* { margin: 0; padding: 0; box-sizing: border-box; }

/* ==================== Custom Scrollbar ==================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #2a2a3a;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #00e59966;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #2a2a3a transparent;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0a0a0f;
    color: #e0e0e0;
    overflow: hidden;
    height: 100vh;
}

/* ==================== Toolbar ==================== */
#toolbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: #12121a;
    border-bottom: 1px solid #2a2a3a;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 6px;
    z-index: 100;
}

#toolbar .logo {
    font-weight: 700;
    font-size: 15px;
    color: #00e599;
    margin-right: 12px;
}

.gate-btn {
    padding: 5px 12px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 6px;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
    user-select: none;
}
.gate-btn:hover { background: #252540; border-color: #00e599; color: #fff; }
.gate-btn.input-btn { border-color: #3388ff; }
.gate-btn.input-btn:hover { border-color: #55aaff; }
.gate-btn.clock-btn { border-color: #ff44aa; }
.gate-btn.clock-btn:hover { border-color: #ff66cc; }
.gate-btn.output-btn { border-color: #ff8833; }
.gate-btn.output-btn:hover { border-color: #ffaa55; }

.separator { width: 1px; height: 24px; background: #2a2a3a; margin: 0 4px; }

.create-component-btn {
    padding: 4px 10px;
    background: #1a1a2e;
    border: 1px solid #9900ff;
    border-radius: 6px;
    color: #9900ff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
    user-select: none;
}
.create-component-btn:hover { background: #252540; border-color: #cc66ff; color: #cc66ff; }
.toolbar-right { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.action-btn {
    padding: 5px 10px;
    background: transparent;
    border: 1px solid #333;
    border-radius: 6px;
    color: #888;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.15s;
}
.action-btn:hover { border-color: #ff4444; color: #ff4444; }
.action-btn.help-btn:hover { border-color: #00e599; color: #00e599; }
.action-btn.sim-btn { border-color: #ff44aa; color: #ff44aa; }
.action-btn.sim-btn:hover { background: #ff44aa22; }
.action-btn.sim-btn.active { background: #ff44aa33; border-color: #ff66cc; color: #ff66cc; }

/* ==================== Toolbar Dropdowns ==================== */
.toolbar-dropdown {
    position: relative;
}

.dropdown-toggle {
    padding: 6px 14px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 6px;
    color: #ccc;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dropdown-toggle:hover {
    background: #252540;
    border-color: #00e599;
    color: #fff;
}

.toolbar-dropdown.open .dropdown-toggle {
    background: #252540;
    border-color: #00e599;
    color: #00e599;
}

.dropdown-arrow {
    font-size: 10px;
    opacity: 0.6;
    transition: transform 0.15s;
}

.toolbar-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
    opacity: 1;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 140px;
    background: #14141e;
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    padding: 4px;
    z-index: 150;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    flex-direction: column;
    gap: 2px;
}

.toolbar-dropdown.open .dropdown-menu {
    display: flex;
}

.dropdown-menu .gate-btn {
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    border-radius: 5px;
    font-size: 12px;
}

.dropdown-menu .create-component-btn {
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    border-radius: 5px;
    font-size: 12px;
}

.dropdown-menu #saved-components {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dropdown-menu .component-btn {
    width: 100%;
    text-align: left;
    padding: 7px 12px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 5px;
    color: #9900ff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
}

.dropdown-menu .component-btn:hover {
    border-color: #9900ff;
    color: #cc66ff;
    background: #252540;
}

/* Example buttons */
.example-btn {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: #ccc;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.example-btn:hover {
    background: #1a1a3a;
    border-color: #00e599;
}

.example-name {
    font-size: 12px;
    font-weight: 600;
    color: #00e599;
}

.example-btn:hover .example-name {
    color: #00ff99;
}

.example-desc {
    font-size: 10px;
    color: #666;
    line-height: 1.3;
}

#examples-menu {
    min-width: 260px;
}

/* ==================== Canvas ==================== */
#canvas {
    position: fixed;
    top: 56px; left: 0; right: 0; bottom: 0;
    cursor: default;
    transition: left 0.2s ease;
}

/* ==================== Waveform Panel ==================== */
#waveform-panel {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: 220px;
    background: #0c0c14;
    border-top: 2px solid #00e599;
    z-index: 90;
    flex-direction: column;
    transition: left 0.2s ease;
}
#waveform-panel.visible { display: flex; }

#wave-toolbar {
    display: flex;
    align-items: center;
    padding: 4px 12px;
    gap: 8px;
    background: #10101a;
    border-bottom: 1px solid #1a1a2a;
    height: 32px;
    flex-shrink: 0;
}

#wave-toolbar span.wave-title {
    font-size: 12px;
    font-weight: 700;
    color: #00e599;
    margin-right: 8px;
}

.wave-btn {
    padding: 3px 10px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 4px;
    color: #aaa;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
}
.wave-btn:hover { border-color: #00e599; color: #fff; }
.wave-btn.active { background: #00e59933; border-color: #00e599; color: #00e599; }
.wave-btn.record { border-color: #ff4444; }
.wave-btn.record.active { background: #ff444433; border-color: #ff4444; color: #ff4444; }

.wave-info { margin-left: auto; font-size: 11px; color: #555; }

#wave-container { display: flex; flex: 1; overflow: hidden; }

#wave-labels {
    width: 100px;
    flex-shrink: 0;
    overflow-y: auto;
    background: #0e0e18;
    border-right: 1px solid #1a1a2a;
}

.wave-label {
    height: 30px;
    display: flex;
    align-items: center;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    border-bottom: 1px solid #111;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wave-label.input-label { color: #3388ff; }
.wave-label.output-label { color: #ff8833; }
.wave-label.gate-label { color: #00e599; }

#wave-canvas { flex: 1; cursor: crosshair; }

/* ==================== Help Modal ==================== */
#help-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
}
#help-modal.visible { display: flex; }

#help-content {
    background: #12121a;
    border: 1px solid #2a2a3a;
    border-radius: 12px;
    padding: 24px;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}
#help-content h2 { color: #00e599; margin-bottom: 12px; font-size: 18px; }
#help-content h3 { color: #ff44aa; margin: 12px 0 8px; font-size: 14px; }
#help-content p, #help-content li { color: #aaa; font-size: 13px; line-height: 1.5; margin-bottom: 6px; }
#help-content ul { padding-left: 20px; }
#help-content kbd {
    background: #1a1a2e;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11px;
    color: #ddd;
}
#help-close {
    margin-top: 12px;
    padding: 6px 18px;
    background: #00e599;
    border: none;
    border-radius: 6px;
    color: #000;
    font-weight: 600;
    cursor: pointer;
}

/* ==================== Resize Handle ==================== */
#wave-resize {
    position: absolute;
    top: -4px; left: 0; right: 0;
    height: 8px;
    cursor: ns-resize;
    z-index: 91;
}

/* ==================== Mode Toggle ==================== */
.mode-toggle {
    display: flex;
    gap: 0;
    border-radius: 6px;
    overflow: hidden;
}

.mode-btn {
    padding: 5px 12px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    color: #888;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
    border-radius: 0;
    margin: 0 -1px;
}

.mode-btn:first-child { border-radius: 6px 0 0 6px; }
.mode-btn:last-child { border-radius: 0 6px 6px 0; }

.mode-btn:hover {
    border-color: #00e599;
    color: #fff;
}

.mode-btn.active {
    background: #00e59922;
    border-color: #00e599;
    color: #00e599;
}

/* ==================== Component Editor Overlay ==================== */
#component-editor-overlay {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    height: 44px;
    background: #1a1a2e;
    border-bottom: 2px solid #9900ff;
    z-index: 90;
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
}

#component-editor-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

#component-editor-title {
    color: #9900ff;
    font-weight: 600;
    font-size: 13px;
    flex: 1;
}

#component-editor-save, #component-editor-cancel {
    padding: 4px 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: all 0.15s;
}

#component-editor-save {
    background: #00e599;
    color: #000;
}

#component-editor-save:hover {
    background: #00ff99;
    box-shadow: 0 0 10px #00e59944;
}

#component-editor-cancel {
    background: transparent;
    border: 1px solid #ff4444;
    color: #ff4444;
}

#component-editor-cancel:hover {
    background: #ff444422;
}

/* Shift canvas when editor is active */
#component-editor-overlay:not([style*="display: none"]) ~ #canvas {
    top: calc(56px + 44px);
}

/* ==================== Puzzle Panels ==================== */
.puzzle-panel {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    width: 340px;
    height: calc(100vh - 56px);
    background: #12121a;
    border-right: 1px solid #2a2a3a;
    z-index: 95;
    flex-direction: column;
    overflow-y: auto;
}

.puzzle-panel.visible {
    display: flex;
}

.puzzle-panel.puzzle-info {
    top: 56px;
    width: 340px;
}

/* When puzzle panel is visible, shift canvas and waveform */
.puzzle-panel.visible ~ #canvas,
body.puzzle-sidebar-open #canvas {
    left: 340px;
}

body.puzzle-sidebar-open #waveform-panel {
    left: 340px;
}

.puzzle-header {
    padding: 16px;
    background: #0a0a0f;
    border-bottom: 1px solid #2a2a3a;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-shrink: 0;
}

.puzzle-header h2 {
    color: #00e599;
    font-size: 18px;
    margin: 0 0 8px 0;
}

.puzzle-header .close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.puzzle-header .close-btn:hover {
    color: #ff4444;
}

.close-btn {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.close-btn:hover {
    color: #ff4444;
}

/* Level Panel */
.levels-container {
    padding: 16px;
    overflow-y: auto;
}

.level-category h3 {
    color: #ff44aa;
    font-size: 14px;
    margin: 16px 0 8px 0;
    padding: 8px 0;
    border-bottom: 1px solid #2a2a3a;
}

.level-card {
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.level-card:hover:not(.locked) {
    border-color: #00e599;
    background: #1a1a3a;
}

.level-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-card.completed {
    border-color: #00e599;
    background: #00e59911;
}

.level-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.level-title {
    color: #fff;
    font-weight: 600;
    font-size: 13px;
}

.level-difficulty {
    color: #ff8833;
    font-size: 11px;
    letter-spacing: 2px;
}

.level-description {
    color: #888;
    font-size: 12px;
    margin-bottom: 8px;
    line-height: 1.4;
}

.level-status {
    color: #00e599;
    font-size: 11px;
    font-weight: 600;
    text-align: right;
}

.level-card.locked .level-status {
    color: #ff8833;
}

/* Puzzle Content */
#puzzle-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.puzzle-description {
    color: #aaa;
    font-size: 13px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.truth-table-section h3,
.available-gates-section h3 {
    color: #ff44aa;
    font-size: 13px;
    margin: 12px 0 8px 0;
    font-weight: 600;
}

/* Truth Table */
.truth-table {
    display: grid;
    gap: 1px;
    margin-bottom: 16px;
    background: #0a0a0f;
    padding: 8px;
    border-radius: 6px;
}

.truth-table-row {
    display: grid;
    grid-auto-flow: column;
    gap: 1px;
}

.truth-table-row.header {
    background: #1a1a2e;
    margin-bottom: 4px;
}

.truth-cell {
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 600;
    background: #0e0e18;
    text-align: center;
    border-radius: 4px;
    min-width: 30px;
}

.truth-table-row.header .truth-cell {
    background: #1a1a2e;
    color: #00e599;
}

.truth-cell.input-cell {
    color: #3388ff;
}

.truth-cell.output-cell {
    color: #ff8833;
}

/* Available Gates */
.available-gates-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.available-gate-btn {
    padding: 6px 10px;
    background: #1a1a2e;
    border: 1px solid #2a2a3a;
    border-radius: 6px;
    color: #aaa;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: all 0.15s;
    white-space: nowrap;
}

.available-gate-btn:hover {
    border-color: #00e599;
    color: #fff;
    background: #1a1a3a;
}

.available-gate-btn:active {
    background: #00e59922;
}

/* Puzzle Actions */
.puzzle-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #2a2a3a;
}

.action-btn.verify-btn {
    background: #00e599;
    border: none;
    color: #000;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.action-btn.verify-btn:hover {
    background: #00ff99;
    box-shadow: 0 0 10px #00e59944;
}

.action-btn.hint-btn,
.action-btn.reset-btn {
    background: transparent;
    border: 1px solid #2a2a3a;
    color: #888;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

.action-btn.hint-btn:hover {
    border-color: #ff44aa;
    color: #ff44aa;
}

.action-btn.reset-btn:hover {
    border-color: #ff8833;
    color: #ff8833;
}

/* Verification Result */
.verification-result {
    margin-top: 16px;
    padding: 12px;
    border-radius: 6px;
    font-size: 12px;
}

.verification-result.success {
    background: #00e59922;
    border: 1px solid #00e599;
    color: #00e599;
}

.verification-result.failure {
    background: #ff444422;
    border: 1px solid #ff4444;
    color: #ff8888;
}

.result-message {
    font-weight: 600;
    margin-bottom: 8px;
}

.verification-result.success .result-message {
    color: #00ff99;
}

.verification-result.failure .result-message {
    color: #ff6666;
}

.failed-tests {
    margin-top: 8px;
    font-size: 11px;
    max-height: 120px;
    overflow-y: auto;
}

.failed-test {
    margin-bottom: 6px;
    padding: 6px;
    background: rgba(0,0,0,0.3);
    border-radius: 4px;
    font-family: monospace;
    color: #ccc;
}

#next-level-btn {
    background: #00e599;
    border: none;
    color: #000;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.15s;
}

#next-level-btn:hover {
    background: #00ff99;
    box-shadow: 0 0 10px #00e59944;
}
