:root {
    --bg-color: #020617;
    --card-bg: rgba(15, 23, 42, 0.6);
    --accent-color: #0ea5e9;
    --accent-hover: #38bdf8;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --message-other: rgba(30, 41, 59, 0.5);
    --message-me: rgba(3, 105, 161, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-image: 
        radial-gradient(at 0% 0%, hsla(199, 89%, 48%, 0.12) 0px, transparent 50%),
        radial-gradient(at 100% 100%, hsla(215, 94%, 18%, 0.1) 0px, transparent 50%);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 500px;
    height: 94vh;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 40px 100px -20px rgba(0, 0, 0, 0.8);
    position: relative;
    margin: 10px;
    overflow: hidden;
}

.animate-pop {
    animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.info-notice {
    background: rgba(14, 165, 233, 0.15);
    border-bottom: 1px solid rgba(14, 165, 233, 0.2);
    color: var(--accent-hover);
    padding: 8px 12px;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 500;
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

@keyframes pop {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #fff, #94a3b8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.active-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
    transition: all 0.3s;
}

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

.badges {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.badge {
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.025em;
    text-transform: uppercase;
}

.badge.secondary {
    color: #10b981;
}

#settings-btn, #about-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

#settings-btn:hover, #about-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

#settings-btn:hover { transform: rotate(30deg); }
#about-btn:hover { transform: translateY(-2px); }

main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

main::-webkit-scrollbar { width: 4px; }
main::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.05); border-radius: 10px; }

#messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 50px; /* Space for the emoji picker of the first message */
}

.message {
    max-width: 88%;
    display: flex;
    gap: 10px;
    margin-bottom: 4px;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

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

.avatar {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message .nickname {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: -2px;
}

.bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
    border: 1px solid var(--glass-border);
}

.message.other .bubble {
    background: var(--message-other);
    border-top-left-radius: 4px;
}

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

.message.me .bubble {
    background: var(--message-me);
    border-top-right-radius: 4px;
    border-color: rgba(14, 165, 233, 0.2);
}

.message.me .nickname { text-align: right; }

.msg-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 8px;
    display: block;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.time {
    font-size: 0.65rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-top: 4px;
}

.message.me .time { text-align: right; }

.bubble-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message.me .bubble-container {
    flex-direction: row-reverse;
}

/* Reacciones Compactas */
.reactions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    min-height: 24px;
}

.reaction-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(4px);
}

.reaction-badge:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.2);
}

.reaction-badge:active {
    transform: scale(0.95);
}

.reaction-count {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.7rem;
}

.message-actions {
    position: absolute;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    z-index: 50;
    top: -46px;
    transform: translateY(10px);
}

.message.other .message-actions {
    left: 0;
}

.message.me .message-actions {
    right: 0;
}

.message.show-picker .message-actions {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.emoji-picker {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    padding: 4px 8px;
    display: flex;
    gap: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.action-emoji {
    cursor: pointer;
    font-size: 1.1rem;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 2px;
    display: block;
}

.action-emoji:hover {
    transform: scale(1.4);
}

@media (max-width: 480px) {
    .message-actions { opacity: 0; }
    .message.show-picker .message-actions { opacity: 1; }

    .action-emoji {
        font-size: 1.4rem;
        padding: 4px;
    }
}

/* Footer / Input */
footer {
    padding: 16px 20px 24px;
}

#chat-form {
    display: flex;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 6px;
    border-radius: 20px;
    position: relative; /* Position relative for absolute children */
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 14px;
    padding-right: 48px; /* Extra space for the floating counter */
    color: white;
    font-size: 16px; /* Exactly 16px prevents iOS Safari from zooming */
    outline: none;
}

.char-counter {
    position: absolute;
    right: 58px;
    bottom: 12px;
    font-size: 0.65rem;
    color: var(--text-secondary);
    background: rgba(15, 23, 42, 0.6);
    padding: 2px 5px;
    border-radius: 6px;
    opacity: 0.5;
    white-space: nowrap;
    pointer-events: none;
    transition: all 0.2s;
}

#send-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 14px;
    width: 40px;
    height: 40px;
    flex-shrink: 0; /* Prevent button from shrinking on mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

#send-btn svg {
    margin-right: 2px;
    margin-top: -1px; /* Visual adjustment for the paper plane orientation */
}

#send-btn:hover { background: var(--accent-hover); }
#send-btn:active { transform: scale(0.95); }

/* System & Typing */
.system-msg {
    align-self: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 12px;
    opacity: 0.8;
}

#typing-indicator {
    padding: 10px;
    font-size: 0.75rem;
    color: #10b981;
    font-style: italic;
    height: 30px;
}

.hidden { display: none !important; }

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    padding: 32px;
    border-radius: 24px;
    width: 90%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-content h3 { font-family: 'Outfit'; font-size: 1.25rem; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 700; }

#nickname-input, #welcome-nickname {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 12px;
    color: white;
    font-size: 16px; /* Exactly 16px prevents iOS Safari from zooming */
    outline: none;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
}

/* Welcome Modal Enhancements */
.welcome-card {
    max-width: 380px !important;
    text-align: center;
}

.welcome-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.welcome-icon {
    font-size: 3rem;
}

.readme-section {
    background: rgba(14, 165, 233, 0.1);
    border: 1px solid rgba(14, 165, 233, 0.2);
    padding: 16px;
    border-radius: 16px;
    text-align: left;
    margin: 10px 0;
}

.readme-section h4 {
    margin-bottom: 6px;
    color: var(--accent-hover);
}

.readme-section p {
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.readme-section strong {
    color: #f87171; /* Warning color */
}

@media (max-width: 480px) {
    .app-container {
        height: 100dvh;
        margin: 0;
        border-radius: 0;
        border: none;
    }
    footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
    .message-actions { opacity: 0; }
}
