/* ============== Tokens ============== */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --surface-3: #f0f0f2;
  --border: #ececef;
  --border-strong: #e2e2e6;
  --text: #0a0a0a;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --accent: #0a0a0a;
  --streak: #ff6b35;
  --xp: #f5b800;
  --success: #34c759;
  --shadow-sm: 0 1px 2px rgba(10, 10, 10, 0.04), 0 0 0 1px rgba(10, 10, 10, 0.04);
  --shadow-md: 0 6px 24px rgba(10, 10, 10, 0.06), 0 0 0 1px rgba(10, 10, 10, 0.04);
  --shadow-lg: 0 20px 50px rgba(10, 10, 10, 0.12);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --radius-xl: 28px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ============== Reset ============== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  color: var(--text);
  background: #e9e9ec;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
  letter-spacing: -0.01em;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
h1, h2, h3, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }

/* ============== Device frame ============== */
.device {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100vh;
  max-height: 932px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 500px) {
  body { display: flex; align-items: center; justify-content: center; padding: 24px; }
  .device {
    height: 900px;
    border-radius: 48px;
    box-shadow: var(--shadow-lg), 0 0 0 8px #111, 0 0 0 9px #2a2a2a;
  }
}

/* ============== Status bar ============== */
.status-bar {
  flex-shrink: 0;
  height: 44px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  font-weight: 600;
  background: var(--bg);
  position: relative;
  z-index: 10;
}
.status-icons { display: flex; gap: 6px; align-items: center; }

/* ============== Pages ============== */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 20px 100px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.page::-webkit-scrollbar { display: none; }
.page.active {
  display: block;
  animation: pageIn 0.35s var(--ease);
}
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============== Page header ============== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 4px 24px;
}
.eyebrow {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 4px;
}
.page-header h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.2s var(--ease), background 0.2s;
}
.avatar-btn:active { transform: scale(0.92); background: var(--surface-3); }
.avatar-initial {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

/* ============== Hero card ============== */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 22px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}
.metric-label {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 4px;
}
.metric-value {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}
.metric-sub {
  font-size: 22px;
  font-weight: 500;
  color: var(--text-3);
  margin-left: 2px;
}
.hero-stats { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  padding: 7px 12px;
  border-radius: 100px;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}
.chip b { font-weight: 700; }
.chip-streak { background: rgba(255, 107, 53, 0.08); color: #b34a1e; }
.chip-xp { background: var(--surface-2); }

.progress-track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #0a0a0a, #2d2d2d);
  border-radius: 100px;
  transition: width 0.6s var(--ease);
}
.hero-caption {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 500;
}

/* ============== Quote banner ============== */
.quote-banner {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.quote-banner p {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.45;
  position: relative;
  z-index: 1;
}
.quote-mark {
  position: absolute;
  top: -20px;
  right: 14px;
  font-size: 120px;
  font-weight: 800;
  color: rgba(255,255,255,0.08);
  font-family: Georgia, serif;
  line-height: 1;
}

/* ============== Section header ============== */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 4px 12px;
}
.section-head.flush { padding-top: 0; }
.section-head h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.section-head .muted { font-size: 13px; color: var(--text-2); font-weight: 500; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s, transform 0.15s var(--ease);
}
.ghost-btn:active { transform: scale(0.96); background: var(--surface-3); }
.ghost-btn.small { padding: 6px 12px; font-size: 12px; }

/* ============== Tasks ============== */
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  transition: transform 0.2s var(--ease), background 0.2s;
}
.task:active { transform: scale(0.99); }
.task[data-done="true"] { background: var(--surface-2); }
.task[data-done="true"] .task-title { color: var(--text-2); text-decoration: line-through; text-decoration-color: var(--text-3); }

.task-check {
  flex-shrink: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.25s var(--ease);
}
.task-check svg { width: 16px; height: 16px; opacity: 0; transform: scale(0.5); transition: all 0.25s var(--ease); }
.task[data-done="true"] .task-check {
  background: var(--accent);
  border-color: var(--accent);
}
.task[data-done="true"] .task-check svg { opacity: 1; transform: scale(1); }

.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.task-meta { font-size: 12px; color: var(--text-2); font-weight: 500; }
.task-emoji { font-size: 22px; flex-shrink: 0; }

/* ============== Groups ============== */
.search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border-radius: 100px;
  padding: 11px 16px;
  margin-bottom: 16px;
}
.search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
}
.search-wrap input::placeholder { color: var(--text-3); }

.pill-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -20px 20px;
  padding: 0 20px 4px;
  scrollbar-width: none;
}
.pill-row::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 100px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  transition: all 0.2s;
}
.pill.active { background: var(--accent); color: #fff; }

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 12px;
  transition: transform 0.2s var(--ease);
}
.group-card:active { transform: scale(0.99); }
.group-card.joined { padding: 18px; }
.group-head { display: flex; align-items: center; gap: 14px; }
.group-emoji {
  width: 44px; height: 44px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.group-info { flex: 1; min-width: 0; }
.group-title { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.group-meta { font-size: 12px; color: var(--text-2); font-weight: 500; }
.join-btn {
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.15s var(--ease);
}
.join-btn:active { transform: scale(0.94); }
.badge-joined {
  background: var(--surface-2);
  color: var(--text-2);
  padding: 6px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}

.section-mini {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 16px;
  margin-bottom: 10px;
}
.section-mini.outside { padding: 0 4px; margin-top: 24px; }

.leaderboard { display: flex; flex-direction: column; gap: 4px; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.leaderboard li:first-child { border-top: none; padding-top: 4px; }
.leaderboard .rank {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.leaderboard .rank-1 { background: #fcd34d; color: #1f1b00; }
.leaderboard .rank-2 { background: #e5e7eb; color: #1f2937; }
.leaderboard .lb-name { flex: 1; font-size: 14px; font-weight: 600; }
.leaderboard .lb-xp { font-size: 13px; color: var(--text-2); font-weight: 500; }
.leaderboard .me .lb-name { color: var(--accent); }
.leaderboard .me .rank { background: var(--accent); color: #fff; }

/* ============== Stats ============== */
.level-card {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 22px;
  margin-bottom: 14px;
  position: relative;
  overflow: hidden;
}
.level-card::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,0.08), transparent 70%);
  border-radius: 50%;
}
.level-row { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; position: relative; z-index: 1; }
.level-label { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.level-sub { font-size: 13px; color: rgba(255,255,255,0.65); margin-top: 2px; font-weight: 500; }
.level-xp { text-align: right; }
.level-xp p { font-size: 32px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.level-xp span { font-size: 12px; color: rgba(255,255,255,0.65); font-weight: 600; letter-spacing: 0.06em; }
.level-card .progress-track { background: rgba(255,255,255,0.15); position: relative; z-index: 1; }
.level-card .progress-fill { background: #fff; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 12px; color: var(--text-2); font-weight: 500; margin-bottom: 8px; }
.stat-value { display: flex; align-items: baseline; gap: 4px; }
.stat-value span:first-child { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.stat-unit { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat-trend { font-size: 11px; color: var(--text-3); font-weight: 600; margin-top: 6px; }
.stat-trend.up { color: var(--success); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 120px;
  gap: 8px;
}
.bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
  justify-content: flex-end;
}
.bar-fill {
  width: 100%;
  background: var(--surface-3);
  border-radius: 6px;
  transition: height 0.6s var(--ease);
  min-height: 4px;
}
.bar.today .bar-fill { background: var(--accent); }
.bar span { font-size: 11px; color: var(--text-3); font-weight: 600; }
.bar.today span { color: var(--accent); }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.badge {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 18px 12px;
  text-align: center;
  opacity: 0.45;
  transition: transform 0.2s var(--ease);
}
.badge:active { transform: scale(0.96); }
.badge.unlocked {
  background: var(--surface);
  border: 1px solid var(--border);
  opacity: 1;
  box-shadow: var(--shadow-sm);
}
.badge-icon { font-size: 30px; margin-bottom: 6px; }
.badge p { font-size: 12px; font-weight: 600; }

/* ============== Settings ============== */
.profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.profile-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  font-weight: 700;
}
.profile-info { flex: 1; }
.profile-name { font-size: 17px; font-weight: 700; }
.profile-handle { font-size: 13px; color: var(--text-2); margin-top: 2px; font-weight: 500; }

.list-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 4px;
  margin: 16px 0 8px;
}
.settings-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.settings-list li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.settings-list li:last-child { border-bottom: none; }
.settings-icon { font-size: 18px; width: 28px; text-align: center; }
.settings-text { flex: 1; font-size: 15px; font-weight: 500; }
.chev { color: var(--text-3); font-size: 22px; font-weight: 400; }
.row-link { cursor: pointer; transition: background 0.15s; }
.row-link:active { background: var(--surface-2); }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer;
  inset: 0;
  background: var(--surface-3);
  border-radius: 100px;
  transition: 0.25s var(--ease);
}
.slider::before {
  content: '';
  position: absolute;
  height: 22px; width: 22px;
  left: 2px; top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.25s var(--ease);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.logout-btn {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  color: #ef4444;
  margin-top: 24px;
  transition: background 0.15s;
}
.logout-btn:active { background: var(--surface-2); }

.version {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 16px;
  font-weight: 500;
}

/* ============== Tab bar ============== */
.tab-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 12px 24px;
  z-index: 50;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--text-3);
  transition: color 0.2s, transform 0.15s var(--ease);
}
.tab svg { width: 22px; height: 22px; }
.tab span { font-size: 10px; font-weight: 600; letter-spacing: 0.01em; }
.tab.active { color: var(--accent); }
.tab:active { transform: scale(0.92); }

/* ============== Toast ============== */
.toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translate(-50%, -20px);
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============== Bottom sheet ============== */
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease);
  z-index: 90;
}
.sheet-backdrop.show { opacity: 1; pointer-events: all; }

.sheet {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  padding: 12px 24px 40px;
  transform: translateY(100%);
  transition: transform 0.4s var(--ease);
  z-index: 95;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}
.sheet.show { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--surface-3);
  border-radius: 100px;
  margin: 0 auto 16px;
}
.sheet h3 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.sheet-sub { font-size: 14px; color: var(--text-2); margin-top: 4px; margin-bottom: 20px; font-weight: 500; }
.proof-dropzone {
  background: var(--surface-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 36px 16px;
  text-align: center;
  margin-bottom: 16px;
  transition: background 0.2s;
}
.proof-dropzone:active { background: var(--surface-3); }
.proof-dropzone p { font-size: 14px; font-weight: 600; margin-top: 10px; }
.primary-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  transition: transform 0.15s var(--ease);
  margin-bottom: 8px;
}
.primary-btn:active { transform: scale(0.98); }
.text-btn {
  width: 100%;
  padding: 12px;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
}

.bottom-spacer { height: 20px; }
