:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --card: #1c1c1c;
  --border: #2a2a2a;
  --border-light: #333;
  --gold: #C9A84C;
  --gold-dim: rgba(201, 168, 76, 0.15);
  --gold-glow: rgba(201, 168, 76, 0.35);
  --blue: #2E6DB4;
  --blue-dim: rgba(46, 109, 180, 0.15);
  --text: #f0f0f0;
  --text-muted: #888;
  --text-dim: #555;
  --green: #4CAF50;
  --header-h: 60px;
  --progress-h: 4px;
  --nav-h: 48px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── HEADER ── */
#main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.header-left { display: flex; align-items: center; gap: 16px; }

.logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--gold);
  text-transform: uppercase;
}

.header-date {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.header-right { display: flex; align-items: center; gap: 10px; }

.streak-pill, .xp-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.streak-pill { border-color: rgba(201, 168, 76, 0.3); }
.xp-pill { border-color: rgba(46, 109, 180, 0.3); color: #7ab3e0; }
.streak-pill .fire-emoji { font-size: 15px; }
#streak-count { color: var(--gold); }
#xp-earned { color: #7ab3e0; }
.xp-sep { color: var(--text-dim); font-weight: 400; }
.pill-label { color: var(--text-muted); font-weight: 400; font-size: 12px; }

.settings-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  transition: color 0.2s, border-color 0.2s;
}
.settings-btn:hover { color: var(--gold); border-color: var(--gold-glow); }

/* ── PROGRESS BAR ── */
.progress-track {
  position: sticky;
  top: var(--header-h);
  z-index: 99;
  height: var(--progress-h);
  background: var(--surface);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue) 0%, var(--gold) 100%);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px var(--gold-glow);
}
.progress-label { display: none; }

/* ── TABS ── */
.tab-nav {
  position: sticky;
  top: calc(var(--header-h) + var(--progress-h));
  z-index: 98;
  background: rgba(13, 13, 13, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0;
  padding: 0 24px;
  height: var(--nav-h);
  align-items: flex-end;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  transition: color 0.2s, border-color 0.2s;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ── MAIN ── */
.main-content { max-width: 1100px; margin: 0 auto; padding: 24px 24px 60px; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── CARDS ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  color: var(--text-muted);
}

/* ── TODAY LAYOUT ── */
.today-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 820px) {
  .today-layout { grid-template-columns: 1fr; }
}

/* ── HABITS CHECKLIST ── */
#habits-list { padding: 8px; }

.habit-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  border: 1px solid transparent;
  user-select: none;
  position: relative;
}
.habit-row:hover { background: rgba(255,255,255,0.03); }
.habit-row.completed {
  background: var(--gold-dim);
  border-color: rgba(201, 168, 76, 0.25);
}

.habit-check {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-radius: 5px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.habit-row.completed .habit-check {
  background: var(--gold);
  border-color: var(--gold);
}
.habit-check svg { display: none; }
.habit-row.completed .habit-check svg { display: block; }

.habit-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  transition: color 0.2s;
}
.habit-row.completed .habit-name {
  color: var(--gold);
}

.habit-xp {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  transition: color 0.2s;
  white-space: nowrap;
}
.habit-row.completed .habit-xp { color: var(--gold); }

/* ── SUMMARY CARD ── */
.summary-card { min-height: 280px; }
.summary-body { padding: 28px 24px; text-align: center; }
.summary-xp-row { display: flex; align-items: baseline; justify-content: center; gap: 0; margin-bottom: 8px; }
.summary-xp-earned { font-size: 48px; font-weight: 800; color: var(--gold); line-height: 1; }
.summary-xp-denom { font-size: 16px; color: var(--text-muted); }
.summary-pct { font-size: 28px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.summary-bar-wrap { height: 6px; background: var(--surface); border-radius: 99px; overflow: hidden; margin-bottom: 20px; }
.summary-bar-fill { height: 100%; background: linear-gradient(90deg, var(--blue), var(--gold)); border-radius: 99px; transition: width 0.4s ease; }
.summary-message { font-size: 18px; font-weight: 700; color: var(--text-muted); letter-spacing: 0.5px; }
.summary-card.perfect .summary-message { color: var(--gold); }
.summary-card.perfect { background: linear-gradient(135deg, #1c1c1c 0%, #222018 100%); border-color: var(--gold-glow); }

/* ── WEEK TAB ── */
.week-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 820px) { .week-layout { grid-template-columns: 1fr; } }

.week-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week-label { font-size: 13px; color: var(--text); font-weight: 600; min-width: 90px; text-align: center; }
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px 4px;
  transition: color 0.2s, border-color 0.2s;
}
.nav-btn:hover { color: var(--gold); border-color: var(--gold-glow); }

.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  margin-left: 4px;
}
.toggle-wrap input { display: none; }
.toggle-track {
  width: 32px;
  height: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--text-dim);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}
.toggle-wrap input:checked + .toggle-track { background: var(--gold-dim); border-color: var(--gold-glow); }
.toggle-wrap input:checked + .toggle-track::after { transform: translateX(14px); background: var(--gold); }
.toggle-text { font-size: 12px; color: var(--text-muted); }

.week-grid { display: flex; gap: 8px; padding: 20px; align-items: flex-end; min-height: 180px; }
.week-day-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.week-day-col.weekend { opacity: 0.6; }
.week-day-col.today .day-name { color: var(--gold); }

.day-bar-wrap { width: 100%; height: 100px; display: flex; align-items: flex-end; }
.day-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: height 0.4s ease;
}
.day-bar.has-data { background: linear-gradient(180deg, var(--gold) 0%, rgba(201,168,76,0.5) 100%); border-color: transparent; }
.day-bar.future { background: var(--surface); opacity: 0.4; }

.day-name { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }
.day-pct { font-size: 12px; font-weight: 700; color: var(--text-muted); }
.day-pct.qualifying { color: var(--gold); }

.week-totals {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 20px;
}
.week-totals strong { color: var(--text); }

/* ── STREAK CARD ── */
.streak-body { padding: 32px 20px; text-align: center; }
.streak-fire-big { font-size: 48px; margin-bottom: 8px; }
.streak-num { font-size: 64px; font-weight: 800; color: var(--gold); line-height: 1; }
.streak-unit { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.streak-threshold { font-size: 12px; color: var(--text-dim); margin-top: 12px; padding: 6px 12px; background: var(--surface); border-radius: 99px; display: inline-block; }

/* ── MONTH / HEATMAP ── */
.heatmap-card {}
.heatmap-grid { padding: 20px; }
.month-controls { display: flex; align-items: center; gap: 8px; }
.month-label { font-size: 14px; font-weight: 700; color: var(--text); min-width: 110px; text-align: center; }

.heatmap-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.heatmap-weekday { text-align: center; font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; padding: 2px 0; }

.heatmap-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.heatmap-day {
  aspect-ratio: 1;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  cursor: default;
  transition: transform 0.15s;
  position: relative;
}
.heatmap-day:hover { transform: scale(1.1); z-index: 1; }
.heatmap-day.empty { background: transparent; pointer-events: none; }
.heatmap-day.today { box-shadow: 0 0 0 2px var(--gold); }
.heatmap-day.future { opacity: 0.3; }
.heatmap-day .day-num { font-size: 12px; font-weight: 700; }
.heatmap-day .day-pct-label { font-size: 9px; font-weight: 600; opacity: 0.85; }

.heatmap-legend { display: flex; align-items: center; gap: 10px; padding: 0 20px 4px; }
.legend-label { font-size: 11px; color: var(--text-dim); }
.legend-scale { display: flex; gap: 3px; }
.legend-swatch { width: 16px; height: 16px; border-radius: 3px; }

.monthly-total {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}
.monthly-total strong { color: var(--text); }

/* ── SETTINGS MODAL ── */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: flex-start; justify-content: flex-end; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-panel {
  position: relative;
  z-index: 1;
  background: var(--card);
  border-left: 1px solid var(--border);
  width: 440px;
  max-width: 100vw;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}
.modal-header h2 { font-size: 16px; font-weight: 700; color: var(--gold); }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  transition: color 0.2s;
}
.modal-close:hover { color: var(--text); }

.editor-list { flex: 1; padding: 8px; }
.editor-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.15s;
}
.editor-row:hover { background: rgba(255,255,255,0.03); }
.editor-row.editing { background: var(--surface); border-color: var(--border); }

.editor-name { flex: 1; font-size: 14px; color: var(--text); }
.editor-xp { font-size: 13px; color: var(--text-muted); font-weight: 600; min-width: 48px; text-align: right; }
.editor-name-input, .editor-xp-input {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 8px;
  outline: none;
}
.editor-name-input:focus, .editor-xp-input:focus { border-color: var(--gold); }
.editor-name-input { flex: 1; }
.editor-xp-input { width: 64px; }

.btn-icon {
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-icon.edit:hover { color: var(--blue); border-color: rgba(46,109,180,0.4); }
.btn-icon.save:hover, .btn-icon.save { color: var(--gold); border-color: var(--gold-glow); }
.btn-icon.delete:hover { color: #e05a5a; border-color: rgba(224,90,90,0.4); }

.add-habit-section {
  padding: 16px 16px 20px;
  border-top: 1px solid var(--border);
}
.add-habit-section h3 { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; margin-bottom: 10px; letter-spacing: 0.5px; }
.add-habit-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.add-habit-form input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  flex: 1;
  min-width: 120px;
}
.add-habit-form input:focus { border-color: var(--gold); }
.btn-gold {
  background: var(--gold);
  border: none;
  border-radius: var(--radius-sm);
  color: #111;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  padding: 8px 16px;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-gold:hover { opacity: 0.85; }

/* ── STREAK BANNER ── */
#streak-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: linear-gradient(90deg, #8a5c0c, #C9A84C, #8a5c0c);
  color: #111;
  font-weight: 700;
  font-size: 15px;
  padding: 14px 20px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  animation: slideDown 0.4s ease;
}
#streak-banner.hidden { display: none; }
@keyframes slideDown { from { transform: translateY(-100%); } to { transform: translateY(0); } }
.banner-close { background: none; border: none; font-size: 18px; cursor: pointer; color: #111; font-weight: 700; padding: 0 4px; }

/* ── MILESTONE OVERLAY ── */
#milestone-overlay {
  position: fixed;
  inset: 0;
  z-index: 600;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease;
}
#milestone-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.milestone-content { text-align: center; }
.milestone-fire { font-size: 80px; margin-bottom: 16px; animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.milestone-number { font-size: 96px; font-weight: 900; color: var(--gold); line-height: 1; }
.milestone-title { font-size: 28px; font-weight: 700; color: var(--gold); margin-bottom: 12px; }
.milestone-sub { font-size: 18px; color: var(--text-muted); margin-bottom: 36px; }
.milestone-btn {
  background: var(--gold);
  border: none;
  border-radius: 99px;
  color: #111;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 40px;
  transition: opacity 0.2s;
}
.milestone-btn:hover { opacity: 0.85; }

/* ── CONFETTI CANVAS ── */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 400;
  display: none;
}

/* ── XP FLOAT ── */
#xp-float-container { position: fixed; top: 0; left: 0; pointer-events: none; z-index: 300; }
.xp-float {
  position: fixed;
  color: var(--gold);
  font-size: 14px;
  font-weight: 800;
  pointer-events: none;
  text-shadow: 0 0 8px var(--gold-glow);
  animation: floatUp 0.9s ease forwards;
}
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-40px); }
}

/* ── AUTH GATE ── */
#auth-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-box {
  width: 100%;
  max-width: 340px;
  padding: 0 24px;
  text-align: center;
}

.auth-logo {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: -1.5px;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.auth-tagline {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 36px;
}

#auth-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  text-align: center;
  letter-spacing: 3px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
  display: block;
}
#auth-input:focus { border-color: var(--gold); }
#auth-input::placeholder { letter-spacing: normal; color: var(--text-dim); }

.auth-submit {
  width: 100%;
  background: var(--gold);
  border: none;
  border-radius: var(--radius);
  color: #111;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  padding: 14px;
  transition: opacity 0.2s;
  margin-bottom: 14px;
}
.auth-submit:hover { opacity: 0.85; }
.auth-submit:disabled { opacity: 0.5; cursor: default; }

.auth-error {
  font-size: 13px;
  font-weight: 600;
  color: #e05555;
  min-height: 18px;
  opacity: 0;
  transition: opacity 0.2s;
}
.auth-error.visible { opacity: 1; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-8px); }
  30%, 60%, 90% { transform: translateX(8px); }
}
.shake { animation: shake 0.4s ease; }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
