:root {
    --theme-yellow: #FFD200;
    --theme-orange: #FF8C00;
    --theme-red: #FF3B30;
    --theme-green: #4CD964;
    --theme-blue: #007AFF;
    --ui-shadow: 0 6px 0 rgba(0,0,0,0.2);
    --ui-shadow-active: 0 2px 0 rgba(0,0,0,0.2);
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #87CEEB; /* Play mode background */
    font-family: 'Nunito', sans-serif;
    user-select: none;
    -webkit-user-select: none;
}

/* Edit Mode Blueprint Background - Applied via JS to body */
body.edit-mode {
    background-color: #fceea7;
}

#game-container {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1; /* Under UI */
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to game */
    z-index: 10;
}

/* Retro-Style Toolbar */
#toolbar {
    pointer-events: auto; /* Catch clicks on toolbar */
    width: 100%;
    height: 70px;
    background: linear-gradient(to bottom, #FFF5A0, var(--theme-yellow));
    border-bottom: 4px solid var(--theme-orange);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    box-sizing: border-box;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    position: relative;
}

/* Add the little rivets/screws on the toolbar */
#toolbar::before, #toolbar::after {
    content: '';
    position: absolute;
    bottom: 5px;
    width: 8px;
    height: 8px;
    background: rgba(0,0,0,0.15);
    border-radius: 50%;
    box-shadow: inset 1px 1px 2px rgba(0,0,0,0.2);
}
#toolbar::before { left: 20px; }
#toolbar::after { right: 20px; }

.toolbar-side {
    width: 200px; /* Fixed width to keep palette centered */
    display: flex;
    align-items: center;
}
.toolbar-side.right { justify-content: flex-end; }

/* Icon Buttons */
.icon-btn {
    background: white;
    border: 3px solid #E6B800;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--ui-shadow);
    transition: transform 0.1s, box-shadow 0.1s;
}
.icon-btn:active {
    transform: translateY(4px);
    box-shadow: var(--ui-shadow-active);
}

/* Block Palette */
.palette-container {
    display: flex;
    gap: 8px;
    background: rgba(255, 255, 255, 0.4);
    padding: 6px 12px;
    border-radius: 20px;
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.1);
    transition: opacity 0.3s, transform 0.3s;
    max-width: 60%;
    overflow-x: auto;
    scrollbar-width: none; /* Hide scrollbar for clean look */
}
.palette-container::-webkit-scrollbar { display: none; }

body:not(.edit-mode) .palette-container {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-20px);
}

.block-btn {
    background: white;
    border: 3px solid #ccc;
    border-radius: 12px;
    width: 60px;
    min-width: 60px;
    height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 0 #ccc;
    transition: all 0.1s;
    position: relative;
    padding: 0;
}

.block-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.block-btn.active {
    border-color: var(--theme-orange);
    box-shadow: 0 4px 0 #CC7000;
    background-color: #FFF9E6;
}

.block-btn.active::after {
    content: '▼';
    position: absolute;
    bottom: -15px;
    font-size: 12px;
    color: var(--theme-orange);
}

.block-icon {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid rgba(0,0,0,0.2);
    box-shadow: inset 2px 2px 0 rgba(255,255,255,0.4);
}
.basic-icon { background: #8B4513; }
.bouncy-icon { background: #FF69B4; border-radius: 50%; } /* Sphere bouncy icon */
.ice-icon { background: #00CED1; }
.boost-icon { background: #32CD32; background-image: repeating-linear-gradient(45deg, transparent, transparent 5px, rgba(255,255,255,0.5) 5px, rgba(255,255,255,0.5) 10px); }
.mud-icon { background: #4b3621; border-radius: 8px; }
.lava-icon { background: #FF4500; box-shadow: inset 0 0 10px #ffff00; }
.super-tramp-icon { background: #8A2BE2; border-radius: 50%; border: 3px solid #FFFF00; }
.glass-icon { background: rgba(135, 206, 250, 0.5); border: 2px solid #87CEFA; }

.block-label {
    font-size: 10px;
    font-weight: 900;
    color: #666;
    margin-top: 4px;
    font-family: 'Fredoka One', cursive;
}

/* Play/Make Clapperboard Toggle */
.toggle-container {
    cursor: pointer;
}

.toggle-bg {
    width: 140px;
    height: 44px;
    background: #444;
    border-radius: 22px;
    border: 3px solid #222;
    position: relative;
    box-shadow: inset 0 4px 8px rgba(0,0,0,0.5), 0 4px 0 rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    overflow: hidden;
}

.toggle-switch {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 76px;
    height: 40px;
    background: var(--theme-yellow);
    border-radius: 20px;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,0.2), inset 0 2px 0 rgba(255,255,255,0.5);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.3s;
    z-index: 2;
}

.toggle-text {
    flex: 1;
    text-align: center;
    font-family: 'Fredoka One', cursive;
    font-size: 16px;
    color: white;
    z-index: 3;
    pointer-events: none;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
    transition: color 0.3s;
}

.make-text { color: #333; text-shadow: none; } /* Active text color */

/* When in Play Mode */
body:not(.edit-mode) .toggle-switch {
    transform: translateX(60px);
    background: var(--theme-green);
}
body:not(.edit-mode) .make-text { color: white; text-shadow: 1px 1px 0 rgba(0,0,0,0.5); }
body:not(.edit-mode) .play-text { color: #114d17; text-shadow: none; }

/* --- STUDIO OVERHAUL UI --- */

/* Panels */
.studio-panel {
    position: absolute;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    color: white;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
    pointer-events: auto; /* Catch clicks */
}

/* Hide animations */
.hidden-left { transform: translateX(-150%); }
.hidden-right { transform: translateX(150%); }

/* 1. Block Explorer */
#explorer-drawer {
    top: 75px;
    left: 15px;
    width: 360px;
    height: calc(100% - 90px);
    border-radius: 15px;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.panel-header h3 {
    margin: 0;
    font-family: 'Fredoka One', cursive;
    color: var(--theme-yellow);
}
.close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 16px;
    cursor: pointer;
}

.explorer-tabs {
    display: flex;
    flex-wrap: wrap;
    background: rgba(0,0,0,0.35);
    padding: 6px;
    gap: 4px;
}
.tab-btn {
    flex: 1 1 30%;
    background: transparent;
    border: none;
    color: #bbb;
    padding: 6px 2px;
    font-family: 'Fredoka One', cursive;
    cursor: pointer;
    font-size: 11px;
    text-align: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}
.tab-btn:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}
.tab-btn.active {
    background: rgba(255,255,255,0.15);
    color: white;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.1);
}

.explorer-content {
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    overflow-y: auto;
}

/* 2. Properties Panel */
#properties-panel {
    top: 75px;
    right: 15px;
    width: 250px;
    border-radius: 15px;
}

.panel-content { padding: 15px; }

.prop-group { margin-bottom: 15px; }
.prop-group label {
    display: block;
    font-weight: bold;
    color: #aaa;
    margin-bottom: 5px;
    font-size: 12px;
}

.vec3-inputs {
    display: flex;
    gap: 5px;
}
.vec3-inputs input {
    width: 100%;
    background: rgba(0,0,0,0.5);
    border: 1px solid #444;
    color: white;
    padding: 5px;
    border-radius: 4px;
    text-align: center;
    outline: none;
}

/* 3. Layers Panel */
#layers-panel {
    right: 15px;
    width: 250px;
    border-radius: 15px;
}

.layer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    border: 1px solid transparent;
}
.layer-item.active {
    border-color: var(--theme-orange);
    background: rgba(204, 112, 0, 0.2);
}
.layer-vis-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
}

/* 4. Transform Toolbar */
#transform-toolbar {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 30px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    pointer-events: auto;
    z-index: 100;
}

.tool-btn {
    background: white;
    border: 3px solid #ccc;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 4px 0 #ccc;
}
.tool-btn.active {
    border-color: var(--theme-blue);
    box-shadow: 0 4px 0 #0056b3;
    background: #e6f2ff;
}
.tool-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* 5. Keybinds Overlay */
#keybinds-overlay {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(0,0,0,0.6);
    padding: 15px;
    border-radius: 10px;
    color: white;
    font-family: monospace;
    font-size: 12px;
    pointer-events: none; /* Let clicks pass */
    z-index: 100;
}

.keybind-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    gap: 20px;
}
.keybind-row .key {
    background: rgba(255,255,255,0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}
.keybind-row .action { color: #ccc; }

/* Hide these in play mode */
body:not(.edit-mode) .studio-panel,
body:not(.edit-mode) #transform-toolbar,
body:not(.edit-mode) #keybinds-overlay {
    display: none !important;
}
