/* ============================================
   CodeGen - Blok Kodlama Oyunu CSS
   ============================================ */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0f0f1a;
    color: #e0e0e0;
}

#app {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

/* ============ HEADER ============ */
#game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a40;
    flex-shrink: 0;
}

#header-left {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

#header-left h1 {
    margin: 0;
    font-size: 1.4rem;
    color: #ffd700;
    letter-spacing: 1px;
}

#level-info {
    font-size: 0.9rem;
    color: #8892b0;
}

#header-controls {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.btn:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.btn:active {
    transform: translateY(0);
}

.btn-run { background: #27ae60; }
.btn-run:hover { background: #2ecc71; }

.btn-reset { background: #7f8c8d; }
.btn-reset:hover { background: #95a5a6; }

.btn-clear { background: #c0392b; }
.btn-clear:hover { background: #e74c3c; }

.btn-load { background: #2c3e7a; }
.btn-load:hover { background: #3a4f9e; }

/* ============ MAIN LAYOUT ============ */
#game-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
#game-main.hidden { display: none; }
#code-pool.hidden { display: none; }

/* ============ LEVEL SELECT SCREEN ============ */
#level-select-screen {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: #0f0f1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 24px;
    gap: 20px;
    overflow-y: auto;
}
#level-select-screen.hidden { display: none; }
#level-select-header h2 {
    font-size: 1.8rem;
    font-weight: 700;
    color: #a0d8ef;
    margin: 0;
}
#level-select-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), 1fr);
    gap: 14px;
    width: 100%;
    max-width: 720px;
}
.level-slot {
    aspect-ratio: 1;
    background: #1e1e30;
    border: 2px solid #2a2a40;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
    font-size: 0.85rem;
    color: #d0d0e0;
    user-select: none;
    padding: 4px;
    text-align: center;
}
.level-slot:hover {
    transform: translateY(-3px);
    border-color: #4a8fd4;
    background: #252540;
}
.level-slot .slot-number {
    font-size: 1.3rem;
    font-weight: 700;
    color: #a0d8ef;
}
.level-slot .slot-name {
    font-size: 0.75rem;
    color: #8888a8;
    margin-top: 4px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}
.level-slot.empty {
    visibility: hidden;
    pointer-events: none;
}
.level-slot.locked {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #1a1a2e;
    background: #141420;
}
.level-slot.locked:hover {
    transform: none;
    border-color: #1a1a2e;
    background: #141420;
}
.level-slot.completed {
    border-color: #3a7a3a;
    background: #1a2e1a;
}
.level-slot.completed:hover {
    border-color: #5aaa5a;
    background: #224422;
}
.level-slot .slot-stars {
    font-size: 0.7rem;
    margin-top: 2px;
    line-height: 1;
}
#level-select-dots {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
}
.level-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #3a3a5e;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}
.level-dot:hover { background: #5a5a8e; }
.level-dot.active {
    background: #4a8fd4;
    transform: scale(1.3);
}

/* ============ CENTER & RIGHT AREA WRAPPERS ============ */
#center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

#right-area {
    width: 390px;
    min-width: 330px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-left: 1px solid #2a2a40;
}

/* ============ TABS ============ */
#tab-headers {
    display: flex;
    gap: 2px;
    padding: 6px 6px 0;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a40;
    flex-shrink: 0;
    align-items: center;
}

.tab-btn {
    flex: 1;
    padding: 8px 10px;
    border: none;
    border-radius: 6px 6px 0 0;
    background: #121220;
    color: #a0a0c0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: #1e1e35;
    color: #d0d0e0;
}

.tab-btn.active {
    background: #161625;
    color: #ffd700;
    box-shadow: 0 -2px 0 #ffd700 inset;
}

#tab-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    padding-left: 6px;
    flex-shrink: 0;
}

#tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.tab-panel {
    flex: 1;
    display: none !important;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tab-panel.active {
    display: flex !important;
}

/* ============ DESCRIPTION PANEL (ORTA ALT) ============ */
#description-panel {
    background: #161625;
    border-top: 1px solid #2a2a40;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 180px;
}
#description-panel.collapsed {
    max-height: 40px;
}
#description-panel.collapsed #description-body {
    display: none;
}
#description-header {
    padding: 8px 12px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #a0d8ef;
    border-bottom: 1px solid #2a2a40;
    background: #1a1a2e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
#description-body {
    flex: 1;
    padding: 10px 12px;
    overflow-y: auto;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #d0d0e0;
}
#description-body p {
    margin: 0;
}
.btn-desc-close {
    background: transparent;
    border: none;
    color: #a0d8ef;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.btn-desc-close:hover { color: #fff; }

/* ============ LEVEL DESCRIPTION MODAL ============ */
#level-desc-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
#level-desc-box {
    background: #1e1e30;
    border: 1px solid #3a3a5e;
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
#level-desc-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #a0d8ef;
    margin-bottom: 16px;
}
#level-desc-content {
    font-size: 1rem;
    line-height: 1.6;
    color: #d0d0e0;
    margin-bottom: 24px;
    text-align: left;
    white-space: pre-line;
}

/* ============ GRID AREA ============ */
#grid-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: #0f0f1a;
    position: relative;
    min-height: 0;
}

#grid-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
}

#viewport {
    width: 100%;
    height: 100%;
    min-height: 120px;
    border: 1px solid #2a2a40;
    border-radius: 6px;
    overflow: hidden;
    background: #141820;
}

#viewport canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.grid-cell {
    background: #1e1e30;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(14px, 2.5vw, 24px);
    transition: background 0.2s;
}

.grid-cell.wall {
    background: #4a4a60;
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 5px,
        rgba(0,0,0,0.15) 5px,
        rgba(0,0,0,0.15) 10px
    );
}

.grid-cell.visited {
    background: #1a3a2a;
}

#status-bar {
    padding: 8px;
    text-align: center;
    font-size: 0.9rem;
    color: #8892b0;
    min-height: 36px;
}

/* Character & Target */
.character {
    z-index: 10;
    font-size: 1.4em;
    transition: all 0.3s ease;
    filter: drop-shadow(0 0 4px rgba(100,200,255,0.5));
}

.target {
    z-index: 5;
    font-size: 1.2em;
    animation: targetPulse 1.5s ease-in-out infinite;
}

@keyframes targetPulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.15); opacity: 1; }
}

/* ============ WORKSPACE ============ */
#workspace {
    flex: 1;
    background: #161625;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#workspace-header {
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #ffd700;
    border-bottom: 1px solid #2a2a40;
    background: #1a1a2e;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#cmd-counter {
    font-size: 0.8rem;
    font-weight: 500;
    color: #a0a0c0;
    background: #0f0f1a;
    padding: 3px 10px;
    border-radius: 10px;
    border: 1px solid #2a2a40;
}

#cmd-counter.limit-reached {
    color: #ff4444;
    border-color: #ff4444;
    font-weight: 700;
}

#zoom-controls,
#tab-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-zoom {
    width: 28px;
    height: 28px;
    border: 1px solid #2a2a40;
    background: #0f0f1a;
    color: #a0d8ef;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-zoom:hover {
    background: #2a2a40;
    border-color: #a0d8ef;
}

.btn-zoom:active {
    transform: scale(0.95);
}

#zoom-level {
    font-size: 0.8rem;
    color: #a0a0c0;
    min-width: 45px;
    text-align: center;
}

#workspace-dropzone {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    position: relative;
}

#workspace-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #4a4a60;
    font-size: 0.85rem;
    text-align: center;
    pointer-events: none;
}

#workspace-blocks {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-height: 100%;
    padding: 0 0 40px 20px;
}

/* ============ FUNCTION PANELS ============ */
.function-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.function-panel + .function-panel {
    border-top: 1px solid #2a2a40;
}

.function-header {
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.85rem;
    color: #e67e22;
    border-bottom: 1px solid #2a2a40;
    background: #1a1a2e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.function-header span:last-child {
    font-size: 0.75rem;
    font-weight: 500;
    color: #a0a0c0;
    background: #0f0f1a;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid #2a2a40;
}

.function-header span:last-child.limit-reached {
    color: #ff4444;
    border-color: #ff4444;
    font-weight: 700;
}

.function-dropzone {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.function-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #4a4a60;
    font-size: 0.8rem;
    text-align: center;
    pointer-events: none;
}

.function-dropzone > div[id$="-blocks"] {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
    padding: 0 0 20px 8px;
    position: relative;
}

/* ============ CODE POOL (sol sütun) ============ */
#code-pool {
    width: 300px;
    min-width: 270px;
    background: #1a1a2e;
    border-right: 1px solid #2a2a40;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}
#code-pool.collapsed {
    width: 40px;
    min-width: 40px;
}
#code-pool.collapsed #pool-header span {
    display: none;
}
#code-pool.collapsed #pool-blocks {
    display: none;
}

#pool-header {
    padding: 10px 12px;
    font-weight: 600;
    font-size: 0.9rem;
    color: #a0d8ef;
    border-bottom: 1px solid #2a2a40;
    background: #1a1a2e;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

#pool-blocks {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 10px 8px 16px;
    overflow-y: auto;
    flex: 1;
}

/* ============ CODE BLOCKS (SVG tabanli) ============ */
.code-block {
    --block-color: #2980b9;
    position: relative;
    width: 132px;
    height: 46px;            /* govde; cikinti svg ile asagi tasar */
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: grab;
    user-select: none;
    touch-action: none;
    background: transparent;
}

.code-block:active {
    cursor: grabbing;
}

/* Blok arka plan sekli - tek parca SVG (girinti seffaf) */
.block-shape {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

/* Body label - SVG uzerine biner */
.block-label {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* Pool blocks */
.pool-block {
    --conn-bg: #1a1a2e;
    flex-shrink: 0;
    transition: transform 0.12s ease;
}

.pool-block:hover {
    transform: translateY(-3px);
}

.pool-block:hover .block-label {
    box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}

/* Workspace blocks - cikinti bir sonraki blogun socket'ine tam otursun */
.workspace-block {
    margin-bottom: 0px;
}

.workspace-block:last-child {
    margin-bottom: 0;
}

.workspace-block.dragging {
    opacity: 0.92;
    z-index: 1000;
    position: fixed;
    pointer-events: none;
}

.workspace-block.dragging .block-shape,
.workspace-block.dragging .repeat-shape {
    filter: drop-shadow(0 10px 18px rgba(0,0,0,0.5));
}

.workspace-block.snapping {
    transition: transform 0.15s ease-out;
}

/* Magnet snap target indicator - SVG path uzerine sari kontur */
.snap-target > .block-shape > path,
.snap-target > .repeat-shape > path {
    stroke: #ffd700;
    stroke-width: 2.5px;
}

/* ============ REPEAT (Tekrarla) C-BLOK (SVG tabanli) ============ */
/* Ic blok merkezi: arm(18) + 132/2 = 84px */
.repeat-block {
    width: 168px;
    height: auto;
}

.repeat-shape {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

.repeat-head {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 12px 12px 12px 14px;
    pointer-events: none;
}

.repeat-title {
    font-size: 0.85rem;
    white-space: nowrap;
}

.repeat-count {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(0,0,0,0.22);
    border-radius: 6px;
    padding: 2px;
    pointer-events: auto;
}

.rc-btn {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: rgba(255,255,255,0.22);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.rc-btn:hover { background: rgba(255,255,255,0.38); }
.rc-btn:disabled { opacity: 0.35; cursor: default; }

.rc-val {
    min-width: 16px;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
}

.repeat-mid {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: stretch;
}

.repeat-arm {
    width: 18px;
    flex-shrink: 0;
}

.repeat-inner {
    flex: 1;
    min-height: 40px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

/* repeat icindeki bloklar tam otursun */
.repeat-inner > .workspace-block {
    margin-bottom: 0px;
    width: 132px;
    align-self: flex-start;
}
.repeat-inner > .workspace-block:last-child {
    margin-bottom: 0;
}

.repeat-inner-placeholder {
    color: #ffffff66;
    font-size: 0.72rem;
    margin: auto;
    pointer-events: none;
    padding: 12px 0;
    align-self: center;
}

.repeat-foot {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 16px;
    pointer-events: none;
}

/* Drop preview: sürüklerken nereye düşeceğini göster */
.drop-preview {
    position: relative;
    width: 100%;
    height: 0;
    pointer-events: none;
    z-index: 5;
}
.drop-preview::before {
    content: '';
    position: absolute;
    left: 0;
    top: -3px;
    width: var(--drop-width, 100%);
    height: 6px;
    background: #ffd700;
    border-radius: 3px;
    box-shadow: 0 0 8px rgba(255,215,0,0.6);
}

/* container drop highlight */
.drop-active {
    outline: 2px dashed #ffd700;
    outline-offset: -2px;
    border-radius: 0 4px 4px 0;
}
#workspace-blocks.drop-active {
    border-radius: 4px;
}

/* Running state overlays */
#game-main.running,
#code-pool.running {
    pointer-events: none;
}

.btn-stop {
    background: #c0392b !important;
}
.btn-stop:hover {
    background: #e74c3c !important;
}

/* ============ COMPLETE MODAL ============ */
#complete-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

#complete-modal {
    background: #1a1a2e;
    border: 1px solid #2a2a40;
    border-radius: 12px;
    padding: 32px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    max-width: 360px;
    width: 90%;
}

#complete-modal h2 {
    margin: 0 0 12px;
    color: #ffd700;
    font-size: 1.5rem;
}

#complete-modal p {
    margin: 0 0 24px;
    color: #b0b8d0;
}

.complete-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* ============ FAIL MODAL ============ */
#fail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

#fail-modal {
    background: #1a1a2e;
    border: 1px solid #2a2a40;
    border-radius: 12px;
    padding: 32px 48px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    max-width: 360px;
    width: 90%;
}

#fail-modal h2 {
    margin: 0 0 12px;
    color: #e74c3c;
    font-size: 1.5rem;
}

#fail-modal p {
    margin: 0 0 24px;
    color: #b0b8d0;
}

#fail-icon {
    font-size: 3.5rem;
    line-height: 1;
    color: #e74c3c;
    margin-bottom: 8px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    #right-area {
        width: 270px;
        min-width: 240px;
    }
    #code-pool {
        width: 180px;
        min-width: 160px;
    }

    .code-block {
        width: 100px;
        font-size: 0.8rem;
    }

    #header-left h1 {
        font-size: 1.1rem;
    }

    #pool-blocks {
        gap: 8px;
        padding: 6px 6px 12px;
    }
}

@media (max-width: 520px) {
    #game-main {
        flex-direction: column;
    }

    #code-pool {
        width: 100%;
        height: 100px;
        min-height: 100px;
        border-right: none;
        border-bottom: 1px solid #2a2a40;
        flex-direction: column;
        order: -1;
    }
    #pool-blocks {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 10px;
        padding: 6px 12px 12px;
    }

    #center-area {
        flex: none;
        height: 200px;
        min-height: 160px;
    }

    #description-panel {
        display: none;
    }

    #right-area {
        width: 100%;
        height: 160px;
        min-height: 160px;
        border-left: none;
        border-top: 1px solid #2a2a40;
    }

    #workspace {
        border-left: none;
    }

    #workspace-dropzone {
        overflow-x: auto;
        overflow-y: hidden;
    }

    #workspace-blocks {
        flex-direction: row;
        align-items: center;
        padding-bottom: 0;
        padding-right: 40px;
        min-height: auto;
    }

    .workspace-block {
        margin-bottom: 0;
        margin-right: -4px;
    }

    .workspace-block:last-child {
        margin-right: 0;
    }

    .workspace-block .block-notch,
    .workspace-block .block-bump {
        display: none;
    }

    .workspace-block .block-label {
        border-radius: 6px;
    }
}

/* ============ OVAL BLOCKS (Value) ============ */
.oval-block {
    position: relative;
    width: 96px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.oval-block .block-label {
    font-size: 11px;
    height: 28px;
    line-height: 1.1;
    text-align: center;
    padding: 0 8px;
    box-sizing: border-box;
}

.oval-shape {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

/* ============ COLOR VALUE BLOCK ============ */
.color-value-inner {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    pointer-events: none;
}

.cv-label {
    font-size: 11px;
    color: #fff;
    font-weight: bold;
}

.cv-preview {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid rgba(255,255,255,0.7);
    pointer-events: auto;
    cursor: pointer;
}

.color-picker-dropdown {
    position: absolute;
    top: 38px;
    left: 50%;
    transform: translateX(-50%);
    background: #2c3e50;
    padding: 6px;
    border-radius: 6px;
    display: grid;
    grid-template-columns: repeat(5, 24px);
    gap: 3px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.cp-swatch {
    width: 24px;
    height: 24px;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
}

.cp-swatch:hover {
    border-color: #fff;
}

/* ============ HEX BLOCKS (Boolean) ============ */
.hex-block {
    position: relative;
    width: 120px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hex-block > .block-label {
    font-size: 14px;
    font-weight: bold;
    height: 40px;
    line-height: 40px;
}

.hex-shape {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

.equals-block, .not-block, .and-block, .or-block {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    height: 32px;
    box-sizing: border-box;
    width: auto;
}

.hex-block .equals-label,
.hex-block .and-label,
.hex-block .or-label,
.hex-block .not-label {
    position: relative;
    z-index: 3;
    width: auto;
    height: 32px;
    color: #fff;
    font-weight: bold;
    font-size: 15px;
    line-height: 32px;
    pointer-events: none;
    white-space: nowrap;
    flex: 0 0 auto;
}

.equals-slot {
    position: relative;
    width: 56px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    flex: 0 0 auto;
    overflow: visible;
}

.equals-slot.filled {
    width: auto;
    min-width: 56px;
}

.slot-number-input {
    position: relative;
    z-index: 10;
    display: block;
    pointer-events: auto;
    border-radius: 12px !important;
}

.equals-slot:not(.filled) > .slot-hex-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.equals-slot.filled::before {
    display: none;
}

.equals-slot .oval-block,
.equals-slot .hex-block,
.equals-slot .number-value-block {
    position: relative;
    z-index: 5;
    pointer-events: auto;
    cursor: grab;
    flex: 0 0 auto;
}

.if-condition-slot .hex-block,
.if-condition-slot .equals-block,
.ifelse-condition-slot .hex-block,
.ifelse-condition-slot .equals-block {
    position: relative;
    z-index: 5;
    pointer-events: auto;
    cursor: grab;
}

.equals-slot.slot-highlight::before {
    border-color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.15);
    box-shadow: 0 0 8px rgba(255,255,255,0.6);
}


/* ============ IF BLOCK (C-Block) ============ */
.if-block {
    position: relative;
    width: 168px;
    height: auto;
}

.if-shape {
    position: absolute;
    top: 0;
    left: -2px;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

.if-head {
    position: relative;
    z-index: 1;
    height: 46px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
    gap: 6px;
}

.if-title {
    color: #fff;
    font-weight: bold;
    font-size: 13px;
    flex-shrink: 0;
}

.if-condition-slot {
    position: relative;
    width: 120px;
    height: 32px;
    margin-top: 4px;
    margin-left: 6px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
}
.if-condition-slot:empty::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    clip-path: polygon(20% 0%, 80% 0%, 100% 50%, 80% 100%, 20% 100%, 0% 50%);
    background: rgba(0,0,0,0.15);
    border: 2px dashed rgba(255,255,255,0.3);
    box-sizing: border-box;
}

.if-condition-slot.filled::before {
    display: none;
}

.if-condition-slot .hex-block {
    position: absolute;
    top: 0;
    left: 0;
}

.if-condition-slot.slot-highlight::before {
    border-color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.15);
    box-shadow: 0 0 8px rgba(255,255,255,0.6);
}

.if-mid {
    position: relative;
    z-index: 1;
    display: flex;
}

.if-arm {
    width: 18px;
    flex-shrink: 0;
}

.if-inner {
    flex: 1;
    min-height: 40px;
    padding: 4px 4px 4px 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.if-foot {
    position: relative;
    z-index: 1;
    height: 16px;
}

/* ============ IF-ELSE BLOCK (Double C-Block) ============ */
.ifelse-block {
    position: relative;
    width: 168px;
    height: auto;
}

.ifelse-shape {
    position: absolute;
    top: 0;
    left: -2px;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    filter: drop-shadow(0 1px 1.5px rgba(0,0,0,0.32));
}

.ifelse-head {
    position: relative;
    z-index: 1;
    height: 46px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    padding-left: 10px;
    padding-right: 10px;
    gap: 6px;
}

.ifelse-title {
    color: #fff;
    font-weight: bold;
    font-size: 13px;
    flex-shrink: 0;
}

.ifelse-condition-slot {
    position: relative;
    width: 120px;
    height: 32px;
    margin-top: 4px;
    margin-left: 6px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
}
.ifelse-condition-slot:empty::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    clip-path: polygon(20% 0%, 80% 0%, 100% 50%, 80% 100%, 20% 100%, 0% 50%);
    background: rgba(0,0,0,0.15);
    border: 2px dashed rgba(255,255,255,0.3);
    box-sizing: border-box;
}

.ifelse-condition-slot.filled::before {
    display: none;
}

.ifelse-condition-slot .hex-block {
    position: absolute;
    top: 0;
    left: 0;
}

.ifelse-condition-slot.slot-highlight::before {
    border-color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.15);
    box-shadow: 0 0 8px rgba(255,255,255,0.6);
}

.ifelse-true-mid,
.ifelse-false-mid {
    position: relative;
    z-index: 1;
    display: flex;
}

.ifelse-arm {
    width: 18px;
    flex-shrink: 0;
}

.ifelse-true-inner,
.ifelse-false-inner {
    flex: 1;
    min-height: 40px;
    padding: 4px 4px 4px 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.ifelse-separator {
    position: relative;
    z-index: 1;
    height: 28px;
    display: flex;
    align-items: center;
    padding-left: 24px;
}

.ifelse-sep-text {
    color: #fff;
    font-weight: bold;
    font-size: 12px;
}

.ifelse-foot {
    position: relative;
    z-index: 1;
    height: 16px;
}

/* ============ COLOR SET BLOCK ============ */
.color-set-block {
    position: relative;
}

.color-set-picker {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cs-preview {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 2px solid rgba(255,255,255,0.7);
    cursor: pointer;
}

.cs-dropdown {
    position: absolute;
    top: 28px;
    right: 0;
    background: #2c3e50;
    padding: 6px;
    border-radius: 6px;
    display: grid;
    grid-template-columns: repeat(5, 22px);
    gap: 3px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.cs-swatch {
    width: 22px;
    height: 22px;
    border-radius: 3px;
    cursor: pointer;
    border: 2px solid transparent;
}

.cs-swatch:hover {
    border-color: #fff;
}

/* ============ CONTEXT MENU ============ */
.context-menu {
    position: fixed;
    z-index: 9999;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 6px 0;
    min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}
.context-menu.hidden {
    display: none;
}
.context-item {
    padding: 8px 16px;
    color: #e2e8f0;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}
.context-item:hover {
    background: #334155;
}
.context-danger {
    color: #ef4444;
}
.context-danger:hover {
    background: #450a0a;
}
.context-separator {
    height: 1px;
    background: #334155;
    margin: 4px 8px;
}

/* ============ TAB HOVER HIGHLIGHT ============ */
.tab-btn.drag-hover {
    background: #4a8fd4;
    color: #fff;
    box-shadow: 0 0 8px rgba(74,143,212,0.6);
}

/* ============ COMPASS ============ */
#compass {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 100;
    pointer-events: none;
}
#compass.hidden { display: none; }

#compass-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(15, 15, 26, 0.75);
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

#compass-needle {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.05s linear;
}

.compass-dir {
    position: absolute;
    font-size: 13px;
    font-weight: bold;
    font-family: 'Segoe UI', sans-serif;
    text-align: center;
    line-height: 18px;
}

.compass-n {
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    color: #5dade2;
}

.compass-s {
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    color: #f39c12;
}

.compass-e {
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: #e74c3c;
}

.compass-w {
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: #27ae60;
}
