:root {
  --bg: #0c1220;
  --bg2: #121a2b;
  --panel: #172033;
  --border: #27324a;
  --text: #eef2ff;
  --muted: #8b96b0;
  --accent: #7c9cff;
  --accent2: #5eead4;
  --mood: #f0abfc;
  --sleep: #7dd3fc;
  --custom: #fbbf24;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(16px + var(--safe-b)); }

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(12px + var(--safe-t)) 14px 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, #2a3a6b, #1a2744);
  border: 1px solid var(--border);
  color: var(--accent2);
  font-size: 18px;
}
.brand h1 { font-size: 18px; font-weight: 800; letter-spacing: 0.2px; }
.tagline { font-size: 11px; color: var(--muted); margin-top: 1px; }

.top-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(124, 156, 255, 0.12);
  border: 1px solid rgba(124, 156, 255, 0.35);
  color: var(--accent);
  white-space: nowrap;
}
.badge.pro {
  background: rgba(94, 234, 212, 0.12);
  border-color: rgba(94, 234, 212, 0.4);
  color: var(--accent2);
}

.icon-btn {
  appearance: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.96); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04);
}

.panel { display: none; }
.panel.active { display: block; }

.date-line {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.stack { display: flex; flex-direction: column; gap: 12px; }

.card, .tracker-card, .empty-card, .entry-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.empty-card { text-align: center; padding: 28px 18px; }
.empty-card h2 { font-size: 18px; margin-bottom: 8px; }
.empty-card p { color: var(--muted); margin-bottom: 16px; font-size: 14px; }

.tracker-card h3 {
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot.mood { background: var(--mood); }
.dot.sleep { background: var(--sleep); }
.dot.custom { background: var(--custom); }

.label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 700;
}

.mood-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.mood-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg2);
  border-radius: 12px;
  padding: 12px 4px;
  font-size: 22px;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s, background 0.12s;
}
.mood-btn.selected {
  border-color: var(--mood);
  background: rgba(240, 171, 252, 0.12);
  box-shadow: 0 0 0 1px rgba(240, 171, 252, 0.25);
}
.mood-btn:active { transform: scale(0.96); }

input[type="number"],
input[type="text"],
input[type="date"],
textarea,
.select {
  width: 100%;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  font-size: 15px;
  margin-bottom: 10px;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
}

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 11px 14px;
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.12s, background 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, #3550a0, #2a6b6a);
  border-color: #3d5f9a;
  color: #fff;
}
.btn.danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.45);
  color: var(--danger);
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
}
.btn.block { width: 100%; }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.section-title { font-size: 16px; font-weight: 800; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.hidden { display: none !important; }

.entry-card {
  box-shadow: none;
  padding: 12px;
}
.entry-card .meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.entry-card .value {
  font-size: 16px;
  font-weight: 700;
}
.entry-card .note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}
.entry-card .del {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
}

.module-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.module-item .info { flex: 1; min-width: 0; }
.module-item h3 { font-size: 15px; margin-bottom: 2px; }
.module-item p { font-size: 12px; color: var(--muted); }
.module-item.locked { opacity: 0.72; }

.toggle {
  position: relative;
  width: 46px; height: 28px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle .slider {
  position: absolute; inset: 0;
  background: #243049;
  border-radius: 999px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  border-radius: 50%;
  background: #c8d0e4;
  transition: transform 0.15s;
}
.toggle input:checked + .slider {
  background: rgba(94, 234, 212, 0.25);
  border-color: rgba(94, 234, 212, 0.5);
}
.toggle input:checked + .slider::before {
  transform: translateX(18px);
  background: var(--accent2);
}
.toggle input:disabled + .slider {
  opacity: 0.5;
  cursor: not-allowed;
}

.plan-card .price {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent2);
}
.checklist {
  list-style: none;
  margin-top: 8px;
}
.checklist li {
  font-size: 13px;
  padding: 6px 0;
  color: var(--muted);
  border-bottom: 1px solid rgba(39, 50, 74, 0.6);
}
.checklist li::before {
  content: "✓ ";
  color: var(--ok);
  font-weight: 800;
}
.checklist li:last-child { border-bottom: 0; }

.danger-zone { margin-top: 16px; }
.danger-zone h3 { font-size: 14px; margin-bottom: 6px; color: var(--danger); }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.62);
  z-index: 40;
}
.drawer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  max-height: min(88vh, 720px);
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(20px + var(--safe-b));
  z-index: 50;
  box-shadow: 0 -20px 50px rgba(0,0,0,0.45);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.drawer-head h2 { font-size: 17px; }
.drawer .stack { margin: 12px 0; }
.drawer .card { margin-top: 12px; box-shadow: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  background: #1e2a44;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}

@media (min-width: 520px) {
  #app { padding-top: 24px; }
}
