/* Blueprint — styles. Colours come from the theme (set in JS as CSS variables). */
:root {
  --bg: #FDF4F7; --surface: #FFFFFF; --text: #0F0F0F; --muted: #6E5A62;
  --accent: #8B3A5A; --soft: #F0D8DF; --line: #EBDCE1; --on-accent: #FFFFFF;
  --good: #2E7D5B; --warn: #B7791F; --bad: #C0392B;
  --font-d: 'Comfortaa', system-ui, sans-serif; --font-b: Verdana, Geneva, sans-serif;
  --r: 18px; --r-sm: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 24px rgba(0,0,0,.05);
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font-b); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, .display { font-family: var(--font-d); font-weight: var(--dw, 700); letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 26px; line-height: 1.15; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hide { display: none !important; }
svg.i { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i.sm { width: 18px; height: 18px; }

/* Layout */
.shell { min-height: 100vh; padding: calc(var(--safe-t) + 14px) 16px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 720px; margin: 0 auto; }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 6px 0 16px; }
.top .actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.icon-btn:active { transform: scale(.96); }
.sync { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); display: inline-block; }
.sync.saving i { background: var(--warn); }
.sync.offline i { background: var(--muted); }
.sync.error i { background: var(--bad); }

.grid { display: grid; gap: 14px; }
.card { background: var(--surface); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-h .link { font-size: 13px; color: var(--accent); font-weight: 600; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 8px; font-weight: 700; }

/* Segmented control */
.seg { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 4px; margin: 0 -2px 14px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--text); }
.chip.on { background: var(--soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.grey { background: color-mix(in srgb, var(--muted) 14%, transparent); color: var(--muted); }
.pill.bad { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

/* Buttons and inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 600; min-height: 44px; }
.btn:active { transform: scale(.98); }
.btn.ghost { background: var(--soft); color: var(--accent); }
.btn.line { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 12px; min-height: 36px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.in { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); min-height: 46px; outline: none; font-size: 16px; }
.in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea.in { min-height: 110px; resize: vertical; line-height: 1.5; }
.in.big { font-size: 28px; font-family: var(--font-d); font-weight: 700; text-align: center; }
.field { margin-bottom: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Progress */
.bar { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.bar.over > i { background: var(--bad); }
.bar.good > i { background: var(--good); }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-family: var(--font-d); font-weight: 700; font-size: 22px; margin-top: 2px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats .stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; }
.big-num { font-family: var(--font-d); font-weight: 700; font-size: 30px; line-height: 1.1; }

/* Lists */
.list { margin: 0; padding: 0; list-style: none; }
.li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .main { flex: 1; min-width: 0; }
.li .title { overflow-wrap: anywhere; }
.li .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 3px; font-size: 12px; color: var(--muted); }
.li.tap { cursor: pointer; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-items: center; flex: none; color: var(--on-accent); }
.check.on { background: var(--accent); }
.check svg { width: 15px; height: 15px; stroke-width: 3; }
.done .title { text-decoration: line-through; color: var(--muted); }
.star { color: var(--line); padding: 4px; }
.star.on { color: var(--accent); }
.star.on svg { fill: currentColor; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amount.pos { color: var(--good); }

/* Water */
.water { display: flex; align-items: center; gap: 16px; }
.ring { width: 92px; height: 92px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: 1.1; }
.ring .lbl b { font-family: var(--font-d); font-size: 22px; }
.water-btns { display: flex; gap: 8px; margin-top: 10px; }
.plus { width: 54px; height: 54px; border-radius: 16px; background: var(--accent); color: var(--on-accent); font-size: 18px; font-weight: 700; display: grid; place-items: center; }
.minus { width: 44px; height: 54px; border-radius: 16px; background: var(--soft); color: var(--accent); font-size: 20px; display: grid; place-items: center; }

/* Mood */
.moods { display: flex; justify-content: space-between; gap: 4px; }
.mood { font-size: 26px; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; filter: grayscale(.85); opacity: .7; transition: .15s; }
.mood.on { background: var(--soft); filter: none; opacity: 1; transform: scale(1.08); }

/* Bars chart */
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; margin: 8px 0; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font-b); }

/* Nav */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 6px 4px calc(6px + var(--safe-b)); }
nav.tabs button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; min-width: 60px; color: var(--muted); font-size: 11px; border-radius: 12px; }
nav.tabs button.on { color: var(--accent); font-weight: 700; }
nav.tabs .brand { display: none; }
.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 21; width: 58px; height: 58px; border-radius: 20px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent); }
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

/* Sheet (bottom drawer) */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; animation: fade .18s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 24px 24px 0 0; max-height: 92vh; overflow-y: auto; padding: 8px 18px calc(22px + var(--safe-b)); animation: up .22s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto; overscroll-behavior: contain; }
.sheet.full { max-height: 100vh; height: 100vh; border-radius: 0; padding-top: calc(var(--safe-t) + 8px); max-width: 720px; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 12px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; position: sticky; top: -8px; background: var(--surface); padding: 8px 0; z-index: 2; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 4px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; text-align: center; }
.quick button .q-ic { width: 42px; height: 42px; border-radius: 14px; background: var(--soft); color: var(--accent); display: grid; place-items: center; font-size: 20px; }

/* Themes */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-tile { border-radius: 14px; border: 2px solid var(--line); padding: 10px; text-align: left; background: var(--bg); }
.theme-tile.on { border-color: var(--accent); }
.theme-tile .sw { display: flex; gap: 4px; margin-bottom: 8px; }
.theme-tile .sw i { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.08); }
.colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.color-in { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; }
.color-in input[type=color] { width: 34px; height: 34px; border: 0; padding: 0; background: none; border-radius: 8px; cursor: pointer; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .box { width: 100%; max-width: 360px; text-align: center; }
.logo { width: 72px; height: 72px; border-radius: 22px; margin: 0 auto 18px; display: block; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Toast and banners */
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 84px); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
.banner { border-radius: var(--r-sm); padding: 12px 14px; background: var(--soft); color: var(--text); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner b { color: var(--accent); }
.demo-flag { background: var(--text); color: var(--bg); text-align: center; font-size: 12px; padding: 6px 10px; border-radius: 10px; margin-bottom: 12px; }
.entry { padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.entry:last-child { border-bottom: 0; }
.entry .snip { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 3px; }
.year { font-family: var(--font-d); font-weight: 700; font-size: 20px; margin: 18px 0 6px; color: var(--accent); }
.tl { border-left: 2px solid var(--soft); margin-left: 6px; padding-left: 16px; }
.tl .ms { position: relative; padding: 8px 0 12px; cursor: pointer; }
.tl .ms::before { content: ''; position: absolute; left: -23px; top: 13px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav b { font-family: var(--font-d); }
.month-nav button { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); }
.tile-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; }
.tile .v { font-family: var(--font-d); font-weight: 700; font-size: 20px; }
.diff.up { color: var(--muted); } .diff.down { color: var(--muted); }

/* Laptop */
@media (min-width: 900px) {
  :root { --nav-h: 0px; }
  .shell { max-width: 1120px; padding: 28px 36px 60px 260px; }
  nav.tabs { top: 0; bottom: 0; right: auto; width: 224px; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 26px 14px; border-top: 0; border-right: 1px solid var(--line); }
  nav.tabs .brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-d); font-weight: 700; font-size: 18px; padding: 0 10px 22px; color: var(--text); }
  nav.tabs .brand img { width: 34px; height: 34px; border-radius: 10px; }
  nav.tabs button { flex-direction: row; gap: 12px; font-size: 15px; padding: 11px 14px; min-width: 0; width: 100%; }
  nav.tabs button.on { background: var(--soft); }
  .fab { bottom: 28px; right: 32px; }
  #toast { bottom: 40px; }
  .grid.cols { display: block; columns: 2; column-gap: 14px; }
  .grid.cols > * { break-inside: avoid; margin-bottom: 14px; display: block; width: 100%; }
  .grid.cols > .stats { display: grid; }
  .grid.cols .span { column-span: all; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 24px; max-height: 86vh; animation: fade .18s; }
  .sheet.full { top: 0; transform: none; height: 100vh; max-height: 100vh; border-radius: 0; right: 0; left: auto; width: 560px; }
  h1 { font-size: 30px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Chip-style radios and checkboxes */
.chip-r { position: relative; display: inline-block; }
.chip-r input { position: absolute; opacity: 0; pointer-events: none; }
.chip-r span { display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; cursor: pointer; user-select: none; }
.chip-r input:checked + span { background: var(--soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-r input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-r .mood-r { font-size: 26px; width: 48px; height: 48px; padding: 0; display: grid; place-items: center; border-radius: 14px; filter: grayscale(.85); opacity: .7; border-color: transparent; background: transparent; }
.chip-r input:checked + .mood-r { filter: none; opacity: 1; background: var(--soft); border-color: var(--accent); }
.link { cursor: pointer; }

.ask { position: fixed; z-index: 71; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 380px); background: var(--surface); border-radius: 20px; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: fade .15s; }
.ask p { font-size: 16px; line-height: 1.45; }
.btn.danger-fill { background: var(--bad); color: #fff; }

/* To-do: the date field shows when "Pick a date…" is chosen */
.when-date { display: none; }
form:has(input[name=When][value=pick]:checked) .when-date { display: block; }
