:root {
  --bg: #f6f5f2; --card: #ffffff; --ink: #1d1f24; --mute: #5f6570; --line: #ecebe8; --soft: #f0efec;
  --accent: #d93a3f; --accent-soft: rgba(217, 58, 63, .12); --accent-ink: #ffffff; --choice: #1e48f0; --choice-soft: rgba(30, 72, 240, .13); --choice-ink: #ffffff; --done: #16a06d; --done-ink: #ffffff;
  --good: #2f9e6e; --warn: #d9962b; --bad: #d9534a;
  --shadow: 0 1px 2px rgba(20, 22, 30, .04), 0 4px 14px rgba(20, 22, 30, .05);
  --r: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111215; --card: #1a1b20; --ink: #eceef2; --mute: #8e94a0; --line: #272930; --soft: #22242a;
    --accent: #ff6b70; --accent-soft: rgba(255, 107, 112, .16); --accent-ink: #1a0a0b; --choice: #6b8cff; --choice-soft: rgba(107, 140, 255, .16); --choice-ink: #08121d; --done: #3ccf8e; --done-ink: #04140c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
/* App shell: a full-screen column. Only #main scrolls; the tab bar is a normal child at the bottom, so it can never float. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; padding-top: env(safe-area-inset-top); }
.page { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.01em; margin: 0; }
button { font: inherit; color: inherit; }
.ic { display: block; flex: none; }
.ink { color: var(--ink); }

/* top bar + page header */
.topbar { display: flex; align-items: center; gap: 8px; padding: 8px 0 0; min-height: 44px; }
.brand { font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.sync { flex: 1; display: flex; align-items: center; gap: 6px; color: var(--mute); font-size: 12px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mute); }
.dot.ok { background: var(--good); } .dot.busy { background: var(--warn); } .dot.bad { background: var(--bad); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 4px; gap: 8px; }
.top .date { text-align: center; flex: 1; }
.top .date small { display: block; color: var(--mute); font-size: 13px; margin-top: 1px; }
.sp { width: 44px; }
.icon-btn { background: var(--card); border: 0; box-shadow: var(--shadow); border-radius: 14px; width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; color: var(--ink); padding: 0; }
.icon-btn.flat { background: transparent; box-shadow: none; color: var(--mute); }
.icon-btn.flat.on { color: var(--accent); }
.center { text-align: center; margin: 2px 0 4px; }
.link { background: none; border: 0; color: var(--accent); font-size: 14px; font-weight: 600; padding: 6px 4px; cursor: pointer; }
.summary { text-align: center; color: var(--mute); font-size: 13px; margin: 6px 0 2px; }

/* sections */
.sec, h2 { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 8px; min-height: 32px; }
.sec h2 { margin: 0; min-height: 0; }
h2 { font-size: 15px; font-weight: 650; color: var(--ink); text-transform: none; letter-spacing: 0; }
.add { display: inline-flex; align-items: center; gap: 4px; border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 7px 14px 7px 10px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 34px; }

.card { background: var(--card); box-shadow: var(--shadow); border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.mute { color: var(--mute); font-size: 14px; }
.small { font-size: 13px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.stat { background: var(--card); box-shadow: var(--shadow); border-radius: 16px; padding: 10px 12px; }
.stat label { display: block; font-size: 12px; color: var(--mute); }
.stat input { width: 100%; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 22px; font-weight: 650; padding: 2px 0; outline: none; min-height: 32px; }
.stat input::placeholder { color: var(--mute); opacity: .45; font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 0; background: var(--soft); border-radius: 999px; padding: 10px 14px; font-size: 14px; cursor: pointer; min-height: 40px; }
.chip.on { background: var(--accent); color: var(--accent-ink); }
.bar { height: 6px; background: var(--soft); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; width: 100%; height: 100%; background: var(--accent); border-radius: 99px; transform-origin: left center; transition: transform .25s; }
.bar > i.done { background: var(--good); }
.bar > i.over { background: var(--bad); }

.fold { width: 100%; display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; min-height: 44px; }
.chev { color: var(--mute); transition: transform .2s; }
.chev.up { transform: rotate(180deg); }

.item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 56px; }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 600; }
.item .emoji { font-size: 22px; width: 30px; text-align: center; }
.empty { color: var(--mute); text-align: center; padding: 10px 0; font-size: 14px; line-height: 1.8; }
.check { width: 44px; height: 44px; margin: -8px -8px -8px -10px; border: 0; background: none; display: grid; place-items: center; cursor: pointer; padding: 0; flex: none; }
.check span { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; color: #fff; }
.check.on span { background: var(--good); border-color: var(--good); }
.done-text { text-decoration: line-through; color: var(--mute); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; margin-left: 6px; }
.tag.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 14px; padding: 12px 18px; font-weight: 600; cursor: pointer; min-height: 46px; }
.btn.ghost { background: var(--soft); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1.5px var(--bad); }
.btn.sm { padding: 7px 14px; font-size: 14px; border-radius: 12px; min-height: 36px; }
.btn:disabled { opacity: .55; }

/* bottom bar with docked + */
.tabs { position: relative; flex: none; background: color-mix(in srgb, var(--card) 90%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); box-shadow: 0 -1px 0 var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabs-in { display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: end; width: 100%; max-width: 640px; }
.tabs button { background: none; border: 0; padding: 9px 0 8px; color: var(--mute); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 56px; }
.tabs button em { font-style: normal; font-size: 11px; }
.tabs button.on { color: var(--accent); }
.tabs .plus { width: 56px; height: 56px; min-height: 0; margin: 0 auto 10px; padding: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); justify-content: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); transform: translateY(-10px); }

.tabs, .tabs button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tabs .plus { touch-action: none; }

/* hold-to-fan quick add */
#fan { position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .28); pointer-events: none; -webkit-user-select: none; user-select: none; }
.fan-item { position: fixed; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: var(--card); box-shadow: 0 6px 18px rgba(0, 0, 0, .28); display: grid; place-items: center; font-size: 26px; animation: pop .18s ease-out both; transition: transform .1s, background .1s; }
.fan-item.on { transform: scale(1.3); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent), 0 8px 22px rgba(0, 0, 0, .3); }
@keyframes pop { from { opacity: 0; transform: translateY(30px) scale(.4); } to { opacity: 1; transform: none; } }

/* scroll wheel (reps) */
.wheel-wrap { position: relative; height: 220px; background: var(--soft); border-radius: 16px; overflow: hidden; }
.wheel { height: 100%; overflow-y: auto; scroll-snap-type: y mandatory; padding: 88px 0; overscroll-behavior: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.wheel::-webkit-scrollbar { display: none; }
.wheel > div { height: 44px; line-height: 44px; text-align: center; font-size: 22px; color: var(--mute); scroll-snap-align: center; cursor: pointer; transition: color .1s, font-size .1s; }
.wheel > div.sel { color: var(--ink); font-size: 30px; font-weight: 700; }
.wheel-band { position: absolute; left: 12px; right: 12px; top: 88px; height: 44px; border-radius: 12px; background: color-mix(in srgb, var(--accent) 14%, transparent); pointer-events: none; }
.btns { display: flex; gap: 6px; }
.reps-total { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 6px 0 4px; font-size: 15px; }
.rep b { font-size: 20px; margin-right: 2px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
.set { border: 0; background: var(--soft); border-radius: 12px; padding: 8px 12px; font-size: 14px; cursor: pointer; min-height: 40px; }
.set small { color: var(--mute); margin-left: 8px; font-size: 12px; }

[hidden] { display: none !important; }

/* standards scorecard */
.score { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 4px; padding: 14px 8px 10px; }
.tile { background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; cursor: pointer; color: var(--ink); }
.tile svg { overflow: visible; }
.tile .trk { fill: none; stroke: var(--soft); stroke-width: 6; }
.tile .arc { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; transition: stroke-dasharray .4s ease; }
.tile.met .arc { stroke: var(--good); }
.tile .rv { fill: var(--ink); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .tl { font-size: 13px; font-weight: 600; margin-top: 2px; }
.tile .ts { font-size: 12px; color: var(--mute); }
.pill.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }

/* food */
.foodseg { margin: 4px 0 14px; }
.mthumb { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; background: var(--soft); flex: none; }
.kc { text-align: right; font-size: 13px; color: var(--mute); }
.kc b { color: var(--ink); font-size: 16px; }
.kc small { display: block; font-size: 11px; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; -webkit-overflow-scrolling: touch; }
.shot { flex: none; width: 92px; height: 92px; border: 0; padding: 0; border-radius: 16px; overflow: hidden; background: var(--soft); cursor: pointer; }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
img.nophoto { visibility: hidden; }
.rhead { display: flex; gap: 12px; align-items: flex-start; }
.rthumb { width: 64px; height: 64px; border-radius: 14px; object-fit: cover; flex: none; background: var(--card); }
.sheet.ed { max-height: 94vh; }
.irow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.irow input { width: 84px; text-align: right; font: inherit; font-size: 16px; color: var(--ink); background: var(--soft); border: 2px solid transparent; border-radius: 12px; padding: 8px 10px; outline: none; }
.irow input:focus { border-color: var(--accent); }
.irow .x { background: none; border: 0; color: var(--mute); font-size: 16px; width: 36px; height: 36px; cursor: pointer; }
.sugg { background: var(--soft); border-radius: 14px; margin-top: 6px; overflow: hidden; }
.sugg button { display: flex; justify-content: space-between; align-items: center; width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; text-align: left; cursor: pointer; font-size: 15px; }
.sugg button:last-child { border-bottom: 0; }
.sugg small { color: var(--mute); }
.newing { background: var(--soft); border-radius: 14px; padding: 12px; margin-top: 6px; }
.totals { background: var(--soft); border-radius: 14px; padding: 10px 12px; margin: 8px 0 12px; font-size: 14px; line-height: 1.5; }
.mphoto { width: 100%; max-height: 220px; object-fit: cover; border-radius: 16px; display: block; margin-bottom: 6px; background: var(--soft); }
.photo-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.wk { display: grid; grid-template-columns: 1fr 86px 64px; gap: 8px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.wk:last-child { border-bottom: 0; }
.wk b { text-align: right; font-size: 15px; }
.wk span:last-child { text-align: right; }
.wk.head { font-size: 12px; color: var(--mute); }
.wk.head span:nth-child(2) { text-align: right; }

/* sleep times */
.times .stat { padding: 8px 8px 4px; text-align: center; box-shadow: none; background: var(--soft); }
.times .stat input { font-size: 17px; text-align: center; min-height: 36px; padding: 0; }
.times .now { padding: 2px 0 4px; font-size: 13px; }
.sleepsum { margin-top: 10px; text-align: center; }
.add.soft { background: var(--soft); color: var(--ink); }
.chk { display: flex; align-items: center; gap: 10px; font-size: 16px !important; color: var(--ink) !important; min-height: 40px; cursor: pointer; }
.chk input { width: 22px; height: 22px; accent-color: var(--accent); }

/* cookbook */
.sheet.book { display: flex; flex-direction: column; height: 92vh; }
.book-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.book-head h3 { margin: 0; }
.search { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--soft); border: 2px solid transparent; border-radius: 14px; padding: 11px 14px; outline: none; margin-bottom: 10px; min-height: 46px; -webkit-appearance: none; appearance: none; }
.search:focus { border-color: var(--accent); background: var(--card); }
.book-chips { margin-bottom: 10px; flex: none; flex-wrap: nowrap; gap: 6px; }
.book-chips .chip { padding: 8px 10px; min-height: 44px; font-size: 13.5px; white-space: nowrap; }
.book-sort { margin-bottom: 10px; flex: none; }
.book-list { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: 8px; }
.rcard { background: var(--soft); border-radius: 18px; padding: 14px 16px; margin-bottom: 10px; }
.rtop { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.rtop b { font-size: 16px; line-height: 1.3; }
.rbits { margin: 4px 0 2px; font-weight: 600; font-size: 14px; }
.rings { margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ractions { display: flex; gap: 8px; margin-top: 12px; }
.ractions .btn { flex: 1; }

/* sheets */
.scrim { position: fixed; inset: 0 0 auto 0; height: 100%; background: rgba(10, 12, 20, .42); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 640px; border-radius: 26px 26px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--soft); border: 2px solid transparent; border-radius: 14px; padding: 12px 14px; outline: none; min-height: 46px; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); background: var(--card); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.actions .btn { flex: 1; }
details.more { margin-bottom: 12px; }
details.more summary { color: var(--accent); font-weight: 600; font-size: 14px; cursor: pointer; padding: 6px 0 10px; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.menu-grid button { background: var(--soft); border: 0; border-radius: 18px; padding: 18px 4px; font-size: 14px; cursor: pointer; }
.menu-grid button span { display: block; font-size: 28px; margin-bottom: 4px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 14px; display: flex; align-items: center; gap: 14px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--accent); font-weight: 700; padding: 4px 6px; cursor: pointer; font-size: 14px; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--mute); padding: 4px 0; }
.cal .d { aspect-ratio: 1; background: var(--card); box-shadow: var(--shadow); border: 0; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 15px; cursor: pointer; position: relative; padding: 0; color: var(--ink); }
.cal .d.out { opacity: .35; }
.cal .d.today { box-shadow: inset 0 0 0 2px var(--accent), var(--shadow); font-weight: 700; }
.cal .d.sel { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.cal .d .dots { display: flex; gap: 2px; height: 6px; margin-top: 2px; }
.cal .d .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal .d.sel .dots i { background: var(--accent-ink); }
.cal .d .dots i.t { background: var(--warn); }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--mute); font-size: 10px; }
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; font-size: 13px; color: var(--mute); cursor: pointer; border-radius: 10px; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--soft); color: var(--mute); }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

/* recipe cards sit on the page now (not inside a sheet) */
#bk-list .rcard { background: var(--card); box-shadow: var(--shadow); }
#bk-list .rcard .btn.ghost { background: var(--soft); }

/* grid children may shrink below their content width (time inputs have a wide default) */
.grid3, .grid2, .two { grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); }
.grid2, .two { --cols: 2; }
.grid3 > *, .grid2 > *, .two > * { min-width: 0; }
.times input { width: 100%; min-width: 0; font-size: 16px; padding: 0 2px; }


/* ---------- accessibility pass ---------- */
:root { color-scheme: light dark; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.stat:focus-within { box-shadow: 0 0 0 2px var(--accent); }
label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
button, a, summary, select, label, input[type=checkbox] { touch-action: manipulation; }
/* tap targets of at least 44px */
.link { min-height: 44px; padding: 10px 8px; }
.add, .btn.sm, .chip, .set, .seg button { min-height: 44px; }
#toast button { min-height: 44px; padding: 0 10px; }
.irow .x { width: 44px; height: 44px; }
/* visually hidden but still focusable (file pickers inside labels) */
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; opacity: 0; }
.btn { position: relative; }
/* reserve space for the big photo preview so the page doesn't jump when it loads */
.mphoto { aspect-ratio: 16 / 10; height: auto; }
.wheel:focus-visible { outline-offset: -2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
