:root {
    /* Core Colors - Warm Beige Theme */
    --bg-main: #f5f5f0;
    /* 柔和的米色背景 */
    --bg-surface: #ffffff;
    /* 纯白表面 */
    --bg-card: #ffffff;
    --bg-input: #fcfcfc;

    /* Text Colors */
    --text-primary: #2c2c2a;
    /* 深炭灰，非纯黑 */
    --text-secondary: #6e6d69;
    --text-tertiary: #a1a09a;

    /* Accents - Terracotta/Clay */
    --accent-primary: #c26d53;
    --accent-secondary: #d98e77;
    --accent-gradient: linear-gradient(135deg, #c26d53 0%, #e08e75 100%);
    --accent-glow: rgba(194, 109, 83, 0.3);

    /* Selection */
    --selection-bg: #e6d0c9;
    --selection-text: #2c2c2a;

    /* Status */
    --status-online: #5da87e;
    /* Sage green */
    --status-waiting: #e0a665;
    --status-offline: #cf6666;

    /* Layout */
    --max-width: 768px;
    --shadow-soft: 0 4px 20px -2px rgba(44, 44, 42, 0.08);
    --shadow-card: 0 10px 30px -5px rgba(44, 44, 42, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

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

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

::-webkit-scrollbar-thumb {
    background: #dcdcd9;
    border-radius: 3px;
}

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

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    width: 100%;
    max-width: var(--max-width);
    position: relative;
    background: var(--bg-main);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.03);
}

@media (min-width: 769px) {
    #app {
        border-left: 1px solid rgba(0, 0, 0, 0.04);
        border-right: 1px solid rgba(0, 0, 0, 0.04);
    }
}

/* --- Header --- */
.header {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 28px;
    background: rgba(245, 245, 240, 0.85);
    /* Matches bg-main with opacity */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 10;
    position: sticky;
    top: 0;
}

.logo {
    font-size: 1.35rem;
    font-weight: 800;
    /* Extra bold */
    letter-spacing: -0.03em;
    color: var(--text-primary);
}

.presence-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(44, 44, 42, 0.04);
    padding: 6px 14px;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    transition: all 0.3s ease;
}

.presence-dot.online {
    background: var(--status-online);
    box-shadow: 0 0 0 3px rgba(93, 168, 126, 0.2);
}

.presence-dot.partial {
    background: var(--status-waiting);
}

/* --- Views --- */
.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* --- Authentication (Unauthorized & Secret) --- */
#view-unauthorized,
#view-secret {
    justify-content: center;
    align-items: center;
    padding: 32px;
}

.secret-modal {
    background: var(--bg-surface);
    padding: 48px;
    border-radius: 32px;
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-card);
    border: 1px solid rgba(255, 255, 255, 0.8);
    animation: modalSlideUp 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.secret-modal h2 {
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 1.75rem;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin-bottom: 36px;
    font-size: 1rem;
    line-height: 1.5;
}

#secret-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

input {
    width: 100%;
    padding: 16px 20px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: 16px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

input:focus {
    outline: none;
    background: #fff;
    border-color: var(--accent-secondary);
    box-shadow: 0 4px 12px rgba(194, 109, 83, 0.1);
}

input::placeholder {
    color: #bbbab5;
}

button {
    padding: 16px 24px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.01em;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--accent-glow);
    background: #b56046;
}

button:active {
    transform: translateY(0);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: #d4d4d0;
}

.error-message {
    color: var(--status-offline);
    margin-top: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    min-height: 20px;
}

/* --- Message Stream --- */
#view-main {
    background: var(--bg-main);
}

.message-stream {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    scroll-behavior: smooth;
}

.message-bubble {
    max-width: 85%;
    padding: 18px 24px;
    border-radius: 24px;
    position: relative;
    animation: messageEntry 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    font-size: 1.05rem;
    line-height: 1.6;
    word-wrap: break-word;
    box-shadow: var(--shadow-soft);
}

@keyframes messageEntry {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--accent-primary);
    background: var(--accent-gradient);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 8px 20px var(--accent-glow);
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-bubble .paragraph {
    margin-bottom: 0;
}

.message-bubble .paragraph+.paragraph {
    margin-top: 0.75em;
}

.copy-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.9);
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.message-bubble:hover .copy-button {
    opacity: 1;
    transform: scale(1);
}

.copy-button svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-secondary);
    transition: all 0.2s;
}

.copy-button:hover {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.copy-button:hover svg {
    stroke: var(--accent-primary);
}

.copy-button.copied {
    background: var(--status-online);
}

.copy-button.copied svg {
    stroke: white;
}

.message-status {
    font-size: 0.75rem;
    margin-top: 8px;
    text-align: right;
    opacity: 0.0;
    transition: opacity 0.3s;
    font-weight: 500;
}

.message-bubble:hover .message-status {
    opacity: 0.7;
}

/* --- Composer --- */
.composer {
    flex-shrink: 0;
    padding: 24px 32px;
    background: rgba(245, 245, 240, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(0, 0, 0, 0.03);
    /* subtle separator */
    display: flex;
    gap: 16px;
    align-items: flex-end;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

#composer-input {
    flex: 1;
    background: var(--bg-surface);
    border: none;
    border-radius: 20px;
    padding: 16px 20px;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    resize: none;
    max-height: 120px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

#composer-input:focus {
    outline: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05), 0 0 0 2px var(--accent-secondary);
}

.send-button {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.send-button svg {
    width: 24px;
    height: 24px;
    transform: translateX(2px);
    stroke-width: 2.5;
}

/* --- Unauthorized View --- */
#view-unauthorized h2 {
    color: var(--status-offline);
}

#device-id-display {
    display: block;
    margin-top: 24px;
    padding: 16px;
    background: #fdf2f2;
    border-radius: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.85rem;
    color: #9c4242;
    word-break: break-all;
    border: 1px dashed rgba(239, 68, 68, 0.2);
}

/* --- Media Queries --- */
@media (max-width: 600px) {
    .secret-modal {
        padding: 32px 24px;
    }

    .message-stream {
        padding: 16px 20px;
    }

    .composer {
        padding: 16px 20px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .message-bubble {
        max-width: 90%;
        padding: 14px 18px;
        font-size: 1rem;
    }
}