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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #14141e;
    --bg-card: #1a1a2e;
    --bg-card-hover: #22223a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b8;
    --text-muted: #6c6c84;
    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --success: #00d4aa;
    --warning: #fbbf24;
    --danger: #ef4444;
    --border: #2a2a42;
    --radius: 16px;
    --radius-sm: 10px;
    --tg-bg: var(--tg-theme-bg-color, #0a0a0f);
    --tg-text: var(--tg-theme-text-color, #ffffff);
    --tg-hint: var(--tg-theme-hint-color, #a0a0b8);
    --tg-link: var(--tg-theme-link-color, #6c5ce7);
    --tg-button: var(--tg-theme-button-color, #6c5ce7);
    --tg-button-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #14141e);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--tg-bg);
    color: var(--tg-text);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 420px;
    min-height: 100vh;
    background: var(--tg-bg);
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.header {
    padding: 16px 16px 12px;
    background: var(--tg-secondary-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.logo-icon {
    font-size: 20px;
    background: linear-gradient(135deg, #6c5ce7, #a855f7);
    padding: 6px;
    border-radius: 10px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-text {
    font-size: 16px;
    font-weight: 800;
    background: linear-gradient(135deg, #ffffff, #a0a0b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    padding: 4px 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 3px;
    flex-wrap: wrap;
}

.stat-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-value {
    font-size: 12px;
    font-weight: 700;
    color: var(--tg-text);
}

.stat-currency {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-divider {
    width: 1px;
    height: 16px;
    background: var(--border);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 12px 16px;
    padding-bottom: 70px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Plan Card */
.plan-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}

.plan-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #6c5ce7, #a855f7, #6c5ce7);
    background-size: 200% 100%;
    animation: gradientMove 3s ease infinite;
}

@keyframes gradientMove {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

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

.plan-icon {
    font-size: 20px;
}

.plan-header h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--tg-text);
    letter-spacing: -0.3px;
}

.plan-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.plan-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--tg-bg);
    padding: 8px;
    border-radius: var(--radius-sm);
}

.plan-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.plan-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--tg-text);
}

.plan-value.highlight {
    color: var(--success);
    font-size: 16px;
}

.plan-description {
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 8px;
    background: var(--tg-bg);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border);
}

.plan-description p {
    margin: 0;
}

/* User Card */
.user-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.user-avatar {
    font-size: 28px;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-text);
}

.user-balance {
    font-size: 12px;
    color: var(--text-secondary);
}

.user-investment {
    text-align: right;
}

.invest-label {
    font-size: 10px;
    color: var(--text-muted);
    display: block;
}

.invest-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--success);
}

/* Invest Button */
.invest-button {
    width: 100%;
    padding: 14px;
    background: var(--tg-button);
    border: none;
    border-radius: var(--radius);
    color: var(--tg-button-text);
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.invest-button:active {
    transform: scale(0.98);
}

.button-icon {
    font-size: 18px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content {
    background: var(--tg-secondary-bg);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 400px;
    width: 100%;
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 {
    font-size: 17px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--tg-text);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input {
    padding: 10px 12px;
    background: var(--tg-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--tg-text);
    font-size: 14px;
    transition: border-color 0.2s;
    outline: none;
    -webkit-appearance: none;
}

.input-group input:focus {
    border-color: var(--tg-link);
}

.input-group input::placeholder {
    color: var(--text-muted);
}

.input-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.input-hint span {
    color: var(--tg-text);
    font-weight: 600;
}

.modal-info {
    background: var(--tg-bg);
    padding: 12px;
    border-radius: var(--radius-sm);
}

.modal-info p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 4px 0;
}

.modal-info .modal-warning {
    color: var(--warning);
    font-size: 11px;
    margin-top: 6px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.modal-button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-button.confirm {
    background: var(--tg-button);
    color: var(--tg-button-text);
}

.modal-button.confirm:active {
    transform: scale(0.98);
}

.modal-button.confirm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.modal-button.cancel {
    background: var(--bg-card);
    color: var(--text-secondary);
}

.modal-button.cancel:active {
    transform: scale(0.98);
}

/* Tab Content */
.tab-content {
    animation: fadeIn 0.3s ease;
}

/* Wallet Tab */
.wallet-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
}

.wallet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.wallet-header h3 {
    font-size: 15px;
    font-weight: 700;
}

.wallet-connect {
    padding: 6px 14px;
    background: var(--tg-button);
    color: var(--tg-button-text);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.wallet-connect:active {
    transform: scale(0.95);
}

.wallet-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wallet-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

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

.wallet-label {
    color: var(--text-secondary);
    font-size: 13px;
}

.wallet-address {
    font-size: 12px;
    color: var(--tg-text);
    font-family: monospace;
    word-break: break-all;
    text-align: right;
    max-width: 60%;
}

.wallet-balance,
.wallet-invested {
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-text);
}

/* Top Tab */
.top-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
}

.top-card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
}

.top-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.top-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--tg-bg);
    border-radius: var(--radius-sm);
}

.top-rank {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    width: 30px;
}

.top-wallet {
    flex: 1;
    font-size: 13px;
    font-family: monospace;
    color: var(--tg-text);
}

.top-amount {
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
}

.top-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px 0;
    font-size: 13px;
}

/* Referral Tab */
.referral-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
}

.referral-card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
}

.referral-info p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}

.referral-link {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.referral-link input {
    flex: 1;
    padding: 8px 12px;
    background: var(--tg-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--tg-text);
    font-size: 12px;
    font-family: monospace;
    outline: none;
}

.copy-button {
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--tg-text);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
}

.copy-button:active {
    transform: scale(0.95);
}

.referral-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.referral-stat {
    background: var(--tg-bg);
    padding: 10px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.referral-stat .stat-label {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.referral-stat .stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--tg-text);
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-width: 420px;
    width: 100%;
    background: var(--tg-secondary-bg);
    border-top: 1px solid var(--border);
    display: flex;
    padding: 6px 0 env(safe-area-inset-bottom);
    z-index: 200;
    flex-shrink: 0;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 6px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

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

.nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 2px;
    background: var(--tg-link);
    border-radius: 0 0 3px 3px;
}

.nav-icon {
    font-size: 20px;
}

.nav-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Responsive */
@media (max-width: 420px) {
    .header {
        padding: 12px 12px 10px;
    }
    
    .stat-value {
        font-size: 11px;
    }
    
    .plan-details {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
    
    .plan-value {
        font-size: 12px;
    }
    
    .plan-value.highlight {
        font-size: 14px;
    }
    
    .main-content {
        padding: 10px 12px;
        padding-bottom: 60px;
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 3px;
}

::-webkit-scrollbar-track {
    background: var(--tg-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--tg-link);
    border-radius: 2px;
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--tg-button);
    animation: spin 0.8s linear infinite;
}

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

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 380px;
    width: 90%;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--tg-text);
    font-size: 13px;
    z-index: 2000;
    animation: slideUp 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

.toast.warning {
    border-color: var(--warning);
}