:root {
  --bg: #f6f8fa;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #656d76;
  --border: #d0d7de;
  --accent: #2da44e;
  --accent-dark: #1a7f37;
  --danger: #cf222e;
  --radius: 10px;
  --l1: #ebedf0; --l2: #9be9a8; --l3: #40c463; --l4: #30a14e; --l5: #216e39;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; }
.topbar nav a { margin-left: 18px; color: var(--ink); }
.topbar nav a.muted { color: var(--muted); }

.container { max-width: 920px; margin: 24px auto; padding: 0 16px; }

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin: 16px 0;
}

.flash { padding: 10px 14px; border-radius: 8px; margin: 10px 0; font-size: 14px; }
.flash.error   { background: #ffebe9; border: 1px solid #ffc1bc; color: var(--danger); }
.flash.success { background: #dafbe1; border: 1px solid #aceebb; color: var(--accent-dark); }

input, select, button { font: inherit; }
input, select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff;
}
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 5px; }
button {
  cursor: pointer; padding: 9px 16px; border: 1px solid transparent;
  border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600;
}
button:hover { background: var(--accent-dark); }
.link-btn { background: none; color: var(--muted); border: none; padding: 4px 6px; font-weight: 500; }
.link-btn:hover { background: none; color: var(--danger); text-decoration: underline; }
.btn-link {
  display: inline-block; background: var(--accent); color: #fff;
  padding: 9px 16px; border-radius: 8px; font-weight: 600;
}
.btn-link:hover { background: var(--accent-dark); text-decoration: none; }

/* Auth */
.auth { max-width: 380px; margin: 8vh auto; text-align: center; }
.auth h1 { font-size: 26px; }
.auth form { text-align: left; margin-top: 16px; }
.auth button { width: 100%; margin-top: 16px; }
.devbox {
  background: #fff8c5; border: 1px solid #eac54f; border-radius: 8px;
  padding: 12px; margin: 16px 0; text-align: left;
}
.devbox code { font-size: 20px; letter-spacing: 3px; }

/* Habit form */
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.field { flex: 1 1 160px; }
.field.grow { flex: 2 1 240px; }
.weekdays { display: flex; gap: 8px; flex-wrap: wrap; }
.chk { display: flex; align-items: center; gap: 4px; font-weight: 500; }
.chk input { width: auto; }
.habit-form button { margin-top: 16px; }

.habit-list { list-style: none; padding: 0; margin: 8px 0 0; }
.habit-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-top: 1px solid var(--border);
}
.tag {
  display: inline-block; font-size: 12px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 9px; margin-left: 6px;
}
.tag.freq { color: var(--accent-dark); }
.tag.due { color: #9a6700; background: #fff8c5; border-color: #eac54f; }
.tag.public { color: var(--accent-dark); }
.tag.private { color: #6e40c9; background: #faf5ff; border-color: #d8b9ff; }
.tag.muted-tag { color: var(--muted); }
.archived { margin-top: 16px; }
.habit-actions { display: flex; align-items: center; gap: 4px; }

/* Nav badge */
.badge {
  display: inline-block; min-width: 16px; padding: 0 5px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  text-align: center; line-height: 16px;
}

/* Group leaderboard */
.board-wrap { overflow-x: auto; }  /* let the table scroll, not break layout, on narrow screens */
.board { width: 100%; border-collapse: collapse; }
.board th, .board td {
  text-align: left; padding: 10px 8px; border-top: 1px solid var(--border);
  vertical-align: top;
}
.board th { color: var(--muted); font-size: 12px; font-weight: 600; border-top: none; }
.board td:first-child, .board th:first-child { width: 28px; }
.board .rank { color: var(--muted); font-weight: 700; }
.board tr.me { background: #f0fff4; }
.board .goals { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.board .goals .tag { margin-left: 0; }

/* Today / check-in */
.day-nav { display: flex; align-items: center; justify-content: space-between; }
.day-nav h1 { text-align: center; }
.checkin-list { list-style: none; padding: 0; }
.checkin {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin: 10px 0;
}
.checkin.done   { border-color: var(--l3); background: #f0fff4; }
.checkin.missed { border-color: #ffc1bc; background: #fff5f4; }
.checkin-actions form { display: flex; align-items: center; gap: 6px; }
.btn-done, .btn-miss { background: #fff; border: 1px solid var(--border); color: var(--ink); }
.btn-done.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-miss.on { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-done:hover { border-color: var(--accent); }
.btn-miss:hover { border-color: var(--danger); }

/* Daily journal */
.journal { margin-top: 18px; }
.journal-head { display: flex; align-items: baseline; justify-content: space-between; }
.journal-head h2 { margin: 0; }
.mood-row { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.mood { position: relative; display: inline-flex; margin: 0; font-weight: 400; cursor: pointer; }
.mood input { position: absolute; opacity: 0; width: 0; height: 0; }
.mood span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; font-size: 20px; line-height: 1;
  border: 1px solid var(--border); border-radius: 50%; background: #fff;
  filter: grayscale(0.4); opacity: 0.7; transition: all 0.1s ease;
}
.mood:hover span { filter: none; opacity: 1; border-color: var(--accent); }
.mood input:checked + span,
.mood.on span { filter: none; opacity: 1; border-color: var(--accent); background: #f0fff4; transform: scale(1.08); }
.mood-clear span { font-size: 13px; color: var(--muted); }
.mood-clear input:checked + span { background: var(--bg); transform: none; border-color: var(--border); }
.journal-entry {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; resize: vertical; min-height: 70px; font: inherit;
}
.journal-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.journal-actions .hint { margin: 0; }

/* Stats */
.stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.stat {
  flex: 1 1 120px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; text-align: center;
}
.stat-num { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; }

/* Analytics date filter */
.date-range { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; }
.date-range label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
.date-range input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }

/* Heatmap */
.site-footer {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 24px 16px; margin-top: 32px; border-top: 1px solid var(--border);
}
.site-footer p { margin: 4px 0; }
.site-footer a { color: var(--accent-dark); }
.site-footer .heart { color: var(--danger); }
.site-footer .built-with {
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.claude-mark { vertical-align: middle; }

.share-row { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.share-link { color: var(--muted); font-size: 0.85rem; font-weight: 500; text-decoration: none; }
.share-link:hover { color: var(--accent); text-decoration: underline; }
.heatmap-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.heatmap { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; }
.weekday-col { display: flex; flex-direction: column; gap: 3px; font-size: 10px; color: var(--muted); padding-top: 1px; }
.weekday-col span { height: 13px; line-height: 13px; }
.weeks { display: flex; gap: 3px; }
.week { display: flex; flex-direction: column; gap: 3px; }
.cell {
  width: 13px; height: 13px; border-radius: 3px; background: var(--l1);
  display: inline-block; border: 1px solid rgba(27,31,36,0.06);
}
.cell.level-1 { background: var(--l1); }
.cell.level-2 { background: var(--l2); }
.cell.level-3 { background: var(--l3); }
.cell.level-4 { background: var(--l4); }
.cell.level-5 { background: var(--l5); }
.cell.future { background: transparent; border-color: transparent; }
/* A small centred dot marks a day that has a journal entry. */
.cell.has-note { position: relative; }
.cell.has-note::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%;
  background: rgba(255,255,255,0.9); box-shadow: 0 0 0 1px rgba(27,31,36,0.25);
}
.cell.has-note.level-1::after { background: var(--muted); box-shadow: none; }

/* Small screens. The rest of the layout is fluid (flex-wrap, %-width inputs,
   scrollable heatmap); the topbar is the one row that needs help — its nav
   has no wrap and per-link margins crowd a phone. Switch it to a wrapping
   flex with gaps so the brand and links stack cleanly. */
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 6px 14px; padding: 10px 14px; }
  .topbar nav { display: flex; flex-wrap: wrap; gap: 14px; }
  .topbar nav a { margin-left: 0; }
  .container { margin: 16px auto; }
}
