body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'system-ui', sans-serif;
    background-color: #111;
    color: #eee;
    display: flex; /* Use flexbox for layout */
    flex-direction: row; /* Arrange items horizontally */
}

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: #fff;
    font-size: 1.5em;
}

#loading-progress-bar {
    width: 80%;
    max-width: 400px;
    height: 20px;
    background-color: #555;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 15px;
    margin-bottom: 10px; /* Space before details */
}

#loading-progress {
    width: 0%;
    height: 100%;
    background-color: #4CAF50;
    transition: width 0.1s linear; /* Smooth progress update */
}

#loading-details {
    font-size: 0.8em;
    color: #ccc;
    margin-top: 5px;
    text-align: center;
    min-height: 1.2em; /* Reserve space */
}


#game-container {
    flex-grow: 1; /* Take remaining horizontal space */
    height: 100%;
    position: relative; /* Needed for joystick zones */
    overflow: hidden; /* Ensure canvas doesn't overflow */
}

#game-canvas {
    display: block; /* Remove extra space below canvas */
    width: 100%;
    height: 100%;
}

#ui-container {
    width: 350px; /* Fixed width for chat/controls */
    height: 100%;
    background-color: #222;
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box; /* Include padding in width */
    border-left: 1px solid #444;
}

#controls-container {
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid #444;
    font-size: 0.9em;
}
#controls-container label {
    margin-right: 5px;
}
#controls-container select,
#controls-container input[type="range"],
#controls-container button {
    margin-bottom: 8px; /* Spacing between controls */
}
#controls-container button {
    padding: 3px 8px;
    margin-left: 5px;
    cursor: pointer;
}
#temperature-value {
    display: inline-block;
    min-width: 25px; /* Ensure space for value */
    text-align: right;
}


#chat-container {
    flex-grow: 1; /* Take remaining vertical space */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent chat from overflowing UI container */
}

#chat-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background-color: #1a1a1a;
    border-radius: 5px;
    margin-bottom: 10px;
    font-size: 0.9em;
    word-wrap: break-word;
}

.chat-message {
    margin-bottom: 8px;
    padding: 5px 8px;
    border-radius: 4px;
    line-height: 1.4;
}

.user-message {
    background-color: #3a3a7a;
    text-align: right;
    margin-left: 40px; /* Indent user messages */
}

.llm-message {
    background-color: #444;
    margin-right: 40px; /* Indent LLM messages */
}

.tool-call-message {
    background-color: #2a5a2a; /* Greenish */
    font-style: italic;
    color: #ccc;
    margin-right: 40px;
    font-size: 0.85em;
}

.error-message {
    background-color: #7a3a3a; /* Reddish */
    color: #fdd;
    font-weight: bold;
}

#chat-input-area {
    display: flex;
}

#chat-input {
    flex-grow: 1;
    padding: 8px;
    border: 1px solid #555;
    background-color: #333;
    color: #eee;
    border-radius: 4px 0 0 4px;
    outline: none;
}
#chat-input:disabled {
    background-color: #444;
    cursor: not-allowed;
}

#send-button {
    padding: 8px 15px;
    border: 1px solid #555;
    background-color: #555;
    color: #eee;
    cursor: pointer;
    border-radius: 0 4px 4px 0;
    border-left: none;
}
#send-button:disabled {
    background-color: #444;
    color: #888;
    cursor: not-allowed;
}
#send-button:hover:not(:disabled) {
    background-color: #666;
}

/* On-screen Joysticks */
.joystick-zone {
    position: absolute;
    bottom: 20px;
    width: 120px; /* Increased size */
    height: 120px; /* Increased size */
    z-index: 10;
    opacity: 0.6;
}
#joystick-move-zone {
    left: 20px;
}
#joystick-rotate-zone {
    right: 20px;
}
/* Style for the nipple element itself (adjust as needed) */
.nipple {
    position: relative !important; /* Override potential absolute positioning from library */
}
.back, .front { /* Style the joystick appearance */
    background-color: rgba(128, 128, 128, 0.5) !important;
    border: 1px solid rgba(255, 255, 255, 0.5) !important;
    border-radius: 50%;
}
.front {
    background-color: rgba(200, 200, 200, 0.7) !important;
}


#llm-status {
    font-size: 0.8em;
    margin-top: 5px;
    padding: 3px;
    text-align: center;
    border-radius: 3px;
}
.status-idle { background-color: #335; color: #ccf;}
.status-thinking { background-color: #553; color: #ffc;}
.status-error { background-color: #533; color: #fcc;}


/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        flex-direction: column; /* Stack vertically on smaller screens */
    }
    #ui-container {
        width: 100%; /* Take full width */
        height: 40%; /* Take fixed portion of height */
        max-height: 300px; /* Limit chat height */
        border-left: none;
        border-top: 1px solid #444;
        order: 2; /* Place below game */
    }
    #game-container {
        height: 60%; /* Take remaining height */
        order: 1; /* Place above UI */
    }
    .joystick-zone { /* Make joysticks slightly smaller on mobile */
        width: 100px;
        height: 100px;
        bottom: 15px;
    }
    #joystick-move-zone { left: 15px; }
    #joystick-rotate-zone { right: 15px; }
}