:root {
  --bg: #0a0d13;
  --bg-2: #0e1220;
  --surface: #151a26;
  --surface-2: #1b2231;
  --border: rgba(255, 255, 255, 0.08);
  --border-2: rgba(255, 255, 255, 0.14);
  --text: #eaf0f7;
  --muted: #8a94a7;
  --faint: #5a6478;

  --accent: #7c6bff;
  --accent-2: #a06bff;
  --accent-grad: linear-gradient(135deg, #6366f1, #a06bff);
  --emerald: #22c55e;
  --emerald-2: #4ade80;
  --amber: #f59e0b;
  --rose: #f472b6;

  /* heatmap ramp */
  --hm-empty: rgba(255, 255, 255, 0.05);
  --hm-future: rgba(255, 255, 255, 0.03);
  --hm-missed: #4a2233;
  --hm-partial: #1f6b4a;
  --hm-floor: #22c55e;
  --hm-full: #6ee7a0;

  --radius: 16px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --tap: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(124, 107, 255, 0.14), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 24px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
h1 { font-size: 22px; margin: 3px 0 2px; font-weight: 800; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 14px; }

.streak {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 8px 12px; min-width: 68px; text-align: center;
}
.streak.risk { border-color: rgba(245, 158, 11, .5); box-shadow: 0 0 0 1px rgba(245,158,11,.25); }
.flame { font-size: 20px; line-height: 1; }
.streak-num { font-size: 22px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.streak-label { font-size: 10px; color: var(--muted); }

/* ---------- pills / status ---------- */
.status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; font-size: 13px; font-weight: 600; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); }
.st-missed { color: var(--muted); }
.st-partial { color: var(--amber); background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.3); }
.st-floor { color: var(--emerald-2); background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.3); }
.st-full { color: var(--emerald-2); background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.45); }
.hint { font-size: 12px; color: var(--faint); }

.banner {
  background: linear-gradient(135deg, rgba(124,107,255,.16), rgba(160,107,255,.08));
  border: 1px solid rgba(124,107,255,.3); border-radius: 14px;
  padding: 12px 14px; font-size: 14px; margin-bottom: 14px; line-height: 1.45;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card-title { font-weight: 700; font-size: 16px; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 3px; line-height: 1.4; }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin: 18px 2px 8px; }
.muted { color: var(--muted); font-weight: 500; }
.small { font-size: 12px; }
.center { text-align: center; }

/* ---------- pillar ---------- */
.pillar { position: relative; overflow: hidden; border-color: color-mix(in srgb, var(--tint) 40%, var(--border)); }
.pillar::before { content: ""; position: absolute; inset: 0; background: var(--tint); opacity: .08; }
.pillar > * { position: relative; }
.pillar-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pillar-emoji { font-size: 20px; }
.pillar-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; flex: 1; }
.dots { display: flex; gap: 5px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); opacity: .5; }
.dot.active { width: 18px; border-radius: 3px; background: var(--dot); opacity: 1; }
.pillar-title { font-size: 17px; font-weight: 800; margin-bottom: 4px; }
.pillar-prompt { color: var(--text); opacity: .82; font-size: 14px; line-height: 1.5; }

/* ---------- counter cards ---------- */
.counter { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.counter.met, .toggle.on { border-color: rgba(34,197,94,.4); background: linear-gradient(180deg, rgba(34,197,94,.07), var(--surface)); }
.counter-info { min-width: 0; }
.tick { color: var(--emerald-2); }
.counter-controls { display: flex; align-items: center; gap: 10px; flex: none; }
.step {
  width: var(--tap); height: var(--tap); border-radius: 14px; border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text); font-size: 26px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .08s ease, filter .15s ease; user-select: none;
}
.step:active { transform: scale(.9); }
.step.plus.accent { background: var(--accent-grad); border: none; box-shadow: 0 3px 12px rgba(124,107,255,.4); }
.count { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.count-val { font-size: 26px; font-weight: 800; }
.count-target { font-size: 15px; color: var(--muted); }

/* ---------- toggle cards ---------- */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; cursor: pointer; font: inherit; color: inherit; }
.check {
  width: var(--tap); height: var(--tap); flex: none; border-radius: 14px;
  border: 2px solid var(--border-2); background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--emerald-2);
  transition: transform .08s ease;
}
.toggle:active .check { transform: scale(.9); }
.toggle.on .check { background: var(--accent-grad); border-color: transparent; color: #fff; }

/* ---------- progress rows ---------- */
.prow { margin: 12px 0; }
.prow:first-child { margin-top: 0; }
.prow:last-child { margin-bottom: 0; }
.prow-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.prow-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.prow.met .prow-count { color: var(--emerald-2); }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent-grad); border-radius: 999px; transition: width .3s ease; }
.prow.met .bar-fill { background: linear-gradient(135deg, var(--emerald), var(--emerald-2)); }

/* ---------- week view ---------- */
.week-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.week-nav-mid { flex: 1; text-align: center; }
.week-name { font-weight: 800; font-size: 16px; }
.ghost { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 22px; cursor: pointer; }
.ghost:disabled { opacity: .3; }
.week-summary { display: flex; align-items: center; gap: 18px; }
.ring { flex: none; }
.ring-bg { fill: none; stroke: var(--surface-2); stroke-width: 7; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.week-stats { line-height: 1.3; }
.big-pct { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; }
.floor-days { font-size: 13px; color: var(--muted); margin-top: 6px; }

.follower-card .follow-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.follow-count { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.follow-right { text-align: right; }
.to-go { font-size: 14px; font-weight: 700; }
.pace-good { color: var(--emerald-2); font-size: 12px; }
.pace-bad { color: var(--amber); font-size: 12px; }
.log-nudge { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.3); color: var(--amber); font-size: 13px; padding: 8px 10px; border-radius: 10px; margin-bottom: 10px; }
.log-follow { display: flex; gap: 8px; margin-bottom: 12px; }
.log-follow input { flex: 1; }

input {
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 12px;
  color: var(--text); font-size: 16px; padding: 12px 14px; width: 100%; font: inherit; font-size: 16px;
}
input:focus { outline: none; border-color: var(--accent); }

.btn {
  background: var(--accent-grad); color: #fff; border: none; border-radius: 12px;
  padding: 0 18px; height: 48px; font-size: 15px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(124,107,255,.35);
}
.btn:active { filter: brightness(.92); }
.btn.full { width: 100%; margin-top: 6px; }
.ghost-btn { background: var(--surface-2); color: var(--text); box-shadow: none; border: 1px solid var(--border-2); margin-bottom: 8px; }
.danger { background: rgba(244,63,94,.12); color: #fb7185; box-shadow: none; border: 1px solid rgba(244,63,94,.35); margin-top: 4px; }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; margin-top: 4px; }
.ch-grid { stroke: var(--border); stroke-width: 1; }
.ch-ylabel, .ch-xlabel { fill: var(--faint); font-size: 9px; }
.ch-goal { stroke: var(--emerald); stroke-width: 1.5; stroke-dasharray: 4 3; }
.ch-goallabel { fill: var(--emerald-2); font-size: 10px; font-weight: 700; }
.ch-pace { stroke: var(--faint); stroke-width: 1.2; stroke-dasharray: 2 3; }
.ch-oct { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 1 3; opacity: .7; }
.ch-line { fill: none; stroke: var(--accent-2); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.ch-dot { fill: var(--accent-2); stroke: var(--bg); stroke-width: 1.5; }
.ch-callout { fill: var(--text); font-size: 11px; font-weight: 700; }

/* ---------- heatmap ---------- */
.heatmap-card { overflow-x: auto; }
.heatmap { width: 100%; height: auto; min-width: 300px; display: block; }
.hm-cell { stroke: rgba(0,0,0,0.2); stroke-width: .5; cursor: pointer; }
/* fill = SVG cells, background = HTML legend swatches (same class, both contexts) */
.hm-empty { fill: var(--hm-empty); background: var(--hm-empty); }
.hm-future { fill: var(--hm-future); background: var(--hm-future); }
.hm-missed { fill: var(--hm-missed); background: var(--hm-missed); }
.hm-partial { fill: var(--hm-partial); background: var(--hm-partial); }
.hm-floor { fill: var(--hm-floor); background: var(--hm-floor); }
.hm-full { fill: var(--hm-full); background: var(--hm-full); }
.hm-today { stroke: var(--accent-2); stroke-width: 1.5; }
.hm-rowlabel, .hm-collabel { fill: var(--faint); font-size: 9px; }
.legend { display: flex; align-items: center; gap: 5px; justify-content: center; margin: 12px 0 4px; font-size: 11px; color: var(--muted); }
.legend .lg { width: 13px; height: 13px; border-radius: 3px; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 6px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px 6px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 10px; color: var(--muted); margin-top: 2px; }
.detail { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- settings ---------- */
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; font-size: 15px; }
.field span { color: var(--muted); flex: none; }
.field input { max-width: 170px; }

.footnote { color: var(--faint); font-size: 12px; text-align: center; margin: 18px 8px 4px; line-height: 1.5; }

/* ---------- tab bar ---------- */
.tabbar {
  flex: none; display: flex; background: rgba(14, 18, 32, 0.9);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0 8px;
  font: inherit; transition: color .15s ease;
}
.tab-icon { font-size: 20px; line-height: 1; }
.tab-label { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--text); }
.tab.active .tab-icon { filter: drop-shadow(0 0 8px rgba(124,107,255,.7)); color: var(--accent-2); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px); background: var(--surface-2);
  border: 1px solid var(--border-2); color: var(--text); padding: 10px 18px;
  border-radius: 999px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 50; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
