:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #151520;
    --gold: #d4af37;
    --gold-light: #f0d98c;
    --gold-dark: #b8962e;
    --text-primary: #e8e6e3;
    --text-secondary: #9e9b98;
    --ink-black: #1a1a24;
    --separator: rgba(212, 175, 55, 0.15);

    --font-serif: "Georgia", "Times New Roman", "Songti SC", "SimSun", serif;
    --font-display: "Ma Shan Zheng", "KaiTi", "楷体", cursive;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Background */
.bg-container {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
}

#bgCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.bg-overlay {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(212, 175, 55, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(212, 175, 55, 0.02) 0%, transparent 50%),
        linear-gradient(180deg, rgba(10, 10, 15, 0.7) 0%, rgba(21, 21, 32, 0.9) 100%);
    pointer-events: none;
}

/* Layout */
.app-layout {
    display: flex;
    width: 95%;
    max-width: 1300px;
    height: 90vh;
    background: rgba(26, 26, 36, 0.75);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid var(--separator);
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(212, 175, 55, 0.1);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.app-layout::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg,
            transparent,
            var(--gold) 30%,
            var(--gold) 70%,
            transparent);
    opacity: 0.3;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: rgba(10, 10, 15, 0.6);
    border-right: 1px solid var(--separator);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(180deg,
            transparent,
            var(--gold) 20%,
            var(--gold) 80%,
            transparent);
    opacity: 0.2;
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid var(--separator);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 0.95rem;
    color: var(--gold);
    font-family: var(--font-serif);
    font-weight: 400;
    letter-spacing: 3px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.history-item {
    padding: 14px 16px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.25s ease;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    font-family: var(--font-serif);
}

.history-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 0;
    background: var(--gold);
    transition: height 0.25s ease;
    border-radius: 0 2px 2px 0;
}

.history-item:hover {
    background: rgba(212, 175, 55, 0.06);
    border-color: rgba(212, 175, 55, 0.15);
    color: var(--gold-light);
}

.history-item:hover::before {
    height: 60%;
}

.history-item.active {
    background: rgba(212, 175, 55, 0.1);
    border-color: var(--gold);
    color: var(--gold);
}

.history-item.active::before {
    height: 80%;
}

.delete-history-item {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.25);
    cursor: pointer;
    font-size: 1.3rem;
    padding: 0 6px;
    opacity: 0;
    transition: all 0.2s;
    line-height: 1;
}

.history-item:hover .delete-history-item {
    opacity: 1;
}

.delete-history-item:hover {
    color: #d4534f;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--separator);
    text-align: center;
}

.text-btn {
    background: none;
    border: none;
    color: var(--gold);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-serif);
    letter-spacing: 2px;
    transition: all 0.3s;
    opacity: 0.7;
}

.text-btn:hover {
    opacity: 1;
    letter-spacing: 3px;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Header */
.app-header {
    padding: 0 40px;
    height: 85px;
    border-bottom: 1px solid var(--separator);
    background: rgba(10, 10, 15, 0.3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.app-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg,
            transparent,
            var(--gold) 30%,
            var(--gold) 70%,
            transparent);
    opacity: 0.2;
}

.title {
    font-family: var(--font-display);
    font-size: 2.8rem;
    background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-dark) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 12px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    filter: drop-shadow(0 2px 8px rgba(212, 175, 55, 0.3));
    display: flex;
    align-items: center;
    gap: 16px;
}

.title-decoration {
    font-size: 1.4rem;
    color: var(--gold);
    opacity: 0.6;
    animation: sparkle 3s ease-in-out infinite;
}

@keyframes sparkle {

    0%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.1);
    }
}

.icon-btn {
    background: rgba(212, 175, 55, 0.08);
    border: 1px solid rgba(212, 175, 55, 0.2);
    color: var(--gold);
    cursor: pointer;
    padding: 11px;
    border-radius: 8px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(212, 175, 55, 0.15);
    border-color: var(--gold);
    transform: translateY(-1px);
}

.new-chat-btn {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.06));
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 11px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-serif);
    font-size: 0.9rem;
    letter-spacing: 2px;
    display: flex;
    gap: 8px;
    align-items: center;
    transition: all 0.3s;
}

.new-chat-btn:hover {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.2), rgba(212, 175, 55, 0.1));
    box-shadow: 0 4px 16px rgba(212, 175, 55, 0.25);
    transform: translateY(-2px);
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 35px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    max-width: 80%;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.system-message {
    align-self: center;
    max-width: 100%;
}

.user-message {
    align-self: flex-end;
}

.ai-message {
    align-self: flex-start;
}

.message-content {
    padding: 20px 26px;
    border-radius: 12px;
    line-height: 1.9;
    background: rgba(26, 26, 36, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(212, 175, 55, 0.1);
    position: relative;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.message-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.15), transparent);
}

.system-message .message-content {
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.08), rgba(212, 175, 55, 0.03));
    border: 1px solid rgba(212, 175, 55, 0.25);
    color: var(--gold-light);
    text-align: center;
    font-family: var(--font-serif);
    font-size: 1.05rem;
    letter-spacing: 1px;
}

.user-message .message-content {
    background: rgba(212, 175, 55, 0.1);
    border-color: rgba(212, 175, 55, 0.3);
    color: var(--text-primary);
}

.ai-message .message-content {
    background: rgba(26, 26, 36, 0.8);
    border-color: rgba(212, 175, 55, 0.12);
    color: var(--text-primary);
}

/* Markdown Styling */
.message-content h1,
.message-content h2,
.message-content h3 {
    color: var(--gold);
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-family: var(--font-serif);
}

.message-content code {
    background: rgba(0, 0, 0, 0.4);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: var(--gold-light);
    font-size: 0.9em;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.5);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    border-left: 3px solid var(--gold);
    margin: 12px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

.message-content ul,
.message-content ol {
    margin-left: 28px;
    margin-top: 10px;
    margin-bottom: 10px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content a {
    color: var(--gold);
    text-decoration: underline;
    transition: all 0.2s;
}

.message-content a:hover {
    color: var(--gold-light);
}

/* Loading Indicator */
.typing-indicator {
    display: flex;
    gap: 7px;
    padding: 10px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold);
    animation: pulse 1.5s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.3;
        transform: scale(0.9);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* Input Area */
.input-area {
    padding: 28px 40px;
    border-top: 1px solid var(--separator);
    background: rgba(10, 10, 15, 0.5);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    position: relative;
}

.input-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold) 50%, transparent);
    opacity: 0.2;
}

.input-wrapper {
    display: flex;
    gap: 16px;
    align-items: flex-end;
}

#userInput {
    flex: 1;
    background: rgba(26, 26, 36, 0.6);
    border: 1px solid rgba(212, 175, 55, 0.2);
    color: var(--text-primary);
    padding: 16px 22px;
    border-radius: 10px;
    font-family: var(--font-serif);
    font-size: 1rem;
    resize: none;
    max-height: 140px;
    transition: all 0.3s;
    line-height: 1.6;
}

#userInput:focus {
    outline: none;
    border-color: var(--gold);
    background: rgba(26, 26, 36, 0.8);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

#userInput::placeholder {
    color: rgba(232, 230, 227, 0.3);
}

#sendBtn {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
    border: none;
    color: var(--ink-black);
    cursor: pointer;
    padding: 16px 22px;
    border-radius: 10px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

#sendBtn:hover {
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5);
    transform: translateY(-2px);
}

#sendBtn:active {
    transform: translateY(0);
}

/* Scrollbar */
.chat-container::-webkit-scrollbar,
.history-list::-webkit-scrollbar {
    width: 8px;
}

.chat-container::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb {
    background: var(--gold);
    border-radius: 4px;
    opacity: 0.6;
}

.chat-container::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--gold-light);
}

/* Mobile Styles - iOS优化 */
@media (max-width: 768px) {
    .app-layout {
        width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        border-radius: 0;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100%;
        transform: translateX(-100%);
        width: 80%;
        max-width: 300px;
        z-index: 101;
        box-shadow: 5px 0 20px rgba(0, 0, 0, 0.5);
        background: rgba(10, 10, 15, 0.85);
        -webkit-backdrop-filter: blur(20px);
        backdrop-filter: blur(20px);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    .title {
        font-size: 1.8rem;
        letter-spacing: 6px;
    }

    .app-header {
        padding: 0 15px;
        height: 65px;
        flex-shrink: 0;
    }

    .chat-container {
        padding: 15px;
        flex: 1;
        min-height: 0;
    }

    .message {
        max-width: 90%;
    }

    .message-content {
        padding: 14px 18px;
        font-size: 0.9rem;
        line-height: 1.5;
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', var(--font-body);
    }

    .system-message .message-content {
        font-size: 0.95rem;
    }

    .input-area {
        padding: 15px;
        flex-shrink: 0;
    }

    #userInput {
        font-size: 16px;
        padding: 12px 16px;
    }

    #sendBtn {
        padding: 12px 18px;
    }

    .new-chat-btn span {
        display: none;
    }
}

.mobile-only {
    display: none;
}