@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700&family=Sora:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;600&display=swap');

/* Shared stylesheet for common rules (keeps pages lightweight and consistent) */
:root {
    color-scheme: light;
    --font-body: "Manrope", "Noto Sans SC", "Noto Sans", sans-serif;
    --font-display: "Sora", "Noto Sans SC", "Noto Sans", sans-serif;
    --ui-bg: #f4f6f8;
    --ui-bg-alt: #eef1f4;
    --ui-surface: rgba(255, 255, 255, 0.88);
    --ui-surface-solid: #ffffff;
    --ui-border: rgba(31, 41, 55, 0.12);
    --ui-text: #2e3643;
    --ui-text-muted: #6b7280;
    --ui-accent: #7b8da3;
    --ui-accent-strong: #5e7084;
    --ui-shadow: 0 26px 55px rgba(15, 23, 42, 0.16);
    --ui-glow: 0 0 60px rgba(123, 141, 163, 0.2);
    --ui-highlight: rgba(123, 141, 163, 0.08);
    --ui-highlight-strong: rgba(123, 141, 163, 0.18);
    --ui-danger: #d27c7c;
    --ui-success: #2b9a6a;
    --ui-ambient-1: rgba(160, 176, 196, 0.28);
    --ui-ambient-2: rgba(186, 198, 214, 0.22);
    --theme-toggle-icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='4'/><line x1='12' y1='2' x2='12' y2='5'/><line x1='12' y1='19' x2='12' y2='22'/><line x1='2' y1='12' x2='5' y2='12'/><line x1='19' y1='12' x2='22' y2='12'/><line x1='4.2' y1='4.2' x2='6.4' y2='6.4'/><line x1='17.6' y1='17.6' x2='19.8' y2='19.8'/><line x1='4.2' y1='19.8' x2='6.4' y2='17.6'/><line x1='17.6' y1='6.4' x2='19.8' y2='4.2'/></svg>");
}

html[data-theme="dark"] {
    color-scheme: dark;
    --ui-bg: #1f1f20;
    --ui-bg-alt: #242426;
    --ui-surface: rgba(45, 46, 49, 0.92);
    --ui-surface-solid: #2b2d31;
    --ui-border: rgba(148, 163, 184, 0.18);
    --ui-text: #e7ebf0;
    --ui-text-muted: #9aa3ad;
    --ui-accent: #7b8fa6;
    --ui-accent-strong: #a7b6c7;
    --ui-shadow: 0 30px 70px rgba(0, 0, 0, 0.45);
    --ui-glow: 0 0 70px rgba(125, 143, 166, 0.22);
    --ui-highlight: rgba(123, 143, 166, 0.2);
    --ui-highlight-strong: rgba(123, 143, 166, 0.3);
    --ui-danger: #e09b9b;
    --ui-success: #62c896;
    --ui-ambient-1: rgba(90, 96, 108, 0.35);
    --ui-ambient-2: rgba(70, 76, 88, 0.3);
    --theme-toggle-icon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'><path d='M21 12.8A8.5 8.5 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8Z'/></svg>");
}

body {
    font-family: var(--font-body);
    color: var(--ui-text);
}

.ui-controls {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    display: flex;
    gap: 0.65rem;
    z-index: 1200;
}

.ui-control {
    appearance: none;
    border: 1px solid var(--ui-border);
    background: var(--ui-surface);
    color: var(--ui-text);
    padding: 0.45rem 1.1rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.14);
}

.ui-control:hover {
    transform: translateY(-1px);
    border-color: var(--ui-accent);
    box-shadow: 0 16px 34px rgba(15, 23, 42, 0.16);
}

.ui-control[data-theme-toggle] {
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    font-size: 0;
    color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ui-control[data-theme-toggle]::before {
    content: "";
    width: 18px;
    height: 18px;
    background-color: var(--ui-text);
    -webkit-mask-image: var(--theme-toggle-icon);
    mask-image: var(--theme-toggle-icon);
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}
.is-hidden {
    display: none !important;
}

@media (max-width: 640px) {
    .ui-controls {
        top: 1rem;
        right: 1rem;
        gap: 0.5rem;
    }

    .ui-control {
        padding: 0.35rem 0.85rem;
        font-size: 0.68rem;
        letter-spacing: 0.12em;
    }

    .ui-control[data-theme-toggle] {
        width: 2.2rem;
        height: 2.2rem;
        padding: 0;
    }
}

/* Mobile: responsive rules for better canvas usage */
@media (max-width: 480px) {
    html {
        font-size: 14px; /* Naturally scale down UI elements by reducing base font size */
    }

    html, body {
        width: 100%;
        height: auto !important; /* Allow body to grow with content */
        min-height: 100vh;
        margin: 0;
        padding: 0 !important;
        overflow-x: hidden;
        overflow-y: auto !important; /* Enable scrolling on the body for mobile */
        display: block;
    }

    /* Dashboard: main content should use all available width */
    .main-content {
        padding: 4rem 1rem 1rem 1rem !important; 
        width: 100% !important;
        height: auto !important; /* Disable fixed height from desktop */
        overflow-y: visible !important; /* Let the body handle the scrolling */
        box-sizing: border-box;
        margin: 0 !important;
    }

    /* Sidebar as a solid overlay with flexible internal layout */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 75vw;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height to account for mobile bars */
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 0;
        box-shadow: 10px 0 20px rgba(0,0,0,0.05);
        display: flex;
        flex-direction: column;
    }
    
    /* Ensure the middle navigation area is scrollable if height is limited */
    .sidebar .nav-container {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Keep the bottom profile anchored but ensure it doesn't get cut off */
    .user-profile {
        margin-top: auto;
        padding: 1rem 1.5rem;
        flex-shrink: 0;
        background: var(--ui-surface-solid); /* Keep it visible over nav scroll */
    }

    /* Small height screens adjustment */
    @media (max-height: 600px) {
        .logo-area { padding-bottom: 1rem; }
        .nav-group { margin-bottom: 1rem; }
    }
    
    .sidebar.open {
        left: 0;
    }

    /* Floating action buttons or inputs */
    input, .action-btn, .btn-action {
        width: 100% !important;
        font-size: 1rem; /* keep input text readable */
    }

    /* Compact variant override: avoid forcing compact buttons to full width on mobile */
    .btn-compact {
        width: auto !important;
        min-width: 96px;
    }

    /* Restore centered, card-like login/register on mobile */
    .main-wrapper {
        max-width: 360px !important;
        width: calc(100% - 32px) !important;
        margin: 3rem auto !important;
        padding: 2rem 1.5rem !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        border-radius: 8px;
        background: var(--ui-surface);
        min-height: auto !important;
    }

    /* Move mobile menu toggle to top-left and avoid overlapping main card */
    .mobile-menu-toggle {
        display: flex !important;
        position: fixed;
        top: 1rem;
        left: 1rem; /* moved to left */
        right: auto;
        z-index: 1100;
        background: var(--ui-surface-solid);
        width: 40px;
        height: 40px;
        border-radius: 50%;
        justify-content: center;
        align-items: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border: 1px solid var(--ui-border);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), background 0.18s, box-shadow 0.18s;
        will-change: transform;
    }

    /* When sidebar opens, slide the toggle to the sidebar edge and change background */
    .mobile-menu-toggle.open {
        transform: translateX(calc(75vw - 36px)); /* nudged further right to reduce overlap */
        background: var(--ui-surface);
        box-shadow: 0 4px 14px rgba(0,0,0,0.08);
        border-color: transparent;
    }

    /* Simple icon sizing inside the toggle */
    .mobile-menu-toggle svg {
        width: 18px;
        height: 18px;
        display: block;
    }
}

/* Aff Management Styles */
.aff-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}
.aff-stat-card {
    background: var(--ui-surface-solid);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}
.aff-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.aff-stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--accent-color);
    opacity: 0.5;
}
.aff-stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.aff-stat-value {
    font-size: 1.8rem;
    font-weight: 300;
    color: var(--text-primary);
}
.aff-invite-area {
    background: var(--ui-surface-solid);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}
.aff-input-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}
.aff-input-group input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--table-header-bg);
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.9rem;
    outline: none;
}
.reward-description {
    background: var(--ui-surface-solid);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
}
.reward-description h3 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 1.2rem;
    color: var(--text-primary);
}
.reward-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.reward-list li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}
.reward-list li::before {
    content: "";
    position: absolute;
    left: 0;
    color: var(--success-color);
    font-weight: bold;
    font-size: 1.2rem;
    top: -2px;
}


/* Token Key / Code Bubble Styles */
.token-key-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.6rem;
    background-color: var(--ui-highlight);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}
.token-key-cell:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
    background-color: var(--ui-surface-solid);
}
.token-key-cell .copy-icon {
    opacity: 0.5;
    transition: opacity 0.2s;
    flex-shrink: 0;
}
.token-key-cell:hover .copy-icon {
    opacity: 1;
}

