:root {
    --font-heading: 'Quicksand', sans-serif;
    --font-body: 'Nunito', sans-serif;
    --transition-speed: 0.4s;
    --shadow-soft: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 15px 40px -10px rgba(0, 0, 0, 0.15);
    --radius-large: 24px;
    --radius-medium: 16px;
    --radius-small: 8px;
    
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --chat-bg: rgba(255, 255, 255, 0.85);
    --text-primary: #3d4655;
    --text-secondary: #64748b;
    --accent-color: #667eea;
    --accent-hover: #5a67d8;
    --message-me-bg: #667eea;
    --message-me-text: #ffffff;
    --message-peer-bg: rgba(0, 0, 0, 0.05);
    --message-peer-text: #2d3748;
    --input-bg: rgba(255, 255, 255, 0.7);
    --border-color: rgba(0,0,0,0.08);
}

[data-theme='cloud'] {
    --bg-gradient: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);
    --chat-bg: rgba(240, 248, 255, 0.8);
    --text-primary: #4a5568;
    --text-secondary: #718096;
    --accent-color: #89a8ff;
    --accent-hover: #7694ea;
    --message-me-bg: #89a8ff;
    --message-me-text: #ffffff;
    --message-peer-bg: rgba(255, 255, 255, 0.5);
    --message-peer-text: #42526e;
    --border-color: rgba(137, 168, 255, 0.2);
}

[data-theme='warm'] {
    --bg-gradient: linear-gradient(120deg, #f6d365 0%, #fda085 100%);
    --chat-bg: rgba(255, 250, 240, 0.8);
    --text-primary: #5d4037;
    --text-secondary: #8d6e63;
    --accent-color: #ffb74d;
    --accent-hover: #ffa726;
    --message-me-bg: #ffcc80;
    --message-me-text: #5d4037;
    --message-peer-bg: rgba(255, 255, 255, 0.5);
    --message-peer-text: #6d4c41;
    --border-color: rgba(255, 183, 77, 0.2);
}

[data-theme='night'] {
    --bg-gradient: linear-gradient(to top, #1e3c72 0%, #2a5298 100%);
    --chat-bg: rgba(26, 32, 44, 0.85);
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --accent-color: #ab47bc;
    --accent-hover: #9c27b0;
    --message-me-bg: #7e57c2;
    --message-me-text: #ffffff;
    --message-peer-bg: rgba(255, 255, 255, 0.1);
    --message-peer-text: #f8fafc;
    --input-bg: rgba(0, 0, 0, 0.2);
    --border-color: rgba(255,255,255,0.1);
}

body {
    font-family: var(--font-body);
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    margin: 0;
    overflow: hidden;
}

header { display: none; }

.main-content {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}

main {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.chat-container {
    width: 95%;
    max-width: 1100px;
    height: 92vh;
    background: var(--chat-bg);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
}

#chat-header {
    padding: 16px 24px;
    background: rgba(255,255,255,0.05);
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-heading);
}

#chat-header-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

[data-theme='night'] #chat-header-title { color: #ffffff; }

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.theme-picker {
    position: fixed;
    top: 24px;
    right: 24px;
    display: flex;
    gap: 12px;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 12px;
    border-radius: 50px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    align-items: center;
}

.feedback-trigger {
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--text-primary);
    opacity: 0.7;
    transition: all 0.3s ease;
}

.feedback-trigger:hover {
    opacity: 1;
    transform: scale(1.1);
}

.feedback-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.feedback-content {
    background: var(--chat-bg);
    padding: 30px;
    border-radius: var(--radius-large);
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-color);
    animation: floatIn 0.4s ease-out;
}

[data-theme='night'] .feedback-trigger {
    color: white;
}

.theme-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.8);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.theme-btn:hover { transform: scale(1.2); }

.mobile-theme-picker {
    display: flex;
    gap: 15px;
    justify-content: center;
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
}

.mobile-welcome-theme-picker {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: -20px;
}

.mobile-welcome-theme-picker .theme-btn {
    width: 35px;
    height: 35px;
    border: 3px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

#welcome-screen, #ending-screen {
    width: 90%;
    max-width: 500px;
    padding: 40px;
    background: var(--chat-bg);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
    text-align: center;
    animation: floatIn 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

#welcome-screen h1 {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--accent-color);
    margin-bottom: 1rem;
    font-size: 2.5rem;
}

.huhu-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 14px 48px;
    border-radius: 50px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    margin-top: 20px;
    letter-spacing: 1px;
}

.huhu-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 12px 25px rgba(0,0,0,0.15);
}

.huhu-btn:active { transform: translateY(-1px) scale(0.98); }

#chat-window {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 0;
}

.message {
    max-width: 75%;
    padding: 8px 14px;
    border-radius: 14px;
    font-size: 1rem;
    line-height: 1.4;
    position: relative;
    animation: messagePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.my-message {
    align-self: flex-end;
    background: var(--message-me-bg);
    color: var(--message-me-text);
    border-bottom-right-radius: 2px;
}

.my-message::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 8px;
    height: 10px;
    background: var(--message-me-bg);
    clip-path: polygon(0 0, 0% 100%, 100% 100%);
}

.peer-message {
    align-self: flex-start;
    background: var(--message-peer-bg);
    color: var(--message-peer-text);
    border-bottom-left-radius: 2px;
}

.peer-message::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 8px;
    height: 10px;
    background: var(--message-peer-bg);
    clip-path: polygon(100% 0, 0% 100%, 100% 100%);
}

.text-muted { color: var(--text-secondary) !important; }
[data-theme='night'] .text-muted { color: #cbd5e1 !important; opacity: 0.9; }

.system-message-container {
    width: 100%;
    text-align: center;
    margin: 16px 0;
}

.system-message {
    font-size: 0.8em;
    color: var(--text-secondary);
    background: rgba(128, 128, 128, 0.15);
    padding: 4px 16px;
    border-radius: 50px;
    display: inline-block;
    backdrop-filter: blur(5px);
}

[data-theme='night'] .system-message { background: rgba(255, 255, 255, 0.15); color: #ffffff; }

.reply-info {
    font-size: 0.75em;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: inherit;
    width: fit-content;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-info::before { content: '↸'; font-size: 1.1em; opacity: 0.7; }
.reply-info:hover { background: rgba(0, 0, 0, 0.15); transform: translateY(-1px); box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.my-message .reply-info { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.2); }
.my-message .reply-info:hover { background: rgba(255, 255, 255, 0.3); }
[data-theme='night'] .reply-info { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.1); }
[data-theme='night'] .reply-info:hover { background: rgba(255, 255, 255, 0.2); }

#cancel-huhu {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.3s ease;
    margin-top: 15px;
    display: inline-block;
    padding: 8px 20px;
    border-radius: 50px;
}

#cancel-huhu:hover { background: rgba(0,0,0,0.05); color: var(--text-primary); }
[data-theme='night'] #cancel-huhu:hover { background: rgba(255,255,255,0.1); color: white; }

#input-area {
    padding: 10px 24px;
    background: transparent;
    display: flex;
    gap: 12px;
    align-items: center;
    border-top: 1px solid var(--border-color);
}

#message-input {
    flex: 1;
    border-radius: 50px;
    border: 2px solid var(--border-color);
    padding: 12px 20px;
    background: var(--input-bg);
    color: var(--text-primary);
}

#message-input::placeholder { color: var(--text-secondary); opacity: 0.7; }
[data-theme='night'] #message-input::placeholder { color: #cbd5e1; opacity: 0.8; }

.btn-primary {
    background: var(--accent-color);
    border: none;
    border-radius: 50px;
    padding: 10px 24px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-2px); }

.btn-outline-primary, .btn-outline-secondary, .btn-outline-danger {
    border-radius: 50px;
    padding: 6px 16px;
    font-weight: 600;
    transition: all 0.3s ease;
}

#typing-indicator { color: var(--text-secondary); }
[data-theme='night'] #typing-indicator { color: #cbd5e1 !important; font-weight: 600; }

.match-transition {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.8s ease;
}

.match-transition.active { opacity: 1; pointer-events: auto; }

.match-story {
    font-family: var(--font-heading);
    font-size: 2rem;
    color: white;
    text-align: center;
    animation: storyPulse 2.5s ease-in-out forwards;
}

@keyframes storyPulse {
    0% { transform: scale(0.9); opacity: 0; }
    30% { transform: scale(1); opacity: 1; }
    70% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.1); opacity: 0; }
}

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

@keyframes messagePop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.huhu-loader {
    font-size: 4rem;
    display: inline-block;
    animation: huhuDeepBreath 4s ease-in-out infinite;
    user-select: none;
    position: relative;
}

@keyframes huhuDeepBreath {
    0%, 100% { 
        transform: scale(0.7);
        opacity: 0.3;
        filter: blur(2px) drop-shadow(0 0 5px rgba(255, 100, 150, 0.2));
    }
    50% { 
        transform: scale(1.4);
        opacity: 1;
        filter: blur(0px) drop-shadow(0 0 35px rgba(255, 100, 150, 0.7));
    }
}

[data-theme='cloud'] .huhu-loader {
    animation-name: huhuDeepBreathCloud;
}

[data-theme='warm'] .huhu-loader {
    animation-name: huhuDeepBreathWarm;
}

[data-theme='night'] .huhu-loader {
    animation-name: huhuDeepBreathNight;
}

@keyframes huhuDeepBreathCloud {
    0%, 100% { transform: scale(0.7); opacity: 0.3; filter: blur(2px) drop-shadow(0 0 5px rgba(142, 197, 252, 0.2)); }
    50% { transform: scale(1.4); opacity: 1; filter: blur(0px) drop-shadow(0 0 35px rgba(142, 197, 252, 0.8)); }
}

@keyframes huhuDeepBreathWarm {
    0%, 100% { transform: scale(0.7); opacity: 0.3; filter: blur(2px) drop-shadow(0 0 5px rgba(253, 160, 133, 0.2)); }
    50% { transform: scale(1.4); opacity: 1; filter: blur(0px) drop-shadow(0 0 35px rgba(253, 160, 133, 0.8)); }
}

@keyframes huhuDeepBreathNight {
    0%, 100% { transform: scale(0.7); opacity: 0.3; filter: blur(2px) drop-shadow(0 0 5px rgba(171, 71, 188, 0.2)); }
    50% { transform: scale(1.4); opacity: 1; filter: blur(0px) drop-shadow(0 0 35px rgba(171, 71, 188, 0.8)); }
}

.huhu-animation {
    position: fixed;
    font-size: 4rem;
    pointer-events: none;
    z-index: 9999;
}

#mobile-menu-toggle { z-index: 2001; }
[data-theme='night'] #mobile-menu-toggle { color: white !important; }

@media (max-width: 768px) {
    #chat-header {
        padding: 15px 20px;
        padding-top: calc(40px + env(safe-area-inset-top));
        min-height: calc(90px + env(safe-area-inset-top));
        display: flex;
        align-items: center;
        background: var(--chat-bg);
        backdrop-filter: blur(15px);
        z-index: 1000;
    }

    #mobile-menu-toggle {
        padding: 10px !important;
        margin-right: -10px;
        color: var(--text-primary) !important;
        background: transparent;
        border: none;
    }

    .header-actions {
        position: absolute;
        top: calc(90px + env(safe-area-inset-top));
        right: 15px;
        flex-direction: column;
        background: var(--chat-bg);
        padding: 20px;
        border-radius: 20px;
        box-shadow: 0 15px 35px rgba(0,0,0,0.2);
        border: 1px solid var(--border-color);
        display: none !important;
        z-index: 2000;
        backdrop-filter: blur(20px);
        width: 200px;
    }

    .header-actions.active { display: flex !important; }

    .chat-container {
        height: 100vh;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
    }
    
    .theme-picker {
        display: none !important;
    }
}
