:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --muted: #6d6a64;
  --line: #e6e3dc;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --day-empty: #ebe8e1;
  --day-missed: #ebe8e1;
  --day-met: #2f9e63;
  --day-paused: #c9c6bf;
  --day-pending: transparent;
  --radius: 10px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1e1e1c;
    --ink: #edebe6;
    --muted: #9c988f;
    --line: #2e2d2a;
    --accent: #3dbb78;
    --accent-ink: #0d1f15;
    --danger: #f2877f;
    --day-empty: #262624;
    --day-missed: #262624;
    --day-met: #3dbb78;
    --day-paused: #4a4945;
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.85em; }
h1, h2 { line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 2rem; margin: 0 0 0.25rem; }

.page { max-width: 58rem; margin: 0 auto; padding: 2rem 16px 4rem; }
.page--narrow { max-width: 24rem; padding-top: 4rem; }

/* Public */
.masthead { margin: 1rem 0 2.5rem; }
.masthead h1 { font-size: clamp(2.25rem, 6vw, 3.25rem); }
.eyebrow { margin: 0; color: var(--muted); font-size: 0.9rem; }
.eyebrow a { text-decoration: none; }
.lede { color: var(--muted); font-size: 1.1rem; margin: 0.5rem 0 0; max-width: 36rem; }
.meta { color: var(--muted); margin: 0.25rem 0 0; font-size: 0.95rem; }
.footnote { color: var(--muted); font-size: 0.85rem; margin-top: 3rem; }
.section-title { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 3rem 0 1rem; }
.empty { color: var(--muted); }

.habit-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.habit-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.habit-card--ended { opacity: 0.75; }
.habit-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.habit-card-head h2 { font-size: 1.25rem; margin: 0; }
.habit-card-head h2 a { text-decoration: none; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge--done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.badge--private { margin-left: 0.25rem; }

.stats { display: flex; gap: 2rem; margin: 0.75rem 0 1rem; }
.stat dt { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat dd { margin: 0; color: var(--muted); }
.stat-number { font-size: 1.75rem; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat--current .stat-number { color: var(--accent); }

/* Heatmap: one column per week, Sunday on top. On narrow screens it scrolls, starting at the most recent week. */
.heatmap-scroll { overflow-x: auto; padding-bottom: 4px; }
.heatmap {
  display: inline-grid;
  grid-template-rows: repeat(7, 11px);
  grid-auto-flow: column;
  grid-auto-columns: 11px;
  gap: 3px;
}
.day { border-radius: 2px; background: var(--day-empty); }
.day--met { background: var(--day-met); }
.day--paused { background: var(--day-paused); }
.day--pending { background: transparent; box-shadow: inset 0 0 0 1px var(--day-met); }
.day--before, .day--future { background: transparent; }

/* Private */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.wordmark { font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; font-size: 0.95rem; }
.topbar nav form { display: inline; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.today-list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.today-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.85rem 1rem; }
.today-item + .today-item { border-top: 1px solid var(--line); }
.today-item-main { display: flex; flex-direction: column; min-width: 0; }
.today-item-name { font-weight: 600; text-decoration: none; }
.today-item-meta { color: var(--muted); font-size: 0.9rem; }
.today-item--done .today-item-name { color: var(--accent); }
.quick-check-in { display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0; }
.quick-check-in input[type=number] { width: 6rem; }
.check { color: var(--accent); font-size: 1.4rem; font-weight: 700; padding: 0 0.75rem; }

.panel { margin-top: 2rem; }
.panel h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
.panel--highlight { background: var(--surface); border: 1px solid var(--accent); border-radius: var(--radius); padding: 1rem; margin: 1rem 0; }
.token { font-family: var(--mono); overflow-x: auto; user-select: all; margin: 0; }
.hint { color: var(--muted); font-size: 0.85rem; display: block; margin-top: 0.25rem; }
.plain-list { padding-left: 1.1rem; }
.plain-list form.inline { display: inline; margin-left: 0.5rem; }

.flash { padding: 0.6rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.flash--alert { border-color: var(--danger); color: var(--danger); }
.flash ul { margin: 0; padding-left: 1.1rem; }

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table th, .table td { padding: 0.5rem 0.5rem 0.5rem 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cell-action { text-align: right; }
.row--muted { color: var(--muted); }

/* Forms */
input, select, textarea {
  font: inherit; color: inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.6rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 0.9rem; color: var(--muted); }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 0.25rem; color: var(--ink); }
.stack-form { display: grid; gap: 1rem; max-width: 32rem; }
.stack-form fieldset { border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 0.75rem; padding: 0.75rem 1rem 1rem; }
.stack-form legend { color: var(--muted); font-size: 0.9rem; padding: 0 0.25rem; }
.choice { display: flex; gap: 0.5rem; align-items: center; color: var(--ink); }
.choice > input { width: auto; display: inline; margin: 0; }
.row-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.row-form label > input { width: auto; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.25rem; }
.inline-form select { max-width: 16rem; }

.button, input[type=submit].button {
  display: inline-block; font: inherit; font-weight: 600; font-size: 0.95rem; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 6px; padding: 0.4rem 0.9rem; text-decoration: none;
}
.button:hover { filter: brightness(1.08); color: var(--accent-ink); }
.button--quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.button--quiet:hover { color: var(--ink); border-color: var(--muted); }
.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link--danger { color: var(--danger); }

@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  .stats { gap: 1.5rem; }
  .today-item { flex-wrap: wrap; }
}
