/* Universal box-sizing and reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Base HTML and Body styles */
html, body {
    height: 100%;
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #e0e0e0; /* Light gray text for the dark theme */
    background-color: #1a1a1a; /* Very dark background */
    overflow: hidden; /* Prevent scrolling, as the UI will manage its own space */
}

/* Main application container */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh; /* Full viewport height */
    width: 100vw; /* Full viewport width */
}

/* Header (Top Bar) */
#top-bar {
    background-color: #2a2a2a; /* Slightly lighter dark gray */
    padding: 10px 20px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Subtle shadow for depth */
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0; /* Prevent header from shrinking */
    z-index: 10; /* Ensure header is above other content */
}

#top-bar h1 {
    font-size: 1.5em;
    color: #00bfff; /* Roblox-like blue for branding */
    margin: 0;
    text-shadow: 0 0 5px rgba(0, 191, 255, 0.5); /* Subtle glow effect */
}

#top-bar nav {
    display: flex;
    gap: 20px; /* Space between nav links */
}

#top-bar nav a {
    color: #e0e0e0;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease, text-shadow 0.3s ease;
    padding: 5px 0; /* Make clickable area slightly larger */
}

#top-bar nav a:hover,
#top-bar nav a:focus { /* Added focus state for accessibility */
    color: #00bfff;
    text-shadow: 0 0 8px rgba(0, 191, 255, 0.7);
    outline: none; /* Remove default focus outline */
}

/* Main content area (holds panels and game view) */
#main-area {
    display: flex;
    flex: 1; /* Takes up all available vertical space */
    overflow: hidden; /* Hide overflow from its children */
}

/* Side Panels (for editor UI like scene hierarchy, properties) */
.panel {
    background-color: #2a2a2a;
    width: 280px; /* Slightly wider for better content display */
    flex-shrink: 0; /* Prevent panels from shrinking */
    padding: 15px;
    overflow-y: auto; /* Enable scrolling for panel content */
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1); /* Inner shadow for depth */
    z-index: 5; /* Below header, above canvas */
    display: flex; /* Make panel content flex for better layout of internal elements */
    flex-direction: column;
}

#left-panel {
    border-right: 1px solid #3a3a3a; /* Explicit right border */
}

#right-panel {
    border-left: 1px solid #3a3a3a; /* Explicit left border */
}

.panel h2 {
    font-size: 1.2em;
    color: #00bfff;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid rgba(0, 191, 255, 0.3); /* Subtle separator */
    padding-bottom: 8px;
    flex-shrink: 0; /* Prevent header from shrinking */
}

/* Editor Tools Content (inside left-panel) */
#editor-tools-content {
    flex-grow: 1; /* Allow content to take available space */
    display: flex;
    flex-direction: column;
    gap: 15px; /* Space between sections */
}

#editor-tools-content h3 {
    font-size: 1.1em;
    color: #cccccc;
    margin-top: 10px;
    margin-bottom: 8px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

/* Scene Hierarchy */
#scene-hierarchy {
    list-style: none;
    padding: 0;
    margin: 0;
    color: #bbbbbb;
    font-size: 0.95em;
    max-height: 200px; /* Limit height for scrolling */
    overflow-y: auto;
    background-color: #222222;
    border-radius: 4px;
    padding: 5px;
}

#scene-hierarchy li {
    padding: 5px 8px;
    cursor: pointer;
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

#scene-hierarchy li:hover {
    background-color: #3a3a3a;
}
#scene-hierarchy li.selected {
    background-color: #00bfff;
    color: #ffffff;
    font-weight: bold;
}

/* Editor Buttons (dynamically added by script.js) */
.editor-button {
    background-color: #007bff; /* A standard blue */
    color: white;
    border: none;
    padding: 8px 15px;
    margin-bottom: 8px; /* Space between buttons */
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background-color 0.2s ease, transform 0.1s ease;
    width: 100%; /* Full width for consistency */
    text-align: center;
}

.editor-button:hover {
    background-color: #0056b3;
    transform: translateY(-1px);
}

.editor-button:active {
    background-color: #004085;
    transform: translateY(0);
}

.editor-button:focus { /* Accessibility focus state */
    outline: 2px solid #00bfff;
    outline-offset: 2px;
}

.delete-button {
    background-color: #dc3545; /* Red for delete action */
    margin-top: 15px; /* More space above delete button */
}

.delete-button:hover {
    background-color: #c82333;
}

.delete-button:focus {
    outline-color: #dc3545;
}

/* Property Editor (inside right-panel, content dynamically generated by script.js) */
#property-editor {
    flex-grow: 1; /* Allow content to take available space */
}

.property-group {
    background-color: #222222;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 15px;
}

.property-group h3, .property-group h4 {
    font-size: 1em;
    color: #00bfff;
    margin-top: 0;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(0, 191, 255, 0.15);
    padding-bottom: 5px;
}

.property-group label {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.9em;
    color: #cccccc;
}

.property-group label input[type="number"],
.property-group label input[type="color"] {
    flex-grow: 1;
    width: auto; /* Override default width for flex item */
    margin-left: 10px;
    padding: 6px 10px;
    background-color: #333333;
    border: 1px solid #555555;
    border-radius: 3px;
    color: #e0e0e0;
    font-size: 0.9em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.property-group label input[type="number"]:focus,
.property-group label input[type="color"]:focus {
    border-color: #00bfff;
    box-shadow: 0 0 5px rgba(0, 191, 255, 0.5);
    outline: none;
}

/* Custom styling for color input */
.property-group label input[type="color"] {
    -webkit-appearance: none; /* Remove default browser styling for color input */
    -moz-appearance: none;
    appearance: none;
    height: 30px; /* Adjust height for better appearance */
    padding: 2px;
    cursor: pointer;
}

.property-group label input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

.property-group label input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 2px;
}

/* Game Canvas Container */
#game-canvas-container {
    flex: 1; /* Takes up all available horizontal space */
    position: relative; /* For positioning the UI overlay */
    background-color: #121212; /* Very dark background for the 3D scene */
    overflow: hidden; /* Ensure canvas doesn't overflow */
}

/* The actual WebGL canvas element */
#webblox-canvas {
    display: block; /* Remove extra space below inline elements */
    width: 100%;
    height: 100%;
}

/* UI Overlay for player HUD and other game-specific elements */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allow clicks to pass through to the canvas by default */
    z-index: 15; /* Ensure it's above the canvas */
    display: flex; /* Make it a flex container to manage its children */
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
}

/* Player HUD (UI Overlay for in-game elements) */
#player-hud {
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Push elements to top/bottom */
    flex-grow: 1; /* Take up available space within ui-overlay */
    padding: 0;
}

.chat-window {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    border-radius: 8px;
    padding: 10px;
    max-width: 300px;
    min-height: 100px;
    overflow-y: auto;
    font-size: 0.9em;
    color: #ffffff;
    pointer-events: auto; /* Re-enable pointer events for chat interaction */
    align-self: flex-start; /* Align to top-left */
}

.chat-window p {
    margin-bottom: 5px;
}

.controls-overlay {
    display: flex;
    gap: 10px;
    align-self: flex-end; /* Align to bottom-right */
    pointer-events: auto; /* Re-enable pointer events for controls interaction */
}

.controls-overlay button {
    background-color: rgba(0, 191, 255, 0.7); /* Semi-transparent blue */
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 50px; /* Pill shape */
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s ease, transform 0.1s ease;
}

.controls-overlay button:hover {
    background-color: rgba(0, 191, 255, 0.9);
    transform: translateY(-2px);
}

.controls-overlay button:active {
    background-color: rgba(0, 191, 255, 1);
    transform: translateY(0);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.controls-overlay button:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* Footer (Bottom Bar) */
#bottom-bar {
    background-color: #2a2a2a;
    padding: 8px 20px;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.2); /* Subtle shadow for depth */
    flex-shrink: 0; /* Prevent footer from shrinking */
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center; /* Center the text */
    z-index: 10;
}

#bottom-bar p {
    font-size: 0.9em;
    color: #cccccc;
    margin: 0;
}

/* Responsive Design for smaller screens */
@media (max-width: 992px) { /* Adjusted breakpoint for panels */
    .panel {
        width: 220px; /* Slightly narrower panels on medium screens */
    }
}

@media (max-width: 768px) {
    #main-area {
        flex-direction: column; /* Stack panels and game view vertically */
    }

    .panel {
        width: 100%; /* Panels take full width */
        max-height: 250px; /* Limit panel height to save screen space */
        border-right: none;
        border-left: none;
        border-bottom: 1px solid #3a3a3a; /* Add bottom border as separator */
    }

    #left-panel, #right-panel {
        order: -1; /* Place panels above the game view */
    }

    #bottom-bar {
        min-height: 60px; /* Taller footer on smaller screens */
    }

    .chat-window {
        max-width: 250px;
    }

    .controls-overlay button {
        padding: 10px 15px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    #top-bar {
        flex-direction: column; /* Stack title and nav vertically */
        align-items: flex-start;
        gap: 5px;
    }

    #top-bar h1 {
        font-size: 1.2em;
    }

    #top-bar nav {
        width: 100%;
        justify-content: space-around; /* Distribute links */
        gap: 0;
    }

    #top-bar, #bottom-bar {
        padding: 8px 15px;
    }

    .panel {
        padding: 10px;
        max-height: 180px;
    }

    .panel h2 {
        font-size: 1em;
        margin-bottom: 10px;
    }

    .chat-window {
        max-width: 100%; /* Full width on very small screens */
        margin-left: auto;
        margin-right: auto;
    }

    .controls-overlay {
        flex-direction: column; /* Stack buttons vertically */
        gap: 5px;
    }
}