/* =====================================================================
   USTOZ Mini App — Premium Design System v2.0
   ===================================================================== */

:root {
    /* Brand */
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #ec4899;
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-purple: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --gradient-sunset: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    --gradient-ocean: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    --gradient-premium: linear-gradient(135deg, #fbbf24 0%, #f59e0b 35%, #ec4899 70%, #8b5cf6 100%);
    --gradient-card: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(236, 72, 153, 0.04) 100%);

    /* Telegram theme integration */
    --tg-bg: var(--tg-theme-bg-color, #ffffff);
    --tg-text: var(--tg-theme-text-color, #0f172a);
    --tg-hint: var(--tg-theme-hint-color, #64748b);
    --tg-link: var(--tg-theme-link-color, #6366f1);
    --tg-button: var(--tg-theme-button-color, #6366f1);
    --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f5f9);
    --tg-section-bg: var(--tg-theme-section-bg-color, #ffffff);
    --tg-header-bg: var(--tg-theme-header-bg-color, #6366f1);

    /* Spacing & radius */
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-2xl: 36px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16);
    --shadow-glow: 0 0 32px rgba(99, 102, 241, 0.35);
    --shadow-glow-pink: 0 0 32px rgba(236, 72, 153, 0.4);

    /* Transitions */
    --t-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    --t-spring: 600ms cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ===== Dark mode auto-detect ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --tg-bg: var(--tg-theme-bg-color, #0f172a);
        --tg-text: var(--tg-theme-text-color, #f1f5f9);
        --tg-hint: var(--tg-theme-hint-color, #94a3b8);
        --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #1e293b);
        --tg-section-bg: var(--tg-theme-section-bg-color, #1e293b);
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}

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

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: var(--tg-bg);
    color: var(--tg-text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 90px;
    min-height: 100vh;
    position: relative;
}

button, input {
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--t-fast);
}

a:active {
    opacity: 0.7;
}

/* ===== Pages ===== */
.page {
    display: none;
    padding: 16px;
    animation: pageFadeIn var(--t-slow);
}

.page.active {
    display: block;
}

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

@keyframes slideInRight {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

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

@keyframes shine {
    0% { background-position: -200% center; }
    100% { background-position: 200% center; }
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(180deg); }
}

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

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px rgba(99, 102, 241, 0.4); }
    50% { box-shadow: 0 0 40px rgba(99, 102, 241, 0.7); }
}

/* ===== HEADER ===== */
.header {
    background: var(--gradient-purple);
    background-size: 200% 200%;
    animation: shine 12s linear infinite;
    margin: -16px -16px 20px;
    padding: 28px 20px 36px;
    border-radius: 0 0 var(--radius-2xl) var(--radius-2xl);
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.header-bg-pattern {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(236, 72, 153, 0.25) 0%, transparent 50%);
    pointer-events: none;
}

.header::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -10%;
    width: 220px;
    height: 220px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.18) 0%, transparent 70%);
    border-radius: 50%;
    animation: float 7s ease-in-out infinite;
    pointer-events: none;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
    position: relative;
    z-index: 1;
}

.user-avatar {
    width: 64px;
    height: 64px;
    background: rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    flex-shrink: 0;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.user-info {
    flex: 1;
}

.user-greeting {
    font-size: 13px;
    opacity: 0.85;
    margin-bottom: 2px;
    font-weight: 500;
}

.user-name {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.user-role-row {
    display: flex;
    gap: 6px;
}

.user-role {
    font-size: 12px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    font-weight: 600;
}

.user-role.premium {
    background: var(--gradient-premium);
    background-size: 300% auto;
    animation: shine 4s linear infinite;
    color: #1a1a1a;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(251, 191, 36, 0.4);
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    position: relative;
    z-index: 1;
}

.stat-card {
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    padding: 14px 10px;
    border-radius: var(--radius-md);
    text-align: center;
    transition: all var(--t-base);
    cursor: pointer;
}

.stat-card:active {
    transform: scale(0.94);
    background: rgba(255, 255, 255, 0.28);
}

.stat-emoji {
    font-size: 26px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 11px;
    opacity: 0.9;
    margin-top: 2px;
    font-weight: 500;
}

/* ===== CTA Card ===== */
.cta-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08) 0%, rgba(236, 72, 153, 0.04) 100%);
    border: 1px solid rgba(99, 102, 241, 0.18);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    transition: all var(--t-base);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.cta-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: translateX(-100%);
    transition: transform 0.8s;
}

.cta-card:active {
    transform: scale(0.98);
}

.cta-card:active::before {
    transform: translateX(100%);
}

.cta-emoji {
    font-size: 40px;
    flex-shrink: 0;
}

.cta-text {
    flex: 1;
}

.cta-title {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 3px;
}

.cta-subtitle {
    font-size: 12px;
    color: var(--tg-hint);
}

.cta-arrow {
    font-size: 24px;
    color: var(--primary);
    font-weight: 700;
}

/* ===== Quick actions ===== */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}

.quick-btn {
    background: var(--tg-secondary-bg);
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all var(--t-base);
    color: var(--tg-text);
}

.quick-btn:active {
    transform: scale(0.95);
    background: rgba(99, 102, 241, 0.1);
}

.quick-icon {
    font-size: 28px;
}

.quick-label {
    font-size: 12px;
    font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    transition: all var(--t-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    user-select: none;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: var(--gradient-purple);
    color: white;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s;
}

.btn-primary:active::before {
    transform: translateX(100%);
}

.btn-ghost {
    background: transparent;
    color: var(--tg-text);
    border: 1.5px solid rgba(127, 127, 127, 0.2);
}

.btn-ghost:active {
    background: var(--tg-secondary-bg);
}

.btn-glass {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 18px;
}

.btn-small {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
    padding: 14px;
    margin-top: 10px;
}

.btn-large {
    padding: 16px;
    font-size: 16px;
    font-weight: 700;
    border-radius: var(--radius-lg);
}

.btn-icon {
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    font-size: 24px;
    cursor: pointer;
    color: var(--tg-text);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    transition: all var(--t-base);
}

.btn-icon:active {
    background: var(--tg-secondary-bg);
    transform: scale(0.92);
}

/* ===== Section titles ===== */
.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 24px 0 12px;
    font-weight: 700;
    font-size: 16px;
}

.section-title span:first-child {
    color: var(--tg-text);
}

.section-link {
    font-size: 13px;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
}

.section-link:active {
    opacity: 0.7;
}

/* ===== Topics grid ===== */
.topics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.topics-grid-full {
    grid-template-columns: repeat(2, 1fr);
}

.topic-card {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: all var(--t-base);
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.topic-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-purple);
    opacity: 0;
    transition: opacity var(--t-base);
    pointer-events: none;
}

.topic-card:active {
    transform: scale(0.96);
    border-color: var(--primary);
}

.topic-card:active::before {
    opacity: 0.05;
}

.topic-icon {
    font-size: 32px;
    margin-bottom: 10px;
    display: block;
}

.topic-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 3px;
    color: var(--tg-text);
}

.topic-desc {
    font-size: 11px;
    color: var(--tg-hint);
    line-height: 1.4;
}

/* ===== Progress list ===== */
.progress-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.progress-item {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all var(--t-base);
}

.progress-item:active {
    transform: scale(0.98);
}

.progress-icon {
    font-size: 28px;
}

.progress-info {
    flex: 1;
    min-width: 0;
}

.progress-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 6px;
}

.progress-bar {
    height: 6px;
    background: rgba(127, 127, 127, 0.15);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-purple);
    border-radius: 3px;
    transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.progress-bar-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    animation: shimmer 2s infinite;
}

.progress-bar-fill.warning { background: var(--gradient-warning); }
.progress-bar-fill.danger { background: var(--gradient-danger); }
.progress-bar-fill.success { background: var(--gradient-success); }

.progress-value {
    font-weight: 700;
    font-size: 15px;
    min-width: 44px;
    text-align: right;
    color: var(--primary);
}

/* ===== Weak topics ===== */
.weak-topics {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weak-item {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.06) 0%, rgba(245, 158, 11, 0.04) 100%);
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all var(--t-base);
}

.weak-item:active {
    transform: scale(0.98);
}

.weak-emoji {
    font-size: 24px;
}

.weak-info {
    flex: 1;
}

.weak-name {
    font-weight: 600;
    font-size: 14px;
}

.weak-meta {
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 2px;
}

.weak-accuracy {
    color: var(--danger);
    font-weight: 800;
    font-size: 18px;
}

/* ===== Premium banner ===== */
.premium-banner {
    background: var(--gradient-premium);
    background-size: 300% auto;
    animation: shine 5s linear infinite;
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-top: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #1a1a1a;
    box-shadow: var(--shadow-lg), 0 0 40px rgba(251, 191, 36, 0.3);
    cursor: pointer;
    transition: transform var(--t-base);
}

.premium-banner:active {
    transform: scale(0.98);
}

.premium-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.premium-emoji {
    font-size: 36px;
    animation: pulse 2s ease-in-out infinite;
}

.premium-title {
    font-weight: 800;
    font-size: 16px;
}

.premium-sub {
    font-size: 12px;
    opacity: 0.85;
}

.premium-arrow {
    font-size: 24px;
    font-weight: 800;
}

/* ===== Admin info ===== */
.admin-info {
    text-align: center;
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 24px;
    padding: 16px;
    line-height: 1.7;
}

.admin-info a {
    font-weight: 600;
}

/* ===== TEST PAGE ===== */
.test-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(127, 127, 127, 0.08);
}

.test-progress {
    flex: 1;
}

.test-progress-text {
    font-size: 13px;
    color: var(--tg-hint);
    margin-bottom: 5px;
    font-weight: 500;
}

.test-progress-bar {
    height: 6px;
    background: var(--tg-secondary-bg);
    border-radius: 3px;
    overflow: hidden;
}

.test-progress-fill {
    height: 100%;
    background: var(--gradient-purple);
    border-radius: 3px;
    transition: width var(--t-slow);
    width: 0;
    position: relative;
}

.test-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    animation: shimmer 2s infinite;
}

.test-timer {
    background: var(--tg-secondary-bg);
    padding: 7px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 700;
    color: var(--tg-hint);
    font-variant-numeric: tabular-nums;
    min-width: 70px;
    text-align: center;
}

.test-topic {
    background: var(--gradient-card);
    border: 1px solid rgba(99, 102, 241, 0.15);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    display: inline-block;
    margin-bottom: 16px;
}

.test-question {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.6;
    margin-bottom: 22px;
    padding: 20px;
    background: var(--gradient-card);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(99, 102, 241, 0.12);
    color: var(--tg-text);
}

/* KaTeX styling */
.math .katex {
    font-size: 1.05em;
}

.test-question .katex-display {
    margin: 12px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* ===== Test options ===== */
.test-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.option-btn {
    background: var(--tg-secondary-bg);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: left;
    cursor: pointer;
    transition: all var(--t-base);
    font-family: inherit;
    font-size: 15px;
    color: var(--tg-text);
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
}

.option-btn:active {
    transform: scale(0.98);
}

.option-btn:hover:not(.disabled) {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
}

.option-letter {
    width: 34px;
    height: 34px;
    background: var(--tg-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: var(--primary);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    transition: all var(--t-base);
}

.option-text {
    flex: 1;
}

.option-btn.correct {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(16, 185, 129, 0.05) 100%);
    border-color: var(--success);
    animation: bounceIn var(--t-spring);
}

.option-btn.correct .option-letter {
    background: var(--success);
    color: white;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.5);
}

.option-btn.incorrect {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.15) 0%, rgba(239, 68, 68, 0.05) 100%);
    border-color: var(--danger);
    animation: shake 0.4s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.option-btn.incorrect .option-letter {
    background: var(--danger);
    color: white;
}

.option-btn.disabled {
    pointer-events: none;
    opacity: 0.55;
}

/* ===== Feedback ===== */
.test-feedback {
    display: none;
    margin-top: 20px;
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-lg);
    padding: 20px;
    animation: slideUp var(--t-spring);
}

.test-feedback.active {
    display: block;
}

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

.feedback-header {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 14px;
}

.feedback-header.correct {
    color: var(--success);
}

.feedback-header.incorrect {
    color: var(--danger);
}

.feedback-explanation {
    font-size: 14px;
    line-height: 1.7;
    color: var(--tg-text);
    background: var(--tg-bg);
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    white-space: pre-wrap;
    border-left: 3px solid var(--primary);
}

.feedback-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== Result ===== */
.result-card {
    text-align: center;
    padding: 48px 24px;
    background: var(--gradient-card);
    border-radius: var(--radius-2xl);
    margin-top: 40px;
    animation: bounceIn var(--t-spring);
    box-shadow: var(--shadow-lg);
}

.result-emoji {
    font-size: 90px;
    margin-bottom: 14px;
    animation: pulse 2s ease-in-out infinite;
}

.result-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--tg-text);
}

.result-score {
    font-size: 56px;
    font-weight: 900;
    background: var(--gradient-purple);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 4px;
    letter-spacing: -2px;
}

.result-accuracy {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 28px;
}

.result-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 28px;
}

.result-stat {
    background: var(--tg-bg);
    border-radius: var(--radius-md);
    padding: 18px;
    box-shadow: var(--shadow-sm);
}

.result-stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary);
}

.result-stat-label {
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 4px;
    font-weight: 500;
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--tg-text);
}

/* ===== Leaderboard ===== */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lb-item {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-md);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all var(--t-base);
    animation: slideInRight var(--t-base);
}

.lb-item:active {
    transform: scale(0.98);
}

.lb-item.top-1 {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.25) 0%, rgba(245, 158, 11, 0.1) 100%);
    border: 1px solid rgba(251, 191, 36, 0.35);
    box-shadow: 0 4px 20px rgba(251, 191, 36, 0.2);
}

.lb-item.top-2 {
    background: linear-gradient(135deg, rgba(203, 213, 225, 0.35) 0%, rgba(148, 163, 184, 0.15) 100%);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.lb-item.top-3 {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.2) 0%, rgba(180, 83, 9, 0.08) 100%);
    border: 1px solid rgba(217, 119, 6, 0.25);
}

.lb-rank {
    font-size: 22px;
    font-weight: 800;
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.lb-info {
    flex: 1;
    min-width: 0;
}

.lb-name {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-meta {
    font-size: 12px;
    color: var(--tg-hint);
    margin-top: 3px;
}

.lb-xp {
    font-weight: 800;
    color: var(--primary);
    font-size: 17px;
    font-variant-numeric: tabular-nums;
}

/* ===== Profile ===== */
.profile-card {
    background: var(--gradient-purple);
    color: white;
    padding: 28px;
    border-radius: var(--radius-xl);
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.profile-card::before {
    content: '';
    position: absolute;
    top: -30%;
    right: -10%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
    border-radius: 50%;
}

.profile-name {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}

.profile-role {
    font-size: 13px;
    opacity: 0.9;
    margin-bottom: 18px;
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.profile-stat {
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    padding: 14px;
}

.profile-stat-label {
    font-size: 12px;
    opacity: 0.9;
    font-weight: 500;
}

.profile-stat-value {
    font-size: 22px;
    font-weight: 800;
    margin-top: 4px;
}

.profile-topics {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== Settings ===== */
.settings-list {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 16px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    cursor: pointer;
    transition: background var(--t-fast);
    border-bottom: 1px solid rgba(127, 127, 127, 0.08);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item:active {
    background: rgba(99, 102, 241, 0.08);
}

.setting-icon {
    font-size: 22px;
    width: 36px;
    text-align: center;
}

.setting-label {
    flex: 1;
    font-weight: 500;
}

.setting-value {
    font-size: 13px;
    color: var(--tg-hint);
    font-weight: 500;
}

/* ===== TUTOR ===== */
.tutor-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    max-height: 700px;
}

.tutor-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    -webkit-overflow-scrolling: touch;
}

.tutor-msg {
    display: flex;
    gap: 10px;
    animation: slideUp var(--t-base);
    align-items: flex-start;
}

.tutor-msg-user {
    flex-direction: row-reverse;
}

.tutor-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    background: var(--gradient-purple);
    box-shadow: var(--shadow-sm);
}

.tutor-msg-user .tutor-avatar {
    background: var(--gradient-ocean);
}

.tutor-bubble {
    background: var(--tg-secondary-bg);
    padding: 12px 14px;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-xs);
    max-width: 80%;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.tutor-msg-user .tutor-bubble {
    background: var(--gradient-purple);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) var(--radius-xs) var(--radius-lg);
}

.tutor-bubble .katex {
    font-size: 1em;
}

.tutor-typing {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.tutor-typing span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.tutor-typing span:nth-child(2) { animation-delay: 0.2s; }
.tutor-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

.tutor-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 4px 0;
    border-top: 1px solid rgba(127, 127, 127, 0.08);
}

.tutor-input {
    flex: 1;
    background: var(--tg-secondary-bg);
    border: 1.5px solid transparent;
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    font-size: 15px;
    color: var(--tg-text);
    transition: all var(--t-base);
    outline: none;
}

.tutor-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.tutor-send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--gradient-purple);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--t-base);
    flex-shrink: 0;
}

.tutor-send-btn:active {
    transform: scale(0.9);
}

.tutor-send-btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ===== Premium lock ===== */
.tutor-premium-lock,
.mock-premium-lock {
    text-align: center;
    padding: 48px 24px;
    background: var(--gradient-card);
    border-radius: var(--radius-xl);
    margin-top: 24px;
}

.lock-emoji {
    font-size: 70px;
    margin-bottom: 14px;
    animation: pulse 2s ease-in-out infinite;
}

.lock-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 8px;
}

.lock-sub {
    font-size: 14px;
    color: var(--tg-hint);
    margin-bottom: 24px;
}

/* ===== Mock Test ===== */
.mock-intro {
    padding: 8px 0;
}

.mock-hero {
    text-align: center;
    padding: 32px 16px;
    background: var(--gradient-purple);
    border-radius: var(--radius-xl);
    color: white;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}

.mock-hero-emoji {
    font-size: 80px;
    margin-bottom: 12px;
    animation: pulse 2s ease-in-out infinite;
}

.mock-hero-title {
    font-size: 18px;
    font-weight: 700;
}

.mock-rules {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.mock-rule {
    background: var(--tg-secondary-bg);
    padding: 14px 18px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 14px;
}

.mock-rule-icon {
    font-size: 26px;
    width: 40px;
}

.mock-note {
    text-align: center;
    margin-top: 14px;
    color: var(--tg-hint);
    font-size: 13px;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: var(--tg-bg);
    border-top: 1px solid rgba(127, 127, 127, 0.1);
    display: flex;
    justify-content: space-around;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    z-index: 100;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.nav-item {
    background: transparent;
    border: none;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    color: var(--tg-hint);
    font-size: 10.5px;
    font-weight: 500;
    transition: all var(--t-base);
    border-radius: var(--radius-md);
    flex: 1;
    min-width: 0;
}

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

.nav-item.active .nav-icon {
    transform: scale(1.2);
    filter: drop-shadow(0 4px 8px rgba(99, 102, 241, 0.4));
}

.nav-icon {
    font-size: 22px;
    transition: transform var(--t-spring);
}

/* ===== Skeleton ===== */
.skeleton-loader {
    background: linear-gradient(90deg,
        var(--tg-secondary-bg) 0%,
        rgba(99, 102, 241, 0.08) 50%,
        var(--tg-secondary-bg) 100%);
    background-size: 200% 100%;
    animation: skeleton 1.5s infinite;
    height: 100px;
    border-radius: var(--radius-md);
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 32px 20px;
    color: var(--tg-hint);
    background: var(--tg-secondary-bg);
    border-radius: var(--radius-md);
    font-size: 14px;
}

.empty-emoji {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.7;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: rgba(15, 23, 42, 0.95);
    color: white;
    padding: 14px 22px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: all var(--t-spring);
    pointer-events: none;
    backdrop-filter: blur(20px);
    max-width: 85%;
    text-align: center;
    box-shadow: var(--shadow-xl);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    background: linear-gradient(135deg, #10b981, #059669);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4);
}

.toast.error {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4);
}

.toast.warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 8px 24px rgba(245, 158, 11, 0.4);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    animation: pageFadeIn var(--t-base);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--tg-bg);
    border-radius: var(--radius-xl);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: bounceIn var(--t-spring);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 28px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--tg-hint);
    transition: background var(--t-fast);
}

.modal-close:active {
    background: var(--tg-secondary-bg);
}

/* ===== Responsive ===== */
@media (max-width: 380px) {
    .stats-grid {
        gap: 6px;
    }

    .stat-value {
        font-size: 18px;
    }

    .topics-grid {
        grid-template-columns: 1fr;
    }

    .nav-label {
        font-size: 9px;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}

/* ===== Hide page-specific elements when not active ===== */
.page:not(.active) {
    display: none !important;
}
