:root {
  --bg: #FAF6F0;
  --surface: #FFFFFF;
  --surface-2: #F3EEE6;
  --line: #E7E0D5;
  --ink: #1D1B18;
  --ink-2: #6B655C;
  --ink-3: #A39C91;
  --accent: #E0702E;
  --accent-soft: #FBE6D8;
  --good: #3F8F5A;
  --good-soft: #DDEFE2;
  --warn: #C2410C;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .05);

  --c-health: #3F8F5A;
  --c-spiritual: #7A5BC4;
  --c-house: #B7791F;
  --c-family: #2B7FB8;
  --c-marriage: #C8456B;
  --c-personal: #0F8C8C;
  --c-projects: #E0702E;
  --c-yard: #6B8E23;
  --c-other: #8A8378;

  --heat-0: #EEE8DF;
  --heat-1: #F6D2B8;
  --heat-2: #EFA877;
  --heat-3: #E0702E;
  --heat-4: #B5501A;

  --r: 16px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151F;
    --surface: #1A1F2C;
    --surface-2: #232938;
    --line: #2C3344;
    --ink: #F2EEE8;
    --ink-2: #A9A397;
    --ink-3: #6E6A63;
    --accent: #F28A4B;
    --accent-soft: #3A2A22;
    --good: #5DBB7C;
    --good-soft: #1F3328;
    --warn: #F59E6B;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);

    --c-health: #5DBB7C;
    --c-spiritual: #A68BEA;
    --c-house: #E0A84A;
    --c-family: #5AAEE3;
    --c-marriage: #EC7598;
    --c-personal: #3CC2C2;
    --c-projects: #F28A4B;
    --c-yard: #9DBF52;
    --c-other: #9A958C;

    --heat-0: #232938;
    --heat-1: #4A3326;
    --heat-2: #7E4628;
    --heat-3: #C2632C;
    --heat-4: #F28A4B;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--ink); }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 14px) 18px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.top-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--accent); text-transform: uppercase; }
h1 { font-family: var(--round); font-size: 32px; line-height: 1.1; margin: 2px 0 0; font-weight: 700; letter-spacing: -.01em; }
.sync {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2); padding: 6px 10px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); margin-bottom: 4px;
}
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.sync.busy .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync.off .dot { background: var(--ink-3); }
.sync.err .dot { background: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

main { padding: 4px 16px calc(var(--tabs-h) + var(--safe-b) + 28px); }

/* ---------- Day switcher + ring ---------- */
.dayhead {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.ring { position: relative; width: 64px; height: 64px; flex: none; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring circle { stroke-width: 7; }
.ring .track { stroke: var(--surface-2); }
.ring .fill { stroke: var(--accent); transition: stroke-dashoffset .5s cubic-bezier(.2,.8,.2,1); }
.ring.full .fill { stroke: var(--good); }
.ring .num { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--round); font-weight: 700; font-size: 17px; }
.dayhead .meta { flex: 1; min-width: 0; }
.dayhead .big { font-family: var(--round); font-weight: 700; font-size: 18px; }
.dayhead .sub { color: var(--ink-2); font-size: 14px; }
.daynav { display: flex; gap: 6px; }
.daynav button {
  width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2);
  display: grid; place-items: center; color: var(--ink-2);
}
.daynav button:disabled { opacity: .35; }
.daynav svg { width: 18px; height: 18px; }

/* ---------- Sections ---------- */
.section { margin: 22px 0 8px; display: flex; align-items: baseline; justify-content: space-between; }
.section h2 { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); margin: 0; }
.section .aside { font-size: 13px; color: var(--ink-3); }
.section button.aside { color: var(--accent); font-weight: 600; }

.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }

/* All-day habit chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px 10px 10px; border-radius: 999px; background: var(--surface);
  box-shadow: var(--shadow); font-size: 15px; font-weight: 500; min-height: 44px;
  transition: background .2s, color .2s;
}
.chip .box { width: 24px; height: 24px; }
.chip.done { background: var(--good-soft); color: var(--good); }

/* Check box */
.box {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 2px solid var(--line); display: grid; place-items: center;
  transition: background .2s, border-color .2s, transform .15s;
}
.box svg { width: 15px; height: 15px; stroke-width: 3; stroke: #fff; opacity: 0; transform: scale(.5); transition: opacity .15s, transform .2s cubic-bezier(.3,1.6,.5,1); }
.done .box { background: var(--good); border-color: var(--good); }
.done .box svg { opacity: 1; transform: scale(1); }
.pop .box { animation: pop .3s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { 40% { transform: scale(1.25); } }

/* Timeline rows */
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; min-height: 60px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row .time { width: 58px; flex: none; font-family: var(--round); font-size: 14px; font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.row .body { flex: 1; min-width: 0; }
.row .name { font-weight: 550; font-size: 16px; line-height: 1.3; }
.row .note { font-size: 13px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.cat { width: 8px; height: 8px; border-radius: 50%; background: var(--c-other); display: inline-block; flex: none; }
.row.done .name { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.row.past:not(.done) .time { color: var(--warn); }
.row.disabled { opacity: .55; pointer-events: none; }

.now {
  display: flex; align-items: center; gap: 8px; padding: 0 14px; height: 0; position: relative;
}
.now::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); position: absolute; left: 10px; top: -4px; }
.now::after { content: ""; position: absolute; left: 18px; right: 14px; top: -1px; height: 2px; background: var(--accent); opacity: .7; border-radius: 2px; }

/* Due items */
.due-row .when { font-size: 12px; font-weight: 600; color: var(--warn); }
.pill-btn {
  padding: 8px 14px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 600; flex: none;
}

/* Project rows */
.prow { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 13px 14px; border-top: 1px solid var(--line); min-height: 56px; }
.prow:first-child { border-top: 0; }
.prow .body { flex: 1; min-width: 0; }
.prow .name { font-weight: 550; line-height: 1.3; }
.prow .meta { font-size: 13px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.prio { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px; flex: none; }
.prio.High { background: var(--accent-soft); color: var(--accent); }
.prio.Medium { background: var(--surface-2); color: var(--ink-2); }
.prio.Low { color: var(--ink-3); }
.status-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); flex: none; position: relative; }
.status-dot.prog { border-color: var(--accent); background: conic-gradient(var(--accent) 0 50%, transparent 50% 100%); }
.status-dot.ongoing { border-color: var(--c-family); border-style: dashed; }
.status-dot.done { border-color: var(--good); background: var(--good); }
.prow.done .name { color: var(--ink-3); text-decoration: line-through; }
.chev { width: 16px; height: 16px; color: var(--ink-3); flex: none; }

/* Filters */
.search {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 0; background: var(--surface);
  box-shadow: var(--shadow); outline: none; margin-bottom: 10px;
}
.scroller { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
.scroller::-webkit-scrollbar { display: none; }
.fchip {
  flex: none; padding: 8px 13px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow);
  font-size: 14px; font-weight: 500; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center;
}
.fchip.on { background: var(--ink); color: var(--bg); }
.fchip .n { font-size: 12px; opacity: .6; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 10px; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Goals */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border-radius: var(--r); padding: 14px 12px; box-shadow: var(--shadow); }
.stat .v { font-family: var(--round); font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.heat { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; padding: 14px; }
.heat .dow { font-size: 11px; color: var(--ink-3); text-align: center; font-weight: 600; }
.heat .cell { aspect-ratio: 1; border-radius: 6px; background: var(--heat-0); position: relative; }
.heat .cell.nodata { background: transparent; border: 1.5px dashed var(--line); }
.heat .cell.future { background: transparent; }
.heat .cell.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.heat .cell[data-l="1"] { background: var(--heat-1); }
.heat .cell[data-l="2"] { background: var(--heat-2); }
.heat .cell[data-l="3"] { background: var(--heat-3); }
.heat .cell[data-l="4"] { background: var(--heat-4); }
.legend { display: flex; align-items: center; justify-content: flex-end; gap: 4px; font-size: 11px; color: var(--ink-3); padding: 0 14px 12px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.habit { padding: 12px 14px; border-top: 1px solid var(--line); }
.habit:first-child { border-top: 0; }
.habit .hrow { display: flex; align-items: center; gap: 10px; }
.habit .name { flex: 1; min-width: 0; font-weight: 550; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit .pct { font-family: var(--round); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.habit .streak { font-size: 12px; color: var(--accent); font-weight: 600; white-space: nowrap; }
.habit .dots { display: flex; gap: 3px; margin-top: 8px; }
.habit .dots i { flex: 1; height: 6px; border-radius: 3px; background: var(--heat-0); }
.habit .dots i.y { background: var(--good); }
.habit .dots i.n { background: var(--surface-2); }
.habit .dots i.x { background: transparent; }
.habit .sub { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.empty { text-align: center; color: var(--ink-3); padding: 28px 16px; font-size: 15px; }

/* ---------- Tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-around;
  height: calc(var(--tabs-h) + var(--safe-b)); padding: 0 8px var(--safe-b);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--ink-3); padding: 8px 0; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.fab {
  width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; flex: none;
  display: grid; place-items: center; margin: 0 6px; transform: translateY(-10px);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
}
.fab svg { width: 26px; height: 26px; stroke-width: 2.5; }
.fab:active { transform: translateY(-10px) scale(.94); }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 20; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 18px calc(var(--safe-b) + 18px);
  transform: translateY(105%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  max-height: 88vh; overflow-y: auto;
}
.sheet.open { transform: none; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { font-family: var(--round); font-size: 22px; margin: 0 0 12px; }
.sheet label { display: block; font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2); margin: 16px 0 8px; }
.sheet .wrapchips { display: flex; flex-wrap: wrap; gap: 8px; }
.field {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
.field:focus { border-color: var(--accent); }
textarea.field { resize: none; min-height: 52px; }
.btn {
  width: 100%; padding: 15px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 17px; margin-top: 20px;
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--surface-2); color: var(--ink); }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.statusbtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.statusbtns button { padding: 12px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); font-weight: 600; font-size: 15px; }
.statusbtns button.on { background: var(--ink); color: var(--bg); }

/* Setup + toast */
.setup { padding: 30px 6px; }
.setup p { color: var(--ink-2); }
.setup ol { color: var(--ink-2); padding-left: 20px; }
.setup li { margin-bottom: 6px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 18px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.banner { background: var(--accent-soft); color: var(--ink); border-radius: var(--r); padding: 14px; font-size: 15px; margin-bottom: 14px; }
.banner b { color: var(--accent); }
.list-plain { padding: 4px 0; }
.list-plain a, .list-plain button { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 14px; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; text-align: left; }
.list-plain > :first-child { border-top: 0; }
.list-plain .v { color: var(--ink-3); font-size: 14px; }
