:root {
    --primary: #4F46E5;
    --secondary: #7C3AED;
    --success: #22C55E;
    --warning: #F59E0B;
    --danger: #EF4444;
    --background: #0F172A;
    --surface: #1E293B;
    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --border: #334155;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 20px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 40px rgba(0,0,0,.45);
    --font: 'Nunito', system-ui, sans-serif;
    --nav-height: 64px;
    --header-height: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: dark;
}

html.light-theme {
    --background: #F8FAFC;
    --surface: #FFFFFF;
    --text: #111827;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --shadow: 0 4px 20px rgba(0,0,0,.08);
    --shadow-lg: 0 10px 40px rgba(79,70,229,.15);
    color-scheme: light;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--background);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

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

.app { min-height: 100vh; display: flex; flex-direction: column; }
.app-main { flex: 1; padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px); }

/* Header */
.app-header {
    display: flex; align-items: center; justify-content: space-between;
    height: var(--header-height); padding: 0 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
}

.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; color: var(--text); }
.logo-icon {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800;
}
.logo-text { font-size: 18px; }
.header-title { font-size: 16px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-stats { display: flex; gap: 8px; }
.stat-coin {
    display: flex; align-items: center; gap: 4px;
    background: #FEF3C7; color: #D97706; padding: 4px 10px;
    border-radius: 20px; font-size: 13px; font-weight: 700;
}
.stat-coin svg { color: #F59E0B; }

.btn-icon {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    border-radius: 10px; color: var(--text); transition: background .2s;
}
.btn-icon:hover { background: var(--background); }

.avatar-sm {
    width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
}
.avatar-icon { width: 100%; height: 100%; background: linear-gradient(135deg, #818CF8, #A78BFA); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 24px; border-radius: var(--radius-sm); font-weight: 700;
    font-size: 15px; transition: all .2s; min-height: 44px; border: 2px solid transparent;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; box-shadow: var(--shadow-lg);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 30px rgba(79,70,229,.3); }
.btn-secondary { background: var(--background); color: var(--primary); border-color: var(--border); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-white { background: #fff; color: var(--primary); }
.btn-sm { padding: 8px 16px; font-size: 13px; min-height: 36px; }
.btn-xl { padding: 16px 40px; font-size: 18px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn.loading { opacity: .7; pointer-events: none; }

/* Hero */
.hero {
    padding: 40px 20px 24px; text-align: center;
    background: linear-gradient(180deg, rgba(79,70,229,.08) 0%, transparent 100%);
}
.logo-big {
    width: 80px; height: 80px; margin: 0 auto 16px; border-radius: 24px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; font-size: 40px; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-lg);
}
.hero-title { font-size: 32px; font-weight: 800; margin-bottom: 8px; }
.hero-slogan { color: var(--text-muted); font-size: 16px; margin-bottom: 28px; }
.btn-play { margin: 0 auto; }

/* Cards */
.card {
    background: var(--surface); border-radius: var(--radius);
    padding: 20px; box-shadow: var(--shadow); margin: 16px;
}
.card-gradient {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; text-align: center;
}
.card-gradient p { margin-bottom: 12px; opacity: .9; }

/* Quick Actions */
.action-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
    padding: 0 16px 16px;
}
.action-card {
    background: var(--surface); border-radius: var(--radius); padding: 20px;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    box-shadow: var(--shadow); transition: transform .2s; color: var(--text);
    font-weight: 700; font-size: 14px;
}
.action-card:hover { transform: translateY(-2px); }
.action-icon {
    width: 52px; height: 52px; border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
}
.action-icon-levels { background: #EDE9FE; color: var(--primary); }
.action-icon-daily { background: #DCFCE7; color: var(--success); }
.action-icon-trophy { background: #FEF3C7; color: var(--warning); }
.action-icon-achievement { background: #FEE2E2; color: var(--danger); }

/* Stats */
.stats-row {
    display: flex; justify-content: space-around; padding: 16px;
    background: var(--surface); margin: 0 16px 16px; border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.stat-item { text-align: center; }
.stat-value { display: block; font-size: 18px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); }

/* Bottom Nav */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
    display: flex; z-index: 100;
}
.nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; color: var(--text-muted);
    font-size: 10px; font-weight: 600; transition: color .2s; min-height: 44px;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 22px; height: 22px; }

/* Auth */
.auth-page .app-main { display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-container { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--surface); border-radius: var(--radius); padding: 32px;
    box-shadow: var(--shadow-lg); text-align: center;
}
.auth-logo {
    width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: #fff; font-size: 28px; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
}
.auth-card h1 { font-size: 24px; margin-bottom: 8px; }
.auth-subtitle { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }
.auth-form { text-align: left; }
.auth-link { margin-top: 16px; font-size: 14px; color: var(--text-muted); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 12px 16px; border: 2px solid var(--border);
    border-radius: var(--radius-sm); font-size: 16px; transition: border .2s;
    background: var(--surface); color: var(--text);
}
.form-group input:focus { outline: none; border-color: var(--primary); }

/* Alerts */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; font-weight: 600; }
.alert-error { background: #FEE2E2; color: var(--danger); }
.alert-success { background: #DCFCE7; color: var(--success); }
.alert-info { background: #EDE9FE; color: var(--primary); }

/* Toast */
.toast-container { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
    padding: 12px 20px; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
    opacity: 0; transform: translateY(-10px); transition: all .3s;
    box-shadow: var(--shadow); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }

/* Levels Map */
.levels-map { padding: 16px; }
.levels-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 10px; max-width: 600px; margin: 0 auto;
}
.level-node {
    aspect-ratio: 1; border-radius: 14px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; font-weight: 800;
    box-shadow: var(--shadow); transition: transform .2s; position: relative;
}
.level-node.unlocked { background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff; cursor: pointer; }
.level-node.unlocked:hover { transform: scale(1.05); }
.level-node.completed { background: linear-gradient(135deg, var(--success), #16A34A); color: #fff; }
.level-node.locked { background: #E2E8F0; color: #94A3B8; cursor: not-allowed; }
.level-num { font-size: 16px; }
.level-stars, .level-status { font-size: 10px; margin-top: 2px; }

/* Daily Word */
.daily-word-card { padding: 0 16px; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge-gold { background: #FEF3C7; color: #D97706; }
.daily-hint { color: var(--text-muted); margin: 12px 0; font-style: italic; }

/* Guest */
.guest-banner, .guest-notice { padding: 0 16px 16px; }
.guest-notice {
    position: fixed; bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
    left: 16px; right: 16px; background: var(--surface); padding: 12px 16px;
    border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 13px; text-align: center; z-index: 50;
}

/* Profile */
.profile-header {
    text-align: center; padding: 32px 20px;
    background: linear-gradient(180deg, rgba(79,70,229,.1) 0%, transparent 100%);
}
.profile-avatar {
    width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 12px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; color: #fff; font-weight: 800;
    border: 4px solid var(--surface); box-shadow: var(--shadow);
}
.profile-name { font-size: 22px; font-weight: 800; }
.profile-level { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
.xp-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin: 0 32px; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 4px; transition: width .5s; }

.profile-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
    padding: 16px;
}
.profile-stat {
    background: var(--surface); border-radius: var(--radius-sm); padding: 16px;
    text-align: center; box-shadow: var(--shadow);
}
.profile-stat-value { font-size: 20px; font-weight: 800; color: var(--primary); display: block; }
.profile-stat-label { font-size: 12px; color: var(--text-muted); }

/* Leaderboard */
.leaderboard-tabs { display: flex; gap: 8px; padding: 16px 16px 0; }
.tab-btn {
    flex: 1; padding: 10px; border-radius: var(--radius-sm); font-weight: 700;
    font-size: 13px; background: var(--background); color: var(--text-muted);
    border: 2px solid transparent; transition: all .2s;
}
.tab-btn.active { background: var(--primary); color: #fff; }
.leaderboard-list { padding: 16px; }
.leaderboard-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 16px;
    background: var(--surface); border-radius: var(--radius-sm); margin-bottom: 8px;
    box-shadow: var(--shadow);
}
.leaderboard-rank {
    width: 32px; height: 32px; border-radius: 50%; display: flex;
    align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
    background: var(--background);
}
.leaderboard-rank.gold { background: #FEF3C7; color: #D97706; }
.leaderboard-rank.silver { background: #F1F5F9; color: #64748B; }
.leaderboard-rank.bronze { background: #FED7AA; color: #EA580C; }
.leaderboard-name { flex: 1; font-weight: 700; }
.leaderboard-score { font-weight: 800; color: var(--primary); }

/* Achievements */
.achievement-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px; }
.achievement-card {
    background: var(--surface); border-radius: var(--radius); padding: 16px;
    text-align: center; box-shadow: var(--shadow); transition: transform .2s;
}
.achievement-card.locked { opacity: .5; }
.achievement-icon { font-size: 32px; margin-bottom: 8px; }
.achievement-title { font-size: 13px; font-weight: 700; }
.achievement-desc { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Daily Tasks */
.daily-reward-banner {
    margin: 16px; padding: 20px; border-radius: var(--radius);
    background: linear-gradient(135deg, #F59E0B, #EF4444); color: #fff; text-align: center;
}
.task-list { padding: 0 16px 16px; }
.task-item {
    display: flex; align-items: center; gap: 12px; padding: 16px;
    background: var(--surface); border-radius: var(--radius-sm); margin-bottom: 8px;
    box-shadow: var(--shadow);
}
.task-progress { flex: 1; }
.task-progress-bar { height: 6px; background: var(--border); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.task-progress-fill { height: 100%; background: var(--success); border-radius: 3px; }
.task-reward { font-size: 13px; font-weight: 700; color: var(--warning); white-space: nowrap; }

/* Statistics */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 16px; }
.stat-card {
    background: var(--surface); border-radius: var(--radius-sm); padding: 16px;
    box-shadow: var(--shadow);
}
.stat-card-value { font-size: 24px; font-weight: 800; color: var(--primary); }
.stat-card-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.chart-container { padding: 16px; margin: 0 16px 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.chart-bar { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 20px; }
.chart-bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar-fill { width: 100%; background: linear-gradient(180deg, var(--primary), var(--secondary)); border-radius: 4px 4px 0 0; min-height: 4px; transition: height .5s; }
.chart-bar-label { font-size: 10px; color: var(--text-muted); }

/* Settings */
.settings-list { padding: 16px; }
.setting-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px; background: var(--surface); border-radius: var(--radius-sm);
    margin-bottom: 8px; box-shadow: var(--shadow);
}
.setting-label { font-weight: 600; }
.toggle {
    width: 48px; height: 28px; min-width: 48px; border-radius: 14px;
    background: var(--border); border: none; padding: 0;
    position: relative; transition: background .2s; cursor: pointer;
    flex-shrink: 0; -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.toggle.active { background: var(--primary); }
.toggle::after {
    content: ''; position: absolute; top: 3px; left: 3px;
    width: 22px; height: 22px; border-radius: 50%; background: #fff;
    transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle.active::after { transform: translateX(20px); }

/* Ad Slots */
.ad-slot { margin: 16px; padding: 12px; background: var(--background); border-radius: var(--radius-sm); text-align: center; min-height: 50px; font-size: 12px; color: var(--text-muted); }

/* Empty State */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* Loading */
.loading-spinner {
    width: 32px; height: 32px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%;
    animation: spin .8s linear infinite; margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* Responsive */
@media (min-width: 768px) {
    .app-main { max-width: 480px; margin: 0 auto; width: 100%; }
    .bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
    .action-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 1024px) {
    .app-main { max-width: 600px; }
    .bottom-nav { max-width: 600px; }
}

/* Dark mode */
html.dark,
body.dark {
    --background: #0F172A;
    --surface: #1E293B;
    --text: #F1F5F9;
    --text-muted: #94A3B8;
    --border: #334155;
    --shadow: 0 4px 20px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 40px rgba(0,0,0,.45);
    color-scheme: dark;
}

html.dark body,
body.dark {
    background: var(--background);
    color: var(--text);
}

html.dark .app-header,
body.dark .app-header {
    background: var(--surface);
    border-bottom-color: var(--border);
}

html.dark .bottom-nav,
body.dark .bottom-nav {
    background: var(--surface);
    border-top-color: var(--border);
}

html.dark .card,
html.dark .action-card,
html.dark .profile-stat,
html.dark .setting-item,
html.dark .stat-card,
html.dark .leaderboard-item,
html.dark .task-item,
html.dark .level-node.unlocked,
html.dark .auth-card,
body.dark .card,
body.dark .action-card,
body.dark .profile-stat,
body.dark .setting-item,
body.dark .stat-card,
body.dark .leaderboard-item,
body.dark .task-item,
body.dark .level-node.unlocked,
body.dark .auth-card {
    background: var(--surface);
    color: var(--text);
}

html.dark .form-group input,
html.dark .form-group select,
html.dark .form-group textarea,
html.dark .profile-edit-content input,
body.dark .form-group input,
body.dark .form-group select,
body.dark .form-group textarea,
body.dark .profile-edit-content input {
    background: var(--background);
    color: var(--text);
    border-color: var(--border);
}

html.dark .btn-secondary,
html.dark .btn-outline,
body.dark .btn-secondary,
body.dark .btn-outline {
    background: var(--background);
    color: var(--text);
    border-color: var(--border);
}

html.dark .nav-item,
body.dark .nav-item {
    color: var(--text-muted);
}

html.dark .nav-item.active,
body.dark .nav-item.active {
    color: var(--primary);
}

html.dark .toggle,
body.dark .toggle {
    background: var(--border);
}

html.dark .stats-row,
html.dark .user-stats-bar .stats-row,
body.dark .stats-row {
    background: var(--surface);
}
