@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@500;700&display=swap');

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #070b14;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

code, pre, .font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Примусовий темний стиль для всіх випадаючих списків (select та option) */
select, select option {
    background-color: #0f172a !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}
select option:hover, select option:checked {
    background-color: #1e293b !important;
    color: #38bdf8 !important;
}

/* Навігація категорій Scratch */
.cat-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    width: 100%;
    padding: 5px 0;
    border-radius: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.cat-nav-btn.active {
    background: rgba(255, 255, 255, 0.08);
}

/* Scratch-кольори категорій */
.block-cat-motion { background-color: #4c97ff; border-color: #3373cc; }
.block-cat-looks { background-color: #9966ff; border-color: #774dc1; }
.block-cat-sound { background-color: #cf63cf; border-color: #bd42bd; }
.block-cat-events { background-color: #ffbf00; border-color: #cc9900; }
.block-cat-control { background-color: #ffab19; border-color: #cf8717; }
.block-cat-pen { background-color: #0fbd8c; border-color: #0b8e6b; }

/* Фірмові Scratch-блоки з пазами */
.scratch-magnetic-block {
    position: relative;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    user-select: none;
    cursor: grab;
    min-height: 38px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    border-width: 1.5px;
    touch-action: none;
    transition: margin 0.15s cubic-bezier(0.2, 0, 0.2, 1);
}
.scratch-magnetic-block:active {
    cursor: grabbing;
}

/* Ефект розсування блоків для вставки */
.drop-gap-bottom {
    margin-bottom: 42px !important;
}

.drop-snap-glow {
    outline: 2.5px solid #22d3ee !important;
    box-shadow: 0 0 18px rgba(34, 211, 238, 0.9), inset 0 0 10px rgba(34, 211, 238, 0.3) !important;
    z-index: 40 !important;
}

.drop-gap-top {
    margin-top: 42px !important;
}

/* Верхній паз */
.scratch-magnetic-block::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 16px;
    width: 20px;
    height: 5px;
    background: inherit;
    border-top: inherit;
    border-left: inherit;
    border-right: inherit;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    z-index: 2;
}

/* Нижній виступ */
.scratch-magnetic-block::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 16px;
    width: 20px;
    height: 5px;
    background: inherit;
    border-bottom: inherit;
    border-left: inherit;
    border-right: inherit;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    z-index: 3;
}

/* Hat-блок подій */
.scratch-magnetic-block.hat-block::before {
    display: none;
}
.scratch-magnetic-block.hat-block {
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
}

/* C-ПОДІБНІ БЛОКИ КЕРУВАННЯ (ЦИКЛИ ТА УМОВИ) */
.scratch-c-block {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 210px;
    user-select: none;
    cursor: grab;
    transition: margin 0.15s cubic-bezier(0.2, 0, 0.2, 1);
}
.scratch-c-block:active {
    cursor: grabbing;
}
.scratch-c-header {
    border-radius: 8px 8px 0 0;
    min-height: 36px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    border-width: 1.5px 1.5px 0 1.5px;
    border-style: solid;
}
.scratch-c-body {
    border-left: 18px solid;
    border-left-color: inherit;
    min-height: 48px;
    padding: 6px 4px 6px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    background: rgba(0, 0, 0, 0.45);
    border-bottom: 1.5px dashed rgba(255, 255, 255, 0.2);
    transition: background 0.15s, border-color 0.15s;
}

/* Розділювач "інакше" для 3D блоку повного розгалуження */
.scratch-c-divider {
    min-height: 26px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 800;
    color: #ffffff;
    background-color: inherit;
    border-left: 18px solid;
    border-left-color: inherit;
    position: relative;
    user-select: none;
}

/* Яскрава підсвітка всередині порожнього C-блоку */
.scratch-c-body.c-drop-target {
    background: rgba(34, 211, 238, 0.25) !important;
    outline: 2.5px dashed #22d3ee !important;
    box-shadow: inset 0 0 16px rgba(34, 211, 238, 0.4) !important;
}

/* Підсвітка зони при наведенні блоку */
.scratch-c-body.c-drop-target {
    background: rgba(56, 189, 248, 0.25) !important;
    outline: 2px dashed #38bdf8 !important;
}

.scratch-c-footer {
    border-radius: 0 0 8px 8px;
    height: 14px;
    border-width: 0 1.5px 1.5px 1.5px;
    border-style: solid;
    position: relative;
}

/* Кнопки швидкого вкладення в тіло C-блоку */
.btn-add-c-child {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.12);
    padding: 2.5px 7px;
    border-radius: 6px;
    border: 1px dashed rgba(255, 255, 255, 0.4);
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-add-c-child:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.8);
    transform: scale(1.05);
}

/* Міні-кнопки переміщення вгору/вниз та видалення всередині C-блока */
.c-child-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0.6;
    transition: opacity 0.15s;
}
.c-child-actions:hover {
    opacity: 1;
}
.c-child-btn {
    width: 18px;
    height: 18px;
    font-size: 9px;
    font-weight: 900;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.35);
    color: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.c-child-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
}
.c-child-btn.btn-del:hover {
    background: #ef4444;
    color: #fff;
}

/* Стек, який зараз перетягується мишкою */
.dragging-stack {
    pointer-events: none !important;
    opacity: 0.92;
    z-index: 1000;
}

/* Інпути в блоках */
.scratch-block-input {
    background: rgba(255, 255, 255, 0.95);
    color: #1e293b;
    border: none;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    outline: none;
    text-align: center;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.scratch-block-select {
    background: #0f172a;
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    outline: none;
}

/* 3D VIEWCUBE */
.viewcube-wrapper {
    width: 60px;
    height: 60px;
    perspective: 260px;
    cursor: pointer;
}
.cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-25deg) rotateY(40deg);
    transition: transform 0.1s ease-out;
}
.face {
    position: absolute;
    width: 60px;
    height: 60px;
    background: rgba(15, 23, 42, 0.88);
    border: 1.5px solid #0284c7;
    color: #f8fafc;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: visible;
    transition: all 0.15s;
}
.face:hover {
    background: #0284c7;
    color: #ffffff;
}
.face.front  { transform: rotateY(0deg) translateZ(30px); }
.face.back   { transform: rotateY(180deg) translateZ(30px); }
.face.right  { transform: rotateY(90deg) translateZ(30px); }
.face.left   { transform: rotateY(-90deg) translateZ(30px); }
.face.top    { transform: rotateX(90deg) translateZ(30px); }
.face.bottom { transform: rotateX(-90deg) translateZ(30px); }

.cube-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #94a3b8;
    transition: all 0.15s;
}
.cube-btn:hover {
    background: #1e293b;
    color: #38bdf8;
}

/* Слайдери в інспекторі */
.cad-slider {
    accent-color: #0284c7;
    height: 4px;
    border-radius: 4px;
    background: #334155;
    outline: none;
}

/* Хмарка мовлення над 3D спрайтом */
.scratch-speech-bubble {
    position: absolute;
    background: #ffffff;
    color: #0f172a;
    font-weight: 800;
    font-size: 11px;
    padding: 6px 12px;
    border-radius: 14px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.6);
    border: 2px solid #0f172a;
    transform: translate(-50%, -100%);
    pointer-events: none;
    white-space: nowrap;
    z-index: 25;
}
.scratch-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #ffffff transparent;
    display: block;
    width: 0;
}

/* Селектор форми перешкод */
.obs-shape-btn.active {
    border-color: #f43f5e;
    background-color: rgba(225, 29, 72, 0.25);
    color: #fff;
}

@keyframes scaleUp {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.animate-scale-up {
    animation: scaleUp 0.18s ease-out forwards;
}

/* Скролбари */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: #090e1c;
}
::-webkit-scrollbar-thumb {
    background: #1e293b;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #334155;
}

/* --- АДАПТИВНІСТЬ ДЛЯ ПЛАНШЕТА ТА ВИСУВНІ ПАНЕЛІ (3D STUDIO) --- */
@supports (height: 100dvh) {
    body {
        height: 100dvh !important;
    }
}

/* Компактні кнопки верхнього меню */
.top-nav-btn {
    padding: 6px 9px;
    border-radius: 10px;
    border-width: 1px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 800;
    transition: all 0.15s ease;
    flex-shrink: 0;
}
.top-nav-btn:active {
    transform: scale(0.95);
}

/* Ліва панель категорій */
.cat-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
    padding: 5px 0;
    border-radius: 10px;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}
.cat-nav-btn:hover { background: rgba(255, 255, 255, 0.05); }
.cat-nav-btn.active { background: rgba(255, 255, 255, 0.1); }
.cat-icon-box {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.cat-nav-btn.active .cat-icon-box {
    box-shadow: 0 0 10px currentColor;
}

/* Ліва висувна панель блоків */
.scratch-drawer-left {
    position: absolute;
    left: 48px;
    top: 0;
    bottom: 0;
    z-index: 35;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    transform: translateX(0);
    opacity: 1;
}
@media (min-width: 640px) {
    .scratch-drawer-left { left: 56px; }
}
.scratch-drawer-left.drawer-closed {
    transform: translateX(-110%);
    opacity: 0;
    pointer-events: none;
}

/* Права висувна панель 3D-інспектора */
.scratch-drawer-right {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 35;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    transform: translateX(0);
    opacity: 1;
}
.scratch-drawer-right.drawer-closed {
    transform: translateX(110%);
    opacity: 0;
    pointer-events: none;
}

/* Підсвітка кошика при наведенні блоку */
#trashDropZone.trash-active .cat-icon-box {
    background-color: #ef4444 !important;
    color: #ffffff !important;
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.9) !important;
    transform: scale(1.15) !important;
}
#trashDropZone.trash-active span {
    color: #f43f5e !important;
    font-weight: 900 !important;
}

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* Кольори категорій Датчиків та Операторів */
.block-cat-sensing   { background-color: #29b5e8; border-color: #1b8fb8; }
.block-cat-operators { background-color: #59c059; border-color: #389438; }

/* Шестикутна форма для датчиків та операторів */
.scratch-boolean-block {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 12px;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    clip-path: polygon(8px 0%, calc(100% - 8px) 0%, 100% 50%, calc(100% - 8px) 100%, 8px 100%, 0% 50%);
    cursor: grab;
    user-select: none;
    min-height: 28px;
    vertical-align: middle;
}

/* Порожнє шестикутне гніздо у блоках "якщо" та операторах */
.boolean-socket {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 24px;
    background: rgba(0, 0, 0, 0.4);
    border: 1.5px dashed rgba(255, 255, 255, 0.5);
    clip-path: polygon(6px 0%, calc(100% - 6px) 0%, 100% 50%, calc(100% - 6px) 100%, 6px 100%, 0% 50%);
    padding: 2px 8px;
    margin: 0 4px;
    vertical-align: middle;
}
.boolean-socket.socket-hover {
    background: rgba(255, 255, 255, 0.4) !important;
    border-color: #fff !important;
}

/* Привид блоку при drag&drop не повинен перехоплювати події миші */
#dragGhostBlock, 
#dragGhostBlock * {
    pointer-events: none !important;
}

/* Рядок шестикутного блоку в бічній висувній палітрі */
.palette-boolean-row {
    display: flex;
    width: 100%;
    margin-bottom: 8px;
}
.palette-boolean-row .scratch-boolean-block {
    width: auto;
    min-width: 130px;
    justify-content: center;
}


/* Панель налаштувань полотна та сітки */
.surface-drawer {
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.18s ease;
    transform: translateX(0);
    opacity: 1;
}
.surface-drawer.drawer-closed {
    transform: translateX(115%);
    opacity: 0;
    pointer-events: none;
}

.cad-preset-btn {
    padding: 5px 7px;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 700;
    background: #090e1a;
    border: 1px solid #1e293b;
    color: #cbd5e1;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.cad-preset-btn:hover {
    border-color: #38bdf8;
    color: #ffffff;
}
.cad-preset-btn.active {
    background: #312e81;
    border-color: #6366f1;
    color: #c7d2fe;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
}

.cad-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-radius: 9px;
    background: #090e1a;
    border: 1px solid #1e293b;
    font-size: 11px;
    color: #cbd5e1;
    cursor: pointer;
    transition: border-color 0.15s;
}
.cad-toggle-row:hover {
    border-color: #334155;
}
.cad-checkbox {
    accent-color: #6366f1;
    width: 15px;
    height: 15px;
    cursor: pointer;
}