:root {
  --bg: #f3f6fb; --card: #ffffff; --ink: #14202e; --muted: #5d6b7d; --line: #dfe6f0;
  --brand: #2563c9; --brand-ink: #ffffff; --warn: #c2410c; --danger: #b42318;
  --kcal: #2563c9; --protein: #12957f; --carbs: #d98e04; --fat: #c2477a;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b; --card: #161e29; --ink: #e6ecf4; --muted: #93a1b3; --line: #263243;
    --brand: #6aa3ff; --brand-ink: #07111f; --warn: #f59e0b; --danger: #f87171;
    --kcal: #6aa3ff; --protein: #3fb593; --carbs: #f2b640; --fat: #ee7fae;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header */
#top { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center;
  justify-content: space-between; padding: 10px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
#who { min-width: 0; max-width: 45%; font-weight: 700; font-size: 1.02rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.datenav { display: flex; align-items: center; gap: 4px; position: relative; }
.datenav button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; }
#datebtn { min-width: 118px; font-weight: 600; }
#datepick { position: absolute; inset: 0; opacity: 0; pointer-events: none; width: 100%; }

main { padding: 14px 16px; max-width: 640px; margin: 0 auto; }

/* tabs */
#tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
#tabs button { flex: 1; border: 0; background: none; padding: 9px 4px 8px; font-size: .78rem;
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
#tabs button span { font-size: 1.25rem; line-height: 1; }
#tabs button { position: relative; }
#tabs .tabdot { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: #d64545; color: #fff; font-style: normal; font-size: .68rem; font-weight: 700;
  line-height: 16px; text-align: center; }
#tabs button.on { color: var(--brand); font-weight: 700; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 1rem; }
.big { font-size: 2rem; font-weight: 750; letter-spacing: -.02em; }
.big small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.bar { height: 9px; border-radius: 9px; background: var(--line); overflow: hidden; margin: 6px 0 2px; }
.bar > i { display: block; height: 100%; border-radius: 9px; background: var(--brand); }
.bar.over > i { background: var(--warn); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.macros b { display: block; font-size: 1.05rem; }
.macros .lab { font-size: .8rem; color: var(--muted); }

/* meals */
.meal { margin-bottom: 12px; }
.meal-h { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 6px; }
.meal-h b { font-size: 1rem; }
.add-sm { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px;
  color: var(--brand); font-weight: 700; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 10px; text-align: left;
  padding: 11px 14px; border: 0; background: none; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .t { min-width: 0; }
.row .t b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row .t > span.small { display: block; }           /* stacked facts, one per line */
.row .t > .badge { display: inline-block; margin-top: 3px; }
.row .k { white-space: nowrap; text-align: right; font-weight: 650; }
.row .k small { display: block; font-weight: 400; color: var(--muted); }
.empty { padding: 12px 14px; color: var(--muted); font-size: .92rem; }
.badge { display: inline-block; font-size: .68rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--muted); margin-right: 4px; vertical-align: 1px; }

/* add view */
.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input { flex: 1; min-width: 0; }
input, select { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 14px; font-weight: 600; white-space: nowrap; }
a.btn { color: var(--ink); text-decoration: none; text-align: center; }   /* download links look like buttons */
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.chips { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: .9rem; white-space: nowrap; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.section-t { margin: 14px 2px 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions .btn { flex: 1 1 28%; }
.note { font-size: .85rem; color: var(--muted); padding: 8px 2px; }
.note.warn { color: var(--warn); }

/* week */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; position: relative; padding-top: 6px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; border: 0; background: none; padding: 0; }
.chart .col i { width: 100%; max-width: 34px; border-radius: 6px 6px 2px 2px; background: var(--brand); min-height: 2px; }
.chart .col.over i { background: var(--warn); }
.chart .col.sel i { outline: 2px solid var(--ink); outline-offset: 1px; }
.chart .col.zero i { background: var(--line); }
.chart .goal { position: absolute; left: 0; right: 0; border-top: 2px dashed var(--muted); opacity: .7; pointer-events: none; }
.labels { display: flex; gap: 6px; margin-top: 4px; }
.labels span { flex: 1; text-align: center; font-size: .75rem; color: var(--muted); }
.labels span.on { color: var(--ink); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.stats b { font-size: 1.2rem; display: block; }

/* sheet */
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 90vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
#sheet h2 { margin: 0 0 2px; font-size: 1.15rem; }
.field { margin: 12px 0; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.pair { display: flex; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preview { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 12px 0; }
.preview b { display: block; font-size: 1.1rem; }
.preview span { font-size: .75rem; color: var(--muted); }
video { width: 100%; border-radius: 12px; background: #000; max-height: 45vh; object-fit: cover; }

#toast { pointer-events: none; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; z-index: 40; font-size: .92rem; max-width: 90%; }

/* auth screens */
.auth { max-width: 360px; margin: 6vh auto 0; }
.auth h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.02em; }
.auth > .muted { margin-bottom: 18px; }
.auth .field label { font-weight: 600; }
.auth .btn.wide { margin-top: 6px; }
#tabs.hidden { display: none !important; }

/* version marker - sits under the content, above the tab bar */
#ver { text-align: center; font-size: .75rem; color: var(--muted); opacity: .8;
  padding: 18px 16px calc(14px + env(safe-area-inset-bottom)); letter-spacing: .02em; }

/* training */
textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font: inherit; resize: vertical; }
.card.live { border-color: var(--brand); border-width: 2px; }
.restbar { display: flex; align-items: center; gap: 8px; margin-top: 12px;
  background: var(--brand); color: var(--brand-ink); padding: 8px 10px 8px 16px; border-radius: 999px;
  font-weight: 650; font-variant-numeric: tabular-nums; }
.restbar.done { background: var(--warn); }
.restbar #restleft { flex: 1; }
.restbar .chip { background: rgba(255,255,255,.18); border-color: transparent; color: inherit; padding: 4px 10px; font-size: .82rem; }
#tabs button span { font-size: 1.2rem; }

/* compete */
#tabs button { font-size: .72rem; padding-left: 2px; padding-right: 2px; }
.row .place { width: 30px; flex: none; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.row.me { background: color-mix(in srgb, var(--brand) 9%, transparent); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.row .t .bar { display: block; margin-top: 6px; max-width: 190px; }
.linkish { border: 0; background: none; color: var(--brand); font-weight: 650; padding: 0; text-decoration: underline; }
.badgegrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 8px; text-align: center; display: flex; flex-direction: column; gap: 3px; align-items: center; }
.badge-tile b { font-size: .8rem; line-height: 1.2; }
.badge-tile .bi { font-size: 1.7rem; line-height: 1; }
.badge-tile.locked { opacity: .42; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); }
.sw.face { background: var(--card); font-size: 1.1rem; }

/* kitchen, shopping list and photos */
.gram { width: 72px; text-align: right; padding: 5px 7px; display: inline-block; }
.row.check { cursor: pointer; }
.row.check .tick { width: auto; margin-right: 10px; flex: none; }
.row.check.done .t b { text-decoration: line-through; opacity: .55; }
.nlrow .k { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.photogrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.phototile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; }
.phototile img { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--line); display: block; }
.phototile .pmeta { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 7px 9px 2px; font-size: .82rem; }
.phototile .chip { margin: 6px 9px 9px; }
.photofull { width: 100%; border-radius: 12px; margin: 8px 0; max-height: 50vh; object-fit: contain; background: var(--line); }

/* ---- banners: update available + admin announcements */
#banners:empty { display: none; }
#banners { padding: 8px 12px 0; display: grid; gap: 6px; }
.banner { display: flex; align-items: center; gap: 10px; justify-content: space-between; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: .9rem; }
.banner.update { border-color: var(--brand); }
.banner .btn { padding: 6px 12px; }
.banner .x { border: 0; background: none; color: var(--muted); font-size: 1rem; padding: 4px 8px; }

.stats.s3 { grid-template-columns: repeat(3, 1fr); }
.stats .small { display: block; }

/* ---- phase progress grid (video programs) */
.phasegrid { margin-top: 12px; display: grid; gap: 6px; }
.pgrow { display: flex; align-items: center; gap: 6px; }
.pgwk { width: 28px; font-size: .7rem; color: var(--muted); }
.pgd { flex: 1; min-width: 0; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-size: .8rem; font-weight: 600; padding: 0; }
.pgd.done { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.pgd.cur { outline: 2px solid var(--brand); outline-offset: 1px; color: var(--ink); }
.pgd.done.cur { color: var(--brand-ink); }

/* groups */
#who .gname { display: block; font-weight: 500; font-size: .72rem; color: var(--muted); line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* tour and help */
.tour { text-align: center; }
.tourdots { display: flex; justify-content: center; gap: 6px; margin: 2px 0 10px; }
.tourdots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); display: block; }
.tourdots i.on { background: var(--brand); }
.touricon { font-size: 2.6rem; line-height: 1.1; margin: 4px 0; }
.tourp { text-align: left; margin: 8px 0; line-height: 1.45; }
.helprow { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; font: inherit; color: inherit; cursor: pointer; }
.helprow:last-child { border-bottom: 0; }

.photocmp { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.photocmp select { width: 100%; font-size: .82rem; margin-bottom: 4px; }
.photocmp img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; background: var(--line); display: block; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin: 8px 0; }
.bars .col2 { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.bars .col2 i { display: block; width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; }

/* ---- planning calendar */
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 10px 0; }
.calh { text-align: center; font-size: .75rem; color: var(--muted); }
.calc { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 2px; font-size: .85rem; }
.calc.empty { border: 0; background: none; }
.calc.today { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.calc.did { background: color-mix(in srgb, var(--brand) 14%, var(--card)); }
.calc span { font-size: .75rem; line-height: 1; min-height: 12px; }
