/* ===================== RESET ===================== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }

:root {
  --bg: #0a0a0b;
  --bg-elev: #0f0f11;
  --surface: #16171a;
  --surface-2: #1d1e22;
  --border: #2a2b31;
  --border-soft: #202127;
  --text: #f3f3f1;
  --text-dim: #8b8c92;
  --text-faint: #5b5c63;
  --gold: #ffc300;
  --gold-soft: rgba(255, 195, 0, 0.14);
  --gold-line: rgba(255, 195, 0, 0.35);
  --red: #ff4438;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ===================== TOP BAR ===================== */
.top-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  padding: calc(var(--safe-top) + 12px) 18px 12px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(180deg, rgba(10,10,11,0.98) 60%, rgba(10,10,11,0.7) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-lock { width: 20px; height: 20px; color: var(--gold); }
.brand-word { font-size: 18px; font-weight: 800; letter-spacing: 2px; }
.brand-word-accent { color: var(--gold); }

.streak-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--gold-soft); color: var(--gold);
  border: 1px solid var(--gold-line);
  padding: 5px 11px; border-radius: 999px;
  font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums;
  transition: transform .2s;
}
.streak-chip.zero { background: var(--surface); color: var(--text-faint); border-color: var(--border); }
.streak-chip.pop { transform: scale(1.12); }

/* ===================== SCROLL / VIEWS ===================== */
.scroll {
  position: absolute; inset: 0;
  padding-top: calc(var(--safe-top) + 58px);
  padding-bottom: calc(var(--safe-bot) + 78px);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.view { display: none; padding: 14px 16px 30px; max-width: 560px; margin: 0 auto; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ===================== MANTRA ===================== */
.mantra {
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--gold);
  background: linear-gradient(90deg, var(--gold-soft), transparent 65%);
  border-radius: 12px; padding: 13px 15px; margin-bottom: 16px;
}
.mantra-title { font-size: 12px; font-weight: 800; letter-spacing: 3px; color: var(--gold); margin-bottom: 5px; }
.mantra-body { font-size: 12.5px; line-height: 1.5; color: var(--text-dim); }

/* ===================== DATE BAR ===================== */
.datebar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.date-nav {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-dim); display: grid; place-items: center; cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
}
.date-nav svg { width: 18px; height: 18px; }
.date-nav:active { background: var(--surface-2); }
.date-nav:disabled { opacity: .3; pointer-events: none; }
.date-center { text-align: center; }
.date-label { font-size: 15px; font-weight: 800; letter-spacing: 2px; }
.date-label.past { color: var(--text-dim); }
.date-sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ===================== PROGRESS RING ===================== */
.progress-wrap { position: relative; width: 170px; height: 170px; margin: 4px auto 20px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 9; }
.ring-fill {
  fill: none; stroke: var(--gold); stroke-width: 9; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .55s cubic-bezier(.2,.8,.2,1), stroke .3s;
}
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-count { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.ring-slash { color: var(--text-faint); margin: 0 1px; font-weight: 600; }
#ring-total { color: var(--text-dim); }
.ring-pct { font-size: 12px; font-weight: 700; letter-spacing: 2px; color: var(--text-faint); margin-top: 2px; }
.locked-stamp {
  position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%) scale(.8);
  background: var(--gold); color: #0a0a0b; font-size: 11px; font-weight: 900; letter-spacing: 2px;
  padding: 3px 10px; border-radius: 999px; opacity: 0; transition: opacity .3s, transform .3s;
  pointer-events: none;
}
.progress-wrap.complete .locked-stamp { opacity: 1; transform: translateX(-50%) scale(1); }
.progress-wrap.complete .ring-fill { filter: drop-shadow(0 0 6px rgba(255,195,0,.5)); }

/* ===================== HABITS ===================== */
.habits { display: flex; flex-direction: column; gap: 8px; }
.habit {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: 13px; padding: 14px 15px; cursor: pointer;
  transition: background .15s, border-color .2s, transform .08s;
  user-select: none;
}
.habit:active { transform: scale(.985); }
.habit.on { border-color: var(--gold-line); background: linear-gradient(90deg, var(--gold-soft), var(--surface) 55%); }

.check {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--border); background: transparent;
  display: grid; place-items: center; transition: background .18s, border-color .18s, transform .18s;
}
.check svg { width: 15px; height: 15px; stroke: #0a0a0b; stroke-width: 3.5;
  stroke-linecap: round; stroke-linejoin: round; fill: none;
  stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset .25s ease .05s; }
.habit.on .check { background: var(--gold); border-color: var(--gold); transform: scale(1.04); }
.habit.on .check svg { stroke-dashoffset: 0; }

.habit-label { font-size: 15px; font-weight: 600; line-height: 1.3; letter-spacing: .1px; transition: color .18s; }
.habit.on .habit-label { color: var(--text-dim); }

/* ===================== GOAL ROW ===================== */
.goal-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 22px; padding: 0 4px; }
.goal-label { font-size: 12px; color: var(--text-faint); }
.goal-seg { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.goal-seg button { background: transparent; border: none; color: var(--text-dim); font-size: 12px; font-weight: 700;
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-variant-numeric: tabular-nums; }
.goal-seg button.active { background: var(--gold); color: #0a0a0b; }

/* ===================== STATS: HERO ===================== */
.stat-hero {
  display: flex; align-items: stretch; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 16px;
  overflow: hidden;
}
.hero-cell { flex: 1; padding: 20px 12px; text-align: center; }
.hero-div { width: 1px; background: var(--border-soft); }
.hero-num { font-size: 42px; font-weight: 800; letter-spacing: -1px; font-variant-numeric: tabular-nums; color: var(--gold); line-height: 1; }
.hero-lbl { font-size: 10.5px; font-weight: 700; letter-spacing: 2px; color: var(--text-faint); margin-top: 8px; }

/* ===================== STATS: MINI CARDS ===================== */
.mini-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.mini {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: 12px;
  padding: 13px 8px; text-align: center;
}
.mini-num { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.mini-lbl { font-size: 10px; font-weight: 600; letter-spacing: .5px; color: var(--text-faint); margin-top: 5px; line-height: 1.25; }

/* ===================== STATS: PERIOD TOGGLE ===================== */
.period-toggle { display: flex; gap: 6px; margin-bottom: 16px; }
.period-toggle button {
  flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  padding: 9px; border-radius: 10px; font-size: 13px; font-weight: 800; letter-spacing: 1px; cursor: pointer;
  transition: all .15s;
}
.period-toggle button.active { background: var(--gold); color: #0a0a0b; border-color: var(--gold); }

/* ===================== STATS: PANELS ===================== */
.panel { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.panel-head h3 { font-size: 14px; font-weight: 700; letter-spacing: .3px; }
.panel-sub { font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
#score-chart { width: 100%; height: 150px; display: block; }

/* ===================== HEATMAP ===================== */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: 2px; }
.heatmap i { width: 100%; aspect-ratio: 1; min-width: 12px; border-radius: 3px; background: var(--surface-2); }
.heat-l0 { background: #1c1d21; } .heat-l1 { background: rgba(255,195,0,.22); }
.heat-l2 { background: rgba(255,195,0,.45); } .heat-l3 { background: rgba(255,195,0,.72); }
.heat-l4 { background: var(--gold); }
.heat-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 10px; font-size: 10px; color: var(--text-faint); }
.heat-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.heat-legend i[data-l="0"]{background:#1c1d21} .heat-legend i[data-l="1"]{background:rgba(255,195,0,.22)}
.heat-legend i[data-l="2"]{background:rgba(255,195,0,.45)} .heat-legend i[data-l="3"]{background:rgba(255,195,0,.72)}
.heat-legend i[data-l="4"]{background:var(--gold)}

/* ===================== HABIT BARS ===================== */
.habit-bars { display: flex; flex-direction: column; gap: 12px; }
.hb-row { }
.hb-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; gap: 10px; }
.hb-name { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-pct { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.hb-track { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hb-fill { height: 100%; border-radius: 4px; transition: width .5s cubic-bezier(.2,.8,.2,1); }

/* ===================== EXPORT / EMPTY ===================== */
.btn-export {
  width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text-dim);
  padding: 13px; border-radius: 12px; font-size: 13px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
.btn-export:active { background: var(--surface-2); }
.stats-empty { display: none; text-align: center; color: var(--text-faint); padding: 60px 20px; font-size: 14px; line-height: 1.6; }
body.no-data .panel, body.no-data .mini-cards, body.no-data .period-toggle, body.no-data .btn-export, body.no-data .stat-hero { display: none; }
body.no-data .stats-empty { display: block; }

/* ===================== BOTTOM NAV ===================== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; padding-bottom: var(--safe-bot);
  background: linear-gradient(0deg, rgba(10,10,11,0.98) 70%, rgba(10,10,11,0.75));
  backdrop-filter: blur(12px); border-top: 1px solid var(--border-soft);
}
.tab {
  flex: 1; background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; color: var(--text-faint); transition: color .15s;
}
.tab svg { width: 22px; height: 22px; }
.tab span { font-size: 10.5px; font-weight: 700; letter-spacing: .6px; }
.tab.active { color: var(--gold); }

/* ===================== TOAST ===================== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bot) + 82px); transform: translateX(-50%) translateY(20px);
  background: var(--gold); color: #0a0a0b; font-weight: 800; font-size: 13px; letter-spacing: .3px;
  padding: 9px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
