/* Codie Maker - Touch-First Light Creative Studio CSS */

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    background: #F8FAFC;
    font-family: 'Fredoka', 'Nunito', sans-serif;
    color: #1E293B;
    user-select: none;
    -webkit-user-select: none;
}

.editor-workspace {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.maker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    background: #FFFFFF;
    border-bottom: 2px solid #E2E8F0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    height: 60px;
    min-height: 60px;
    z-index: 20;
    gap: 12px;
    box-sizing: border-box;
}

.maker-header .logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    white-space: nowrap;
}

.maker-header .logo-text {
    font-family: 'Fredoka', cursive;
    font-size: 20px;
    font-weight: 700;
    color: #0F172A;
}

.maker-header .logo-dot {
    color: #38BDF8;
}

.maker-header #langSwitcher {
    margin: 0 auto;
}

.maker-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Standardized equal-height header controls */
.maker-title-input {
    background: #F1F5F9;
    border: 2px solid #CBD5E1;
    color: #0F172A;
    padding: 0 14px;
    height: 38px;
    border-radius: 19px;
    font-family: 'Fredoka', sans-serif;
    font-size: 14px;
    font-weight: 600;
    width: 160px;
    text-align: center;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.maker-title-input:focus {
    outline: none;
    border-color: #38BDF8;
    background: #FFFFFF;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.btn-test {
    background: linear-gradient(135deg, #10B981, #059669);
    color: white;
    border-radius: 19px;
    height: 38px;
    padding: 0 16px;
    font-weight: 700;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    transition: all 0.2s ease;
    white-space: nowrap;
    box-sizing: border-box;
}

.btn-test:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.btn-home {
    background: #FFE4E6;
    color: #E11D48;
    border: 2px solid #FDA4AF;
    border-radius: 19px;
    height: 38px;
    padding: 0 14px;
    font-weight: 700;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

.btn-home:hover {
    background: #FECDD3;
}

/* Layout */
.codie-maker-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: #F0F9FF;
    position: relative;
    box-sizing: border-box;
}

/* Central Stage Grid Wrapper */
.maker-stage {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    overflow: hidden;
    position: relative;
}

/* GUARANTEED 1:1 SQUARE GRID WRAPPER */
.grid-wrapper {
    background: #FFFFFF;
    padding: 10px;
    border-radius: 24px;
    border: 4px solid #E2E8F0;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.06);
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

.grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 2px;
    width: 100%;
    height: 100%;
    background: #CBD5E1;
    border-radius: 14px;
    overflow: hidden;
}

.cell {
    background: #F8FAFC;
    position: relative;
    cursor: pointer;
    transition: filter 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    background-size: cover !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

.cell:hover {
    filter: brightness(0.92);
}

/* REAL GAME SPRITE TEXTURES & CSS STYLES */
.cell.goal { background: #DCFCE7 url('../images/cells/grass1 128.png') center/cover no-repeat; }

.cell.wall {
    background-image: linear-gradient(135deg, #78909c 25%, #607d8b 25%, #607d8b 50%, #78909c 50%, #78909c 75%, #607d8b 75%, #607d8b 100%) !important;
    background-size: 16px 16px !important;
}

.cell.fence-wood {
    background: linear-gradient(180deg, #8D6E63 0%, #5D4037 100%) !important;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.2);
    position: relative;
}
.cell.fence-wood::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 80%;
    background: repeating-linear-gradient(0deg, #A1887F 0px, #A1887F 4px, #6D4C41 4px, #6D4C41 8px);
    border-radius: 2px;
}

.cell.fence-stone {
    background: #78909C !important;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.2);
    position: relative;
}
.cell.fence-stone::before {
    content: '';
    position: absolute;
    inset: 10%;
    background:
        linear-gradient(135deg, #90A4AE 25%, transparent 25%),
        linear-gradient(225deg, #90A4AE 25%, transparent 25%),
        linear-gradient(45deg, #607D8B 25%, transparent 25%),
        linear-gradient(315deg, #607D8B 25%, transparent 25%);
    background-size: 50% 50%;
    border-radius: 3px;
}

.cell.grass-1 { background-image: url('../images/cells/grass1 128.png'); }
.cell.grass-2 { background-image: url('../images/cells/grass2 128.png'); }
.cell.grass-3 { background-image: url('../images/cells/grass3 128.png'); }
.cell.flowers { background-image: url('../images/cells/grass1 128.png'); }
.cell.dirt-1 { background-image: url('../images/cells/dirt1 128.png'); }
.cell.dirt-2 { background-image: url('../images/cells/dirt2 128.png'); }
.cell.water { background-image: url('../images/cells/water 128.png'); }
.cell.lava { background-image: url('../images/cells/lava 128.png'); }
.cell.dense-tree { background-image: url('../images/cells/dense_tree 128.png'); }
.cell.rock { background-image: url('../images/cells/rock 128.png'); }
.cell.cactus { background-image: url('../images/cells/cactus 128.png'); }
.cell.ice { background-image: url('../images/cells/ice 128.png'); }
.cell.sand-1 { background-image: url('../images/cells/sand1 128.png'); }
.cell.sand-2 { background-image: url('../images/cells/sand2 128.png'); }
.cell.snow { background-image: url('../images/cells/snow 128.png'); }

/* Tree Overlays on Cells (Reset transform & align 100% centered in cell) */
.tree-overlay {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    background-size: contain !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
    pointer-events: none;
    z-index: 5;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}
.tree-overlay.tree1 { background-image: url('../images/cells/tree1 128.png') !important; }
.tree-overlay.tree2 { background-image: url('../images/cells/tree2 128.png') !important; }
.tree-overlay.tree3 { background-image: url('../images/cells/tree3 128.png') !important; }

/* Special Tile Elements Overlays */
.cell .coin-overlay {
    color: #F59E0B;
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
    z-index: 3;
}

.cell .goal-overlay {
    color: #10B981;
    font-size: 26px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
    z-index: 3;
}

.cell .character-overlay {
    width: 90%;
    height: 90%;
    background: url('../images/down.png') center/contain no-repeat;
    filter: drop-shadow(0 2px 5px rgba(0,0,0,0.3));
    z-index: 4;
}

/* Palette Panel */
.maker-palette-container {
    background: #FFFFFF;
    z-index: 10;
    box-sizing: border-box;
}

/* Tab Bar with Touch Scroll Fix */
.palette-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.tab-btn {
    padding: 8px 14px;
    border-radius: 16px;
    background: #F1F5F9;
    border: 2px solid transparent;
    color: #64748B;
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    touch-action: manipulation;
}

.tab-btn:hover {
    background: #E2E8F0;
}

.tab-btn.active {
    background: #E0F2FE;
    color: #0284C7;
    border-color: #38BDF8;
}

/* Palette Tools Container with Smooth Touch Scroll */
.palette-tools {
    display: flex;
    overflow-x: auto;
    overflow-y: visible;
    padding: 6px 2px;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.palette-group {
    display: none;
    gap: 10px;
    overflow: visible;
}

.palette-group.active {
    display: flex;
}

.maker-tool-btn {
    min-width: 58px;
    height: 58px;
    border-radius: 16px;
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    padding: 4px;
    box-sizing: border-box;
    position: relative;
    touch-action: manipulation;
}

.maker-tool-btn:hover {
    border-color: #38BDF8;
    background: #FFFFFF;
}

.maker-tool-btn.active {
    border-color: #10B981;
    background: #ECFDF5;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.3);
}

.maker-tool-btn .tool-preview {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

/* Wall & Fence Previews */
.tool-preview.preview-wall {
    background-image: linear-gradient(135deg, #78909c 25%, #607d8b 25%, #607d8b 50%, #78909c 50%, #78909c 75%, #607d8b 75%, #607d8b 100%) !important;
    background-size: 8px 8px !important;
}

.tool-preview.preview-fence-wood {
    background: linear-gradient(180deg, #8D6E63 0%, #5D4037 100%) !important;
}
.tool-preview.preview-fence-wood::before {
    content: '';
    position: absolute;
    top: 10%; left: 50%; transform: translateX(-50%);
    width: 60%; height: 80%;
    background: repeating-linear-gradient(0deg, #A1887F 0px, #A1887F 3px, #6D4C41 3px, #6D4C41 6px);
}

.tool-preview.preview-fence-stone {
    background: #78909C !important;
}
.tool-preview.preview-fence-stone::before {
    content: '';
    position: absolute; inset: 10%;
    background:
        linear-gradient(135deg, #90A4AE 25%, transparent 25%),
        linear-gradient(225deg, #90A4AE 25%, transparent 25%),
        linear-gradient(45deg, #607D8B 25%, transparent 25%),
        linear-gradient(315deg, #607D8B 25%, transparent 25%);
    background-size: 50% 50%;
}

.maker-tool-btn .label {
    font-size: 10px;
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
    text-align: center;
}

/* Toast Status Message */
.status-message {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: #0F172A;
    color: #FFFFFF;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    z-index: 100;
    display: none;
    white-space: nowrap;
}

/* ════════════════════════════════════════
   TABLET & DESKTOP LAYOUT (min-width: 700px)
   Left Sidebar Palette + Maximized 1:1 Canvas
   ════════════════════════════════════════ */
@media (min-width: 700px) {
    .codie-maker-layout {
        flex-direction: row;
    }

    .maker-palette-container {
        width: 280px;
        min-width: 280px;
        border-right: 2px solid #E2E8F0;
        padding: 20px 15px;
        display: flex;
        flex-direction: column;
        gap: 15px;
        overflow-y: auto;
    }

    .palette-tabs {
        flex-direction: column;
        overflow: visible;
        gap: 8px;
    }

    .tab-btn {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 16px;
        font-size: 14px;
    }

    .palette-tools {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 6px;
    }

    .palette-group.active {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        align-content: start;
        gap: 10px;
        width: 100%;
    }

    .maker-stage {
        padding: 20px;
    }

    .grid-wrapper {
        width: min(65vw, 75vh, 580px);
        height: min(65vw, 75vh, 580px);
    }

    .maker-blocks-container {
        width: 290px;
        min-width: 290px;
        border-left: 2px solid #E2E8F0;
        background: #FFFFFF;
        padding: 20px 15px;
        display: flex;
        flex-direction: column;
        gap: 15px;
        overflow-y: auto;
        box-sizing: border-box;
    }
}

/* ════════════════════════════════════════
   ALLOWED COMMAND BLOCKS PANEL STYLES
   ════════════════════════════════════════ */
.blocks-panel-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 2px dashed #E2E8F0;
}

.blocks-panel-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.blocks-panel-title-group .panel-icon {
    font-size: 26px;
    color: #0284C7;
    background: #E0F2FE;
    padding: 8px;
    border-radius: 14px;
}

.blocks-panel-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: #0F172A;
    margin: 0;
    line-height: 1.2;
}

.blocks-panel-sub {
    font-family: 'Nunito', sans-serif;
    font-size: 12px;
    color: #64748B;
    margin: 2px 0 0;
}

.blocks-panel-actions {
    display: flex;
    gap: 8px;
}

.btn-blocks-quick {
    flex: 1;
    padding: 5px 10px;
    border-radius: 10px;
    background: #F1F5F9;
    border: 1px solid #CBD5E1;
    color: #334155;
    font-family: 'Fredoka', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-blocks-quick:hover {
    background: #E0F2FE;
    color: #0284C7;
    border-color: #7DD3FC;
}

.btn-blocks-clear:hover {
    background: #FFE4E6;
    color: #E11D48;
    border-color: #FDA4AF;
}

/* Blocks List Container */
.blocks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

/* Command Block Toggle Card */
.block-toggle-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    background: #F8FAFC;
    border: 2px solid #E2E8F0;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    touch-action: manipulation;
}

.block-toggle-card:hover {
    border-color: #BAE6FD;
    background: #FFFFFF;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

.block-card-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.block-card-badge {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s ease;
}

.badge-blue { background: #E0F2FE; color: #0284C7; }
.badge-amber { background: #FEF3C7; color: #D97706; }
.badge-green { background: #D1FAE5; color: #059669; }
.badge-purple { background: #EDE9FE; color: #7C3AED; }
.badge-pink { background: #FCE7F3; color: #DB2777; }
.badge-rose { background: #FFE4E6; color: #E11D48; }

.block-card-title {
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

/* Custom Switch Slider */
.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #CBD5E1;
    transition: .25s ease;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .25s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, #10B981, #059669);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* Card Checked Active Style */
.block-toggle-card:has(input:checked) {
    background: #F0F9FF;
    border-color: #38BDF8;
    box-shadow: 0 4px 14px rgba(56, 189, 248, 0.12);
}

.block-toggle-card:has(input:checked) .block-card-title {
    color: #0F172A;
}

/* ════════════════════════════════════════
   MOBILE LAYOUT (max-width: 699px)
   100% Width Containment + Zero Clipping + Vertical Page Scrolling
   ════════════════════════════════════════ */
@media (max-width: 699px) {
    html, body {
        height: auto !important;
        min-height: 100vh;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .editor-workspace {
        height: auto !important;
        min-height: 100vh;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        box-sizing: border-box;
    }

    .codie-maker-layout {
        flex-direction: column;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        height: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* Mobile Header */
    .maker-header {
        padding: 8px 12px;
        height: auto;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .maker-header #langSwitcher {
        margin: 0;
    }

    .maker-header-actions {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .maker-title-input {
        flex: 1;
        min-width: 0;
        height: 36px;
        border-radius: 18px;
        font-size: 13px;
    }

    .btn-test {
        height: 36px;
        border-radius: 18px;
        font-size: 12px;
        padding: 0 10px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .btn-home {
        height: 36px;
        border-radius: 18px;
        font-size: 12px;
        padding: 0 8px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Mobile Palette Panel */
    .maker-palette-container {
        border-top: 2px solid #E2E8F0;
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.04);
        padding: 8px 10px 12px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .palette-tabs {
        justify-content: flex-start;
        padding-bottom: 6px;
        width: 100%;
        box-sizing: border-box;
    }

    .palette-tools {
        padding: 6px 0;
        width: 100%;
        box-sizing: border-box;
    }

    .palette-group {
        flex-wrap: nowrap;
    }

    .maker-tool-btn {
        min-width: 52px;
        height: 52px;
    }

    /* Mobile Grid Stage */
    .maker-stage {
        padding: 10px 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .grid-wrapper {
        width: min(92vw, 52vh);
        height: min(92vw, 52vh);
        padding: 6px;
        border-radius: 18px;
        box-sizing: border-box;
    }

    /* Mobile Commands Section below map and palette */
    .maker-blocks-container {
        display: flex;
        flex-direction: column;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        border-left: none;
        border-top: 4px solid #E2E8F0;
        padding: 16px 12px 40px;
        background: #FFFFFF;
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.03);
        box-sizing: border-box;
    }

    .blocks-panel-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        box-sizing: border-box;
        gap: 8px;
    }

    .blocks-panel-title-group {
        gap: 8px;
        min-width: 0;
    }

    .blocks-panel-title {
        font-size: 14px;
    }

    .blocks-panel-sub {
        font-size: 11px;
    }

    .blocks-panel-actions {
        flex-shrink: 0;
    }

    .blocks-list {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        overflow-y: visible;
        margin-top: 10px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .block-toggle-card {
        padding: 8px 10px;
        box-sizing: border-box;
        min-width: 0;
    }

    .block-card-info {
        gap: 6px;
        min-width: 0;
        flex: 1;
    }

    .block-card-badge {
        width: 28px;
        height: 28px;
        font-size: 16px;
        flex-shrink: 0;
    }

    .block-card-title {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .toggle-switch {
        flex-shrink: 0;
        transform: scale(0.9);
        transform-origin: right center;
    }
}
