/* General Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* CSS Variables for Theming */
:root {
    --bg-primary: #282c34; /* Body background */
    --bg-secondary: #21252b; /* Side panels, header, footer */
    --bg-tertiary: #1e2227; /* Viewport background */

    --text-color: #abb2bf;
    --text-muted: #6a737d;
    --text-highlight: #61afef; /* Blue for titles, highlights */
    --label-color: #9da5b4; /* Slightly lighter grey for labels */

    --border-color: #3b4048;
    --shadow-light: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-dark: 0 -2px 4px rgba(0, 0, 0, 0.2);

    --button-bg: #4a515f;
    --button-hover-bg: #5c6470;
    --button-active-bg: #3d434e;
    --button-disabled-bg: #3b4048;
    --button-disabled-color: #7f848e;

    --input-bg: #3b4048;
    --input-border: #4a515f;
    --input-focus-border: #61afef;
    --input-focus-shadow: rgba(97, 175, 239, 0.3);

    --panel-header-color: #61afef;
    --panel-padding: 10px;
    --panel-width: 280px; /* Width for the UI panels */

    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* HTML and Body - Full viewport height, dark theme, flex layout */
html {
    height: 100%;
}

body {
    height: 100%;
    overflow: hidden; /* Prevent scrollbars on the body */
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-color);
    display: flex;
    flex-direction: column; /* Stack header, main content, footer */
}

/* Main Application Container */
#app-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allow app container to fill remaining space */
    overflow: hidden; /* Prevent inner scrollbars from affecting outer layout */
}

/* Top Bar (Header) */
#top-bar {
    background-color: var(--bg-secondary);
    color: var(--text-color);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Prevent shrinking */
    box-shadow: var(--shadow-light);
    z-index: 10;
}

#top-bar h1 {
    font-size: 1.6em;
    color: var(--text-highlight);
    margin: 0;
}

#top-bar nav button {
    margin: 0; /* Override generic button margin for top bar buttons */
}

/* Main Content Area (panels + viewport) */
#main-content {
    display: flex; /* Arrange editor panels and viewport side-by-side */
    flex-direction: row;
    flex-grow: 1; /* Allow main content to fill available vertical space */
    overflow: hidden; /* Hide overflow from children (e.g., scrollable panels) */
}

/* Editor Panels (Left and Right Sidebars) */
aside { /* Apply common styles to both #editor-panel and #properties-panel */
    width: var(--panel-width);
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    padding: var(--panel-padding);
    overflow-y: auto; /* Enable scrolling for panel content */
    flex-shrink: 0; /* Prevent panel from shrinking */
    box-shadow: var(--shadow-light); /* Subtle shadow */
    z-index: 5; /* Below top bar, above canvas */
}

#editor-panel {
    border-right: 1px solid var(--border-color); /* Separator from viewport */
}

#properties-panel {
    border-left: 1px solid var(--border-color); /* Separator from viewport */
}

.panel-section {
    margin-bottom: 20px;
}

.panel-section:last-child {
    margin-bottom: 0;
}

.panel-header {
    font-size: 1.2em;
    color: var(--text-highlight);
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-color);
}

/* Viewport Container for 3D Canvas */
#viewport-container {
    flex-grow: 1; /* Take up remaining space */
    position: relative;
    overflow: hidden;
    background-color: var(--bg-tertiary);
}

/* Three.js Canvas */
#render-canvas { /* Changed ID from #three-canvas to #render-canvas */
    display: block;
    width: 100%;
    height: 100%;
    outline: none; /* Remove focus outline */
}

/* Status Bar (Footer) */
#status-bar {
    background-color: var(--bg-secondary);
    color: var(--text-muted);
    padding: 8px 20px;
    font-size: 0.85em;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* Prevent shrinking */
    box-shadow: var(--shadow-dark);
    z-index: 10;
}

/* Generic Button Styles */
button {
    background-color: var(--button-bg);
    color: var(--text-color);
    border: none;
    padding: 8px 15px;
    margin-top: 8px; /* Add some space between buttons */
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9em;
    transition: background-color 0.2s ease, color 0.2s ease;
    text-align: center;
}

button:first-of-type {
    margin-top: 0; /* No top margin for the first button in a section */
}

button:hover {
    background-color: var(--button-hover-bg);
}

button:active {
    background-color: var(--button-active-bg);
}

button:focus-visible { /* For accessibility and keyboard navigation */
    outline: 2px solid var(--input-focus-border);
    outline-offset: 2px;
}

button:disabled {
    background-color: var(--button-disabled-bg);
    color: var(--button-disabled-color);
    cursor: not-allowed;
}

/* Generic Input Styles */
input[type="text"],
input[type="number"],
select {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-color);
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 0; /* Managed by .property-group */
    width: 100%;
    font-size: 0.9em;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--input-focus-border);
    box-shadow: 0 0 0 2px var(--input-focus-shadow);
}

label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8em; /* Slightly smaller for property labels */
    color: var(--label-color);
}

/* Styles for properties panel content */
#properties-panel h4 { /* This selector is no longer directly used in index.html, using .panel-header instead */
    font-size: 1.1em;
    font-weight: bold;
    color: var(--panel-header-color);
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* Space between buttons */
    margin-top: 10px;
}

.button-group button {
    margin-top: 0; /* Buttons in a group manage their own spacing via gap */
    flex-grow: 1; /* Allow buttons in a group to fill space */
}

.property-group {
    margin-bottom: 12px;
}

/* Specific styling for color input */
input[type="color"] {
    -webkit-appearance: none; /* Remove default browser styling */
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    height: 30px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    padding: 2px;
    cursor: pointer;
    background-color: var(--input-bg); /* Ensure background matches other inputs */
}

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

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

/* Delete button specific style */
button#delete-object-btn {
    background-color: #e06c75; /* Red color */
    margin-top: 15px;
}

button#delete-object-btn:hover {
    background-color: #ec7c86;
}

/* "No object selected" text in properties panel */
#properties-panel > .panel-section > p { /* Adjusted selector for the new structure */
    font-style: italic;
    color: var(--text-muted);
    margin-top: 10px;
    text-align: center;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Play mode specific styles */
body.play-mode #top-bar,
body.play-mode #editor-panel,
body.play-mode #properties-panel,
body.play-mode #status-bar {
    display: none;
}

body.play-mode #main-content {
    flex-direction: column; /* Ensure viewport takes full height within main-content */
}

body.play-mode #viewport-container {
    width: 100%; /* Make viewport fill the entire width */
    height: 100%; /* Make viewport fill the entire height */
    flex-grow: 1; /* Ensure it takes all available space */
}

/* Scrollbar styling for panels (Webkit browsers) */
aside::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

aside::-webkit-scrollbar-track {
    background: var(--bg-primary); /* Use primary background for track */
}

aside::-webkit-scrollbar-thumb {
    background-color: var(--button-bg); /* Use button background for thumb */
    border-radius: 4px;
    border: 2px solid var(--bg-primary);
}

aside::-webkit-scrollbar-thumb:hover {
    background-color: var(--button-hover-bg);
}