/* =========================================
   青 — Harrison He's Soul Fragment (分魂)
   Dark Chinese Ink Wash (水墨) Theme
   ========================================= */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Serif+SC:wght@400;700&display=swap');

/* ---------- CSS Variables ---------- */
:root {
    --bg-void: #050507;
    --bg-base: #0a0a0c;
    --bg-surface: #111114;
    --bg-card: rgba(255, 255, 255, 0.02);
    --bg-message-harrison: rgba(184, 168, 154, 0.08);
    --bg-message-user: rgba(107, 123, 141, 0.12);

    --text-primary: #e8e0d4;
    --text-secondary: #8a817a;
    --text-muted: #5a534d;

    --accent-ink: #b8a89a;
    --accent-mist: #6b7b8d;
    --accent-warm: #c4a882;
    --accent-gold: #d4b896;

    --gradient-ink: linear-gradient(135deg, var(--accent-mist), var(--accent-ink));
    --gradient-mist: linear-gradient(180deg, rgba(107, 123, 141, 0.06), transparent);

    --font-main: 'Inter', sans-serif;
    --font-cn: 'Noto Serif SC', serif;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- Reset ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    height: 100%;
}

body {
    background-color: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.6;
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none;
    color: inherit;
}

/* =========================================
   Landing / Intro Screen
   ========================================= */
#landing-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-void);
    transition: opacity 1.2s ease, transform 1.2s ease;
    cursor: pointer;
}

#landing-screen.fade-out {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}

.landing-glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    opacity: 0.2;
}

.landing-glow-1 {
    width: 500px;
    height: 500px;
    top: 20%;
    left: 30%;
    background: radial-gradient(circle, rgba(184, 168, 154, 0.3), transparent 70%);
    animation: glowPulse 6s ease-in-out infinite;
}

.landing-glow-2 {
    width: 400px;
    height: 400px;
    bottom: 20%;
    right: 25%;
    background: radial-gradient(circle, rgba(107, 123, 141, 0.25), transparent 70%);
    animation: glowPulse 8s ease-in-out infinite 2s;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.15; transform: scale(1); }
    50% { opacity: 0.3; transform: scale(1.1); }
}

.landing-character {
    font-family: var(--font-cn);
    font-size: clamp(5rem, 15vw, 12rem);
    font-weight: 700;
    color: transparent;
    background: linear-gradient(180deg, var(--accent-ink), var(--text-muted));
    -webkit-background-clip: text;
    background-clip: text;
    letter-spacing: 0.3em;
    opacity: 0;
    animation: characterReveal 2s ease-out 0.5s forwards;
    filter: drop-shadow(0 0 40px rgba(184, 168, 154, 0.15));
    position: relative;
    z-index: 2;
    user-select: none;
}

@keyframes characterReveal {
    0% { opacity: 0; transform: translateY(30px) scale(0.9); letter-spacing: 0.8em; }
    60% { opacity: 1; }
    100% { opacity: 1; transform: translateY(0) scale(1); letter-spacing: 0.3em; }
}

.landing-subtitle {
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    color: var(--text-muted);
    letter-spacing: 4px;
    text-transform: uppercase;
    margin-top: 1.5rem;
    opacity: 0;
    animation: subtitleReveal 1.5s ease-out 2s forwards;
    position: relative;
    z-index: 2;
    font-weight: 300;
}

@keyframes subtitleReveal {
    0% { opacity: 0; transform: translateY(15px); }
    100% { opacity: 0.6; transform: translateY(0); }
}

.landing-enter {
    margin-top: 3rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 3px;
    text-transform: uppercase;
    opacity: 0;
    animation: enterPulse 2s ease-in-out 3s infinite, subtitleReveal 1s ease-out 3s forwards;
    position: relative;
    z-index: 2;
}

@keyframes enterPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* =========================================
   Main Chat Interface
   ========================================= */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    opacity: 0;
    transition: opacity 0.8s ease 0.5s;
    background:
        radial-gradient(ellipse at 15% 30%, rgba(80, 70, 60, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 70%, rgba(60, 70, 80, 0.04) 0%, transparent 50%),
        var(--bg-base);
}

#app.visible {
    opacity: 1;
}

/* ---------- Header ---------- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.2rem 2rem;
    background: rgba(10, 10, 12, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(184, 168, 154, 0.06);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

.chat-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(184, 168, 154, 0.15), transparent);
}

.header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(184, 168, 154, 0.15);
    filter: grayscale(0.3) contrast(1.05);
    transition: var(--transition-smooth);
}

.header-avatar:hover {
    filter: grayscale(0) contrast(1.1);
    border-color: rgba(184, 168, 154, 0.3);
    box-shadow: 0 0 20px rgba(184, 168, 154, 0.1);
}

.header-info {
    flex: 1;
}

.header-name {
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 1px;
    color: var(--text-primary);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-ink);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 0.5; box-shadow: 0 0 0 0 rgba(184, 168, 154, 0.3); }
    50% { opacity: 1; box-shadow: 0 0 8px 3px rgba(184, 168, 154, 0.15); }
}

.header-quote {
    font-family: var(--font-cn);
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    opacity: 0.6;
    transition: var(--transition-smooth);
    display: none;
}

@media (min-width: 768px) {
    .header-quote {
        display: block;
    }
}

.header-quote:hover {
    opacity: 1;
    color: var(--accent-ink);
}

/* ---------- Messages Area ---------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    scroll-behavior: smooth;
    position: relative;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(184, 168, 154, 0.15);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(184, 168, 154, 0.3);
}

/* ---------- Message Bubbles ---------- */
.message {
    display: flex;
    gap: 0.8rem;
    max-width: 75%;
    opacity: 0;
    transform: translateY(12px);
    animation: messageIn 0.4s ease-out forwards;
}

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

.message-harrison,
.message-qing {
    align-self: flex-start;
}

.message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid rgba(184, 168, 154, 0.1);
    filter: grayscale(0.4);
    margin-top: 4px;
}

.message-user .message-avatar {
    display: none;
}

.message-bubble {
    padding: 0.9rem 1.2rem;
    border-radius: var(--radius-lg);
    font-size: 0.92rem;
    line-height: 1.65;
    font-weight: 400;
    position: relative;
    word-wrap: break-word;
}

.message-harrison .message-bubble,
.message-qing .message-bubble {
    background: var(--bg-message-harrison);
    border: 1px solid rgba(184, 168, 154, 0.06);
    border-left: 2px solid rgba(184, 168, 154, 0.2);
    border-top-left-radius: var(--radius-sm);
    color: var(--text-primary);
}

.message-user .message-bubble {
    background: var(--bg-message-user);
    border: 1px solid rgba(107, 123, 141, 0.1);
    border-top-right-radius: var(--radius-sm);
    color: var(--text-primary);
}

/* ---------- Typing Indicator ---------- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    max-width: 75%;
    align-self: flex-start;
    opacity: 0;
    animation: messageIn 0.3s ease-out forwards;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 1rem 1.2rem;
    background: var(--bg-message-harrison);
    border: 1px solid rgba(184, 168, 154, 0.06);
    border-left: 2px solid rgba(184, 168, 154, 0.2);
    border-radius: var(--radius-lg);
    border-top-left-radius: var(--radius-sm);
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-ink);
    opacity: 0.4;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Suggestions / Quick Chips ---------- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0 2rem;
    margin-bottom: 0.5rem;
    opacity: 0;
    transform: translateY(8px);
    transition: var(--transition-smooth);
}

.chat-suggestions.visible {
    opacity: 1;
    transform: translateY(0);
}

.suggestion-chip {
    padding: 0.45rem 1rem;
    background: rgba(184, 168, 154, 0.06);
    border: 1px solid rgba(184, 168, 154, 0.1);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 400;
    cursor: pointer;
    transition: var(--transition-fast);
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.suggestion-chip:hover {
    background: rgba(184, 168, 154, 0.12);
    border-color: rgba(184, 168, 154, 0.25);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.suggestion-chip:active {
    transform: translateY(0);
}

/* ---------- Input Bar ---------- */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 1rem 2rem 1.5rem;
    background: rgba(10, 10, 12, 0.8);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(184, 168, 154, 0.04);
    position: relative;
    flex-shrink: 0;
}

.chat-input-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(184, 168, 154, 0.1), transparent);
}

#chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(184, 168, 154, 0.08);
    border-radius: var(--radius-xl);
    padding: 0.8rem 1.4rem;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-smooth);
    caret-color: var(--accent-ink);
}

#chat-input::placeholder {
    color: var(--text-muted);
    font-weight: 300;
}

#chat-input:focus {
    border-color: rgba(184, 168, 154, 0.2);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 0 3px rgba(184, 168, 154, 0.04);
}

#chat-send {
    width: 42px;
    height: 42px;
    border: none;
    background: rgba(184, 168, 154, 0.1);
    border: 1px solid rgba(184, 168, 154, 0.15);
    border-radius: 50%;
    color: var(--accent-ink);
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition-spring);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-send:hover {
    background: rgba(184, 168, 154, 0.2);
    border-color: rgba(184, 168, 154, 0.3);
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

#chat-send:active {
    transform: scale(0.95);
}

#chat-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    transform: rotate(-45deg);
    transition: var(--transition-fast);
}

#chat-send:hover svg {
    transform: rotate(-45deg) translateX(1px);
}

/* ---------- Ink Particles Container ---------- */
#ink-particles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.ink-particle {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184, 168, 154, var(--particle-opacity, 0.1)), transparent);
    animation: inkFloat var(--duration, 15s) ease-in-out var(--delay, 0s) infinite;
}

@keyframes inkFloat {
    0%, 100% {
        transform: translateY(0) translateX(0) scale(1);
        opacity: var(--particle-opacity, 0.1);
    }
    25% {
        transform: translateY(calc(var(--drift-y, -40px))) translateX(calc(var(--drift-x, 20px))) scale(1.3);
        opacity: calc(var(--particle-opacity, 0.1) * 2.5);
    }
    50% {
        transform: translateY(calc(var(--drift-y, -40px) * 2)) translateX(calc(var(--drift-x, 20px) * -0.5)) scale(1);
        opacity: calc(var(--particle-opacity, 0.1) * 1.5);
    }
    75% {
        transform: translateY(calc(var(--drift-y, -40px) * 0.7)) translateX(calc(var(--drift-x, 20px) * 1.2)) scale(1.2);
        opacity: calc(var(--particle-opacity, 0.1) * 2);
    }
}

/* ---------- Welcome Message ---------- */
.welcome-message {
    text-align: center;
    padding: 2rem 1rem;
    opacity: 0;
    animation: messageIn 0.6s ease-out 0.3s forwards;
}

.welcome-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(184, 168, 154, 0.12);
    margin-bottom: 1rem;
    filter: grayscale(0.3);
    transition: var(--transition-smooth);
}

.welcome-avatar:hover {
    filter: grayscale(0);
    border-color: rgba(184, 168, 154, 0.3);
    box-shadow: 0 0 30px rgba(184, 168, 154, 0.1);
    transform: scale(1.05);
}

.welcome-title {
    font-family: var(--font-cn);
    font-size: 1.3rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
    letter-spacing: 2px;
}

.welcome-sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 300;
    letter-spacing: 0.5px;
    max-width: 400px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---------- Message timestamp ---------- */
.message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    opacity: 0;
    transition: var(--transition-fast);
}

.message:hover .message-time {
    opacity: 0.7;
}

/* ---------- Quote decoration on 青's messages ---------- */
.message-harrison .message-bubble .quote-line,
.message-qing .message-bubble .quote-line {
    display: block;
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(184, 168, 154, 0.08);
    font-family: var(--font-cn);
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    letter-spacing: 1px;
}

/* =========================================
   Responsive
   ========================================= */
@media (max-width: 768px) {
    .chat-messages {
        padding: 1rem;
        gap: 0.8rem;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-bar {
        padding: 0.8rem 1rem 1.2rem;
    }

    .chat-header {
        padding: 1rem 1.2rem;
    }

    .chat-suggestions {
        padding: 0 1rem;
    }

    .landing-character {
        font-size: clamp(4rem, 20vw, 8rem);
    }
}

@media (max-width: 480px) {
    .message {
        max-width: 95%;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
    }

    .message-bubble {
        font-size: 0.88rem;
        padding: 0.7rem 1rem;
    }

    .suggestion-chip {
        font-size: 0.75rem;
        padding: 0.35rem 0.8rem;
    }
}

/* =========================================
   Utility Animations
   ========================================= */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Ink ripple effect on send */
@keyframes inkRipple {
    0% {
        box-shadow: 0 0 0 0 rgba(184, 168, 154, 0.3);
    }
    100% {
        box-shadow: 0 0 0 15px rgba(184, 168, 154, 0);
    }
}

.ink-ripple {
    animation: inkRipple 0.6s ease-out;
}

/* =========================================
   API Key Modal
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(5, 5, 7, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.modal-overlay.visible {
    opacity: 1;
}

.modal-card {
    background: rgba(17, 17, 20, 0.95);
    border: 1px solid rgba(184, 168, 154, 0.1);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    max-width: 440px;
    width: 90%;
    text-align: center;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: translateY(20px);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.visible .modal-card {
    transform: translateY(0);
}

.modal-icon {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    filter: grayscale(0.3);
}

.modal-title {
    font-family: var(--font-cn);
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 0.8rem;
    letter-spacing: 2px;
}

.modal-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    font-weight: 300;
    margin-bottom: 0.5rem;
}

.modal-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 1.5rem;
}

.modal-hint a {
    color: var(--accent-ink);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.modal-hint a:hover {
    color: var(--text-primary);
}

.modal-input-group {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.modal-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(184, 168, 154, 0.12);
    border-radius: var(--radius-md);
    padding: 0.8rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
    caret-color: var(--accent-ink);
}

.modal-input::placeholder {
    color: var(--text-muted);
    font-weight: 300;
}

.modal-input:focus {
    border-color: rgba(184, 168, 154, 0.25);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 3px rgba(184, 168, 154, 0.05);
}

.modal-btn {
    border: none;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.85rem;
    border-radius: var(--radius-md);
    transition: var(--transition-smooth);
    letter-spacing: 0.5px;
}

.modal-btn-primary {
    background: rgba(184, 168, 154, 0.15);
    color: var(--text-primary);
    border: 1px solid rgba(184, 168, 154, 0.2);
    padding: 0.8rem 1.5rem;
    white-space: nowrap;
}

.modal-btn-primary:hover {
    background: rgba(184, 168, 154, 0.25);
    border-color: rgba(184, 168, 154, 0.4);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.modal-btn-skip {
    background: transparent;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

.modal-btn-skip:hover {
    color: var(--text-secondary);
}

/* Setup key button in welcome message */
.setup-key-btn {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.6rem 1.2rem;
    background: rgba(184, 168, 154, 0.1);
    border: 1px solid rgba(184, 168, 154, 0.15);
    border-radius: var(--radius-md);
    color: var(--accent-ink);
    font-family: var(--font-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    letter-spacing: 0.5px;
}

.setup-key-btn:hover {
    background: rgba(184, 168, 154, 0.2);
    border-color: rgba(184, 168, 154, 0.3);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
