/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
    /* Backgrounds */
    --bg-primary:       #f9fafb;
    --bg-secondary:     #f2f3f7;
    --bg-card:          #f5f6fa;
    --bg-card-hover:    #edeef4;
    --bg-input:         rgba(0,0,0,0.035);

    /* Accents — Telegram-inspired blue palette */
    --accent-primary:   #5865f2;
    --accent-secondary: #2aabee;
    --accent-danger:    #ff4d6d;
    --accent-warning:   #ffb347;
    --accent-success:   #00e676;

    /* Gradients */
    --grad-primary: linear-gradient(135deg, #5865f2 0%, #2aabee 100%);
    --grad-success: linear-gradient(135deg, #00e676 0%, #00c2aa 100%);
    --grad-danger:  linear-gradient(135deg, #ff9a3c 0%, #ff4d6d 100%);

    /* Text */
    --text-primary:   #1a1c2e;
    --text-secondary: #3d4263;
    --text-muted:     #7b80a0;

    /* Borders */
    --border:           rgba(0,0,0,0.09);
    --border-hover:     rgba(0,0,0,0.16);
    --border-focus:     rgba(88,101,242,0.45);

    /* Glow */
    --glow:    0 0 24px rgba(88,101,242,0.12);
    --glow-sm: 0 0 12px rgba(88,101,242,0.08);
    --glow-success: 0 0 20px rgba(0,230,118,0.1);

    /* Radius */
    --radius:    16px;
    --radius-sm: 12px;
    --radius-xs: 8px;

    /* Shadows */
    --shadow-sm: 0 2px 8px  rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);

    /* Typography */
    --font-head:    'Syne', sans-serif;
    --font-body:    'DM Sans', sans-serif;
    --font-mono:    'JetBrains Mono', monospace;
    --font-numeric: 'Inter', 'DM Sans', sans-serif;

    /* Layout */
    --nav-height:  64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --page-h-pad:  1rem;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0; padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    -webkit-user-select: none;
}

img { display: block; max-width: 100%; }
button { border: none; cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; color: var(--text-primary); }
a { color: var(--accent-secondary); text-decoration: none; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */
#app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateY(8px);
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* ── Background Mesh ───────────────────────────────────────────────────────── */
.bg-mesh {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.04;
    animation: blobDrift 22s ease-in-out infinite alternate;
    will-change: transform;
}

.bg-blob-1 {
    width: 480px; height: 480px;
    background: #5865f2;
    top: -220px; left: -160px;
    animation-duration: 24s;
}

.bg-blob-2 {
    width: 340px; height: 340px;
    background: #2aabee;
    bottom: -80px; right: -80px;
    animation-duration: 28s;
    animation-direction: alternate-reverse;
    opacity: 0.03;
}

.bg-blob-3 {
    width: 240px; height: 240px;
    background: #5865f2;
    top: 45%; left: 55%;
    opacity: 0.025;
    animation-duration: 32s;
}

#app, .screen { z-index: 1; }

/* ── Loading Screen ────────────────────────────────────────────────────────── */
.screen-loading {
    background: #f9fafb;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-icon {
    width: 68px; height: 68px;
    border-radius: 22px;
    background: var(--grad-primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    box-shadow: var(--glow);
    animation: pulse 2s ease-in-out infinite;
}

.loading-title {
    font-family: var(--font-head);
    font-size: 1.4rem;
    font-weight: 800;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Onboarding ────────────────────────────────────────────────────────────── */
.onboarding-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem var(--page-h-pad);
    text-align: center;
    gap: 1.1rem;
}

.onboarding-emoji { font-size: 4.5rem; animation: float 3s ease-in-out infinite; }
.onboarding-title {
    font-family: var(--font-head);
    font-size: 2rem; font-weight: 800;
    background: var(--grad-primary);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.onboarding-sub { color: var(--text-secondary); font-size: 0.95rem; max-width: 300px; line-height: 1.65; }

.onboarding-features {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
    max-width: 320px;
    margin: 0.5rem 0;
}

.onboard-feat {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.7rem 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: left;
}

/* ── Page Content Scroll ───────────────────────────────────────────────────── */
.page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 0 0 calc(var(--nav-height) + var(--safe-bottom) + 0.5rem);
    scrollbar-width: none;
    background: var(--bg-secondary);
}
.page-content::-webkit-scrollbar { display: none; }

/* ── Page Sections ─────────────────────────────────────────────────────────── */
.page-header {
    padding: 1rem 1rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header-title {
    font-family: var(--font-head);
    font-size: 1.25rem;
    font-weight: 700;
}

.page-section {
    padding: 1rem;
}

.section-title {
    font-family: var(--font-head);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 0.65rem;
}

/* ── Bottom Navigation (4-item TMA style) ──────────────────────────────────── */
.bottom-nav {
    display: flex;
    align-items: stretch;
    background: var(--bg-card);
    backdrop-filter: blur(24px) saturate(1.6);
    -webkit-backdrop-filter: blur(24px) saturate(1.6);
    border-top: 1px solid var(--border);
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    flex-shrink: 0;
    position: relative;
    z-index: 50;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.22rem;
    background: none;
    color: var(--text-muted);
    padding: 0.45rem 0.25rem;
    transition: color 0.18s;
    position: relative;
    min-width: 0;
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0; left: 20%; right: 20%;
    height: 2px;
    border-radius: 0 0 3px 3px;
    background: var(--accent-primary);
    transform: scaleX(0);
    transition: transform 0.2s;
}

.nav-item.active {
    color: var(--accent-primary);
}

.nav-item.active::before {
    transform: scaleX(1);
}

.nav-item:active { opacity: 0.7; }

.nav-icon  { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; transition: transform 0.18s; }
.nav-icon svg { width: 22px; height: 22px; }
.nav-item.active .nav-icon { transform: scale(1.12); }
.nav-label { font-size: 0.64rem; font-weight: 500; letter-spacing: 0.15px; white-space: nowrap; }

/* ── Typography Utilities ──────────────────────────────────────────────────── */
.mono  { font-family: var(--font-mono); }
.muted { color: var(--text-secondary); }
.small { font-size: 0.78rem; }
.bold  { font-weight: 600; }

.gradient-text {
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ── Spacing ───────────────────────────────────────────────────────────────── */
.mt-0  { margin-top: 0; }
.mt-xs { margin-top: 0.4rem; }
.mt-sm { margin-top: 0.75rem; }
.mt-md { margin-top: 1.25rem; }
.mb-xs { margin-bottom: 0.4rem; }
.mb-sm { margin-bottom: 0.75rem; }
.mb-md { margin-bottom: 1rem; }

/* ── Stagger animation ──────────────────────────────────────────────────────── */
.stagger > * { animation: fadeInUp 0.35s ease both; }
.stagger > *:nth-child(1) { animation-delay: 0.04s; }
.stagger > *:nth-child(2) { animation-delay: 0.08s; }
.stagger > *:nth-child(3) { animation-delay: 0.12s; }
.stagger > *:nth-child(4) { animation-delay: 0.16s; }
