/* Jess Fit. Light and dark are both chosen, not flipped. */
:root {
  color-scheme: light;
  --bg: #f6f4f1;
  --card: #ffffff;
  --line: #ece8e3;
  --track: #efebe6;
  --text: #191919;
  --text-2: #666666;
  --accent: #d4508a;         /* brand: magenta */
  --accent-ink: #ffffff;
  --kcal: #f47230;           /* metric identity: orange, violet, aqua, blue (validated adjacent order) */
  --protein: #6a4ce2;
  --steps: #00b894;
  --exercise: #257de0;
  --good-bg: #e3f4e6; --good: #0b6b1c;
  --warn-bg: #fdecd8; --warn: #8a4a00;
  --danger: #c33233;
  /* sequential (goals hit 0-4): one hue, light -> dark */
  --lv0: #f6e9ee; --lv1: #f7c6da; --lv2: #ee7fac; --lv3: #d4508a; --lv4: #9c2a5e;
  --lv-ink: #191919; --lv-ink-strong: #ffffff;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(60 30 10 / .06);
  --r: 20px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111113; --card: #1c1c1f; --line: #2a2a2e; --track: #2b2b30;
    --text: #efefef; --text-2: #9c9c9c;
    --accent: #e24d8b;
    --kcal: #e76624; --protein: #9887ef; --steps: #00a888; --exercise: #338ced;
    --good-bg: #12301a; --good: #7fdc8f; --warn-bg: #3a2610; --warn: #f5b971;
    --danger: #ff7a7a;
    --lv0: #26222a; --lv1: #4a2236; --lv2: #7d2d52; --lv3: #b83a72; --lv4: #f07aa8;
    --lv-ink: #efefef; --lv-ink-strong: #111113;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 750; }
h2 { font-size: 16px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 14px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; display: block; margin-inline: auto; }
.big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.ok { color: var(--good); font-weight: 600; }

#view {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px calc(var(--tab-h) + var(--safe-b) + 90px);
  display: flex; flex-direction: column; gap: 12px;
}

.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }

/* metric identity */
.m-kcal { --c: var(--kcal); } .m-protein { --c: var(--protein); }
.m-steps { --c: var(--steps); } .m-exercise { --c: var(--exercise); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); display: inline-block; flex: none; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0 2px; }
.top .title { text-align: center; flex: 1; }
.top .title small { color: var(--text-2); font-size: 13px; font-weight: 500; }
.top > .title:first-child { text-align: left; }
.icon {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--card);
  font-size: 26px; line-height: 1; box-shadow: var(--shadow); cursor: pointer; padding-bottom: 4px;
}
.icon:disabled { opacity: .3; }

/* rings */
.ring .ring-track { stroke: var(--track); }
.ring .ring-fill { stroke: var(--c); transition: stroke-dasharray .5s ease; }
.ring .ring-lap { stroke: var(--c); filter: brightness(.7); }
.hero { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 22px; }
.hero-ring { position: relative; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-center .big { font-size: 40px; }
.ring-center span { color: var(--text-2); font-size: 14px; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; text-align: center; }
.hero-stats div { display: flex; flex-direction: column; }
.hero-stats div + div { border-left: 1px solid var(--line); }
.hero-stats small { color: var(--text-2); font-size: 12px; }
.hero-stats b { font-size: 18px; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; background: var(--track); color: var(--text-2); border: 0; }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }

.minis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mini { padding: 14px 8px 12px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mini-ring { position: relative; width: 92px; height: 92px; margin-bottom: 4px; }
.mini-ring > span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 17px; }
.mini h3 { justify-content: center; }
.mini p { margin: 0; font-size: 14px; }
.mini small { font-size: 12px; }
@media (max-width: 360px) { .mini-ring { transform: scale(.85); margin: -6px 0 -2px; } }

/* lists */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.list-head small { font-size: 12px; text-align: right; }
.row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%;
  padding: 12px 0; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer;
}
.row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--text-2); font-size: 14px; white-space: nowrap; }
.row-meta b, .row.total b { color: var(--text); }
.row.total { cursor: default; font-weight: 600; color: var(--text-2); font-size: 14px; }
.empty { color: var(--text-2); margin: 4px 0 2px; font-size: 14px; }
.steps { margin: 2px 0 12px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.quick .btn { flex: 1; }

/* buttons */
.btn {
  border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 650; cursor: pointer;
  background: var(--track); color: var(--text); min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.small { padding: 6px 12px; min-height: 34px; border-radius: 999px; font-size: 14px; }
.btn.link { background: none; color: var(--accent); }
.btn.danger { background: none; color: var(--danger); margin-right: auto; }
.btn:disabled { opacity: .5; }
.btn:active, .icon:active, .row:active, #fab:active { transform: scale(.97); }

/* forms */
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
input, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 17px; font-weight: 500; min-height: 48px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
form.card, #calc { display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.goal { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.goal > span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.goal-name { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 16px; font-weight: 650; }
.goal small { color: var(--text-2); font-weight: 500; font-size: 12px; padding-left: 18px; }
.goal input { width: 110px; flex: none; text-align: right; }
.calc summary { font-weight: 650; cursor: pointer; color: var(--accent); }
.calc[open] summary { margin-bottom: 14px; }
.err { color: var(--danger); margin: 0; font-size: 14px; }

/* login */
.login { padding-top: 10vh; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.login h1 { font-size: 32px; }
.login form { width: 100%; text-align: left; margin-top: 12px; }
body.signed-out .tabbar, body.signed-out #fab { display: none; }

/* week / month */
.headline { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 14px 8px; }
.headline div { display: flex; flex-direction: column; gap: 4px; }
.headline div + div { border-left: 1px solid var(--line); }
.headline .big { font-size: 28px; }
.headline small { color: var(--text-2); font-size: 12px; line-height: 1.25; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.tile-num { margin: 0; }
.tile-num b { font-size: 22px; font-weight: 750; }
.tile-num span { font-size: 13px; }
.tile small { font-size: 12px; }
.meter { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 4px; background: var(--c); }

.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar { fill: var(--c); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--text-2); font-size: 10px; }
.chart .axis.now { fill: var(--text); font-weight: 700; }
.chart .goal { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 4 4; opacity: .55; }
.chart .goal-label { fill: var(--text); font-size: 10px; font-weight: 650; paint-order: stroke; stroke: var(--card); stroke-width: 4px; stroke-linejoin: round; }
.chart .band { fill: var(--good-bg); opacity: .8; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit.on { fill: var(--text); opacity: .05; }
.tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%); pointer-events: none; z-index: 2;
  background: var(--text); color: var(--bg); border-radius: 10px; padding: 6px 10px; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; white-space: nowrap;
}
.tip[hidden] { display: none; }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-h { text-align: center; font-size: 11px; color: var(--text-2); font-weight: 600; }
.cal-d {
  aspect-ratio: 1; border: 0; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
  display: grid; place-items: center; font-style: normal; color: var(--lv-ink);
}
.cal-d:disabled { opacity: .35; cursor: default; }
.cal-d.now { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }
.lvx { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); color: var(--text-2); }
.lv0 { background: var(--lv0); } .lv1 { background: var(--lv1); } .lv2 { background: var(--lv2); }
.lv3 { background: var(--lv3); color: var(--lv-ink-strong); } .lv4 { background: var(--lv4); color: var(--lv-ink-strong); }
.cal-legend { display: flex; align-items: center; gap: 5px; margin-top: 12px; font-size: 12px; flex-wrap: wrap; }
.cal-legend .cal-d { width: 22px; height: 22px; aspect-ratio: auto; border-radius: 6px; font-size: 11px; cursor: default; }
.cal-legend .muted { margin: 0 4px; }

.seg { display: flex; background: var(--track); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* tab bar + add button */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--text-2); text-decoration: none; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); }
#sync { position: absolute; top: 8px; right: 10px; width: 7px; height: 7px; border-radius: 50%; background: transparent; }
#sync[data-state=syncing] { background: var(--text-2); animation: pulse 1s infinite; }
#sync[data-state=offline], #sync[data-state=error] { background: var(--kcal); }
@keyframes pulse { 50% { opacity: .2; } }

#fab {
  position: fixed; z-index: 6; right: max(18px, calc(50% - 262px)); bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  width: 62px; height: 62px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-size: 34px; font-weight: 400; line-height: 1;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
}

/* bottom sheet */
dialog#sheet {
  width: 100%; max-width: 560px; margin: auto auto 0; border: 0; padding: 0;
  border-radius: 24px 24px 0 0; background: var(--card); color: var(--text);
  max-height: 92dvh;
}
dialog#sheet[open] { animation: up .22s ease-out; }
dialog#sheet::backdrop { background: rgb(0 0 0 / .35); }
@keyframes up { from { transform: translateY(40%); opacity: .4; } }
#sheet form { padding: 10px 18px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
#sheet h2 { font-size: 20px; justify-content: space-between; }
#sheet h2 small { font-size: 14px; font-weight: 500; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips > small { width: 100%; }
.chip.pick { cursor: pointer; color: var(--text); font-weight: 550; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.sheet-actions .primary { min-width: 110px; }
.menu { display: grid; gap: 10px; }
.big-choice { display: flex; align-items: center; gap: 12px; font-size: 18px; padding: 18px; text-align: left; }
.big-choice .dot { width: 14px; height: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 92px); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
