:root {
    --primary-bg: #0a0a1f; /* Deep dark blue */
    --secondary-bg: #1a1a3f; /* Slightly lighter dark blue for UI elements */
    --tertiary-bg: #2a2a5f; /* Even lighter for accents or hover states */
    --primary-text: #e0e0ff; /* Light lavender/blueish white */
    --accent-color: #00ffff; /* Cyan/aqua */
    --accent-color-darker: #00cccc;
    --error-color: #ff4d4d;
    --font-family: 'Electrolize', sans-serif;
    --border-radius: 8px;
    --input-height: 40px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--primary-bg);
    color: var(--primary-text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* To ensure canvas doesn't cause scrollbars initially */
    position: relative; /* For canvas positioning */
}

#neuralNetworkCanvas {
    position: fixed; /* Changed from absolute to fixed to cover viewport */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1; /* Behind all content */
}

.chat-container {
    width: 90%;
    max-width: 700px;
    height: 85vh;
    max-height: 800px;
    background-color: rgba(26, 26, 63, 0.85); /* var(--secondary-bg) with some transparency */
    backdrop-filter: blur(10px);
    border: 1px solid var(--accent-color);
    border-radius: var(--border-radius);
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.3), 0 0 40px rgba(0, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Ensures children don't overflow rounded corners */
    z-index: 1;
}

.chat-header {
    background-color: rgba(42, 42, 95, 0.9); /* var(--tertiary-bg) with transparency */
    padding: 15px 20px;
    border-bottom: 1px solid var(--accent-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 1.5em;
    color: var(--accent-color);
    text-shadow: 0 0 5px var(--accent-color);
}

.ai-status {
    display: flex;
    align-items: center;
    font-size: 0.9em;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    transition: background-color 0.3s ease;
}

.status-indicator.idle { background-color: #4caf50; /* Green */ }
.status-indicator.typing { background-color: #ffc107; /* Amber */ }
.status-indicator.error { background-color: var(--error-color); /* Red */ }


.chat-history {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: var(--secondary-bg);
}

.chat-history::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 4px;
}

.chat-history::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color-darker);
}

.message {
    padding: 10px 15px;
    border-radius: var(--border-radius);
    max-width: 80%;
    line-height: 1.5;
    word-wrap: break-word;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInMessage 0.3s ease forwards;
}

@keyframes fadeInMessage {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background-color: var(--tertiary-bg);
    color: var(--primary-text);
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.message.ai {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    align-self: flex-start;
    border-bottom-left-radius: 0;
}

.message.error {
    background-color: var(--error-color);
    color: white;
    align-self: center;
    max-width: 100%;
    text-align: center;
}

.message strong {
    font-weight: bold;
    color: var(--accent-color);
}

.message.ai strong {
    color: var(--primary-bg);
}
.message.ai .command-list strong { 
    color: var(--primary-bg);
}


.chat-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid var(--accent-color);
    background-color: rgba(42, 42, 95, 0.9); /* var(--tertiary-bg) with transparency */
    position: relative; 
}

#userInput {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid var(--accent-color);
    border-radius: var(--border-radius);
    background-color: var(--secondary-bg);
    color: var(--primary-text);
    font-family: var(--font-family);
    resize: none; 
    min-height: var(--input-height);
    max-height: 120px; 
    overflow-y: auto; 
    line-height: 1.4;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#userInput:focus {
    border-color: var(--accent-color-darker);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

#userInput::placeholder {
    color: #888eb0;
}

#sendButton {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    border: none;
    border-radius: var(--border-radius);
    padding: 0 15px; 
    margin-left: 10px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background-color 0.3s ease, transform 0.1s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--input-height); 
    width: 50px; 
}

#sendButton svg {
    width: 20px;
    height: 20px;
}

#sendButton:hover {
    background-color: var(--accent-color-darker);
}

#sendButton:active {
    transform: scale(0.95);
}

#sendButton:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.loading-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: currentColor; 
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    margin: 0 2px;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/* Command Suggestions */
.command-suggestions-container {
    position: absolute;
    bottom: calc(100% - 10px); 
    left: 15px; 
    right: 15px; 
    max-height: 200px;
    overflow-y: auto;
    background-color: var(--secondary-bg);
    border: 1px solid var(--accent-color);
    border-bottom: none; 
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    z-index: 10;
    display: none; 
    box-shadow: 0 -5px 15px rgba(0, 255, 255, 0.1);
}

.command-suggestions-container ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.command-suggestions-container li {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--tertiary-bg);
    display: flex;
    align-items: center;
    gap: 10px;
}

.command-suggestions-container li:last-child {
    border-bottom: none;
}

.command-suggestions-container li:hover,
.command-suggestions-container li.selected {
    background-color: var(--tertiary-bg);
    color: var(--accent-color);
}

.command-suggestions-container .cmd-icon {
    font-size: 1.2em;
}
.command-suggestions-container .cmd-name {
    font-weight: bold;
}
.command-suggestions-container .cmd-description {
    font-size: 0.9em;
    color: var(--primary-text); 
    opacity: 0.8;
}
.command-suggestions-container li.selected .cmd-description,
.command-suggestions-container li:hover .cmd-description {
    color: var(--accent-color);
    opacity: 0.9;
}


/* Calculator Modal */
.calculator-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.calculator-modal.hidden {
    display: none;
}

.calculator {
    background-color: var(--secondary-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.4);
    width: 320px;
    padding: 15px;
}

.calculator-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--accent-color);
    font-size: 1.2em;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tertiary-bg);
}

.calculator-close-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
}
.calculator-close-btn:hover {
    color: var(--accent-color);
}

.calculator-display {
    background-color: var(--primary-bg);
    color: var(--primary-text);
    font-size: 2em;
    padding: 15px;
    text-align: right;
    border-radius: var(--border-radius);
    margin-bottom: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border: 1px solid var(--tertiary-bg);
}

.calculator-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.calculator-buttons button {
    background-color: var(--tertiary-bg);
    color: var(--primary-text);
    border: 1px solid var(--primary-bg);
    border-radius: var(--border-radius);
    font-size: 1.2em;
    padding: 15px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    font-family: var(--font-family);
}

.calculator-buttons button:hover {
    background-color: #3a3a6f; 
}

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

.calculator-buttons button.operator {
    background-color: var(--accent-color);
    color: var(--primary-bg);
}
.calculator-buttons button.operator:hover {
    background-color: var(--accent-color-darker);
}

.calculator-buttons button.span-two {
    grid-column: span 2;
}

/* HTML Runner Modal */
.html-runner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.html-runner-modal.hidden {
    display: none;
}

.html-runner-container {
    background-color: var(--secondary-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.4);
    width: 90%;
    max-width: 800px;
    height: 70vh;
    max-height: 600px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.html-runner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--accent-color);
    font-size: 1.2em;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tertiary-bg);
}

.html-runner-close-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
}
.html-runner-close-btn:hover {
    color: var(--accent-color);
}

.html-runner-body {
    display: flex;
    flex-grow: 1;
    gap: 15px;
    overflow: hidden; /* Prevent content from breaking layout */
}

.html-input-section, .html-output-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--primary-bg);
    padding: 10px;
    border-radius: var(--border-radius);
    border: 1px solid var(--tertiary-bg);
}

.html-input-section label, .html-output-section label {
    margin-bottom: 8px;
    color: var(--accent-color);
    font-size: 0.9em;
}

#htmlCodeInput {
    flex-grow: 1;
    background-color: var(--secondary-bg);
    color: var(--primary-text);
    border: 1px solid var(--tertiary-bg);
    border-radius: var(--border-radius);
    padding: 10px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    resize: none; /* Height is auto-adjusted by JS */
    min-height: 100px; /* Minimum height */
    margin-bottom: 10px;
    outline: none;
}

#htmlCodeInput:focus {
    border-color: var(--accent-color);
}

#runHtmlCodeBtn {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    border: none;
    border-radius: var(--border-radius);
    padding: 10px 15px;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background-color 0.3s ease;
    align-self: flex-start;
}

#runHtmlCodeBtn:hover {
    background-color: var(--accent-color-darker);
}

#htmlOutputFrame {
    flex-grow: 1;
    background-color: #ffffff; /* White background for typical HTML rendering */
    border: 1px solid var(--tertiary-bg);
    border-radius: var(--border-radius);
    width: 100%;
    height: 100%; /* Ensure it fills its container */
}

/* UGS Viewer Modal */
.ugs-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.ugs-viewer-modal.hidden {
    display: none;
}

.ugs-viewer-container {
    background-color: var(--secondary-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.4);
    width: 90%;
    max-width: 900px; /* Wider for PDF viewing */
    height: 85vh;
    max-height: 700px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.ugs-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--accent-color);
    font-size: 1.2em;
    margin-bottom: 10px; /* Reduced margin */
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tertiary-bg);
}

.ugs-viewer-close-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
}
.ugs-viewer-close-btn:hover {
    color: var(--accent-color);
}

.ugs-viewer-body {
    flex-grow: 1;
    background-color: var(--primary-bg);
    border: 1px solid var(--tertiary-bg);
    border-radius: var(--border-radius);
    overflow: hidden; /* For iframe */
}

#ugsPdfFrame {
    width: 100%;
    height: 100%;
    border: none;
}

.ugs-viewer-footer {
    padding-top: 10px;
    margin-top: 10px;
    border-top: 1px solid var(--tertiary-bg);
    text-align: center;
    font-size: 0.9em;
    color: var(--primary-text);
}

.ugs-viewer-footer a {
    color: var(--accent-color);
    text-decoration: none;
}

.ugs-viewer-footer a:hover {
    text-decoration: underline;
}

/* Games Modal */
.games-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.games-modal.hidden {
    display: none;
}

.games-container {
    background-color: var(--secondary-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--accent-color);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.4);
    width: 90%;
    max-width: 800px; 
    height: 80vh;
    max-height: 650px;
    padding: 15px;
    display: flex;
    flex-direction: column;
}

.games-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--accent-color);
    font-size: 1.2em;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--tertiary-bg);
    position: relative; 
}

#gamesHeaderInfo {
    color: var(--primary-text); 
    font-size: 0.7em; 
    font-style: italic;
    text-align: center; 
    flex-grow: 1; 
    margin: 0 10px; 
    opacity: 0.8; 
}

.games-close-btn {
    background: none;
    border: none;
    color: var(--primary-text);
    font-size: 1.8em;
    cursor: pointer;
    line-height: 1;
}
.games-close-btn:hover {
    color: var(--accent-color);
}

.games-body {
    flex-grow: 1;
    background-color: var(--primary-bg);
    border: 1px solid var(--tertiary-bg);
    border-radius: var(--border-radius);
    overflow-y: auto; /* For game list if it gets long */
    padding: 15px;
    text-align: center;
}

.games-body p {
    margin-bottom: 20px;
}

.game-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
}

.game-list li {
    background-color: var(--tertiary-bg);
    color: var(--primary-text);
    padding: 15px 20px;
    font-size: 1em;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    border: 1px solid var(--accent-color-darker);
    min-width: 150px;
    text-align: center;
}

.game-list li:hover {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    transform: translateY(-3px);
}

.game-viewport {
    width: 100%;
    height: 100%; /* Will take full space of games-body when active */
    border: none;
    background-color: #000; /* Default background for game iframe */
}

.game-viewport.hidden {
    display: none;
}

.url-loader-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--tertiary-bg);
    text-align: center;
}

.url-loader-section p {
    margin-bottom: 10px;
    font-size: 0.95em;
}

#gameUrlInput {
    width: calc(100% - 130px); /* Adjust width based on button */
    padding: 10px;
    margin-right: 10px;
    border: 1px solid var(--accent-color);
    border-radius: var(--border-radius);
    background-color: var(--primary-bg);
    color: var(--primary-text);
    font-family: var(--font-family);
    font-size: 0.9em;
    outline: none;
}

#gameUrlInput:focus {
    border-color: var(--accent-color-darker);
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.4);
}

#loadGameFromUrlBtn {
    background-color: var(--accent-color);
    color: var(--primary-bg);
    border: none;
    border-radius: var(--border-radius);
    padding: 10px 15px;
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.9em;
    transition: background-color 0.3s ease;
}

#loadGameFromUrlBtn:hover {
    background-color: var(--accent-color-darker);
}

.url-loader-note {
    font-size: 0.8em;
    color: #aaa; /* Less prominent */
    margin-top: 15px;
}

/* UGS Banner */
.ugs-banner {
    background-color: var(--tertiary-bg);
    color: var(--primary-text);
    padding: 8px 15px;
    font-size: 0.85em;
    text-align: center;
    border-radius: var(--border-radius);
    margin-bottom: 15px;
    border: 1px solid var(--accent-color);
}

.ugs-banner a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: bold;
}

.ugs-banner a:hover {
    text-decoration: underline;
}