/* General styles */
* {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    margin: 0;
    padding: 0;
    font-family: "Shantell Sans", cursive;
    font-optical-sizing: auto;
    font-weight: 400;
    font-style: normal;
    background: linear-gradient(135deg, #3d5a80 0%, #2c4a6e 50%, #3d5a80 100%);
    height: 100%;
    height: 100dvh;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    /* Prevent iOS bounce/overscroll */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Snowflakes animation */
.snowflakes {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    overflow: hidden;
}

.snowflake {
    position: absolute;
    top: -50px;
    color: #fff;
    font-size: 1.5rem;
    opacity: 0;
    animation: fall linear infinite;
}

@keyframes fall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0;
    }
    5% {
        opacity: 0.8;
    }
    95% {
        opacity: 0.8;
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* Chat container */
.chat-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    overflow: hidden;
}

/* Chat header */
.chat-header {
    background: linear-gradient(135deg, #d35f5f 0%, #b84a4a 100%);
    color: white;
    padding: 15px 20px;
    border-radius: 20px 20px 0 0;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.chat-header h1 {
    margin: 0;
    font-size: 1.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.chat-header .subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 5px;
}

/* Chat messages area */
.chat-messages {
    flex: 1;
    min-height: 0;
    background: url('/img/bg.jpg') center top / cover no-repeat;
    padding: 20px;
    padding-bottom: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-left: 3px solid #d35f5f;
    border-right: 3px solid #d35f5f;
    border-bottom: 3px solid #d35f5f;
    border-radius: 0 0 20px 20px;
}

/* When chat input is visible, remove bottom border/radius from messages */
.chat-messages:has(~ .chat-input-area:not(.hidden)) {
    border-bottom: none;
    border-radius: 0;
}

/* Message bubbles */
.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: messageAppear 0.4s ease-out;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.ded-moroz {
    flex-direction: row;
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.message.ded-moroz .message-avatar {
    background: linear-gradient(135deg, #d35f5f 0%, #b84a4a 100%);
}

.message.user .message-avatar {
    background: linear-gradient(135deg, #5a9e5f 0%, #4a8f50 100%);
}

.message-content {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.ded-moroz .message-content {
    background: linear-gradient(135deg, #fff 0%, #fafafa 100%);
    border: 2px solid #d35f5f;
    border-bottom-left-radius: 4px;
}

.message.user .message-content {
    background: linear-gradient(135deg, #eef6ee 0%, #dceedd 100%);
    border: 2px solid #5a9e5f;
    border-bottom-right-radius: 4px;
}

.message-text {
    font-size: 1rem;
    line-height: 1.5;
    color: #4a4a4a;
}

/* Ded Moroz greeting card */
.greeting-card {
    text-align: center;
    padding: 20px 10px;
    padding-top: 60px;
    margin-top: auto;
    margin-bottom: auto;
    animation: bounceIn 0.8s ease-out;
    width: 100%;
    max-width: 100%;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.ded-moroz-image {
    width: 150px;
    height: 150px;
    margin: 0 auto 15px;
    border-radius: 50%;
    background: linear-gradient(135deg, #d35f5f 0%, #b84a4a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 6rem;
    box-shadow: 0 8px 25px rgba(211, 95, 95, 0.3);
    border: 4px solid #e8c547;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 8px 25px rgba(211, 95, 95, 0.3);
    }
    50% {
        box-shadow: 0 8px 35px rgba(211, 95, 95, 0.4), 0 0 20px rgba(232, 197, 71, 0.2);
    }
}

.greeting-text {
    font-size: 1.2rem;
    color: #4a4a4a;
    margin-bottom: 20px;
    line-height: 1.6;
}

/* Chat input area */
.chat-input-area {
    background: linear-gradient(135deg, #3d5a80 0%, #2c4a6e 100%);
    padding: 12px;
    border-radius: 0 0 20px 20px;
    border: 3px solid #d35f5f;
    border-top: none;
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    width: 100%;
}

.chat-input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 2px solid #e8c547;
    border-radius: 20px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    color: #4a4a4a;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    resize: none;
    overflow-y: auto;
    line-height: 1.4;
    min-height: 46px;
    max-height: 90px;
}

.chat-input:focus {
    border-color: #d35f5f;
    box-shadow: 0 0 10px rgba(211, 95, 95, 0.2);
}

.chat-input::placeholder {
    color: #999;
}

.send-button {
    width: 46px;
    height: 46px;
    min-width: 46px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #d35f5f 0%, #b84a4a 100%);
    color: white;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(211, 95, 95, 0.3);
    flex-shrink: 0;
}

.send-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(211, 95, 95, 0.4);
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Name input special styling */
.name-input-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    padding: 0 10px;
    width: 100%;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.name-input {
    padding: 12px 18px;
    border: 2px solid #e8c547;
    border-radius: 15px;
    font-size: 1.1rem;
    font-family: inherit;
    text-align: center;
    background: #fff;
    color: #4a4a4a;
    outline: none;
    transition: all 0.3s ease;
}

.name-input:focus {
    border-color: #d35f5f;
    box-shadow: 0 0 15px rgba(211, 95, 95, 0.2);
}

.start-chat-button {
    padding: 12px 30px;
    border: none;
    border-radius: 25px;
    background: linear-gradient(135deg, #5a9e5f 0%, #4a8f50 100%);
    color: white;
    font-size: 1.1rem;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(90, 158, 95, 0.3);
}

.start-chat-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(90, 158, 95, 0.4);
}

.start-chat-button:active {
    transform: scale(0.98);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 10px 15px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #d35f5f;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Success tree in chat */
.success-tree {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    padding: 20px;
    animation: bounce 1s ease infinite;
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-15px);
    }
}

/* Decorations */
.decorations {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.decoration {
    position: absolute;
    font-size: 2rem;
    opacity: 0.3;
}

/* Hidden class */
.hidden {
    display: none !important;
}

/* Error state */
.error {
    border-color: #d35f5f !important;
    background-color: #fff0f0 !important;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .chat-container {
        padding: 5px;
    }

    .chat-header {
        padding: 12px 15px;
        border-radius: 15px 15px 0 0;
    }

    .chat-header h1 {
        font-size: 1.2rem;
    }

    .chat-messages {
        padding: 15px 10px;
    }

    .ded-moroz-image {
        width: 100px;
        height: 100px;
        font-size: 4rem;
    }

    .greeting-text {
        font-size: 1rem;
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
    }

    .message-content {
        max-width: 80%;
        padding: 10px 12px;
    }

    .message-text {
        font-size: 0.9rem;
    }

    .chat-input-area {
        padding: 10px;
        border-radius: 0 0 15px 15px;
    }

    .chat-input {
        padding: 10px 14px;
        font-size: 0.9rem;
    }

    .send-button {
        width: 42px;
        height: 42px;
        min-width: 42px;
        font-size: 1.2rem;
    }

    .name-input {
        font-size: 1rem;
        padding: 10px 14px;
    }

    .start-chat-button {
        font-size: 1rem;
        padding: 10px 25px;
    }
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #d35f5f;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #b84a4a;
}
