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

:root {
    --bg: #0f0f0f;
    --surface: #1a1a1a;
    --surface2: #242424;
    --border: #333;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #6c8cff;
    --accent-hover: #8da6ff;
    --danger: #ff4d4d;
    --user-bg: #1e2a4a;
    --ai-bg: #1a1a2e;
    --recording: #ff4d4d;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.screen {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Login */
.login-box {
    margin: auto;
    padding: 3rem;
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.login-box h1 {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.login-box input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    margin-bottom: 1rem;
    outline: none;
}

.login-box input:focus {
    border-color: var(--accent);
}

.login-box button {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.login-box button:hover {
    background: var(--accent-hover);
}

.error {
    color: var(--danger);
    margin-top: 1rem;
    font-size: 0.85rem;
    min-height: 1.2em;
}

/* Header */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.25rem;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

select {
    padding: 0.5rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

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

#reset-btn {
    padding: 0.5rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

#reset-btn:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* Prompt button */
#prompt-btn {
    padding: 0.5rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

#prompt-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.modal-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

#prompt-close-btn {
    padding: 0.4rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

#prompt-close-btn:hover {
    background: var(--accent-hover);
}

#system-prompt {
    width: 100%;
    padding: 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    resize: vertical;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    min-height: 120px;
}

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

/* Conversation */
#conversation {
    flex: 1;
    overflow-y: auto;
    overflow-anchor: none;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.message.user {
    background: var(--user-bg);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--ai-bg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message .role-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

/* Markdown content in AI messages */
.message.assistant .content {
    white-space: normal;
}

.message.assistant .content p {
    margin-bottom: 0.5em;
}

.message.assistant .content p:last-child {
    margin-bottom: 0;
}

.message.assistant .content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
    font-size: 0.85rem;
}

.message.assistant .content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.15em 0.35em;
    border-radius: 3px;
    font-size: 0.88em;
}

.message.assistant .content pre code {
    background: none;
    padding: 0;
}

.message.assistant .content ul,
.message.assistant .content ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

.message.assistant .content h1,
.message.assistant .content h2,
.message.assistant .content h3 {
    margin: 0.75em 0 0.25em;
    font-size: 1em;
    font-weight: 600;
}

.message.assistant .content h1 { font-size: 1.15em; }
.message.assistant .content h2 { font-size: 1.05em; }

/* Footer */
footer {
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    text-align: center;
}

/* Text input */
#text-input-row {
    display: flex;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0 auto 0.75rem;
}

#text-input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
}

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

#send-btn {
    padding: 0.6rem 1rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

#send-btn:hover {
    background: var(--accent-hover);
}

#record-btn {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
    background: var(--surface2);
    border: 2px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 0 auto;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    -webkit-touch-callout: none;
}

#record-btn:hover {
    border-color: var(--accent);
}

#record-btn.recording {
    background: rgba(255, 77, 77, 0.15);
    border-color: var(--recording);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.3); }
    50% { box-shadow: 0 0 0 10px rgba(255, 77, 77, 0); }
}

#record-icon {
    font-size: 1.5rem;
}

#status-bar {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    min-height: 1.2em;
}

/* Scrollbar */
#conversation::-webkit-scrollbar {
    width: 6px;
}

#conversation::-webkit-scrollbar-track {
    background: transparent;
}

#conversation::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .message {
        max-width: 95%;
    }

    header {
        padding: 0.75rem 1rem;
    }

    #conversation {
        padding: 1rem;
    }

    footer {
        padding: 0.75rem 1rem;
    }
}
