/* ===== CSS Variables & Theme ===== */
:root {
    /* Colors - Dark Premium Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    
    /* Accent Colors */
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
    --accent-glow: rgba(99, 102, 241, 0.4);
    
    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);
    
    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    
    /* Wheel Colors */
    --wheel-1: #6366f1;
    --wheel-2: #8b5cf6;
    --wheel-3: #a855f7;
    --wheel-4: #d946ef;
    --wheel-5: #ec4899;
    --wheel-6: #f43f5e;
    
    /* Dimensions */
    --header-height: 70px;
    --nav-height: 70px;
    --border-radius: 16px;
    --border-radius-sm: 10px;
    
    /* Shadows */
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--accent-glow);
    
    /* Telegram Theme Integration */
    --tg-bg: var(--tg-theme-bg-color, var(--bg-primary));
    --tg-text: var(--tg-theme-text-color, var(--text-primary));
    --tg-button: var(--tg-theme-button-color, var(--accent-primary));
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.hidden {
    display: none !important;
}

/* ===== Error Screen ===== */
.error-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 9999;
}

.error-content {
    text-align: center;
    padding: 40px;
}

.error-icon {
    font-size: 80px;
    margin-bottom: 24px;
    animation: pulse 2s infinite;
}

.error-content h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
}

.error-content p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    max-width: 280px;
}

/* ===== Buttons ===== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 32px;
    background: var(--accent-gradient);
    color: white;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px var(--accent-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-full {
    width: 100%;
}

/* ===== App Container ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    max-width: 500px;
    margin: 0 auto;
    background: var(--bg-primary);
}

/* ===== Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.username {
    font-size: 15px;
    font-weight: 600;
}

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

.wallet {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bg-card);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.wallet:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-primary);
}

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

.wallet-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

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

.coins-label {
    font-size: 11px;
    color: var(--text-muted);
}

.wallet-arrow {
    font-size: 18px;
    color: var(--text-muted);
}

/* ===== Pages Container ===== */
.pages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.page {
    display: none;
    min-height: 100%;
    padding: 20px 16px;
    padding-bottom: calc(var(--nav-height) + 20px);
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

.page-header {
    text-align: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Spin Wheel Page ===== */
.spin-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 10px;
}

.spins-remaining {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    margin-bottom: 30px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.spins-icon {
    font-size: 24px;
}

.spins-count {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent-primary);
}

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

.wheel-wrapper {
    position: relative;
    width: 300px;
    height: 300px;
    margin-bottom: 30px;
}

.wheel-glow {
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
    animation: pulse 3s infinite;
    pointer-events: none;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

#wheel-canvas {
    position: relative;
    z-index: 2;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

.wheel-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: var(--bg-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    z-index: 3;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.1);
}

.wheel-pointer {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 36px;
    color: var(--warning);
    z-index: 4;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
    animation: bounce 1s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(5px); }
}

.spin-button {
    position: relative;
    padding: 18px 60px;
    font-size: 20px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-glow);
}

.spin-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 60px var(--accent-glow);
}

.spin-button:active:not(:disabled) {
    transform: scale(0.98);
}

.spin-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.spin-button-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shine 3s infinite;
}

@keyframes shine {
    0%, 100% { left: -100%; }
    50% { left: 100%; }
}

.spin-hint {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-muted);
}

/* ===== Win Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 40px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    animation: modalPop 0.4s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.win-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: celebrate 0.5s ease;
}

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

.win-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 12px;
}

.win-amount {
    font-size: 36px;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 24px;
}

/* ===== Confetti ===== */
.confetti-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100%) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(400px) rotate(720deg);
        opacity: 0;
    }
}

/* ===== Tasks Page ===== */
.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.3s ease;
}

.task-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-primary);
}

.task-card.completed {
    opacity: 0.5;
}

.task-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.task-info {
    flex: 1;
}

.task-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.task-reward {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--success);
}

.task-action {
    padding: 10px 20px;
    background: transparent;
    border: 2px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: 50px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.task-action:hover {
    background: var(--accent-primary);
    color: white;
}

.task-card.completed .task-action {
    background: var(--success);
    border-color: var(--success);
    color: white;
    cursor: default;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-card);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ===== Wallet Page ===== */
.wallet-balance-card {
    background: var(--accent-gradient);
    border-radius: var(--border-radius);
    padding: 30px;
    text-align: center;
    margin-bottom: 24px;
    box-shadow: var(--shadow-glow);
}

.balance-label {
    font-size: 14px;
    opacity: 0.8;
    margin-bottom: 8px;
}

.balance-amount {
    font-size: 48px;
    font-weight: 800;
}

.balance-coins {
    font-size: 16px;
    opacity: 0.8;
}

.withdrawal-section {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.withdrawal-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
}

.withdrawal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.form-group input,
.form-group select {
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.withdrawal-history h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: var(--border-radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-amount {
    font-size: 15px;
    font-weight: 600;
}

.history-date {
    font-size: 12px;
    color: var(--text-muted);
}

.history-status {
    padding: 6px 12px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 600;
}

.history-status.pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.history-status.approved {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.history-status.rejected {
    background: rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* ===== Bottom Navigation ===== */
.bottom-nav {
    display: flex;
    align-items: center;
    justify-content: space-around;
    height: var(--nav-height);
    background: var(--bg-secondary);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: var(--border-radius-sm);
}

.nav-item:hover {
    color: var(--text-secondary);
}

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

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

.nav-label {
    font-size: 11px;
    font-weight: 500;
}

/* ===== Toast Notification ===== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    transition: transform 0.3s ease;
}

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

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

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

.toast-message {
    font-size: 14px;
    font-weight: 500;
}

/* ===== Responsive Adjustments ===== */
@media (max-width: 360px) {
    .wheel-wrapper {
        width: 260px;
        height: 260px;
    }
    
    #wheel-canvas {
        width: 260px;
        height: 260px;
    }
    
    .spin-button {
        padding: 16px 40px;
        font-size: 18px;
    }
}

@media (min-width: 500px) {
    #app {
        border-left: 1px solid rgba(255, 255, 255, 0.05);
        border-right: 1px solid rgba(255, 255, 255, 0.05);
    }
}
