@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');

:root {
  --bg:             #111210;
  --surface:        #1c1c1e;
  --surface2:       #242426;
  --border:         rgba(255,255,255,0.07);
  --border-strong:  rgba(255,255,255,0.13);
  --text:           #f0eeea;
  --text-secondary: #8a8886;
  --text-tertiary:  #5a5856;
  --green:          #63cf7a;
  --red:            #e05555;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 16px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: var(--font); touch-action: manipulation; cursor: pointer; }
input  { font-family: var(--font); }

::-webkit-scrollbar       { width: 3px; height: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ── Splash / auth ──────────────────────────────────────────────────────── */
.splash { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 100; }
.splash-inner { width: 100%; max-width: 320px; padding: 0 24px; text-align: center; }
.splash-mark { font-size: 40px; margin-bottom: 10px; }
.splash-title { font-size: 28px; font-weight: 800; margin-bottom: 32px; letter-spacing: -0.5px; }
.auth-input { display: block; width: 100%; padding: 13px 15px; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 16px; font-family: var(--font); outline: none; transition: border-color 0.15s; }
.auth-input:focus { border-color: var(--border-strong); }
.auth-btn { width: 100%; padding: 14px; background: var(--text); color: var(--bg); border: none; border-radius: 10px; font-size: 15px; font-weight: 700; font-family: var(--font); cursor: pointer; margin-top: 4px; letter-spacing: 0.01em; touch-action: manipulation; }
.auth-error { font-size: 11px; color: var(--red); margin-top: 10px; min-height: 16px; font-family: var(--mono); letter-spacing: 0.02em; }

/* ── App shell ──────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

/* Glass sticky header — from Perks Ledger */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 18px 12px; flex-shrink: 0;
  background: rgba(17,18,16,0.88);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.header-date { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
.header-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); color: var(--text-secondary); font-size: 18px; line-height: 1; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.15s; touch-action: manipulation; }
.icon-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* Monitor-style nav — bottom border indicator, icons + labels */
.nav {
  display: flex; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  padding: 0;
}
.nav-btn {
  flex: 1; padding: 10px 4px 8px; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none; color: var(--text-tertiary);
  font-size: 9px; font-weight: 600; font-family: var(--mono);
  cursor: pointer; transition: all 0.15s;
  letter-spacing: 0.08em; text-transform: uppercase;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  touch-action: manipulation;
}
.nav-btn svg { transition: opacity 0.15s; }
.nav-btn.active { color: var(--text); border-bottom-color: rgba(255,255,255,0.55); }

.main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--safe-bottom) + 32px); }

/* ── Section label — consistent across all views ────────────────────────── */
.section-label {
  font-size: 9px; color: var(--text-tertiary); font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.12em; font-weight: 600;
  margin-bottom: 10px;
}

/* ── Today view — habit cards ───────────────────────────────────────────── */
.today-list { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }

.habit-card {
  position: relative; height: 108px; border-radius: var(--radius);
  overflow: hidden; user-select: none; -webkit-user-select: none; flex-shrink: 0;
  /* GPU layer — prevents compositing blur on border-radius */
  transform: translateZ(0); -webkit-transform: translateZ(0);
}
.habit-card.done { opacity: 0.5; }
.habit-card.dragging { opacity: 0.28; transform: scale(0.97) translateZ(0); }
.habit-card.drag-over::after {
  content: ''; position: absolute; inset: 0; border-radius: var(--radius);
  border: 1.5px solid rgba(255,255,255,0.35); pointer-events: none;
}

.card-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center top;
  transform: translateZ(0); /* crisp GPU-composited rendering */
  image-rendering: -webkit-optimize-contrast;
}
.card-overlay { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(0,0,0,0.68) 0%, rgba(0,0,0,0.22) 100%); }

.card-swipe-reveal {
  position: absolute; left: 0; top: 0; bottom: 0; width: 80px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: #fff; opacity: 0;
  background: linear-gradient(90deg, rgba(99,207,122,0.9), transparent);
  pointer-events: none; z-index: 2; transition: opacity 0.06s;
}

.card-content {
  position: relative; z-index: 3; display: flex; align-items: center;
  height: 100%; padding: 0 16px 0 6px; gap: 8px;
  transition: transform 0.15s ease; cursor: pointer;
}

.drag-handle { color: rgba(255,255,255,0.25); font-size: 15px; flex-shrink: 0; padding: 4px 6px; cursor: grab; touch-action: none; line-height: 1; }
.drag-handle:active { cursor: grabbing; }

.card-info { flex: 1; min-width: 0; }
.card-title { font-size: 16px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px; }
.card-streak { font-size: 10px; color: rgba(255,255,255,0.55); margin-top: 4px; font-weight: 500; font-family: var(--mono); letter-spacing: 0.02em; }

.card-check {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.45);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: #fff;
  cursor: pointer; transition: all 0.2s; touch-action: manipulation;
}
.habit-card.done .card-check { border-color: transparent; }

@keyframes pop { 0%{transform:scale(1)} 40%{transform:scale(1.25)} 100%{transform:scale(1)} }
.card-check.popping { animation: pop 0.25s ease; }

.today-empty { padding: 60px 24px; text-align: center; color: var(--text-tertiary); font-size: 14px; line-height: 1.7; }

/* ── History view ───────────────────────────────────────────────────────── */
.history-wrap { padding: 0 0 16px; }

.habit-cover {
  width: 100%; height: 210px; position: relative; flex-shrink: 0; margin-bottom: 20px;
  overflow: hidden;
  transform: translateZ(0); /* crisp GPU compositing */
  background-position: center top !important; /* portrait images: show top */
}
.habit-cover-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center top;
  transform: scale(1.01); /* prevent sub-pixel gap at edges */
}
.habit-cover-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.82) 0%, rgba(0,0,0,0.1) 55%, transparent 100%);
  display: flex; align-items: flex-end; padding: 20px;
}
.habit-cover-title { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,0.6); }
.cover-expand-hint { font-size: 9px; color: rgba(255,255,255,0.4); margin-top: 6px; font-family: var(--mono); letter-spacing: 0.08em; text-transform: uppercase; }

.history-back { display: flex; align-items: center; gap: 5px; padding: 10px 14px 4px; cursor: pointer; color: var(--text-secondary); font-size: 13px; font-weight: 600; touch-action: manipulation; }
.history-back:active { opacity: 0.6; }

/* ── Stats ──────────────────────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; padding: 0 14px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 10px; text-align: center; }
.stat-val { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.stat-label { font-size: 8px; color: var(--text-tertiary); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.09em; margin-top: 4px; }

/* ── Insights — analytics section ───────────────────────────────────────── */
.insights-section { padding: 0 14px; margin-bottom: 20px; }
.insight-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.insight-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 10px; text-align: center;
}
.insight-val { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; font-family: var(--font); }
.insight-sub { font-size: 9px; font-family: var(--mono); color: var(--text-tertiary); margin-top: 2px; }
.insight-label { font-size: 8px; color: var(--text-tertiary); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 5px; }
.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }

/* Monitor-style severity tag */
.tag {
  display: inline-flex; align-items: center;
  font-size: 9px; font-family: var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  border: 1px solid; padding: 2px 6px; border-radius: 3px;
}
.tag-green { color: var(--green); border-color: rgba(99,207,122,0.3); }
.tag-red   { color: var(--red);   border-color: rgba(224,85,85,0.3);  }
.tag-dim   { color: var(--text-tertiary); border-color: var(--border); }

/* ── Heatmap ────────────────────────────────────────────────────────────── */
.heatmap-wrap { margin-bottom: 20px; padding: 0 14px; }
.heatmap-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap-grid { display: flex; gap: 3px; }
.heatmap-col { display: flex; flex-direction: column; gap: 3px; }
.heatmap-cell { width: 11px; height: 11px; border-radius: 2px; background: var(--surface2); flex-shrink: 0; }
.heatmap-cell.l4 { background: var(--habit-color, var(--green)); }

/* ── Calendar ───────────────────────────────────────────────────────────── */
.recent-section { margin-top: 4px; padding: 0 14px; }
.calendar-month { margin-bottom: 20px; }
.cal-month-label { font-size: 13px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.1px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 40px); gap: 4px; }
.cal-day-label { font-size: 8px; color: var(--text-tertiary); text-align: center; font-family: var(--mono); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 2px; }
.cal-day { aspect-ratio: 1; border-radius: 7px; background: var(--surface); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--text-secondary); font-weight: 500; cursor: pointer; transition: transform 0.1s; touch-action: manipulation; }
.cal-day:active { transform: scale(0.86); }
.cal-day.done { color: #fff; font-weight: 700; }
.cal-day.empty { background: none; cursor: default; }
.cal-day.today-cell { outline: 1px solid var(--border-strong); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badges-section { padding: 0 14px; margin-bottom: 20px; }
.badge-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.badge-item { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 58px; user-select: none; }
.badge-icon {
  width: 50px; height: 50px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; font-family: var(--mono);
  letter-spacing: -0.02em; transition: all 0.2s; line-height: 1;
}
.badge-icon.earned { background: var(--habit-color, var(--green)); color: #fff; }
.badge-icon.locked { background: var(--surface2); color: var(--text-tertiary); }
.badge-label { font-size: 8px; color: var(--text-tertiary); text-align: center; font-family: var(--mono); line-height: 1.4; }

/* ── Profile view ───────────────────────────────────────────────────────── */
.profile-wrap { padding: 0 14px 32px; }
.profile-header {
  display: flex; flex-direction: column; align-items: center;
  padding: 28px 0 24px; gap: 10px;
}
.profile-avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-strong); }
.profile-avatar-placeholder {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--surface2); border: 2px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 34px;
}
.profile-name { font-size: 21px; font-weight: 800; letter-spacing: -0.4px; }
.profile-email { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); }
.profile-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 24px; }
.profile-habit-section { margin-bottom: 24px; }
.profile-habit-label { font-size: 14px; font-weight: 700; margin-bottom: 12px; letter-spacing: -0.2px; display: flex; align-items: center; gap: 8px; }
.profile-habit-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.avatar-wrap { position: relative; display: inline-block; cursor: pointer; }
.avatar-edit-badge { position: absolute; bottom: 2px; right: 2px; width: 22px; height: 22px; background: var(--surface2); border: 1.5px solid var(--border-strong); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; pointer-events: none; }

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 14px; font-weight: 500; }
.settings-sub { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); margin-top: 2px; }

/* Toggle switch */
.toggle { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; border-radius: 13px;
  background: var(--surface2); border: 1px solid var(--border);
  transition: background 0.2s; cursor: pointer;
}
.toggle input:checked + .toggle-track { background: var(--green); border-color: var(--green); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text-secondary); transition: transform 0.2s, background 0.2s;
  pointer-events: none;
}
.toggle input:checked ~ .toggle-thumb { transform: translateX(18px); background: #fff; }

.time-input {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 14px; font-family: var(--mono); padding: 6px 10px;
  outline: none; cursor: pointer; color-scheme: dark;
}
.time-input:focus { border-color: var(--border-strong); }

.settings-section-title {
  font-size: 10px; color: var(--text-tertiary); font-family: var(--mono);
  text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600;
  margin: 20px 0 4px;
}

.danger-btn {
  width: 100%; padding: 13px; margin-top: 8px;
  background: none; border: 1px solid rgba(224,85,85,0.3);
  border-radius: 10px; color: var(--red); font-size: 14px; font-weight: 600;
  font-family: var(--font); cursor: pointer; touch-action: manipulation;
  transition: all 0.15s;
}
.danger-btn:hover { background: rgba(224,85,85,0.06); }

/* Sign out — flat text (Monitor style) */
.signout-icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text-tertiary);
  font-size: 11px; font-weight: 600; font-family: var(--mono);
  cursor: pointer; display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 7px; transition: all 0.15s;
  touch-action: manipulation; letter-spacing: 0.04em;
}
.signout-icon-btn:hover { color: var(--text-secondary); border-color: var(--border-strong); }

/* ── Add habit / Sheet ───────────────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.75); display: flex; align-items: flex-end; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.sheet { width: 100%; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 20px calc(var(--safe-bottom) + 28px); max-height: 88vh; overflow-y: auto; border-top: 1px solid var(--border-strong); }
.sheet-handle { width: 32px; height: 3px; background: rgba(255,255,255,0.12); border-radius: 2px; margin: 10px auto 20px; }
.sheet-title { font-size: 19px; font-weight: 800; margin-bottom: 20px; letter-spacing: -0.3px; }
.sheet-label { font-size: 9px; color: var(--text-tertiary); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; margin-top: 16px; font-weight: 600; }
.sheet-input { width: 100%; padding: 12px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 16px; font-family: var(--font); outline: none; transition: border-color 0.15s; }
.sheet-input:focus { border-color: var(--border-strong); }
.emoji-input { font-size: 22px; text-align: center; letter-spacing: 3px; }
.sheet-btn { width: 100%; padding: 14px; margin-top: 20px; background: var(--text); color: var(--bg); border: none; border-radius: 10px; font-size: 15px; font-weight: 700; font-family: var(--font); cursor: pointer; letter-spacing: 0.01em; touch-action: manipulation; }

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch { width: 32px; height: 32px; border-radius: 50%; cursor: pointer; border: 2.5px solid transparent; transition: border-color 0.15s; touch-action: manipulation; }
.color-swatch.selected { border-color: #fff; }

.freq-row { display: flex; gap: 6px; flex-wrap: wrap; }
.freq-btn { padding: 6px 14px; border-radius: 7px; border: 1px solid var(--border); background: none; color: var(--text-secondary); font-size: 12px; font-weight: 600; font-family: var(--font); cursor: pointer; touch-action: manipulation; transition: all 0.15s; }
.freq-btn.selected { background: var(--surface2); color: var(--text); border-color: var(--border-strong); }
