:root {
  --bg: #f3f5fb;
  --card: #ffffff;
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --accent: #00d2a0;
  --coin: #f5a623;
  --danger: #ff5c5c;
  --text: #22243a;
  --text-dim: #7a7d95;
  --border: #e9ebf5;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(40, 40, 90, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: #dfe3ef;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
}

.phone {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow-x: hidden;
}

/* ---------- Screens ---------- */
.screen { display: none; }
.screen.active { display: block; }
.main-app { display: none; flex-direction: column; min-height: 100vh; }
.main-app.active { display: flex; }

/* ---------- Auth ---------- */
.auth-wrap {
  padding: 60px 28px 28px;
  display: flex; flex-direction: column; align-items: center;
  min-height: 100vh; position: relative;
  background: linear-gradient(180deg, #6c5ce7 0%, #a29bfe 45%, var(--bg) 45%);
}
.auth-logo { font-size: 30px; font-weight: 800; color: #fff; margin-bottom: 4px; }
.auth-sub { color: #eee; margin-bottom: 28px; font-size: 14px; }
.auth-tabs {
  display: flex; background: var(--card); border-radius: 14px; padding: 4px;
  width: 100%; margin-bottom: 20px; box-shadow: var(--shadow);
}
.auth-tab {
  flex: 1; padding: 10px; border: none; background: transparent; border-radius: 10px;
  font-weight: 600; color: var(--text-dim); cursor: pointer; font-size: 14px;
}
.auth-tab.active { background: var(--primary); color: #fff; }
.auth-form { display: none; flex-direction: column; width: 100%; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form input {
  padding: 14px; border-radius: 12px; border: 1px solid var(--border);
  font-size: 15px; background: var(--card);
}
.auth-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; }
.settings-gear {
  position: absolute; top: 18px; right: 18px; background: rgba(255,255,255,0.2);
  border: none; border-radius: 50%; width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}

.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 14px;
  border-radius: 12px; font-weight: 700; font-size: 15px; cursor: pointer;
  box-shadow: 0 4px 14px rgba(108, 92, 231, 0.35);
}
.btn-primary:active { background: var(--primary-dark); }
.btn-primary.btn-sm { padding: 10px 16px; font-size: 13px; }
.btn-secondary {
  background: #eef0fa; color: var(--text); border: none; padding: 14px;
  border-radius: 12px; font-weight: 600; font-size: 14px; cursor: pointer; margin: 16px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; background: linear-gradient(135deg, var(--primary), #8a7ffb);
  color: #fff; position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.avatar-badge {
  width: 42px; height: 42px; background: rgba(255,255,255,0.2); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 20px;
}
.top-name { font-weight: 700; font-size: 14px; }
.top-level { font-size: 12px; opacity: 0.85; }
.topbar-right { display: flex; gap: 8px; }
.coin-pill, .streak-pill {
  background: rgba(255,255,255,0.18); padding: 6px 10px; border-radius: 20px;
  font-size: 13px; font-weight: 700;
}

/* ---------- Content / cards ---------- */
.content { flex: 1; padding: 16px; padding-bottom: 90px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.section-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 18px 4px 10px;
}
.section-header h3 { margin: 0; font-size: 15px; }
.link { color: var(--primary); font-size: 13px; text-decoration: none; font-weight: 600; }

/* ---------- Hero / dashboard ---------- */
.hero-card { background: linear-gradient(135deg, #fff, #f4f2ff); }
.hero-row { display: flex; gap: 14px; align-items: center; }
.hero-avatar {
  width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; font-size: 28px; color: #fff; flex-shrink: 0;
}
.hero-info { flex: 1; }
.hero-name { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.xp-bar-wrap { width: 100%; }
.xp-bar { height: 10px; background: #ecebfa; border-radius: 8px; overflow: hidden; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width: 0%; transition: width .4s; }
.xp-label { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

.hero-stats { display: flex; justify-content: space-around; margin-top: 18px; }
.stat { text-align: center; }
.stat-val { font-size: 18px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-dim); }

.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-track { flex: 1; height: 10px; background: #ecebfa; border-radius: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width .4s; }
.progress-text { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.notif-panel { min-height: 40px; }
.empty-hint { color: var(--text-dim); font-size: 13px; text-align: center; padding: 6px 0; }
.notif-item { display: flex; justify-content: space-between; font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.notif-item:last-child { border-bottom: none; }

/* ---------- Quests ---------- */
.quest-tabs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.qtab {
  flex-shrink: 0; padding: 9px 16px; border-radius: 20px; border: none;
  background: #eceafc; color: var(--primary); font-weight: 600; font-size: 13px; cursor: pointer;
}
.qtab.active { background: var(--primary); color: #fff; }

.quest-list { display: flex; flex-direction: column; gap: 10px; }
.quest-card {
  background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.quest-card.done { opacity: 0.55; }
.quest-check {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; cursor: pointer;
  font-size: 15px; color: var(--primary); background: #fff;
}
.quest-check.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.quest-main { flex: 1; min-width: 0; }
.quest-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.quest-desc { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quest-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge-diff, .badge-reward { font-size: 10px; padding: 3px 8px; border-radius: 10px; font-weight: 700; }
.badge-diff.easy { background: #e3f9ee; color: #12b76a; }
.badge-diff.medium { background: #fff4e0; color: #d68b00; }
.badge-diff.hard { background: #ffe6e6; color: #e5484d; }
.badge-diff.epic { background: #f1e6ff; color: #8b3ff2; }
.badge-reward.xp { background: #eef0ff; color: var(--primary); }
.badge-reward.coin { background: #fff6e0; color: var(--coin); }
.quest-del { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; padding: 4px; }

.fab {
  position: fixed; bottom: 90px; right: 24px; max-width: 480px;
  background: var(--primary); color: #fff; border: none; padding: 14px 20px;
  border-radius: 30px; font-weight: 700; box-shadow: 0 6px 18px rgba(108,92,231,0.4);
  cursor: pointer; z-index: 20;
}

/* ---------- Shop ---------- */
.shop-balance { text-align: center; font-size: 14px; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.item-card {
  background: var(--card); border-radius: 16px; padding: 14px; text-align: center;
  box-shadow: var(--shadow); cursor: pointer;
}
.item-icon { font-size: 34px; margin-bottom: 8px; }
.item-name { font-size: 12px; font-weight: 700; margin-bottom: 4px; line-height: 1.3; }
.rarity-tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 8px; margin-bottom: 6px; text-transform: uppercase; }
.rarity-common { background: #eef0f5; color: #666; }
.rarity-rare { background: #e0f0ff; color: #1a73e8; }
.rarity-epic { background: #f1e6ff; color: #8b3ff2; }
.rarity-legendary { background: #fff2d6; color: #cc8b00; }
.item-price { font-size: 13px; font-weight: 800; color: var(--coin); }
.item-owned { font-size: 11px; color: var(--accent); font-weight: 700; }

.premium-card { background: linear-gradient(135deg, #2d2160, #6c5ce7); color: #fff; text-align: center; }
.premium-title { font-size: 17px; font-weight: 800; margin-bottom: 6px; }
.premium-desc { font-size: 13px; opacity: 0.9; margin-bottom: 14px; }
.premium-card .btn-primary { background: #fff; color: var(--primary); width: 100%; }

/* ---------- Leaderboard ---------- */
.lb-list { display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.lb-rank { width: 26px; text-align: center; font-weight: 800; color: var(--text-dim); }
.lb-row.top1 .lb-rank { color: #f5a623; }
.lb-row.top2 .lb-rank { color: #a0a0a0; }
.lb-row.top3 .lb-rank { color: #b4691e; }
.lb-avatar { width: 36px; height: 36px; border-radius: 50%; background: #eceafc; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.lb-info { flex: 1; }
.lb-name { font-weight: 700; font-size: 13px; }
.lb-sub { font-size: 11px; color: var(--text-dim); }
.lb-xp { font-weight: 800; color: var(--primary); font-size: 13px; }

/* ---------- Profile ---------- */
.profile-card { text-align: center; }
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%; margin: 0 auto 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center; font-size: 36px; color: #fff;
}
.profile-name { font-weight: 800; font-size: 18px; }
.profile-username { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; }

.achievements-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.achv-badge { background: var(--card); border-radius: 14px; padding: 10px 4px; text-align: center; box-shadow: var(--shadow); }
.achv-icon { font-size: 22px; }
.achv-title { font-size: 9px; font-weight: 700; margin-top: 4px; line-height: 1.2; }

/* ---------- Social ---------- */
.post-form { display: flex; gap: 8px; margin-bottom: 16px; }
.post-form input { flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); font-size: 14px; }
.feed-list { display: flex; flex-direction: column; gap: 10px; }
.post-card { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); }
.post-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.post-avatar { width: 30px; height: 30px; border-radius: 50%; background: #eceafc; display: flex; align-items: center; justify-content: center; font-size: 14px; }
.post-author { font-weight: 700; font-size: 13px; }
.post-meta { font-size: 11px; color: var(--text-dim); }
.post-content { font-size: 14px; margin-bottom: 8px; }
.post-actions { display: flex; gap: 16px; font-size: 12px; color: var(--text-dim); }
.post-actions button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px; font-weight: 600; }
.post-actions button.liked { color: var(--danger); }
.post-comments { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
.comment-row { font-size: 12px; margin-bottom: 4px; }
.comment-form { display: flex; gap: 6px; margin-top: 6px; }
.comment-form input { flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); font-size: 12px; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; background: #fff; display: flex;
  border-top: 1px solid var(--border); z-index: 15;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1; background: none; border: none; padding: 10px 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-dim); font-size: 10px; font-weight: 600;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 19px; }

/* ---------- Sub header (social) ---------- */
.subheader {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px; background: #fff; border-bottom: 1px solid var(--border);
  font-weight: 700; position: sticky; top: 0; z-index: 10;
}
.back-btn { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text); }

/* ---------- Modals ---------- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(20,20,40,0.5);
  z-index: 100; align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 480px; border-radius: 22px 22px 0 0;
  padding: 24px 20px 30px; display: flex; flex-direction: column; gap: 10px;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal h3 { margin: 0 0 4px; }
.modal input, .modal textarea, .modal select {
  padding: 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 14px; width: 100%; font-family: inherit;
}
.modal-label { font-size: 12px; color: var(--text-dim); font-weight: 700; margin-top: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 10px; }
.modal-actions button { flex: 1; }
.reward-anim { font-size: 48px; text-align: center; }
.reward-lines { text-align: center; font-size: 14px; color: var(--text-dim); margin-bottom: 6px; }
.item-preview-icon { font-size: 50px; text-align: center; }
#modal-item h3 { text-align: center; }
#modal-item p { text-align: center; color: var(--text-dim); font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #22243a; color: #fff; padding: 10px 18px; border-radius: 30px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
