@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@400;600&display=swap');

:root {
    --bg-top: #ffe5c8;
    --bg-bottom: #ffd0d4;
    --surface: rgba(255, 255, 255, 0.96);
    --primary: #f28a62;
    --primary-strong: #ef6a7c;
    --accent: #ffce6d;
    --mint: #87f5e0;
    --text: #4a2b33;
    --muted: #7a5560;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.08);
    --glow: 0 0 0 10px rgba(255, 206, 109, 0.18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, rgba(255, 206, 109, 0.28), transparent 35%),
                radial-gradient(circle at 80% 30%, rgba(239, 106, 124, 0.25), transparent 40%),
                radial-gradient(circle at 50% 80%, rgba(135, 245, 224, 0.25), transparent 40%),
                linear-gradient(135deg, var(--bg-top), var(--bg-bottom));
    font-family: 'Baloo 2', 'Poppins', system-ui, -apple-system, sans-serif;
    color: var(--text);
    padding: clamp(16px, 4vw, 32px);
}

a {
    color: inherit;
}

h1, h2 {
    margin: 0;
    font-weight: 600;
    color: var(--primary-strong);
}

.hidden {
    display: none !important;
}

#chatContainer {
    width: min(980px, 100%);
    max-width: 980px;
    background: var(--surface);
    border-radius: 32px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 16px;
    padding: clamp(18px, 4vw, 28px);
    border: 2px solid rgba(242, 138, 98, 0.14);
    backdrop-filter: blur(6px);
    position: relative;
}

#chatContainer::before,
#chatContainer::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.7;
    z-index: 0;
}

#chatContainer::before {
    width: 180px;
    height: 180px;
    background: rgba(239, 106, 124, 0.18);
    top: 24px;
    right: 14px;
}

#chatContainer::after {
    width: 220px;
    height: 220px;
    background: rgba(135, 245, 224, 0.2);
    bottom: 12px;
    left: 10px;
}

header {
    text-align: center;
    position: relative;
    z-index: 1;
}

.title-wrap {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 248, 242, 0.95));
    border-radius: 24px;
    padding: 16px 18px;
    border: 2px dashed rgba(242, 138, 98, 0.22);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.05);
}

header h1 {
    font-size: clamp(26px, 5vw, 36px);
    letter-spacing: 1px;
}

.subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: clamp(14px, 3.5vw, 17px);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--mint), var(--accent));
    color: #3d2b32;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    box-shadow: 0 10px 22px rgba(135, 245, 224, 0.35);
}

#messageBox {
    background: rgba(255, 255, 255, 0.86);
    border-radius: 22px;
    padding: clamp(12px, 3vw, 18px);
    overflow-y: auto;
    max-height: 60vh;
    min-height: 320px;
    border: 1px solid rgba(255, 206, 109, 0.45);
    box-shadow: inset 0 10px 25px rgba(0, 0, 0, 0.03);
    backdrop-filter: blur(3px);
    position: relative;
    z-index: 1;
}

.message {
    margin-bottom: 12px;
    padding: 12px 14px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(255, 206, 109, 0.18), rgba(242, 138, 98, 0.1));
    color: var(--text);
    border: 1px solid rgba(242, 138, 98, 0.12);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.04);
    position: relative;
    overflow: hidden;
}

.message strong {
    color: var(--primary-strong);
}

.message::after {
    content: "✨";
    position: absolute;
    right: 12px;
    bottom: 8px;
    font-size: 14px;
    opacity: 0.35;
}

.message.myMessage {
    background: linear-gradient(135deg, rgba(242, 138, 98, 0.26), rgba(239, 106, 124, 0.18));
    border-color: rgba(239, 106, 124, 0.3);
    margin-left: auto;
    max-width: 85%;
    box-shadow: 0 8px 18px rgba(239, 106, 124, 0.16);
}

#inputArea {
    display: grid;
    grid-template-columns: 1fr 140px;
    gap: 12px;
    align-items: center;
    position: relative;
    z-index: 1;
}

#messageInput, #usernameInput {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid rgba(122, 85, 96, 0.2);
    border-radius: 16px;
    font-size: 16px;
    color: var(--text);
    background: #fff9f2;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.12s ease;
}

#messageInput:focus, #usernameInput:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(242, 138, 98, 0.15);
    transform: translateY(-1px);
}

button {
    border: none;
    cursor: pointer;
    font-weight: 700;
    border-radius: 16px;
    padding: 14px 16px;
    font-size: 16px;
    color: #3d2b32;
    background: linear-gradient(135deg, var(--mint), var(--accent));
    box-shadow: 0 10px 25px rgba(239, 106, 124, 0.25), var(--glow);
    transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 0.4px;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(239, 106, 124, 0.24);
    filter: brightness(1.03);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(239, 106, 124, 0.25);
}

/* Popup styling */
#namePopup {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 50% 30%, rgba(242, 138, 98, 0.16), rgba(255, 208, 212, 0.36));
    backdrop-filter: blur(5px);
    z-index: 999;
}

.popup-content {
    background: var(--surface);
    padding: 28px;
    border-radius: 22px;
    width: min(420px, 90vw);
    text-align: center;
    box-shadow: var(--shadow);
    border: 2px solid rgba(255, 206, 109, 0.3);
}

.popup-content input {
    margin-top: 16px;
    margin-bottom: 16px;
}

.sparkles {
    font-size: 26px;
    animation: floaty 2.2s ease-in-out infinite;
}

@keyframes floaty {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Scrollbar */
#messageBox::-webkit-scrollbar {
    width: 10px;
}

#messageBox::-webkit-scrollbar-track {
    background: rgba(255, 248, 242, 0.7);
    border-radius: 12px;
}

#messageBox::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--primary), var(--accent));
    border-radius: 12px;
}

#messageBox::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--primary-strong), var(--accent));
}

@media (max-width: 640px) {
    #chatContainer {
        padding: 16px;
        border-radius: 24px;
    }

    header h1 {
        font-size: 26px;
    }

    #inputArea {
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
    }

    #messageBox {
        min-height: 240px;
    }
}

@media (max-width: 480px) {
    body {
        align-items: flex-start;
    }

    #chatContainer {
        gap: 12px;
    }

    .title-wrap {
        padding: 14px;
    }

    #messageBox {
        max-height: 50vh;
    }
}