:root {
    --green-dark: #105547;
    --brown: #785631;
    --gold: #c09d52;
    --cream: #f5e6c8;
    --bg: #0d3d34;
    --surface: rgba(245, 230, 200, 0.08);
    --glass: rgba(255, 255, 255, 0.08);
    --text: #f5e6c8;
    --text-muted: rgba(245, 230, 200, 0.7);
    --radius: 16px;
    --shadow: 0 8px 32px rgba(0,0,0,.35);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 72px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body.app-body {
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: radial-gradient(circle at top, #1a6b5c 0%, var(--bg) 45%, #062821 100%);
    color: var(--text);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

.app-shell {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
    position: relative;
}

.glass {
    background: var(--glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(245, 230, 200, 0.12);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    margin: 12px 16px 0;
}

.stat-pill {
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.9rem;
    background: linear-gradient(135deg, rgba(192,157,82,.25), rgba(16,85,71,.4));
}

.page { padding: 16px; }
.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 16px;
    background: linear-gradient(90deg, var(--cream), var(--gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.card {
    padding: 20px;
    margin-bottom: 16px;
    animation: fadeUp .45s ease both;
}

.card h3 { margin-bottom: 8px; font-size: 1.1rem; }
.card p { color: var(--text-muted); font-size: .9rem; margin-bottom: 16px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 14px;
    padding: 14px 20px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, opacity .15s;
    width: 100%;
    touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
    background: linear-gradient(135deg, var(--gold), #e8c878);
    color: #2a1f0f;
    box-shadow: 0 6px 20px rgba(192,157,82,.35);
}
.btn-secondary {
    background: linear-gradient(135deg, var(--green-dark), #1a7a66);
    color: var(--cream);
}
.btn-outline {
    background: transparent;
    border: 1px solid rgba(245,230,200,.3);
    color: var(--cream);
}
.btn-sm { padding: 10px 14px; font-size: .9rem; width: auto; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-size: .9rem; color: var(--text-muted); }
.form-control {
    width: 100%;
    padding: 14px 16px;
    border-radius: 12px;
    border: 1px solid rgba(245,230,200,.15);
    background: rgba(0,0,0,.2);
    color: var(--cream);
    font-family: inherit;
    font-size: 1rem;
}
.form-control:focus { outline: 2px solid var(--gold); border-color: transparent; }

.tabs { display: flex; gap: 10px; margin-bottom: 20px; }
.tab-btn {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(245,230,200,.15);
    background: transparent;
    color: var(--cream);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
}
.tab-btn.active { background: linear-gradient(135deg, var(--green-dark), #1a6b5c); border-color: var(--gold); }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    display: flex;
    background: rgba(6, 40, 33, .92);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(245,230,200,.1);
    z-index: 100;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: .75rem;
    transition: color .2s;
}
.nav-item.active { color: var(--gold); }
.nav-icon { font-size: 1.35rem; }

.avatar { position: relative; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 40px; height: 40px; }
.avatar-md { width: 56px; height: 56px; }
.avatar-lg { width: 80px; height: 80px; }
.avatar.vip-ring::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--gold), #fff8dc, var(--gold), transparent, var(--gold));
    animation: spin 4s linear infinite;
    z-index: -1;
}
.avatar.vip-ring::after {
    content: '⭐';
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: .75rem;
    animation: pulse 1.5s ease infinite;
}

.vip-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--gold), #ffe082);
    color: #3e2a0a;
    font-size: .7rem;
    font-weight: 700;
}

#toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: min(440px, calc(100% - 32px));
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(16,85,71,.95);
    border: 1px solid var(--gold);
    color: var(--cream);
    animation: fadeUp .3s ease;
    box-shadow: var(--shadow);
}
.toast.error { border-color: #e74c3c; background: rgba(120,30,30,.95); }
.toast.success { border-color: #2ecc71; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: fadeIn .2s ease;
}
.modal {
    width: 100%;
    max-width: 400px;
    padding: 24px;
    max-height: 85vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 12px; }

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state .emoji { font-size: 3rem; margin-bottom: 12px; }

.skeleton {
    background: linear-gradient(90deg, rgba(255,255,255,.05), rgba(255,255,255,.12), rgba(255,255,255,.05));
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    border-radius: 12px;
    height: 60px;
    margin-bottom: 12px;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 14px;
    margin-bottom: 10px;
    background: var(--surface);
    text-decoration: none;
    color: inherit;
}

.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: .95rem;
}
.chat-bubble.mine {
    margin-right: auto;
    background: linear-gradient(135deg, var(--green-dark), #1a7a66);
    border-bottom-left-radius: 4px;
}
.chat-bubble.theirs {
    margin-left: auto;
    background: rgba(120,86,49,.5);
    border-bottom-right-radius: 4px;
}
.chat-meta { font-size: .7rem; color: var(--text-muted); margin-top: 4px; }

.ranking-top3 {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 10px;
    margin: 20px 0 24px;
    min-height: 180px;
}
.rank-podium {
    text-align: center;
    padding: 16px 10px;
    border-radius: 16px;
    flex: 1;
    animation: fadeUp .5s ease both;
}
.rank-podium.first {
    background: linear-gradient(180deg, rgba(192,157,82,.35), rgba(192,157,82,.1));
    transform: scale(1.05);
    order: 2;
}
.rank-podium.second { order: 1; }
.rank-podium.third { order: 3; }

.match-overlay {
    position: fixed;
    inset: 0;
    background: rgba(6,40,33,.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 24px;
    text-align: center;
}
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(245,230,200,.2);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin-bottom: 16px;
}

.link { color: var(--gold); text-decoration: none; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Splash */
.splash-screen {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
}
.splash-logo {
    width: 120px;
    height: 120px;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--gold), var(--brown));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
    animation: logoIn 1s ease both;
}
.splash-title {
    margin-top: 24px;
    font-size: 2rem;
    font-weight: 700;
    animation: fadeUp .8s .3s ease both;
}
.splash-tagline {
    margin-top: 8px;
    color: var(--text-muted);
    animation: fadeUp .8s .5s ease both;
}
@keyframes logoIn {
    0% { transform: scale(.3) rotate(-20deg); opacity: 0; }
    60% { transform: scale(1.08) rotate(5deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

.auth-page { padding: 24px 16px; }
.auth-header { text-align: center; margin-bottom: 24px; }
.avatar-upload {
    width: 96px;
    height: 96px;
    margin: 0 auto 16px;
    border-radius: 50%;
    border: 2px dashed var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}
.avatar-upload img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.footer-links {
    text-align: center;
    padding: 16px;
    font-size: .85rem;
    color: var(--text-muted);
}
