/* ─── RESET & BASE ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #22263a;
  --border: #2e3350;
  --accent: #6c63ff;
  --accent2: #4ecdc4;
  --gold: #ffd700;
  --green: #4caf50;
  --red: #f44336;
  --orange: #ff9800;
  --text: #e8eaf0;
  --muted: #7a7f9a;
  --radius: 12px;
  --radius-sm: 8px;
}
html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── UTILS ─────────────────────────────────────────────────── */
.text-muted { color: var(--muted); }
.small { font-size: 0.8em; }
.mt-1 { margin-top: 1rem; }
.error-text { color: var(--red); font-size: 0.85em; min-height: 1.2em; }
.token-input-wrap { position: relative; }
.token-input-wrap .input-field { padding-right: 44px; }
.token-eye {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1.1em; opacity: 0.6;
  padding: 4px;
}
.token-eye:hover { opacity: 1; }
.badge-level {
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.75em;
  font-weight: 700;
}

/* ─── BUTTONS ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9em;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #574fd6; border-color: #574fd6; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { background: #c62828; }
.btn-full { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 0.8em; }
.btn-complete {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  background: var(--bg3);
  border: 2px solid var(--border);
  font-size: 1.3em;
  cursor: pointer;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.btn-complete:hover { border-color: var(--green); background: rgba(76,175,80,0.15); }
.btn-complete.done { border-color: var(--green); background: rgba(76,175,80,0.2); color: var(--green); }
.btn-complete.maxed { opacity: 0.4; cursor: not-allowed; }

/* ─── INPUTS ────────────────────────────────────────────────── */
.input-field {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95em;
}
.input-field:focus { outline: none; border-color: var(--accent); }
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.8em; color: var(--muted); margin-bottom: 4px; }
select.input-field { appearance: none; }

/* ─── SCREEN OVERLAYS ───────────────────────────────────────── */
.screen-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.login-box, .onboarding-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 1rem;
  text-align: center;
}
.login-logo, .ob-logo { font-size: 3rem; }
.onboarding-box { max-width: 460px; text-align: left; }
.onboarding-box h2 { text-align: center; }
.onboarding-step { display: flex; flex-direction: column; gap: 1rem; }

.ob-templates { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.ob-template-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 0.75rem;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1em; font-weight: 600;
  transition: border-color 0.15s;
}
.ob-template-card:has(input:checked) { border-color: var(--accent); background: rgba(108,99,255,0.1); }
.ob-template-card input { display: none; }
.ob-template-card small { font-size: 0.7em; font-weight: 400; color: var(--muted); }

/* ─── APP LAYOUT ────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ─── TOP BAR ───────────────────────────────────────────────── */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.char-info { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.char-avatar { font-size: 1.8rem; } /* fallback */
.char-details { flex: 1; min-width: 0; }
.char-name-level { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.char-name-level span:first-child { font-weight: 700; font-size: 1em; }
.xp-bar-wrap { height: 6px; background: var(--border); border-radius: 3px; margin: 3px 0; }
.xp-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; transition: width 0.4s ease; }
.xp-label { font-size: 0.7em; color: var(--muted); }
.char-resources { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.res-item { font-size: 0.85em; white-space: nowrap; }

/* ─── DAILY BANNER ──────────────────────────────────────────── */
.daily-banner {
  display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: rgba(108,99,255,0.12);
  border-bottom: 1px solid rgba(108,99,255,0.3);
  font-size: 0.85em;
}
.daily-banner span { color: var(--accent2); font-weight: 600; }

/* ─── MAIN CONTENT ──────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; padding: 0.75rem 1rem calc(5rem + env(safe-area-inset-bottom, 0px)); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.section-title { font-size: 0.85em; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }

/* ─── TASK CARDS ────────────────────────────────────────────── */
.task-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.5rem; }
.task-card {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  transition: border-color 0.2s;
}
.task-card.completed-today { opacity: 0.55; }
.task-card:hover { border-color: var(--accent); }
.task-info { flex: 1; min-width: 0; }
.task-name { font-weight: 600; font-size: 0.95em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { font-size: 0.75em; color: var(--muted); display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 2px; }
.task-xp { color: var(--accent2); font-weight: 600; }
.task-coins { color: var(--gold); font-weight: 600; }
.task-actions { display: flex; gap: 6px; align-items: center; }
.task-count { font-size: 0.75em; color: var(--muted); min-width: 24px; text-align: center; }

/* Boss progress */
.boss-progress-bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: 4px; }
.boss-progress-fill { height: 100%; background: linear-gradient(90deg, var(--orange), var(--gold)); border-radius: 2px; transition: width 0.3s; }

.tab-filter { display: flex; gap: 4px; }
.filter-btn {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8em;
  transition: all 0.15s;
}
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── TASK GROUPS ───────────────────────────────────────────── */
.task-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0.6rem 0.75rem;
  margin: 0.5rem 0 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9em;
  user-select: none;
  transition: background 0.15s;
}
.task-group-header:hover { background: var(--bg3); }
.task-group-header:first-child { margin-top: 0; }
.group-count {
  margin-left: auto;
  background: var(--bg3);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.8em;
  color: var(--muted);
}
.group-arrow { color: var(--muted); font-size: 0.75em; }
.task-group-body { margin-bottom: 0.25rem; }

/* ─── SHOP ──────────────────────────────────────────────────── */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; margin-bottom: 0.5rem; }
.shop-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 4px;
}
.shop-card-name { font-weight: 600; font-size: 0.9em; }
.shop-card-desc { font-size: 0.75em; color: var(--muted); }
.shop-card-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.shop-price { color: var(--gold); font-weight: 700; font-size: 0.9em; }
.shop-card-actions { display: flex; gap: 4px; align-items: center; }

.purchases-list { display: flex; flex-direction: column; gap: 0.4rem; }
.purchase-row { font-size: 0.82em; color: var(--muted); display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); }
.purchase-row .purchase-cost { color: var(--gold); }

/* ─── ACHIEVEMENTS ──────────────────────────────────────────── */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.5rem; }
.ach-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  display: flex; flex-direction: column; gap: 4px;
  transition: border-color 0.2s;
}
.ach-card.unlocked { border-color: var(--gold); background: rgba(255,215,0,0.05); }
.ach-card.locked { opacity: 0.5; }
.ach-icon { font-size: 1.8rem; }
.ach-name { font-weight: 700; font-size: 0.9em; }
.ach-desc { font-size: 0.75em; color: var(--muted); }
.ach-reward { font-size: 0.75em; color: var(--gold); }
.ach-date { font-size: 0.7em; color: var(--accent2); }

/* ─── STAT BARS ─────────────────────────────────────────────── */
#stat-bars { display: flex; flex-direction: column; gap: 8px; margin-top: 0.75rem; }
.stat-bar-row { display: flex; flex-direction: column; gap: 3px; }
.stat-bar-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82em;
}
.stat-bar-icon { font-size: 1em; width: 18px; text-align: center; }
.stat-bar-name { flex: 1; font-weight: 600; color: var(--text); }
.stat-bar-level {
  font-size: 0.75em; font-weight: 700;
  color: var(--accent);
  background: rgba(108,99,255,0.12);
  border-radius: 4px;
  padding: 1px 5px;
}
.stat-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 3px;
  transition: width 0.5s ease;
  min-width: 2px;
}
.stat-bar-xp {
  font-size: 0.7em;
  color: var(--muted);
  text-align: right;
}

/* ─── PROFILE ───────────────────────────────────────────────── */
.profile-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 1rem 0; }
.profile-avatar { font-size: 4rem; }
.profile-name { font-size: 1.4rem; font-weight: 800; }
.profile-title { color: var(--accent); font-weight: 600; }
.profile-level { color: var(--muted); font-size: 0.85em; }

.profile-resources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin: 0.5rem 0; }
.res-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem;
  text-align: center;
  font-size: 1.3em;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.res-card span { font-size: 0.65em; font-weight: 700; display: block; color: var(--text); }
.res-card small { font-size: 0.5em; color: var(--muted); display: block; }

.chart-wrap { position: relative; height: 280px; width: 280px; margin: 0 auto; }
.chart-wrap-bar { position: relative; height: 180px; margin: 0 auto; }

.protection-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.prot-card {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}
.prot-icon { font-size: 1.5rem; }
.prot-info { flex: 1; }
.prot-sub { font-size: 0.8em; color: var(--muted); }

.name-edit-row { display: flex; gap: 0.5rem; }
.name-edit-row .input-field { flex: 1; }

/* ─── EVENTS LOG ────────────────────────────────────────────── */
.events-list { display: flex; flex-direction: column; gap: 0.3rem; }
.event-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82em;
}
.event-desc { flex: 1; }
.event-deltas { text-align: right; display: flex; flex-direction: column; gap: 1px; white-space: nowrap; }
.event-xp { color: var(--accent2); }
.event-coins { color: var(--gold); }
.event-time { font-size: 0.7em; color: var(--muted); }

/* ─── BOTTOM NAV ────────────────────────────────────────────── */
.bottom-nav {
  display: flex;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 10;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 0.5rem 0;
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.65em;
  transition: color 0.15s;
}
.nav-btn .nav-icon { font-size: 1.5em; }
.nav-btn.active { color: var(--accent); }

/* ─── MODALS ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg2); z-index: 1;
}
.modal-header h3 { font-size: 1.1em; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: 4px; }
.modal-body { padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; }

.confirm-modal { border-radius: var(--radius); max-width: 300px; padding: 1.5rem; text-align: center; }
.confirm-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.confirm-text { margin-bottom: 1rem; }
.confirm-btns { display: flex; gap: 0.5rem; justify-content: center; }

/* ─── TOAST ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.2rem;
  font-size: 0.9em;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
  white-space: nowrap;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

/* ─── AVATAR ─────────────────────────────────────────────────── */
.char-avatar-mini {
  width: 44px; height: 44px; min-width: 44px;
  overflow: hidden;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
}
.char-avatar-mini svg { width: 100%; height: 100%; }


/* ─── WEEKLY TASKS ───────────────────────────────────────────── */
.weekly-bar { height: 5px; background: var(--border); border-radius: 3px; margin-top: 5px; }
.weekly-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 3px; transition: width 0.4s ease; }
.weekly-done-badge {
  font-size: 0.7em; font-weight: 700;
  background: rgba(76,205,196,0.15); color: var(--accent2);
  border: 1px solid var(--accent2);
  border-radius: 10px; padding: 1px 7px;
}

/* ─── DANGER ZONE ────────────────────────────────────────────── */
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid rgba(244,67,54,0.25); }
.reset-confirm-box {
  margin-top: 0.75rem;
  background: rgba(244,67,54,0.08);
  border: 1px solid rgba(244,67,54,0.3);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.reset-confirm-box p { font-size: 0.85em; color: var(--muted); }

/* ─── RESPONSIVE ─────────────────────────────────────────────── */
@media (min-width: 600px) {
  .main-content { padding: 1rem 1.5rem 5rem; }
  .profile-resources { grid-template-columns: repeat(4, 1fr); }
  .ob-templates { grid-template-columns: repeat(4, 1fr); }
}
