:root {
    --bg: #000000;
    --surface: #000000;
    --surface-2: #111111;
    --border: rgba(255, 255, 255, 0.08);
    --text: #f0f0f0;
    --text-muted: #555;
    --user-bubble: #1e1e1e;
    --ai-bubble: #0d0d0d;
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
}

* { box-sizing: border-box; }

/* ── Loading Screen ── */
#loading-screen {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.6s ease;
}

#loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
}

#loader-grid {
    display: grid;
    grid-template-columns: repeat(10, 16px);
    grid-template-rows: repeat(8, 16px);
    gap: 3px;
}

.loader-cell {
    width: 16px;
    height: 16px;
    background: transparent;
    border-radius: 1px;
    transition: background 0.06s;
}

.loader-cell.active {
    background: #e8e8e8;
    animation: blockDrop 0.14s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes blockDrop {
    from { transform: translateY(-16px) scale(0.7); opacity: 0; }
    to   { transform: translateY(0)     scale(1);   opacity: 1; }
}

#loader-label {
    color: #2a2a2a;
    font-family: monospace;
    font-size: 13px;
    letter-spacing: 6px;
    animation: labelPulse 1.4s ease-in-out infinite;
}

@keyframes labelPulse {
    0%, 100% { opacity: 0.3; }
    50%       { opacity: 0.8; }
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

.chat-container {
    width: 680px;
    height: 92vh;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 0;
    border: none;
    overflow: hidden;
}

.chat-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 24px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#avatar-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
}

.chat-header h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.2px;
}

.header-subtitle {
    margin: 5px 0 0;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.45);
    text-align: center;
    letter-spacing: 0.2px;
}

.header-subtitle a {
    color: inherit;
    text-decoration: none;
}

.header-subtitle a:hover {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: underline;
    text-underline-offset: 3px;
}

#terminal-output {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#terminal-output::-webkit-scrollbar { width: 3px; }
#terminal-output::-webkit-scrollbar-track { background: transparent; }
#terminal-output::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
}

.msg {
    max-width: 72%;
    padding: 11px 15px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.msg-user {
    align-self: flex-end;
    background: var(--user-bubble);
    color: var(--text);
    border-radius: 18px 18px 4px 18px;
}

.msg-ai {
    align-self: flex-start;
    background: var(--ai-bubble);
    color: var(--text);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid var(--border);
}

.msg-system {
    align-self: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 2px 0;
}

.input-area {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
    gap: 10px;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    padding: 11px 16px;
    outline: none;
    transition: border-color 0.2s;
    -webkit-font-smoothing: antialiased;
}

#user-input:focus {
    border-color: rgba(255, 255, 255, 0.18);
}

#user-input::placeholder {
    color: var(--text-muted);
}

#ban-notice {
    display: none;
    padding: 10px 20px;
    text-align: center;
    color: #ff5555;
    font-size: 13px;
    border-top: 1px solid rgba(255, 85, 85, 0.2);
    background: rgba(255, 50, 50, 0.04);
}

#mute-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
}

#mute-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

#mute-btn.muted {
    color: #ff5555;
}

#clear-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
}

#clear-btn:hover {
    color: #ff5555;
    background: rgba(255, 85, 85, 0.08);
}

.chat-header h1 a {
    color: inherit;
    text-decoration: none;
}

.chat-header h1 a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

#mic-level {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 20px;
}

#mic-level span {
    width: 3px;
    background: #44dd44;
    border-radius: 2px;
    height: 4px;
    transition: height 0.08s ease;
}

/* ── Site Footer ── */
#site-footer {
    text-align: center;
    padding: 6px 16px 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#site-footer p {
    margin: 0;
    font-size: 10px;
    color: #2e2e2e;
    line-height: 1.7;
    letter-spacing: 0.2px;
}

@keyframes mic-bounce {
    from { height: 4px; }
    to   { height: 18px; }
}

#send-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
}

#send-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

#mic-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s, background 0.2s;
}

#mic-btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

#mic-btn.listening {
    color: #ff4444;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.rag-tag {
    display: block;
    margin-top: 6px;
    font-size: 11px;
    color: #444;
    letter-spacing: 0.3px;
}

/* ── Right Panel ── */
#right-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    position: relative;
    background: var(--surface);
}

/* Light theme overrides — scoped to right panel only */
#right-panel.theme-light {
    --surface: #ffffff;
    --surface-2: #f2f2f2;
    --border: rgba(0, 0, 0, 0.09);
    --text: #1a1a1a;
    --text-muted: #999;
    --user-bubble: #e4e4e4;
    --ai-bubble: #efefef;
}

/* ── Theme Toggle ── */
#theme-toggle {
    display: none; /* hidden on mobile */
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 10;
}

#theme-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}

#theme-btn:hover {
    color: var(--text);
    background: rgba(128, 128, 128, 0.1);
    border-color: rgba(128, 128, 128, 0.2);
}

#theme-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    min-width: 118px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.theme-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.theme-opt:hover {
    background: rgba(128, 128, 128, 0.1);
}

.theme-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    border: 1.5px solid var(--text-muted);
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
}

.theme-opt.active .theme-dot {
    background: var(--text);
    border-color: var(--text);
}

@media (min-width: 1024px) {
    .chat-container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100vw;
        height: 90vh;
    }
    .chat-header {
        grid-column: 1;
        grid-row: 1;
        flex-direction: column;
        justify-content: center;
        border-bottom: none;
        border-right: 1px solid var(--border);
        padding: 32px 24px;
        height: 100%;
    }
    #right-panel {
        grid-column: 2;
        grid-row: 1;
        height: 100%;
    }
    #theme-toggle {
        display: block;
    }
    .chat-header h1 {
        font-size: 32px;
        letter-spacing: 0.4px;
        margin-top: 38px;
    }
    .header-subtitle {
        font-size: 12px;
        margin-top: 8px;
    }
}

@media (max-width: 768px) {
    body {
        overflow-y: auto;
        align-items: flex-start;
        height: auto;
    }
    .chat-container {
        width: 100%;
        height: auto;
        min-height: 100vh;
    }
    .input-area {
        padding: 8px 8px;
        gap: 1px;
    }
    #user-input {
        font-size: 16px; /* 防止 iOS 自动缩放 */
        padding: 9px 10px;
    }
    #send-btn, #mic-btn, #mute-btn, #clear-btn {
        padding: 4px;
        min-width: 28px;
    }
}
