/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #000;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    height: 100vh;
    overflow: hidden;
}

/* Builder Container */
.builder-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.builder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid #333;
    background-color: #111;
}

.builder-header h1 {
    font-size: 1.2rem;
    font-weight: normal;
}

.back-link {
    color: #888;
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: #fff;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.header-btn {
    background: transparent;
    border: 1px solid #444;
    color: #888;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:hover {
    border-color: #fff;
    color: #fff;
}

.header-btn.submit-btn {
    border-color: #2d5a3d;
    color: #4ade80;
}

.header-btn.submit-btn:hover {
    background-color: #1a472a;
    border-color: #4ade80;
}

/* Main Content */
.builder-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Chat Panel */
.chat-panel {
    width: 40%;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #333;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.message {
    margin-bottom: 16px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-content {
    padding: 12px 16px;
    border-radius: 4px;
    line-height: 1.5;
    font-size: 0.9rem;
}

.message.user .message-content {
    background-color: #1a1a2e;
    border: 1px solid #333;
    margin-left: 20%;
}

.message.assistant .message-content {
    background-color: #0f0f0f;
    border: 1px solid #222;
}

.message.error .message-content {
    background-color: #2a1515;
    border: 1px solid #5a2020;
    color: #ff6b6b;
}

/* Example Prompts */
.example-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 16px 20px;
    animation: fadeIn 0.3s ease;
}

.prompt-chip {
    background-color: #1a1a2e;
    border: 1px solid #333;
    color: #888;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 20px;
}

.prompt-chip:hover {
    background-color: #2a2a4e;
    border-color: #555;
    color: #fff;
}

/* Chat Input */
.chat-input-form {
    display: flex;
    gap: 10px;
    padding: 16px;
    border-top: 1px solid #333;
    background-color: #0a0a0a;
}

#chatInput {
    flex: 1;
    background-color: #111;
    border: 1px solid #333;
    color: #fff;
    padding: 12px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

#chatInput:focus {
    border-color: #555;
}

#chatInput::placeholder {
    color: #555;
}

#sendBtn {
    background-color: #fff;
    color: #000;
    border: none;
    padding: 12px 24px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

#sendBtn:hover {
    background-color: #ddd;
}

#sendBtn:disabled {
    background-color: #333;
    color: #666;
    cursor: not-allowed;
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #0a0a0a;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #222;
    font-size: 0.9rem;
    color: #888;
}

.run-btn {
    background-color: #1a472a;
    border: 1px solid #2d5a3d;
    color: #4ade80;
    padding: 6px 16px;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.run-btn:hover:not(:disabled) {
    background-color: #2d5a3d;
    border-color: #4ade80;
}

.run-btn:disabled {
    background-color: #1a1a1a;
    border-color: #333;
    color: #555;
    cursor: not-allowed;
}

.preview-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    min-height: 0;
}

.preview-placeholder {
    text-align: center;
    color: #444;
}

.preview-placeholder p {
    margin-bottom: 8px;
}

.preview-placeholder .hint {
    font-size: 0.8rem;
    color: #333;
}

#gamePreview {
    width: 400px;
    height: 400px;
    border: 1px solid #333;
    background-color: #000;
}

/* Code Viewer */
.code-toggle {
    padding: 8px 20px;
    border-top: 1px solid #222;
}

.toggle-btn {
    background: transparent;
    border: 1px solid #333;
    color: #666;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn:hover {
    border-color: #555;
    color: #888;
}

.code-viewer {
    max-height: 200px;
    overflow-y: auto;
    border-top: 1px solid #222;
    background-color: #0f0f0f;
}

.code-viewer pre {
    margin: 0;
    padding: 16px;
}

.code-viewer code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.8rem;
    color: #8b8b8b;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 2px solid #333;
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: #888;
    font-size: 0.9rem;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #111;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Responsive */
@media (max-width: 768px) {
    .builder-main {
        flex-direction: column;
    }

    .chat-panel {
        width: 100%;
        min-width: unset;
        height: 50%;
        border-right: none;
        border-bottom: 1px solid #333;
    }

    .preview-panel {
        height: 50%;
    }

    #gamePreview {
        width: 100%;
        max-width: 400px;
        height: auto;
        aspect-ratio: 1;
    }

    .message.user .message-content {
        margin-left: 10%;
    }
}
