/* Same palette as the iOS app (Shared.swift), light and dark. */
:root {
  --paper: #F4F0E8; --card: #FDFBF7; --cell: #F1EDE5; --ink: #2A2723; --muted: #958E83;
  --green: #2F5D50; --tick: #2E7D5B; --line: #5B4FC4; --zone-green: #DCEFD9; --zone-red: #F8DEDC;
  --quote-top: #E9ECF6; --quote-bottom: #DDE2F2; --orange: #E8890C;
  --grouped: #F2F2F7; --group-cell: #FFFFFF; --sep: rgba(60, 60, 67, .18); --label2: rgba(60, 60, 67, .6);
  --danger: #D93A2F; --accent: #2F5D50;
  --serif: ui-serif, "New York", Georgia, serif;
  --sans: -apple-system, system-ui, "Helvetica Neue", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1A1917; --card: #252421; --cell: #302E2A; --ink: #EEE9E0; --muted: #8E887E;
    --green: #5FA38B; --tick: #4FB286; --line: #9A90F2; --zone-green: #21372A; --zone-red: #3D2524;
    --quote-top: #2A2D3A; --quote-bottom: #232631;
    --grouped: #000; --group-cell: #1C1C1E; --sep: rgba(84, 84, 88, .6); --label2: rgba(235, 235, 245, .6);
    --danger: #FF453A; --accent: #5FA38B; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #1A1917; --card: #252421; --cell: #302E2A; --ink: #EEE9E0; --muted: #8E887E;
  --green: #5FA38B; --tick: #4FB286; --line: #9A90F2; --zone-green: #21372A; --zone-red: #3D2524;
  --quote-top: #2A2D3A; --quote-bottom: #232631;
  --grouped: #000; --group-cell: #1C1C1E; --sep: rgba(84, 84, 88, .6); --label2: rgba(235, 235, 245, .6);
  --danger: #FF453A; --accent: #5FA38B; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink); font: 17px/1.3 var(--sans);
  display: flex; flex-direction: column; overflow: hidden; overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .3; cursor: default; }
input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 14px; height: 14px; stroke-width: 2.6; }
.i.xs { width: 11px; height: 11px; }
.i.lg { width: 40px; height: 40px; stroke-width: 1.6; }

/* MARK: Top bar */
.topbar {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: calc(env(safe-area-inset-top) + 8px) max(20px, env(safe-area-inset-right)) 22px max(20px, env(safe-area-inset-left));
}
.title { flex: 1; min-width: 0; position: relative; }
.month-pick { position: relative; display: flex; align-items: baseline; gap: 6px; white-space: nowrap; overflow: hidden; }
.month-pick select { position: absolute; inset: 0; opacity: 0; width: 100%; font-size: 16px; }
.month-name { font: 600 clamp(22px, 7.6vw, 34px)/1.1 var(--serif); }
.year { font: clamp(15px, 5vw, 20px) var(--serif); color: var(--muted); }
.side { position: absolute; left: 0; bottom: -17px; display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.dot { width: 14px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--muted) 35%, transparent); }
.topbar:not(.on-tracker) .dot.a, .topbar.on-tracker .dot.b { background: var(--green); }
.circle {
  width: 40px; height: 40px; border-radius: 50%; background: var(--card); display: grid; place-items: center; flex: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}

/* MARK: Pager */
.pager {
  flex: 1; min-height: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%; width: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  overflow-y: auto; overscroll-behavior-y: contain; position: relative;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.stack { display: flex; flex-direction: column; gap: 14px; max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: 20px; padding: 12px; box-shadow: 0 2px 8px rgba(0, 0, 0, .04); }
.h2 { font: 600 22px var(--serif); }
.h3 { font: 600 20px var(--serif); margin-bottom: 8px; }

/* MARK: Journal */
.quote {
  position: relative; min-height: 120px; border-radius: 20px; overflow: hidden; padding: 16px;
  background: linear-gradient(var(--quote-top), var(--quote-bottom));
}
.mountains { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 70px; }
.mountains .sun { fill: rgba(255, 165, 0, .25); }
.mountains .m1 { fill: color-mix(in srgb, var(--line) 18%, transparent); }
.mountains .m2 { fill: color-mix(in srgb, var(--line) 22%, transparent); }
.quote-label { font-size: 11px; font-weight: 600; letter-spacing: 1.5px; color: var(--muted); margin-bottom: 8px; position: relative; }
.quote-label .q { font: 16px var(--serif); }
.quote-text { font: 20px/1.3 var(--serif); margin: 0; max-width: 240px; position: relative; }
.quote-text.placeholder { color: var(--muted); }
.quote-edit {
  position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, var(--card) 80%, transparent); color: var(--muted);
}
.quote-edit .i { width: 16px; height: 16px; }

.rows { padding: 4px 12px; }
.row { display: flex; align-items: center; gap: 14px; padding: 4px 0; min-height: 50px; position: relative; cursor: text; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 56px; right: 0; border-top: .5px solid var(--sep); }
.daybox {
  width: 42px; height: 42px; flex: none; border-radius: 12px; background: var(--cell);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
.daybox b { font-size: 17px; font-weight: 600; }
.daybox small { font-size: 11px; }
.row.today .daybox { background: var(--green); color: #fff; }
.row.future { opacity: .55; }
.entry { flex: 1; min-width: 0; font: 17px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry.empty { font-style: italic; color: color-mix(in srgb, var(--muted) 70%, transparent); }
.entry-input {
  flex: 1; min-width: 0; font: 17px/1.3 var(--serif); border: 0; background: none; resize: none; padding: 0; outline: none;
  caret-color: var(--green); overflow: hidden;
}
.row.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 40% { background: color-mix(in srgb, var(--green) 14%, transparent); } }

/* MARK: Tracker */
.stat-head { position: relative; display: inline-flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stat-head select, .capsule select { position: absolute; inset: 0; opacity: 0; font-size: 16px; width: 100%; }
.stat-icon { font-size: 20px; }
.chart { width: 100%; height: auto; display: block; }
.chart .z-red { fill: var(--zone-red); }
.chart .z-green { fill: var(--zone-green); }
.chart .grid { stroke: var(--sep); stroke-width: .6; stroke-dasharray: 2 3; }
.chart .ylab { font: 10.5px var(--sans); fill: var(--muted); text-anchor: end; }
.chart .xlab { font: 10.5px var(--sans); fill: var(--muted); text-anchor: middle; }
.chart .line { fill: none; stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.chart .pt { fill: var(--line); }

.stat-input { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.grow { flex: 1; }
.capsule {
  position: relative; display: inline-flex; align-items: center; gap: 4px; height: 40px; padding: 0 12px;
  border-radius: 20px; background: var(--cell); font-weight: 500; white-space: nowrap;
}
.round { width: 40px; height: 40px; border-radius: 50%; background: var(--cell); display: grid; place-items: center; }
.stat-value { min-width: 64px; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--line); text-align: center; }
.stat-value.empty { color: var(--muted); }
.clear { width: 26px; height: 26px; border-radius: 50%; background: var(--muted); color: var(--card); display: grid; place-items: center; }
.clear .i { width: 14px; height: 14px; stroke-width: 3; }
.clear.hidden { visibility: hidden; }

.ins-row { display: flex; align-items: center; gap: 8px; font-size: 15px; padding: 3px 0; }
.ins-icon { width: 24px; text-align: center; }
.ins-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ins-val { margin-left: auto; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.segmented { display: flex; background: color-mix(in srgb, var(--muted) 18%, transparent); border-radius: 9px; padding: 2px; }
.segmented button { flex: 1; padding: 6px 0; font-size: 14px; font-weight: 500; border-radius: 7px; }
.segmented button.on { background: var(--card); box-shadow: 0 2px 6px rgba(0, 0, 0, .12); font-weight: 600; }

.habits .h2, .checklist .h2 { margin-bottom: 8px; }
.ghead, .grow-row { display: grid; align-items: center; padding: 0 4px; }
.hcol { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 1px 6px; min-width: 0; }
.hicon { font-size: 20px; }
.hname { font-size: 11px; text-align: center; line-height: 1.15; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badge { display: inline-flex; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; }
.badge.met { color: var(--tick); }
.badge.behind { color: var(--orange); }
.grow-row { border-radius: 8px; }
.grow-row.today { background: color-mix(in srgb, var(--green) 8%, transparent); }
.gday { font-size: 15px; white-space: nowrap; }
.gday small { color: var(--muted); font-size: 11px; }
.grow-row.today .gday b { font-weight: 700; }
.tick { height: 34px; display: grid; place-items: center; }
.tick::before { content: ""; grid-area: 1 / 1; width: 22px; height: 22px; border-radius: 50%; background: var(--cell); }
.tick.done::before { background: var(--tick); }
.tick .i { grid-area: 1 / 1; width: 14px; height: 14px; color: #fff; stroke-width: 3; }

.crow { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 4px; border-radius: 8px; text-align: left; font-size: 15px; }
.crow.today { background: color-mix(in srgb, var(--green) 8%, transparent); }
.crow.today .cday { font-weight: 700; }
.cday { width: 26px; flex: none; }
.ctext { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctext.muted { color: color-mix(in srgb, var(--muted) 50%, transparent); }
.ccount { font-size: 12px; font-weight: 600; color: var(--muted); }
.ccount.all { color: var(--tick); }

/* MARK: Sheets (iOS-style grouped lists) */
.sheet-wrap { position: fixed; inset: 0; z-index: 10; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .25); opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; top: calc(env(safe-area-inset-top) + 12px);
  max-width: 640px; margin: 0 auto; background: var(--grouped); border-radius: 12px 12px 0 0;
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .8, .2, 1);
}
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px 8px; gap: 8px; }
.sheet-bar h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
.bar-r { text-align: right; }
.bar-btn { color: var(--accent); display: inline-flex; align-items: center; gap: 2px; }
.bar-btn.bold { font-weight: 600; }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }

.group-title { font-size: 13px; text-transform: uppercase; color: var(--label2); margin: 22px 16px 7px; }
.group { background: var(--group-cell); border-radius: 10px; overflow: hidden; }
.group-footer { font-size: 13px; color: var(--label2); margin: 7px 16px 0; line-height: 1.35; }
.group-footer.install { margin-top: 24px; text-align: center; }
.cell { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 16px; width: 100%; text-align: left; position: relative; }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.cell > span:first-child { flex: 1; }

.switch { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: color-mix(in srgb, var(--muted) 35%, transparent); position: relative; transition: background .2s; flex: none; margin: 0; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.select-wrap { position: relative; display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.select-wrap select { appearance: none; -webkit-appearance: none; border: 0; background: none; color: var(--accent); text-align: right; font-size: 17px; padding-right: 0; }

.field input { flex: 2; border: 0; background: none; text-align: right; outline: none; min-width: 0; color: var(--label2); }
.field input:focus { color: inherit; }
.emoji-input { font-size: 22px; }
.stepper .steps { display: inline-flex; background: color-mix(in srgb, var(--muted) 18%, transparent); border-radius: 8px; }
.stepper .steps button { width: 47px; height: 32px; display: grid; place-items: center; }
.stepper .steps button + button { border-left: .5px solid var(--sep); }
.stepper .steps .i { width: 16px; height: 16px; }

.list-row { padding: 0 8px 0 16px; }
.list-main { flex: 1; display: flex; align-items: center; gap: 10px; min-height: 44px; min-width: 0; text-align: left; }
.li-icon { width: 26px; text-align: center; font-size: 19px; }
.li-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail { color: var(--label2); font-size: 15px; }
.chev-r { color: var(--label2); font-size: 22px; padding: 0 6px; }
.mini { width: 32px; height: 32px; display: grid; place-items: center; color: var(--label2); flex: none; }
.mini .i { width: 17px; height: 17px; }
.mini.danger { color: #fff; }
.mini.danger::before { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); }
.mini.danger .i { position: relative; width: 14px; height: 14px; stroke-width: 3; }
.add-row { color: var(--accent); gap: 8px; }
.add-row.danger { color: var(--danger); justify-content: center; }
.group + .group { margin-top: 22px; }

.todo { padding-left: 12px; }
.todo-check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; flex: none; }
.todo-check.done { background: var(--tick); border-color: var(--tick); }
.todo-check .i { width: 15px; height: 15px; color: #fff; stroke-width: 3; }
.todo-text { flex: 1; min-width: 0; border: 0; background: none; outline: none; }
.todo-text.struck { text-decoration: line-through; color: var(--label2); }
.plus-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none !important; }
.plus-dot .i { width: 15px; height: 15px; stroke-width: 3; }
.todo.add input { flex: 1; border: 0; background: none; outline: none; }

.search-box { display: flex; align-items: center; gap: 6px; background: color-mix(in srgb, var(--muted) 16%, transparent); border-radius: 10px; padding: 0 10px; margin-top: 4px; }
.search-box input { flex: 1; border: 0; background: none; outline: none; height: 38px; font-size: 17px; }
.tip, .result { flex-direction: column; align-items: flex-start; gap: 2px; }
.tip code { font: 17px ui-monospace, Menlo, monospace; }
.tip small, .rdetails { color: var(--label2); font-size: 12px; }
.rdate { font-size: 12px; font-weight: 600; color: var(--muted); }
.rtext { font: 17px var(--serif); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: rgba(255, 204, 0, .35); color: inherit; border-radius: 2px; }
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; margin-top: 70px; color: var(--label2); }
.empty-state b { color: var(--ink); font-size: 20px; }

/* MARK: Dialogs */
.dialog-wrap { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(0, 0, 0, .3); padding: 24px; }
.dialog { width: 270px; background: color-mix(in srgb, var(--group-cell) 94%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-radius: 14px; text-align: center; overflow: hidden; }
.dialog h3 { margin: 18px 16px 2px; font-size: 17px; }
.dialog p { margin: 4px 16px 0; font-size: 13px; line-height: 1.35; }
.dialog input { display: block; width: calc(100% - 32px); margin: 10px 16px 0; padding: 7px 8px; border: .5px solid var(--sep); border-radius: 7px; background: var(--group-cell); font-size: 15px; outline: none; }
.dialog input + input { margin-top: -1px; }
.dialog-btns { display: flex; margin-top: 18px; border-top: .5px solid var(--sep); }
.dialog-btns button { flex: 1; height: 44px; color: var(--accent); font-size: 17px; }
.dialog-btns button + button { border-left: .5px solid var(--sep); }
.dialog-btns .default { font-weight: 600; }
.dialog-btns .destructive { color: var(--danger); }

/* MARK: Lock */
.lock { position: fixed; inset: 0; z-index: 30; background: var(--paper); display: grid; place-items: center; padding: 24px; }
.lock-inner { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 280px; }
.lock-icon { width: 44px; height: 44px; color: var(--green); }
.lock h1 { font: 600 24px var(--serif); margin: 0; }
.lock input { width: 100%; height: 44px; border-radius: 10px; border: 0; background: var(--card); text-align: center; font-size: 18px; outline: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .06); }
.btn-primary { background: var(--green); color: #fff; font-weight: 600; padding: 10px 28px; border-radius: 22px; }
#lock-error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: 15px; }
