* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Theme defaults (dark) */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f0f23;
    --bg-accent: #0a3d8f;
    --bg-accent-hover: #072b6b;
    --bg-accent-muted: #2a3658;
    --text-primary: #eeeeee;
    --text-heading: #ffffff;
    --text-muted: #cbd5e1;
    --text-faint: #555555;
    --text-link: #4d9fff;
    --border-color: #334455;
    --border-focus: #0a3d8f;
    --error-bg: #dc2626;
    --copy-bg: #2a3658;
    --copy-fg: #8899bb;
    --copy-hover-bg: #3a4a70;
    --copy-hover-fg: #ccd5e8;
    --copied-bg: #1a4a2e;
    --copied-fg: #6fcf97;
    --copied-border: #2a5a3e;
    --disabled-bg: #4a4a6a;
    --msg-user-bg: var(--bg-accent);
    --msg-assistant-bg: var(--bg-tertiary);
    --blockquote-border: var(--bg-accent);
    --blockquote-fg: #aaaaaa;
    --table-header-bg: var(--bg-primary);
    --strong-fg: var(--text-heading);
    --hr-color: var(--border-color);
}

:root.light {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8ecf1;
    --bg-accent: #1a73e8;
    --bg-accent-hover: #1557b0;
    --bg-accent-muted: #d3e3fd;
    --text-primary: #1f1f1f;
    --text-heading: #111111;
    --text-muted: #5f6368;
    --text-faint: #999999;
    --text-link: #1a73e8;
    --border-color: #dadce0;
    --border-focus: #1a73e8;
    --error-bg: #d93025;
    --copy-bg: #e8ecf1;
    --copy-fg: #5f6368;
    --copy-hover-bg: #d3d8de;
    --copy-hover-fg: #1f1f1f;
    --copied-bg: #e6f4ea;
    --copied-fg: #137333;
    --copied-border: #a8dab5;
    --disabled-bg: #c4c7cc;
    --msg-user-bg: var(--bg-accent);
    --msg-assistant-bg: var(--bg-tertiary);
    --blockquote-border: var(--bg-accent);
    --blockquote-fg: #5f6368;
    --table-header-bg: var(--bg-tertiary);
    --strong-fg: var(--text-heading);
    --hr-color: var(--border-color);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary) url('https://veamcast.com/images/lighthouse18.jpg') no-repeat center center fixed;
    background-size: cover;
    color: var(--text-primary);
    min-height: 100vh;
}

.light body,
:root.light body {
    background-image: none;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header h1 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-heading);
}

.api-key-help {
    background: var(--bg-accent-muted);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.api-key-help a {
    color: var(--text-link);
    text-decoration: none;
}

.api-key-help a:hover {
    text-decoration: underline;
}

.settings {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    min-width: 80px;
    font-size: 14px;
}

.setting-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 14px;
}

.setting-row select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 18px;
}

.setting-row button {
    padding: 8px 16px;
    background: var(--bg-accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.setting-row button:hover {
    background: var(--bg-accent-hover);
}

.icon-btn {
    padding: 8px 10px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
}

.icon-btn svg {
    display: block;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.spin {
    animation: spin 0.8s linear infinite;
}

.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    position: relative;
}

/* Welcome overlay & theme toggle */
.welcome-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.welcome-overlay.hidden {
    display: none;
}

.welcome-view h2 {
    color: var(--text-heading);
    font-size: 1.6em;
    font-weight: 300;
    opacity: 0.7;
}

.theme-view {
    text-align: center;
}

.theme-label {
    color: var(--text-heading);
    font-size: 1.4em;
    font-weight: 300;
    margin-bottom: 8px;
}

.theme-hint {
    color: var(--text-faint);
    font-size: 0.85em;
}

.hidden {
    display: none !important;
}

.theme-btn {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: none;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, filter 0.2s;
    /* Dark mode = lit bulb */
    color: #f5c842;
    filter: drop-shadow(0 0 8px rgba(245, 200, 66, 0.6)) drop-shadow(0 0 20px rgba(245, 200, 66, 0.3));
}

.theme-btn:hover {
    color: #ffe082;
    filter: drop-shadow(0 0 12px rgba(245, 200, 66, 0.8)) drop-shadow(0 0 28px rgba(245, 200, 66, 0.4));
}

/* Light mode = unlit bulb */
:root.light .theme-btn {
    color: #999;
    filter: none;
}

:root.light .theme-btn:hover {
    color: #666;
    filter: none;
}

.message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 80%;
}

.message.user {
    background: var(--msg-user-bg);
    color: white;
    margin-left: auto;
}

.message.assistant {
    background: var(--msg-assistant-bg);
    position: relative;
}

.message.error {
    background: var(--error-bg);
    color: white;
}

.message pre {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    margin: 0;
}

.chat-form {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: var(--bg-tertiary);
}

.chat-form textarea {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    resize: none;
    font-family: inherit;
}

.chat-form textarea:focus {
    outline: none;
    border-color: var(--border-focus);
}

.chat-form button {
    padding: 12px 24px;
    background: var(--bg-accent);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.chat-form button.icon-btn {
    padding: 12px 16px;
}

.chat-form button:hover {
    background: var(--bg-accent-hover);
}

.chat-form button:disabled {
    background: var(--disabled-bg);
    cursor: not-allowed;
}

.streaming {
    opacity: 0.7;
}

.streaming::after {
    content: '|';
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Markdown rendered content */
.markdown-body {
    line-height: 1.6;
    word-break: break-word;
}

.markdown-body p {
    margin-bottom: 0.75em;
}

.markdown-body p:last-child {
    margin-bottom: 0;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: 0.75em 0 0.5em;
    color: var(--text-heading);
}

.markdown-body h1 { font-size: 1.4em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.1em; }

.markdown-body ul, .markdown-body ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.markdown-body li {
    margin-bottom: 0.25em;
}

.markdown-body code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: 'Consolas', 'Monaco', monospace;
}

.markdown-body .code-block {
    position: relative;
    margin: 0.75em 0;
}

.markdown-body .code-block pre {
    background: var(--bg-primary);
    padding: 12px;
    padding-right: 80px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0;
}

.markdown-body pre {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.75em 0;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    user-select: all;
    -webkit-user-select: all;
}

.copy-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--copy-bg);
    color: var(--copy-fg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    z-index: 1;
}

.code-block:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: var(--copy-hover-bg);
    color: var(--copy-hover-fg);
}

.copy-btn.copied {
    background: var(--copied-bg);
    color: var(--copied-fg);
    border-color: var(--copied-border);
    opacity: 1;
}

.markdown-body blockquote {
    border-left: 3px solid var(--blockquote-border);
    padding-left: 12px;
    margin: 0.75em 0;
    color: var(--blockquote-fg);
}

.markdown-body a {
    color: var(--text-link);
}

.markdown-body table {
    border-collapse: collapse;
    margin: 0.75em 0;
    width: 100%;
}

.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}

.markdown-body th {
    background: var(--table-header-bg);
}

.markdown-body strong {
    color: var(--strong-fg);
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--hr-color);
    margin: 1em 0;
}

.usage-info {
    position: absolute;
    bottom: 4px;
    right: 8px;
    font-size: 10px;
    font-style: italic;
    color: var(--text-faint);
}

/* ── Tab bar ── */
.tab-bar {
    display: flex;
    gap: 2px;
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    flex-shrink: 0;
}

.tab-bar::-webkit-scrollbar {
    height: 4px;
}

.tab-bar::-webkit-scrollbar-track {
    background: transparent;
}

.tab-bar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: none;
    border-radius: 6px 6px 0 0;
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.15s, box-shadow 0.15s;
    position: relative;
}

.tab-item .tab-icon {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    opacity: 0.7;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.tab-item .tab-label {
    background: linear-gradient(135deg, #4d9fff 0%, #a855f7 50%, #ec4899 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.tab-item:hover .tab-label {
    opacity: 0.85;
}

.tab-item:hover .tab-icon {
    opacity: 0.85;
}

.tab-item:hover {
    background: var(--bg-secondary);
}

.tab-item.active {
    background: var(--bg-secondary);
    box-shadow: inset 0 2px 0 0 #a855f7;
}

.tab-item.active .tab-label {
    background: linear-gradient(135deg, #60b0ff 0%, #c084fc 50%, #f472b6 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 1;
    font-weight: 600;
}

.tab-item.active .tab-icon {
    color: #a855f7;
    opacity: 1;
}

/* Light mode tab adjustments */
:root.light .tab-item .tab-label {
    background: linear-gradient(135deg, #1a73e8 0%, #7c3aed 50%, #db2777 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

:root.light .tab-item.active .tab-label {
    background: linear-gradient(135deg, #1557b0 0%, #6d28d9 50%, #be185d 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

:root.light .tab-item.active {
    box-shadow: inset 0 2px 0 0 #7c3aed;
}

:root.light .tab-item.active .tab-icon {
    color: #7c3aed;
}

.tab-notice {
    padding: 6px 14px;
    background: var(--bg-accent-muted);
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    text-align: center;
    border-top: 1px solid var(--border-color);
    transition: opacity 0.3s;
}

.tab-notice.hidden {
    opacity: 0;
    pointer-events: none;
}
