/* ---------- Design tokens ---------- */
:root {
  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --card: rgba(255, 255, 255, 0.05);
  --card-border: rgba(255, 255, 255, 0.08);
  --text: #f2f3f7;
  --text-muted: #8b90a1;
  --primary: #7c3aed;
  --primary-2: #ec4899;
  --accent: #22d3ee;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --nav-h: 76px;
  --header-h: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body {
  background:
    radial-gradient(circle at 15% 0%, rgba(124, 58, 237, 0.25), transparent 45%),
    radial-gradient(circle at 90% 15%, rgba(236, 72, 153, 0.18), transparent 40%),
    var(--bg);
  min-height: 100dvh;
}
button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }

/* ---------- Glass ---------- */
.glass {
  background: var(--card);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px;
  border-radius: var(--radius-lg);
  padding: 36px 28px;
  text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-card p { margin: 0 0 24px; font-size: 14px; }
#login-form { display: flex; flex-direction: column; gap: 14px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

input[type="text"], input[type="password"], input[type="date"], input[type="datetime-local"],
input[type="number"], input[type="tel"], input[type="email"], textarea, select {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  font-size: 15px;
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  background: rgba(255,255,255,0.09);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }

.btn {
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  transition: transform .08s ease, opacity .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.35);
}
.btn-ghost {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--card-border);
}
.btn-danger { background: rgba(248,113,113,0.15); color: var(--danger); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--radius-sm); }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 18px; padding-right: 14px;
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 13, 18, 0.75);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--card-border);
}
.header-title { font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.streak-badge {
  background: linear-gradient(135deg, #f97316, #ef4444);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
  font-size: 17px;
}

.view-content {
  flex: 1;
  padding: 18px 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex; align-items: center; justify-content: space-around;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--card-border);
  z-index: 30;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; color: var(--text-muted);
  padding: 6px 10px;
  transition: color .15s ease, transform .15s ease;
}
.nav-btn.active { color: var(--accent); transform: translateY(-2px); }
.nav-icon { font-size: 21px; }
.nav-btn-fab {
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white; justify-content: center;
  margin-top: -26px;
  box-shadow: 0 10px 24px rgba(124, 58, 237, 0.45);
}
.nav-btn-fab .nav-icon { font-size: 26px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin: 0 0 10px; font-weight: 700; }
.section-title { font-size: 20px; font-weight: 800; margin: 4px 0 16px; }

/* ---------- Mood ---------- */
.mood-picker { display: flex; justify-content: space-between; gap: 6px; margin: 14px 0 18px; }
.mood-opt {
  flex: 1; text-align: center; padding: 12px 4px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.04);
  font-size: 26px;
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .15s ease, box-shadow .15s ease;
  border: 2px solid transparent;
}
.mood-opt.selected {
  transform: scale(1.18) translateY(-4px);
  background: rgba(124, 58, 237, 0.18);
  border-color: var(--primary);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.35);
}
.mood-opt:active { transform: scale(0.92); }

/* ---------- Journal entries ---------- */
.entry-card { display: flex; gap: 12px; align-items: flex-start; }
.entry-emoji { font-size: 28px; }
.entry-date { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.entry-text { font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; }

/* ---------- Mood chart ---------- */
.mood-chart-wrap { width: 100%; overflow-x: auto; }
#mood-chart { display: block; }

/* ---------- Events / calendar ---------- */
.day-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 14px; scrollbar-width: none; }
.day-strip::-webkit-scrollbar { display: none; }
.day-chip {
  flex: 0 0 auto; width: 52px; padding: 10px 0; text-align: center;
  border-radius: var(--radius-sm); background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
}
.day-chip.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.day-chip .dow { font-size: 11px; color: var(--text-muted); display: block; }
.day-chip.active .dow { color: rgba(255,255,255,0.85); }
.day-chip .num { font-size: 16px; font-weight: 700; }
.day-chip.today { border-color: var(--accent); }

.event-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--card-border); }
.event-item:last-child { border-bottom: none; }
.event-time { font-size: 12px; color: var(--accent); font-weight: 700; min-width: 48px; }
.event-cat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.event-title { font-weight: 600; font-size: 14.5px; }
.event-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Todos ---------- */
.category-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; }
.tab-btn {
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: rgba(255,255,255,0.05); color: var(--text-muted); white-space: nowrap;
}
.tab-btn.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; }

.todo-item {
  display: flex; align-items: center; gap: 12px; padding: 13px 4px;
  border-bottom: 1px solid var(--card-border);
}
.todo-item:last-child { border-bottom: none; }
.todo-check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--text-muted);
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
  transition: all .2s cubic-bezier(.34,1.56,.64,1);
  font-size: 14px;
}
.todo-check.done { background: var(--success); border-color: var(--success); transform: scale(1.05); }
.todo-title { font-size: 14.5px; flex: 1; transition: opacity .2s ease; }
.todo-item.done .todo-title { text-decoration: line-through; opacity: 0.5; }
.todo-due { font-size: 11px; color: var(--text-muted); }
.priority-flag { color: var(--danger); font-size: 12px; }

/* ---------- Contacts ---------- */
.contact-item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--card-border); }
.contact-item:last-child { border-bottom: none; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: white; flex: 0 0 auto;
}
.contact-name { font-weight: 600; font-size: 14.5px; }
.contact-sub { font-size: 12px; color: var(--text-muted); }
.search-bar { margin-bottom: 14px; }

/* ---------- Stats / Gamification ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.stat-tile { border-radius: var(--radius-md); padding: 16px; text-align: center; background: var(--card); border: 1px solid var(--card-border); }
.stat-value { font-size: 26px; font-weight: 800; }
.stat-label { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge-tile {
  aspect-ratio: 1; border-radius: var(--radius-md); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; padding: 8px; text-align: center;
  background: rgba(255,255,255,0.03); border: 1px solid var(--card-border); opacity: 0.35;
}
.badge-tile.unlocked {
  opacity: 1;
  background: linear-gradient(135deg, rgba(124,58,237,0.25), rgba(236,72,153,0.2));
  border-color: rgba(124,58,237,0.4);
}
.badge-icon { font-size: 26px; }
.badge-name { font-size: 10px; font-weight: 700; line-height: 1.2; }

/* ---------- Empty state ---------- */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; z-index: 100;
  animation: fadeIn .15s ease;
}
.modal-sheet {
  width: 100%; max-height: 88dvh; overflow-y: auto;
  background: var(--bg-elevated);
  border-radius: 26px 26px 0 0;
  padding: 22px 20px calc(28px + var(--safe-bottom));
  border-top: 1px solid var(--card-border);
  animation: slideUp .22s cubic-bezier(.32,.72,0,1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 40px; height: 4px; border-radius: 4px; background: var(--card-border); margin: 0 auto 16px; }
.modal-title { font-size: 18px; font-weight: 800; margin: 0 0 18px; }
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 600; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; }
.chip-select { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-opt {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; background: rgba(255,255,255,0.05);
  border: 1px solid var(--card-border); color: var(--text-muted);
}
.chip-opt.selected { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: white; border-color: transparent; }

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed; top: calc(var(--safe-top) + 12px); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: var(--bg-elevated); border: 1px solid var(--card-border);
  padding: 12px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn .25s cubic-bezier(.34,1.56,.64,1), toastOut .25s ease 2.5s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
.toast-badge { border-color: rgba(251,191,36,0.5); background: linear-gradient(135deg, rgba(251,191,36,0.18), rgba(236,72,153,0.15)); }

/* ---------- Confetti ---------- */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 300; }

/* ---------- Misc ---------- */
.fab-menu { display: flex; flex-direction: column; gap: 10px; }
.fab-option {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: rgba(255,255,255,0.05); border-radius: var(--radius-md); font-size: 15px; font-weight: 600;
}
.fab-option .emoji { font-size: 22px; }

@media (min-width: 700px) {
  .badge-grid { grid-template-columns: repeat(4, 1fr); }
}
