/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f0f0f0;
    overflow: hidden;
}

/* Main container */
#container {
    display: flex;
    height: 100vh;
    width: 100vw;
    min-height: 600px;
    overflow: hidden;
}

/* Left panel - Game area */
#game-panel {
    flex: 0 0 70%;
    background-color: #2c3e50;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

#game-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100%;
}



/* Right panel - Block programming interface */
#blocks-panel {
    flex: 0 0 30%;
    background-color: #ecf0f1;
    padding: 15px;
    overflow: hidden;
    border-left: 3px solid #bdc3c7;
    min-width: 300px;
    max-width: 450px;
    display: flex;
    flex-direction: column;
    position: relative; /* For absolute positioning of play button */
}

/* Game info display */
#game-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

#goal-display, #score-display {
    flex: 1;
    background-color: #fff;
    color: #2c3e50;
    padding: 10px 12px;
    border-radius: 4px;
    border: 2px solid #bdc3c7;
    font-weight: 600;
    font-size: clamp(0.8rem, 1.6vw, 0.9rem);
}

#goal-display {
    flex: 2;
}

#goal-text, #score-value {
    display: block;
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    margin-top: 2px;
    color: #34495e;
    font-weight: 700;
}

/* Audio play button */
.audio-play-button {
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    margin-left: 8px;
    vertical-align: middle;
    transition: transform 0.2s ease, opacity 0.2s ease;
    width: 41px;
    height: 41px;
    display: inline-block;
}

.audio-play-button img {
    width: 100%;
    height: 100%;
    display: block;
}

.audio-play-button:hover {
    transform: scale(1.15);
    opacity: 0.8;
}

.audio-play-button:active {
    transform: scale(0.95);
}

#game-info .qr-button {
    width: 50px;
    height: 50px;
    flex-shrink: 0;
}

/* Blockly workspace */
#blocklyDiv {
    flex: 1;
    min-height: 400px;
    border: 2px solid #bdc3c7;
    border-radius: 8px;
    background-color: #fff;
    margin-bottom: 15px;
    overflow: hidden !important; /* Prevent all scrolling - Blockly handles its own */
    position: relative;
}

/* Fix Blockly SVG to prevent touch issues */
#blocklyDiv > .injectionDiv {
    overflow: hidden !important;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

#blocklyDiv svg.blocklySvg {
    display: block;
    overflow: visible !important;
}

/* Prevent horizontal scrolling in Blockly SVG */
.blocklyMainWorkspace {
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

/* Lock horizontal scrollbars */
.blocklyScrollbarHorizontal {
    display: none !important;
}

/* Keep vertical scrollbars visible */
.blocklyScrollbarVertical {
    display: block !important;
}

/* Constrain workspace content horizontally */
.blocklyWorkspace {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* Custom Blockly styling for kid-friendly interface */
.blocklyToolboxDiv {
    background-color: #f8f9fa !important;
    border-right: 3px solid #28a745 !important;
    min-width: 70px !important; /* Ensure toolbox has a minimum width */
}

/* Push the flyout to the right of the toolbox */
.blocklyFlyout {
    left: 25px !important; /* Start after the toolbox */
}

/* Ensure workspace doesn't overlap with toolbox on small screens */
.blocklyMainBackground {
    x: 70 !important; /* SVG x coordinate - push workspace right */
}

/* Category button styling */
.blocklyToolboxCategory {
    background: rgba(40, 167, 69, 0.85) !important; /* Semi-transparent green */
    border-radius: 5px !important;
    margin: 4px !important;
    padding: 4px !important; /* Reduced from 16px */
    box-shadow: 0 2px 6px rgba(0,0,0,0.15) !important;
    transition: all 0.3s ease !important;
    min-height: fit-content !important; /* Auto instead of fixed 70px */
    width: fit-content !important; /* Only as wide as needed */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
}

.blocklyToolboxCategory:hover {
    background: rgba(40, 167, 69, 0.95) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 12px rgba(0,0,0,0.3) !important;
}

.blocklyToolboxCategory:active,
.blocklyToolboxCategory.blocklyTreeSelected {
    background: rgba(40, 167, 69, 1) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 3px 8px rgba(0,0,0,0.25) !important;
}

/* Logo image styling */
.category-logo {
    transition: all 0.3s ease !important;
}

/* Old tree-based styling (fallback) */
.blocklyTreeRow {
    background: rgba(40, 167, 69, 0.85) !important;
    border-radius: 8px !important;
    margin: 4px !important;
    padding: 12px 16px !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    transition: all 0.3s ease !important;
    min-height: 50px !important;
    display: flex !important;
    align-items: center !important;
}

.blocklyTreeRow:hover {
    background: rgba(40, 167, 69, 1) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 12px rgba(0,0,0,0.25) !important;
    cursor: pointer !important;
}

.blocklyTreeRow.blocklyTreeSelected {
    background: rgba(40, 167, 69, 1) !important;
}

.blocklyTreeIcon {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-right: 12px !important;
    border-radius: 6px !important;
    padding: 4px !important;
}

.blocklyTreeIcon img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

.blocklyTreeLabel {
    color: white !important;
    font-weight: bold !important;
    font-size: 18px !important;
    text-shadow: 2px 2px 3px rgba(0,0,0,0.4) !important;
    flex: 1 !important;
}

/* Hide the default expand/collapse functionality */
.blocklyTreeIcon::before {
    display: none !important;
}

.blocklyTreeIconOpen,
.blocklyTreeIconClosed {
    display: none !important;
}

/* Style the workspace background with a fun pattern */
.blocklyMainBackground {
    fill: #f0f8ff !important;
}

/* Make the trash can more colorful and kid-friendly */
.blocklyTrash {
    fill: rgba(40, 167, 69, 0.85) !important; /* Green by default */
    transition: fill 0.3s ease !important;
}

.blocklyTrash:hover {
    fill: rgba(40, 167, 69, 1) !important; /* Solid green on hover */
}

/* Change trash can to red when dragging over it */
.blocklyTrash.blocklyTrashDelete {
    fill: #dc3545 !important; /* Red when ready to delete */
    animation: pulse-trash 0.5s ease-in-out infinite !important;
}

/* Pulse animation for trash when dragging over */
@keyframes pulse-trash {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

/* Add delete icon overlay when dragging */
.blocklyTrashLid {
    transition: all 0.3s ease !important;
}

.blocklyTrash.blocklyTrashDelete .blocklyTrashLid {
    transform: translateY(-5px) !important;
}

/* Position trash can to bottom left of workspace */
.blocklyTrashBody {
    transform: translate(0, 0) !important;
}

/* Move trash can to bottom left */
g.blocklyTrash {
    transform: translate(15px, calc(100% - 80px)) !important;
}

/* Ensure trash can stays in bottom left during drag */
.blocklyTrash[transform] {
    transform: translate(15px, calc(100% - 80px)) !important;
}

/* Add some fun animations to blocks */
.blocklyDraggable:hover {
    filter: brightness(1.1) !important;
}

/* Style the toolbox background */
.blocklyFlyoutBackground {
    fill: rgb(255, 255, 255) !important; /* Light green tint */
    stroke: #949494 !important;
    stroke-width: 2 !important;
}

/* Hide the entire flyout scrollbar container when not needed */
.blocklyFlyout .blocklyScrollbarVertical {
    opacity: 0 !important;
    display: none !important;
    visibility: hidden !important;
    transition: opacity 0.2s ease !important;
}

/* Show flyout scrollbar only when flyout is open and has content */
.blocklyFlyout.blocklyFlyoutOpen .blocklyScrollbarVertical {
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}

/* Additional safety - hide ALL scrollbars by default */
.blocklyScrollbarVertical {
    opacity: 0 !important;
    display: none !important;
    visibility: hidden !important;
}

/* Allow workspace scrollbars but not flyout scrollbars */
.blocklyMainWorkspace .blocklyScrollbarVertical {
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}

/* Additional safety - hide scrollbars in closed flyout */
.blocklyFlyout:not(.blocklyFlyoutOpen) .blocklyScrollbarVertical {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Ensure workspace stays within bounds */
.blocklyBlockCanvas {
    overflow: visible !important;
}

/* Hide horizontal scroll indicators everywhere */
.blocklyScrollbarHandle[data-orientation="horizontal"],
.blocklyScrollbarHorizontal {
    display: none !important;
}

/* Keep main workspace vertical scrollbars but hide flyout scrollbars when closed */
.blocklyMainWorkspace .blocklyScrollbarHandle[data-orientation="vertical"] {
    fill: #28a745 !important;
    stroke: #218838 !important;
}

.blocklyMainWorkspace .blocklyScrollbarBackground[data-orientation="vertical"] {
    fill: #f8f9fa !important;
    stroke: #bdc3c7 !important;
}

/* Style vertical scrollbar to match theme - only when flyout is open */
.blocklyFlyout .blocklyScrollbarHandle[data-orientation="vertical"] {
    fill: #28a745 !important;
    stroke: #218838 !important;
}

.blocklyFlyout .blocklyScrollbarBackground[data-orientation="vertical"] {
    fill: #f8f9fa !important;
    stroke: #bdc3c7 !important;
}

/* Hide scrollbars when flyout is closed */
.blocklyFlyout[style*="display: none"] .blocklyScrollbarVertical,
.blocklyFlyout[style*="display:none"] .blocklyScrollbarVertical {
    display: none !important;
}

/* Only show flyout scrollbars when flyout is actually open and visible */
.blocklyFlyout:not([style*="display: none"]):not([style*="display:none"]) .blocklyScrollbarVertical {
    display: block !important;
}

.blocklyFlyout[style*="visibility: hidden"] .blocklyScrollbarVertical,
.blocklyFlyout[style*="visibility:hidden"] .blocklyScrollbarVertical {
    display: none !important;
}

/* Prevent blocks from being dragged too far */
.blocklyDragging {
    opacity: 0.8 !important;
}



/* Add visual feedback for workspace boundaries */
.blocklyMainBackground {
    fill: #f0f8ff !important;
    stroke: #FF6B6B !important;
    stroke-width: 2 !important;
    stroke-dasharray: 5,5 !important;
    stroke-opacity: 0.3 !important;
}

/* Play button - positioned absolutely to overlay blocks area */
.play-button {
    position: absolute;
    bottom: 40px;
    right: 25px; /* Moved to bottom right */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #27ae60;
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 4px;
    z-index: 10; /* Lower than Blockly flyout (default ~1000) */
}

.play-button:hover {
    background-color: #229954;
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.play-button:active {
    transform: scale(0.95);
}

.qr-button {
    width: 50px;
    height: 50px;
    border-radius: 8px;
    background-color: #fff;
    border: 2px solid #bdc3c7;
    cursor: pointer;
    padding: 5px;
    transition: all 0.3s;
}

.qr-button:hover {
    border-color: #95a5a6;
    transform: scale(1.05);
}

.qr-button:active {
    transform: scale(0.95);
}

/* Modal styles */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fff;
    padding: 30px;
    border-radius: 12px;
    max-width: 500px; /* Limit max width */
    max-height: 90%;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content img {
    max-width: 100%;
    max-height: 70vh; /* Limit height to 70% of viewport */
    height: auto;
    width: auto;
    object-fit: contain;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 35px;
    font-weight: bold;
    color: #7f8c8d;
    cursor: pointer;
    transition: color 0.3s;
}

.close-modal:hover {
    color: #2c3e50;
}

/* Responsive design */
@media (max-width: 1200px) {
    #blocks-panel {
        min-width: 280px;
        padding: 12px;
    }
    
    #program-controls button {
        font-size: clamp(0.65rem, 1.3vh, 0.75rem);
        padding: clamp(5px, 1vh, 7px) clamp(6px, 1.2vw, 10px);
    }
}

@media (max-width: 900px) {
    #container {
        flex-direction: column;
        height: 100vh;
    }
    
    #game-panel {
        flex: 0 0 65%;
        min-height: 400px;
    }
    
    #blocks-panel {
        flex: 0 0 35%;
        min-width: unset;
        max-width: unset;
        padding: 10px;
        border-left: none;
        border-top: 3px solid #bdc3c7;
    }
    
    #blocklyDiv {
        min-height: 200px;
        margin-bottom: 10px;
    }
    
    #program-controls button {
        font-size: 0.7rem;
        padding: 6px 8px;
    }
}

@media (max-width: 600px) {
    #game-panel {
        flex: 0 0 60%;
    }
    
    #blocks-panel {
        flex: 0 0 40%;
        padding: 8px;
    }
    

    
    #blocklyDiv {
        min-height: 150px;
    }
    
    #program-controls button {
        font-size: 0.65rem;
        padding: 5px 6px;
    }
}

@media (max-height: 600px) {
    #container {
        min-height: 500px;
    }
    
    #blocks-panel {
        padding: 8px;
    }
    
    #blocks-panel h3 {
        margin-bottom: 8px;
        font-size: 1rem;
    }
    
    #blocklyDiv {
        min-height: 120px;
        margin-bottom: 8px;
    }
    
    #program-controls button {
        padding: 4px 6px;
        font-size: 0.65rem;
    }
}

/* Loading and status indicators */
.loading {
    color: #7f8c8d;
    text-align: center;
    padding: 20px;
    font-style: italic;
}

.status-message {
    background-color: #fff;
    border-left: 4px solid #3498db;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Make all Blockly block text white */
.blocklyText {
    fill: white !important;
    font-weight: bold !important;
}

/* Ensure input fields and numbers are also white */
.blocklyEditableText > text {
    fill: white !important;
}

/* Make field text white */
.blocklyFieldLabel {
    fill: white !important;
}

/* Make dropdown text white */
.blocklyDropdownText {
    fill: white !important;
}

/* Win/Lose Animation Overlays */
.animation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    backdrop-filter: blur(5px);
}

.animation-overlay .animation-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.animation-overlay canvas {
    display: block;
    /* Canvas will be sized by JavaScript */
}

.animation-overlay .animation-text {
    text-align: center;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin-top: 30px;
    padding: 0 20px;
}

.animation-overlay .animation-text p {
    font-size: 28px;
    font-weight: bold;
    margin: 0;
    line-height: 1.4;
}

.animation-overlay .animation-text h2 {
    font-size: 48px;
    margin: 0 0 10px 0;
    font-weight: bold;
}

.animation-overlay .animation-text p {
    font-size: 24px;
    margin: 5px 0;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .animation-overlay {
        width: 100%;
    }
    
    .animation-overlay .animation-text h2 {
        font-size: 36px;
    }
    
    .animation-overlay .animation-text p {
        font-size: 20px;
    }
}