:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --border: #e3e3de;
  /* Sage, from incrementup.com (#81a58f). Too light for text on this
     background, so the light-mode accent is a deeper sage (4.75:1 on --bg). */
  --accent: #53765f;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-text: #ffffff; /* 6.6:1 on --danger */
  --success: #53765f;
  --empty-cell: #ebebe6;
  --radius: 10px;
  --habit: #489267;
  /* Header band: the incrementup.com look, wordmark greys on sage. */
  --header-bg: #81a58f;
  --header-border: #6f9480;
  --header-fg: #181719;
  --brand-increment: #444342;
  --brand-up: #181719;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ececea;
    --muted: #9c9c96;
    --border: #33332f;
    /* True sage reads well on dark (6.6:1); buttons get dark text on it. */
    --accent: #81a58f;
    --accent-text: #16221b;
    --danger: #f97066;
    --danger-text: #2a0d0b; /* the light red needs dark text */
    --success: #81a58f;
    --empty-cell: #2a2a27;
    --header-bg: #1d2620;
    --header-border: #2c3a31;
    --header-fg: #ececea;
    --brand-increment: #a9a7a4;
    --brand-up: #ececea;
    color-scheme: dark;
  }
}

/* Habit palette: .c-<name> sets --habit for everything inside.
   Softened to sit with the sage header: every colour is OKLCH lightness 0.60
   and chroma 0.10 (gray 0.012), keeping the original hues. All are 3.7-4.2:1
   on white and 4.0-4.4:1 on the dark surface, so the white tick stays clear. */
.c-green  { --habit: #489267; }
.c-blue   { --habit: #5982bb; }
.c-purple { --habit: #8274b7; }
.c-pink   { --habit: #b0667e; }
.c-orange { --habit: #af6e45; }
.c-yellow { --habit: #987d30; }
.c-teal   { --habit: #12938f; }
.c-gray   { --habit: #818179; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: .25rem 0 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem 1rem; padding: .75rem 1rem;
  border-bottom: 1px solid var(--header-border); background: var(--header-bg);
}
/* The accent focus ring is too faint on the sage band, so use the header text colour. */
.site-header :focus-visible { outline: 2px solid var(--header-fg); outline-offset: 2px; }
/* Wordmark, after the incrementup.com page: INCREMENT in grey, UP stronger in
   both colour and weight, with a slight space between them. Archivo, widened
   (self-hosted, see layout.html). */
.brand {
  font-family: "Archivo Wordmark", "Arial Black", sans-serif;
  font-stretch: 112%; font-size: 1.6rem; line-height: 1;
  letter-spacing: .01em; text-transform: uppercase; text-decoration: none;
}
.brand-increment { color: var(--brand-increment); font-weight: 700; margin-right: .2em; }
.brand-up { color: var(--brand-up); font-weight: 900; }
.site-header nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
.site-header nav a, .site-header button.link { color: var(--header-fg); }
.site-header nav a { text-decoration: none; }
/* The current section: underlined, so it reads on both the sage and dark bands. */
.site-header nav a[aria-current="page"] {
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .35em; font-weight: 600;
}
.site-header nav a:hover { text-decoration: underline; }
.site-header form { margin: 0; }

/* Cards & forms */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1rem 0;
}
.card > :first-child, .small-heading { margin-top: 0; }
.small-heading { font-size: .9rem; color: var(--muted); font-weight: 600; }
.auth { max-width: 24rem; margin: 2rem auto; }

label { display: block; font-weight: 600; margin: .75rem 0 .25rem; }
label .muted { font-weight: 400; }
input:not([type=radio]), textarea {
  width: 100%; padding: .5rem .6rem; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, button:focus-visible, .cell:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.counter { display: block; text-align: right; font-size: .8rem; }
.field-hint { margin: 0 0 .35rem; }
input[type=date] { max-width: 12rem; }
.started { margin: .1rem 0 .75rem; }
.inline { display: flex; flex-wrap: wrap; gap: .5rem; }
.inline input { flex: 1 1 12rem; }

button, .button {
  display: inline-block; font: inherit; cursor: pointer; text-decoration: none;
  padding: .45rem .9rem; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text);
}
button.secondary, .button.secondary {
  background: transparent; color: var(--text); border-color: var(--border);
}
/* Destructive actions (deleting a habit). Filled for the final confirm;
   outlined (with .secondary) for the link that leads to it. */
button.danger, .button.danger {
  background: var(--danger); border-color: var(--danger); color: var(--danger-text);
}
button.secondary.danger, .button.secondary.danger {
  background: transparent; color: var(--danger); border-color: var(--danger);
}
button.link {
  background: none; border: none; padding: 0; color: var(--text);
}
button.link:hover { text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: 1rem; }
.actions form { margin: 0; }

.error { color: var(--danger); font-weight: 600; }
.success { color: var(--success); font-weight: 600; }
.notice {
  background: var(--surface); border-left: 3px solid var(--muted);
  padding: .4rem .75rem; margin: .5rem 0;
}

.colors { border: none; padding: 0; margin: .75rem 0 0; }
.colors legend { font-weight: 600; margin-bottom: .25rem; }
.swatch {
  display: inline-flex; margin: 0 .35rem .35rem 0; cursor: pointer;
  width: 1.9rem; height: 1.9rem; border-radius: 50%; background: var(--habit);
  align-items: center; justify-content: center;
}
.swatch input { appearance: none; margin: 0; width: 100%; height: 100%; border-radius: 50%; cursor: pointer; }
.swatch input:checked { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--habit); }

/* Habit list */
.page-head { margin: 1rem 0; }
/* Today page: ‹ › Heading, reusing the calendar's arrows (both before the
   heading, so they stay put); "Back to today" sits on the line below. */
.day-nav { gap: .25rem; }
.day-nav h1 { margin: 0 0 0 .5rem; }
.day-head p { margin: .35rem 0 0; }
.day-head .today-link { margin-left: 0; }
.habit-list { list-style: none; margin: 0; padding: 0; }
.habit-row {
  display: flex; align-items: flex-start; gap: .75rem;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--habit); border-radius: var(--radius);
  padding: .75rem; margin-bottom: .5rem;
}
.habit-row .dot { margin-top: .5rem; }
.empty { padding: 1rem 0; }

.check {
  flex: none; width: 2.5rem; height: 2.5rem; border-radius: 50%; padding: 0;
  background: transparent; border: 2px solid var(--habit); color: transparent;
  font-size: 1.2rem; line-height: 1;
}
.check:hover { color: var(--habit); }
.check.done { background: var(--habit); color: #fff; }

.habit-main { flex: 1; min-width: 0; }
.habit-name { display: block; font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.habit-name:hover { text-decoration: underline; }
.streak { font-size: .875rem; }
.desc summary { cursor: pointer; font-size: .875rem; color: var(--muted); }

.row-actions { display: flex; gap: .25rem; flex: none; }
.icon {
  width: 2rem; height: 2rem; padding: 0; line-height: 1;
  background: transparent; color: var(--muted); border: 1px solid var(--border);
}
.icon:hover { color: var(--text); }
/* Move up/down at the ends of the list: shown but greyed out. */
.icon:disabled { opacity: .35; cursor: default; }
.icon:disabled:hover { color: var(--muted); }

.dot {
  display: inline-block; width: .75rem; height: .75rem; border-radius: 50%;
  background: var(--habit); margin-right: .5rem; vertical-align: middle;
}

/* Habit switcher on a habit's page (partials/habit_switcher.html): a sidebar
   on wide screens, a "Switch habit" dropdown on phones. Both are in the page;
   the breakpoint decides which shows. */
.habit-layout { display: grid; gap: 0 2rem; }
.habit-content { min-width: 0; }
.switcher-list { list-style: none; margin: 0; padding: 0; }
.switcher-list a {
  display: flex; align-items: center; padding: .4rem .6rem; border-radius: 8px;
  color: var(--text); text-decoration: none; overflow-wrap: anywhere;
  border-left: 3px solid transparent;
}
.switcher-list a .dot { flex: none; width: .6rem; height: .6rem; }
.switcher-list a:hover { background: var(--surface); }
.switcher-list a[aria-current="page"] {
  background: var(--surface); border-left-color: var(--habit); font-weight: 600;
}

.habit-side .small-heading { margin: 1rem 0 .4rem .6rem; }
.habit-side .small-heading a { color: inherit; text-decoration: none; }
.habit-side .small-heading a:hover { text-decoration: underline; }

.habit-drop { position: relative; margin: .75rem 0 0; }
.habit-drop summary {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; list-style: none;
  padding: .4rem .8rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); font-size: .9rem; font-weight: 600;
}
.habit-drop summary::-webkit-details-marker { display: none; }
.habit-drop summary::after { content: "▾"; font-size: .8em; color: var(--muted); }
.habit-drop[open] summary::after { content: "▴"; }
/* The open list floats over the page rather than pushing it down. */
.habit-drop nav {
  position: absolute; z-index: 10; top: calc(100% + .3rem); left: 0;
  min-width: 15rem; max-width: calc(100vw - 2rem); max-height: 60vh; overflow-y: auto;
  padding: .3rem; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / .18);
}
.habit-drop .all-habits {
  display: block; margin-top: .2rem; padding: .45rem .6rem; border-top: 1px solid var(--border);
  font-size: .875rem;
}

@media (min-width: 60rem) {
  /* Room for the sidebar beside the usual 44rem column. */
  main:has(.habit-layout) { max-width: 62rem; }
  .habit-layout { grid-template-columns: 13rem minmax(0, 1fr); align-items: start; }
  .habit-side { position: sticky; top: .5rem; }
  .habit-drop { display: none; }
}
@media (max-width: 59.99rem) {
  .habit-side { display: none; }
}

/* Habits overview: each habit's last two weeks as a row of small squares. */
.overview .habit-row { align-items: center; flex-wrap: wrap; }
.overview .habit-main { flex: 1 1 12rem; min-width: 0; }
.recent { display: flex; gap: 3px; list-style: none; margin: 0; padding: 0; }
.recent li { width: .8rem; height: .8rem; border-radius: 3px; background: var(--empty-cell); }
.recent li.done { background: var(--habit); }
.recent li.before { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }

/* Collapsible new-habit form: the summary is the "+ New habit" button.
   Once open, the form's Cancel button closes it, so the summary hides. */
.new-habit { margin-top: 1rem; }
.new-habit > summary { list-style: none; }
.new-habit > summary::-webkit-details-marker { display: none; }
.new-habit[open] > summary { display: none; }
.new-habit > .card { margin-top: 0; }

/* Stats */
.stat-grid {
  display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem; display: flex; flex-direction: column;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--habit); }
.stat-label { font-size: .8rem; color: var(--muted); }

/* Year heatmap: a weekday-label column plus one column per week (53 or 54
   for a calendar year). Cells are fluid so a whole year fits on desktop;
   below the minimum cell size the grid overflows and .heatmap-scroll scrolls
   (app.js starts the current year scrolled to the right-hand end). */
.heatmap-scroll { overflow-x: auto; padding-bottom: .5rem; }
.heatmap {
  display: grid; gap: 2px;
  grid-template-columns: 2rem;
  grid-auto-flow: column;
  grid-auto-columns: minmax(8px, 1fr);
}
.week { display: grid; grid-template-rows: 1rem repeat(7, auto); gap: 2px; }
.month {
  font-size: .7rem; line-height: 1rem; color: var(--muted);
  white-space: nowrap; width: 0; overflow: visible;
}
.weekday-labels { position: sticky; left: 0; z-index: 1; background: var(--bg); }
.weekday-labels span { font-size: .6rem; line-height: 1; color: var(--muted); align-self: center; }
.weekday-labels span.month { font-size: .7rem; }
.cell {
  width: 100%; aspect-ratio: 1; border-radius: 2px; padding: 0; border: none;
  background: var(--empty-cell); display: block;
}
button.cell { cursor: pointer; }
button.cell:hover { outline: 1px solid var(--habit); }
.cell.done { background: var(--habit); }
.cell.future { background: transparent; box-shadow: inset 0 0 0 1px var(--border); }
.cell.locked { opacity: .5; }
.cell.blank { background: transparent; }
.cell.before { background: var(--empty-cell); opacity: .35; }
.month a { color: inherit; text-decoration: none; }
.month a:hover { color: var(--text); text-decoration: underline; }

/* Calendar header: ‹ title › [Today]   [Month | Year] */
.calendar { margin-top: 1.5rem; }
.cal-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem 1rem; margin-bottom: .75rem;
}
.cal-nav { display: flex; align-items: center; gap: .25rem; }
.cal-title { margin: 0 0 0 .4rem; font-size: 1.1rem; }
.cal-arrow {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: 6px; font-size: 1.3rem; line-height: 1;
  color: var(--text); text-decoration: none; border: 1px solid var(--border);
}
.cal-arrow:hover { background: var(--surface); }
.cal-arrow.disabled { color: var(--border); }
.today-link { margin-left: .5rem; font-size: .875rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg a { padding: .3rem .8rem; font-size: .875rem; color: var(--text); text-decoration: none; }
.seg a + a { border-left: 1px solid var(--border); }
.seg a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

/* Month view is capped at a comfortable calendar width and centered as one
   block (header, grid, summary), keeping the Month | Year toggle next to the
   calendar. The year heatmap uses the full width. */
.calendar.view-month { max-width: 28rem; margin-inline: auto; }

/* Month view: 7 columns, Monday first, square day cells. */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { font-size: .75rem; color: var(--muted); text-align: center; padding-bottom: .25rem; }
.day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; font: inherit; font-size: .9rem; padding: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
button.day { cursor: pointer; }
button.day:hover { border-color: var(--habit); }
.day.done { background: var(--habit); border-color: var(--habit); color: #fff; font-weight: 600; }
.day.today { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--habit); }
.day.future { background: transparent; color: var(--muted); border-style: dashed; }
.day.locked:not(.future) { opacity: .6; }
.day.blank { background: transparent; border: none; }
/* Before the habit's start date: not tracked, so no box at all. */
.day.before { background: transparent; border: none; color: var(--muted); opacity: .45; }
.cal-summary { margin: .5rem 0 0; }

@media (max-width: 30rem) {
  .habit-row { gap: .5rem; padding: .6rem; }
  .row-actions { gap: .15rem; }
  .icon { width: 1.75rem; height: 1.75rem; }
}
