:root {
  --bg: #F4F4EF;
  --card: #FFFFFF;
  --ink: #16201B;
  --muted: #5B655F;
  --faint: #6B736E;
  --line: #DCDDD3;
  --line2: #E4E4DC;
  --chip: #E7E8E0;
  --green: #1F6B4F;
  --green-soft: #E3F0E8;
  --lime: #D9F36A;
  --blue: #3346A0;
  --blue-soft: #E6EAF7;
  --warn-soft: #FDEBDD;
  --danger: #B4461A;

  /* day status colours */
  --st-done: #1E7A4C;
  --st-done-ink: #FFFFFF;
  --st-partial: #F2A23A;
  --st-partial-ink: #16201B;
  --st-missed: #C8372D;
  --st-missed-ink: #FFFFFF;

  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Bricolage Grotesque', 'DM Sans', system-ui, sans-serif;
  --nav-h: 70px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
body.sheet-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app { max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: var(--bg); position: relative; }
.screen { padding: 24px 20px calc(var(--nav-h) + 32px + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; }
.screen.no-nav { padding-bottom: calc(120px + var(--safe-b)); }

/* ---------- headings & text ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head .titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.eyebrow { font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0.02em; text-transform: uppercase; }
h1.title { margin: 0; font-family: var(--display); font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
h2.section { margin: 0; font-size: 17px; font-weight: 700; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; font-size: 15px; }
p { margin: 0; line-height: 1.45; }
.error { color: var(--danger); font-size: 13px; font-weight: 600; margin-top: -8px; }

/* ---------- buttons ---------- */
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; text-decoration: none; }
.icon-btn.solid { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.icon-btn.plain { border: none; background: transparent; color: var(--muted); }
.icon-btn[disabled] { opacity: 0.35; cursor: default; }
.btn { min-height: 52px; border-radius: 16px; border: none; padding: 0 20px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 16px; font-weight: 700; text-decoration: none; text-align: center; }
.btn.block { width: 100%; }
.btn.primary { background: var(--ink); color: #FFFFFF; }
.btn.lime { background: var(--lime); color: var(--ink); }
.btn.outline { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); font-weight: 600; }
.btn.danger { background: var(--card); color: var(--danger); border: 1.5px solid #E9C3AE; font-weight: 600; }
.btn.danger-solid { background: var(--danger); color: #FFFFFF; }
.btn.sm { min-height: 44px; font-size: 14px; border-radius: 12px; padding: 0 14px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.segmented { display: flex; background: var(--chip); border-radius: 14px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; min-height: 44px; border-radius: 11px; border: none; background: transparent; font-size: 15px; font-weight: 500; color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--card); font-weight: 700; box-shadow: 0 1px 3px rgba(22, 32, 27, 0.15); }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: 20px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.row { flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; }
.card.dashed { background: transparent; border: 1.5px dashed #B9BEB3; }
.card.warn { background: var(--warn-soft); }
.tile-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg); color: var(--muted); }
.tile-icon.green { background: var(--green-soft); color: var(--green); }
.tile-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.list { display: flex; flex-direction: column; gap: 8px; }
.tag { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg); padding: 4px 8px; border-radius: 8px; flex-shrink: 0; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 12px; align-items: center; }

.hero-card { background: var(--ink); color: #F4F4EF; border-radius: 24px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.hero-card h2 { margin: 0; font-family: var(--display); font-size: 22px; font-weight: 700; }
.hero-card p { color: #C9CFC9; font-size: 14px; }
.pill { align-self: flex-start; background: var(--lime); color: var(--ink); font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }

/* ---------- category badge ---------- */
.badge { width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #FFFFFF; font-weight: 700; font-size: 18px; font-family: var(--display); }
.badge.sm { width: 28px; height: 28px; border-radius: 9px; font-size: 13px; }

/* ---------- day status colours (week bar, calendar, legend) ---------- */
.st-done { --c: var(--st-done); --ci: var(--st-done-ink); }
.st-partial { --c: var(--st-partial); --ci: var(--st-partial-ink); }
.st-missed { --c: var(--st-missed); --ci: var(--st-missed-ink); }

.week-wrap { background: var(--card); border-radius: 20px; padding: 12px 8px 10px; display: flex; flex-direction: column; gap: 10px; }
.week { display: flex; justify-content: space-between; gap: 2px; }
.week .day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: none; padding: 2px 0; min-height: 44px; border-radius: 12px; min-width: 0; }
.week .dname { font-size: 12px; font-weight: 500; color: var(--muted); }
.week .dnum { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); }
.week .st-none .dnum { border-color: var(--line2); color: var(--faint); font-weight: 500; }
.week .st-done .dnum, .week .st-partial .dnum, .week .st-missed .dnum { background: var(--c); border-color: var(--c); color: var(--ci); }
.week .is-today .dname { color: var(--ink); font-weight: 700; }
.week .is-today .dnum { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.week .is-sel:not(.is-today) .dnum { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px #8A928D; }

.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; justify-content: center; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--c, var(--card)); border: 1.5px solid var(--c, var(--line)); }

.count-pill { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--chip); color: var(--ink); }
.count-pill.st-done, .count-pill.st-partial { background: var(--c); color: var(--ci); }

/* ---------- today: category rows ---------- */
.cat-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 12px; background: var(--card); border-radius: 18px; min-height: 72px; }
.check { width: 48px; height: 48px; flex-shrink: 0; border-radius: 14px; border: 2px solid #C9CEC6; background: var(--card); color: #FFFFFF; display: flex; align-items: center; justify-content: center; padding: 0; }
.check[aria-pressed="true"] { background: var(--st-done); border-color: var(--st-done); }
.check.static { cursor: default; border-style: dashed; }
.cat-open { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: none; padding: 6px 8px 6px 2px; text-align: left; border-radius: 12px; color: var(--muted); min-height: 52px; }
.cat-open .name, .cat-card .name { font-size: 17px; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.cat-row.is-done .name { text-decoration: line-through; color: var(--muted); }
.cat-open .detail, .cat-card .detail { font-size: 13px; color: var(--muted); }
.done-card { background: var(--green-soft); }

/* ---------- categories list ---------- */
.cat-card { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; background: var(--card); border-radius: 18px; text-decoration: none; color: var(--muted); min-height: 72px; }

/* ---------- category editor ---------- */
.back-head { display: flex; align-items: center; gap: 12px; }
.back-head h1 { margin: 0; font-family: var(--display); font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; margin-bottom: -8px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.input, textarea.input { min-height: 52px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); font-size: 16px; width: 100%; }
textarea.input { padding: 12px 14px; resize: vertical; min-height: 110px; line-height: 1.45; }
.input:focus { border-color: var(--ink); outline: none; }
.input[aria-invalid="true"] { border-color: var(--danger); }
fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: none; color: #FFFFFF; display: flex; align-items: center; justify-content: center; padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--ink); }
.days7 { display: flex; justify-content: space-between; gap: 4px; }
.days7 button { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); font-size: 14px; font-weight: 700; padding: 0; flex-shrink: 0; }
.days7 button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; }
.ex-item { display: flex; align-items: flex-start; gap: 8px; background: var(--card); border-radius: 14px; padding: 12px 6px 12px 14px; }
.sheet .ex-item { padding-right: 14px; }
.ex-item .name { font-size: 15px; font-weight: 700; }
.ex-item .desc { font-size: 14px; color: var(--muted); line-height: 1.45; white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ex-item .desc.full { display: block; -webkit-line-clamp: unset; overflow: visible; }
.day-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.day-actions > * { flex: 1 1 140px; }
.form-bar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; padding: 12px 20px calc(16px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line2); display: flex; gap: 10px; z-index: 20; }
.form-bar .btn { flex: 1; }

/* ---------- progress ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.stat .num { font-family: var(--display); font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lab { font-size: 12px; color: var(--muted); }
.st-done-text { color: var(--st-done); }
.st-partial-text { color: #A8620C; }
.st-missed-text { color: var(--st-missed); }
.month-nav { display: flex; gap: 6px; }
.month-nav .icon-btn { width: 40px; height: 40px; border: none; background: var(--bg); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; text-align: center; }
.cal .h { font-size: 11px; font-weight: 600; color: var(--muted); }
.cal .day, .cal .blank { aspect-ratio: 1; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); padding: 0; min-width: 0; max-width: 100%; }
.cal .blank { border: none; background: transparent; }
.cal .st-none { border-color: var(--line2); color: var(--faint); font-weight: 400; }
.cal .st-done, .cal .st-partial, .cal .st-missed { background: var(--c); border-color: var(--c); color: var(--ci); }
.cal .is-today { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ink); }
.rate { display: flex; flex-direction: column; gap: 6px; }
.rate-top { display: flex; align-items: center; gap: 10px; }
.rate-top .name { flex: 1; font-weight: 700; font-size: 15px; min-width: 0; }
.meter { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--st-done); border-radius: 4px; }

/* ---------- bottom nav ---------- */
.nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; display: flex; justify-content: space-around; padding: 6px 8px calc(10px + var(--safe-b)); background: var(--card); border-top: 1px solid var(--line2); z-index: 20; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 88px; min-height: 52px; text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500; border-radius: 12px; }
.nav a[aria-current="page"] { color: var(--green); font-weight: 700; }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(22, 32, 27, 0.45); z-index: 50; }
.sheet { position: fixed; z-index: 51; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 480px; max-height: 88vh; max-height: 88dvh; overflow-y: auto; background: var(--bg); color: var(--ink); border-radius: 24px 24px 0 0; padding: 10px 20px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; animation: up 0.18s ease-out; }
.sheet .handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); align-self: center; }
.sheet h2 { margin: 0; font-family: var(--display); font-size: 22px; font-weight: 700; flex: 1; min-width: 0; }
.sheet .sheet-head { display: flex; align-items: center; gap: 12px; }
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0.4; } to { transform: translate(-50%, 0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 28px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--ink); color: #FFFFFF; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 60; max-width: calc(100% - 40px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- welcome ---------- */
.welcome { padding: 48px 24px calc(32px + var(--safe-b)); display: flex; flex-direction: column; gap: 22px; min-height: 100vh; min-height: 100dvh; }
.welcome .logo { width: 72px; height: 72px; border-radius: 22px; }
.welcome h1 { margin: 0; font-family: var(--display); font-size: 36px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.welcome .lead { font-size: 16px; color: var(--muted); }
.welcome ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.welcome li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.welcome li svg { flex-shrink: 0; color: var(--green); margin-top: 1px; }
.welcome .grow { flex: 1; }
.welcome .actions { display: flex; flex-direction: column; gap: 10px; }
