[data-theme="dark"] {
    --bg: #0a0a0a;
    --surface: #111111;
    --surface-elevated: #1a1a1a;
    --border: rgba(255, 255, 255, 0.12);
    --border-focus: rgba(255, 255, 255, 0.35);
    --text: #f5f5f5;
    --text-muted: #737373;
    --accent: #ffffff;
    --accent-text: #0a0a0a;
    --accent-hover: #e5e5e5;
    --user-bg: #262626;
    --composer-fade: rgba(10, 10, 10, 0.92);
    --shadow: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] {
    --bg: #ffffff;
    --surface: #f5f5f5;
    --surface-elevated: #ffffff;
    --border: rgba(0, 0, 0, 0.12);
    --border-focus: rgba(0, 0, 0, 0.35);
    --text: #0a0a0a;
    --text-muted: #525252;
    --accent: #0a0a0a;
    --accent-text: #ffffff;
    --accent-hover: #262626;
    --user-bg: #e5e5e5;
    --composer-fade: rgba(255, 255, 255, 0.92);
    --shadow: rgba(0, 0, 0, 0.08);
}

html {
    color-scheme: dark light;
}
[data-theme="dark"] { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

:root {
    --max-width: 768px;
    --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.45s ease, color 0.35s ease;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-image: url(../img/topography.svg);
    background-position: center;
    background-repeat: repeat;
    background-size: 800px;
}

.header {
    flex-shrink: 0;
    padding: 14px 48px 14px 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
    background: var(--surface);
    position: relative;
    transition: background 0.4s ease, border-color 0.4s ease;
}

.theme-toggle {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-elevated);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.25s, box-shadow 0.25s, transform 0.2s;
    box-shadow: 0 2px 8px var(--shadow);
}

.theme-toggle:hover {
    border-color: var(--border-focus);
    transform: translateY(-50%) scale(1.05);
}

.theme-toggle svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.header h1,
.header-brand {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.header p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px 16px;
    scroll-behavior: smooth;
    background: transparent;
}

.messages-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    gap: 16px;
    width: 100%;
    max-width: 100%;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
}

.message.assistant .avatar {
    background: var(--accent);
    color: var(--accent-text);
}

.message.user .avatar {
    background: var(--user-bg);
    color: var(--text-muted);
}

.bubble {
    flex: 0 1 auto;
    min-width: 0;
    font-size: 0.9375rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.bubble strong { font-weight: 700; }

.message.user .bubble {
    background: var(--user-bg);
    padding: 12px 16px;
    border-radius: var(--radius);
    max-width: 85%;
    margin-left: auto;
}

.message.assistant .bubble {
    background: var(--accent);
    color: var(--accent-text);
    padding: 12px 16px;
    border-radius: var(--radius);
    max-width: 85%;
    margin-right: auto;
}

.message.typing .bubble { color: var(--text-muted); }

.typing-dots span { animation: blink 1.4s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0%, 60%, 100% { opacity: 0.2; }
    30% { opacity: 1; }
}

.composer-wrap {
    flex-shrink: 0;
    padding: 12px 16px 24px;
    background: linear-gradient(transparent, var(--composer-fade) 40%);
    transition: background 0.4s ease;
}

.composer {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 8px 8px 8px 20px;
    box-shadow: 0 2px 12px var(--shadow);
    transition: border-color 0.25s, box-shadow 0.25s, background 0.4s ease;
}

.composer:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 2px 16px var(--shadow);
}

.composer textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9375rem;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    padding: 10px 0;
    outline: none;
    font-family: inherit;
}

.composer textarea::placeholder { color: var(--text-muted); }

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: scale(1.04);
}

.send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.send-btn svg { width: 18px; height: 18px; }

.footer-note {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 10px;
    max-width: var(--max-width);
    margin-left: auto;
    margin-right: auto;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (max-width: 640px) {
    .message.user .bubble,
    .message.assistant .bubble { max-width: 92%; }
    .avatar { display: none; }
    .message { gap: 0; }
}
