:root {
    --primary: #2A9D8F;
    --primary-dark: #238276;
    --primary-light: #3FB4A5;
    --bg: #F4F1DE;
    --white: #FFFFFF;
    --text: #3D405B;
    --text-light: #6B6E87;
    --msg-me: #81B29A;
    --msg-partner: #E07A5F;
    --msg-ai: #F2CC8F;
    --private-color: #6B5B95;
    --shared-color: #FF6B6B;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body { 
    margin: 0; 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg); 
    color: var(--text); 
    height: 100vh; 
    overflow: hidden;
    font-size: 16px;
    line-height: 1.6;
}

/* ============================================
   SCREENS & NAVIGATION
   ============================================ */
.screen { 
    display: none; 
    height: 100%; 
    flex-direction: column; 
}

.screen.active { 
    display: flex; 
}

/* ============================================
   LOGIN & REGISTER SCREENS
   ============================================ */
#screen-login, #screen-register { 
    justify-content: center; 
    padding: 40px 30px;
    text-align: center; 
    background: linear-gradient(135deg, #F4F1DE 0%, #E8E4CF 100%);
}

.logo-wrapper { 
    width: 120px; 
    height: 120px; 
    margin: 0 auto 30px; 
    border-radius: 50%; 
    overflow: hidden; 
    background: var(--primary);
    box-shadow: 0 8px 20px var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeInScale 0.5s ease-out;
}

.logo-wrapper.small { 
    width: 80px; 
    height: 80px; 
    margin-bottom: 20px;
}

.logo { 
    width: 100%; 
    height: 100%; 
    object-fit: cover; 
}

h1 {
    font-size: 2rem;
    margin-bottom: 30px;
    color: var(--text);
    font-weight: 700;
}

.form-group {
    max-width: 400px;
    margin: 0 auto;
}

input { 
    width: 100%; 
    padding: 16px 20px;
    margin: 10px 0; 
    border: 2px solid #E0DED0; 
    border-radius: 12px; 
    box-sizing: border-box;
    font-size: 1.1rem;
    background: var(--white);
    transition: all 0.3s ease;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.1);
}

button { 
    width: 100%; 
    padding: 16px 20px; 
    background: var(--primary); 
    color: white; 
    border: none; 
    border-radius: 12px; 
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer; 
    margin-top: 15px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px var(--shadow);
}

button:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-strong);
}

button:active {
    transform: translateY(0);
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.link { 
    margin-top: 25px; 
    color: var(--primary); 
    cursor: pointer; 
    font-size: 1.1rem;
    font-weight: 500;
}

.link b {
    font-weight: 700;
}

.link:hover {
    text-decoration: underline;
}

hr {
    margin: 20px 0;
    border: none;
    border-top: 1px solid #E0DED0;
}

/* ============================================
   CHAT SCREEN
   ============================================ */
header { 
    background: var(--white); 
    padding: 18px 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    box-shadow: 0 2px 10px var(--shadow);
    z-index: 100;
}

header > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

header img {
    height: 36px;
    border-radius: 50%;
}

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

.btn-logout { 
    width: auto; 
    padding: 10px 18px; 
    font-size: 1rem;
    margin: 0; 
    background: #666;
    border-radius: 8px;
}

.btn-logout:hover {
    background: #555;
}

/* Invite Box */
#invite-box { 
    background: linear-gradient(135deg, #fff3cd 0%, #ffe9a8 100%);
    color: #856404; 
    padding: 20px; 
    text-align: center; 
    border-bottom: 2px solid #ffeeba;
    animation: slideDown 0.4s ease-out;
}

#invite-box p {
    font-size: 1.1rem;
    margin: 8px 0;
}

#my-code {
    font-size: 2rem;
    letter-spacing: 4px;
    font-weight: bold;
    color: var(--primary);
    margin: 15px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    display: inline-block;
}

#invite-box small {
    font-size: 1rem;
    opacity: 0.9;
}

/* ============================================
   DUAL-ROOM TABS
   ============================================ */
.room-tabs {
    display: flex;
    background: var(--white);
    border-bottom: 2px solid #E0DED0;
    padding: 0;
    gap: 0;
}

.tab-btn {
    flex: 1;
    padding: 16px 20px;
    background: transparent;
    border: none;
    border-radius: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
    margin: 0;
    box-shadow: none;
}

.tab-btn:hover {
    background: rgba(42, 157, 143, 0.05);
    transform: none;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(42, 157, 143, 0.08);
}

.tab-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f5f5f5;
}

.tab-btn.disabled:hover {
    background: #f5f5f5;
}

/* LOCK STATE */
.tab-btn.locked {
    opacity: 0.6;
    cursor: pointer;
    background: #f9f9f9;
}

.tab-btn.locked:hover {
    background: #f0f0f0;
}

.lock-badge {
    font-size: 0.75rem;
    background: #ff6b6b;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
}

.unlock-badge {
    font-size: 0.75rem;
    background: #51cf66;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 600;
    animation: blink 2s ease-in-out 3;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Room Info Box */
.room-info {
    background: #f9f9f9;
    padding: 12px 20px;
    font-size: 1rem;
    color: var(--text);
    border-bottom: 1px solid #E0DED0;
}

.room-info-content {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.room-info-content.active {
    display: block;
}

.room-info strong {
    color: var(--primary);
}

/* Chat Container */
#chat-container { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 16px; 
    background: linear-gradient(180deg, #F4F1DE 0%, #E8E4CF 100%);
    scroll-behavior: smooth;
}

#chat-container::-webkit-scrollbar {
    width: 8px;
}

#chat-container::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

#chat-container::-webkit-scrollbar-thumb {
    background: rgba(42, 157, 143, 0.3);
    border-radius: 4px;
}

#chat-container::-webkit-scrollbar-thumb:hover {
    background: rgba(42, 157, 143, 0.5);
}

/* Messages */
.msg { 
    max-width: 80%; 
    padding: 14px 18px; 
    border-radius: 18px; 
    font-size: 1.15rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 8px var(--shadow);
    animation: fadeInUp 0.3s ease-out;
    word-wrap: break-word;
}

.msg.me { 
    align-self: flex-end; 
    background: var(--msg-me); 
    color: white; 
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.msg.partner { 
    align-self: flex-start; 
    background: var(--msg-partner); 
    color: white; 
    border-bottom-left-radius: 4px;
}

.msg.ai { 
    align-self: center; 
    background: var(--white); 
    border: 2px solid var(--msg-ai); 
    color: var(--text); 
    width: 90%; 
    text-align: left;
    padding: 18px 20px;
    border-radius: 16px;
}

.ai-label { 
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px; 
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-label::before {
    content: "🤖";
    font-size: 1.2rem;
}

/* Footer (Input Area) */
footer { 
    padding: 16px 20px; 
    background: var(--white); 
    display: flex; 
    gap: 12px; 
    border-top: 2px solid #eee;
    box-shadow: 0 -2px 10px var(--shadow);
}

#msg-input { 
    margin: 0; 
    border-radius: 24px;
    flex: 1;
    padding: 14px 20px;
    font-size: 1.1rem;
    border: 2px solid #E0DED0;
}

#msg-input:focus {
    border-color: var(--primary);
}

footer button { 
    width: 56px;
    height: 56px;
    margin: 0; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    font-size: 1.8rem;
    padding: 0;
    flex-shrink: 0;
}

/* ============================================
   LOADING & STATES
   ============================================ */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 1rem;
    border: 1px solid #f5c6cb;
}

.success-message {
    background: #d4edda;
    color: #155724;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 1rem;
    border: 1px solid #c3e6cb;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
    h1 {
        font-size: 1.8rem;
    }
    
    .msg {
        max-width: 85%;
        font-size: 1.1rem;
    }
    
    #my-code {
        font-size: 1.8rem;
    }

    .tab-btn {
        font-size: 1rem;
        padding: 14px 10px;
    }
}

@media (min-width: 768px) {
    #screen-login, #screen-register {
        background: radial-gradient(circle at top right, #E8E4CF 0%, #F4F1DE 100%);
    }
    
    .msg {
        max-width: 70%;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
