/* Habits: tokens first, then layout. Activity colours are the first three categorical slots of the
   dataviz reference palette (blue, orange, aqua), which pass all-pairs CVD checks in light and dark. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --empty: #ebeae4;
  --focus: #2a78d6;
  --primary: #0b0b0b;
  --primary-ink: #ffffff;
  --danger: #d03b3b;
  --warn-bg: #fdf0d2;
  --warn-ink: #7a5200;
  --cold-bg: #fbe2e2;
  --cold-ink: #8f2323;
  --error-bg: #fbe2e2;
  --meditation: #2a78d6;
  --exercise: #eb6834;
  --daygame: #1baf7a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --line: #2c2c2a;
    --line-strong: #383835;
    --empty: #262624;
    --focus: #3987e5;
    --primary: #ffffff;
    --primary-ink: #0b0b0b;
    --danger: #e66767;
    --warn-bg: #3a2c05;
    --warn-ink: #fab219;
    --cold-bg: #3b1616;
    --cold-ink: #f19a9a;
    --error-bg: #3b1616;
    --meditation: #3987e5;
    --exercise: #d95926;
    --daygame: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --line-strong: #383835; --empty: #262624; --focus: #3987e5;
  --primary: #ffffff; --primary-ink: #0b0b0b; --danger: #e66767;
  --warn-bg: #3a2c05; --warn-ink: #fab219; --cold-bg: #3b1616; --cold-ink: #f19a9a; --error-bg: #3b1616;
  --meditation: #3987e5; --exercise: #d95926; --daygame: #199e70;
}

.act-meditation { --act: var(--meditation); }
.act-exercise { --act: var(--exercise); }
.act-daygame { --act: var(--daygame); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: .85rem; }
.center { text-align: center; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Nav */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--page);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.nav { max-width: 760px; margin: 0 auto; display: flex; gap: 4px; padding: 8px 12px; align-items: center; }
.nav a { text-decoration: none; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); }
.nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.nav .brand { font-weight: 700; color: var(--ink); margin-right: auto; }
.foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .9rem; gap: 12px; flex-wrap: wrap; }
.inline { display: inline; margin: 0; }
.linkish { background: none; border: 0; color: inherit; text-decoration: underline; font: inherit; cursor: pointer; padding: 8px 0; }

/* Cards */
.page-title { margin: 4px 0 16px; display: flex; align-items: center; gap: 8px; }
.cards { display: grid; gap: 12px; }
@media (min-width: 700px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--act); flex: none; display: inline-block; }
.since { margin: 10px 0 6px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.since-main { font-size: 1.5rem; font-weight: 650; }
.pill { font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.cold { background: var(--cold-bg); color: var(--cold-ink); }
.counts { display: flex; gap: 20px; margin: 0 0 10px; flex-wrap: wrap; }
.counts div { min-width: 0; }
.counts dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.counts dd { margin: 0; font-size: 1.15rem; font-weight: 600; }
.counts .of { color: var(--muted); font-weight: 400; font-size: .9rem; }
.last-session { margin: 0 0 10px; color: var(--ink-2); font-size: .95rem; }
.note-preview { display: block; color: var(--muted); font-style: italic; margin-top: 2px; }
.mini { margin-top: 4px; max-width: 300px; }
.mini-caption { margin: 6px 0 0; font-size: .75rem; color: var(--muted); }

/* Heatmaps */
.heatmap { display: block; width: 100%; height: auto; }
.heatmap rect, .hm-legend rect { fill: var(--empty); }
.heatmap .lv1, .hm-legend .lv1 { fill: color-mix(in oklab, var(--act) 30%, var(--empty)); }
.heatmap .lv2, .hm-legend .lv2 { fill: color-mix(in oklab, var(--act) 55%, var(--empty)); }
.heatmap .lv3, .hm-legend .lv3 { fill: color-mix(in oklab, var(--act) 78%, var(--empty)); }
.heatmap .lv4, .hm-legend .lv4 { fill: var(--act); }
.heatmap .fut { fill: transparent; stroke: var(--line); stroke-width: 1; }
.heatmap a:hover rect { stroke: var(--ink); stroke-width: 1.5; }
.hm-label { font-size: 9px; fill: var(--muted); }
.hscroll { overflow-x: auto; margin: 10px 0 6px; padding-bottom: 10px; -webkit-overflow-scrolling: touch; }
.hscroll .heatmap { min-width: 620px; max-width: 900px; }
.hm-legend { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.hm-legend svg { width: 64px; height: 11px; }
.hm-legend svg.one { width: 11px; }
.year-card { margin-bottom: 12px; }

/* Month grid */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; }
.pager h1 { text-align: center; flex: 1; }
.legend { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .9rem; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { font-size: .75rem; color: var(--muted); text-align: center; padding-bottom: 2px; }
.mday {
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 58px; padding: 5px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none;
}
.mday.out { opacity: .45; }
.mday.fut { background: transparent; }
.mday.today { box-shadow: inset 0 0 0 2px var(--ink); }
.mday .num { font-size: .85rem; font-weight: 600; }
.dots { display: grid; grid-template-columns: repeat(2, 10px); gap: 3px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 1px var(--line); display: inline-block; }
.dot.on { background: var(--act); box-shadow: none; }
@media (min-width: 560px) { .dots { grid-template-columns: repeat(4, 10px); } .mday { min-height: 72px; } }

/* Day view */
.entries { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.entry { border-left: 4px solid var(--act); }
.metrics { margin: 6px 0 0; font-weight: 600; }
.note { margin: 6px 0 0; white-space: pre-wrap; color: var(--ink-2); overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.section-title { margin: 16px 0 10px; font-size: 1rem; color: var(--ink-2); }
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; min-width: 44px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { visibility: hidden; }
.btn.add { min-height: 40px; }
.stack { display: grid; gap: 14px; }
label { display: grid; gap: 4px; font-size: .9rem; font-weight: 600; color: var(--ink-2); }
input, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--ink); background: var(--page);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { resize: vertical; line-height: 1.45; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
.actions { display: flex; gap: 10px; }
.actions .btn.primary { flex: 1; }
.quick-dates, .chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips { margin: 0 0 12px; }
.chip {
  font: inherit; font-size: .85rem; padding: 6px 12px; min-height: 34px;
  border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); text-decoration: none; cursor: pointer;
  display: inline-flex; align-items: center;
}
.chip[aria-current="page"] { border-color: var(--act); box-shadow: inset 0 0 0 1px var(--act); color: var(--ink); font-weight: 600; }
.delete-form { margin-top: 20px; text-align: center; }
.error { background: var(--error-bg); color: var(--ink); border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; }
.error ul { margin: 0; padding-left: 18px; }
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { margin-bottom: 16px; }

/* Activity history */
.act-link { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: inherit; }
.act-link:hover { text-decoration: underline; }
.chev { color: var(--muted); font-weight: 400; }
.page-head { margin: 4px 0 6px; }
.page-head h1 { display: flex; align-items: center; gap: 8px; }
.history-sub { margin: 0 0 12px; font-size: .9rem; }
.month-label { font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 6px; }
.history { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.history li + li { border-top: 1px solid var(--line); }
.hrow {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px;
  padding: 12px 16px; text-decoration: none; color: inherit; border-left: 4px solid var(--act);
}
.hrow:hover { background: var(--page); }
.hdate { font-weight: 600; }
.hmetric { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.hnote { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { display: flex; gap: 8px; margin: 16px 0 4px; }
.search input { flex: 1; }
.filter-line { margin: 8px 0 0; font-size: .9rem; color: var(--ink-2); }
.hrow.current { background: var(--page); }
.types .hrow { padding-top: 10px; padding-bottom: 10px; }
