:root {
  --accent: #c8102e;
  --accent-dark: #a00d25;
  --ink: #17181a;
  --ink-2: #5b6067;
  --ink-3: #9aa0a7;
  --line: #e6e8ea;
  --bg: #f7f7f8;
  --card: #ffffff;
  --good: #1a7f37;
  --on-ink: #ffffff;        /* text placed on an --ink background */
  --hit-bg: #1a7f37;  --hit-fg: #ffffff;   /* set reached target reps */
  --short-bg: #f5c518; --short-fg: #3d2f00; /* set fell short of target */
  --radius: 14px;
  --tabbar-h: 64px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}
.hidden { display: none !important; }
.loading { text-align: center; padding: 4rem 1rem; color: var(--ink-3); }

/* Status bar is translucent (index.html) so we always own the top inset ourselves —
   iOS is inconsistent about reserving space for it in standalone mode. */
#app { max-width: 560px; margin: 0 auto; padding: env(safe-area-inset-top) 14px 20px; }
/* Backdrop behind the status bar: content scrolls under it instead of under the
   clock. Above page content, below the modal overlay (50) and rest timer (40). */
body::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; z-index: 35;
  height: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  pointer-events: none;
}

/* ---------- header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 10px; gap: 8px;
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.daypick {
  appearance: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 8px 30px 8px 14px; font-size: 15px; font-weight: 600;
  color: var(--ink); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235b6067' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.badge {
  font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: #efeff1; color: var(--ink-2); white-space: nowrap;
}
.badge.deload { background: #fff3cd; color: #7a5a00; }

/* ---------- segmented tabs (Workout / Warmup) ---------- */
.seg { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.seg button {
  flex: 1; background: none; border: none; padding: 10px 0; font-size: 15px;
  font-weight: 600; color: var(--ink-3); border-bottom: 2px solid transparent;
}
.seg button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- exercise cards ---------- */
.excard { background: var(--card); border-radius: var(--radius); padding: 14px 14px 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.exhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.exname { font-size: 17px; font-weight: 700; }
.exrx { font-size: 15px; font-weight: 700; color: var(--accent); white-space: nowrap; }
/* play button linking to the exercise's how-to video — a real link, opens in the browser */
.howto {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; margin-left: 6px; vertical-align: 2px; padding-left: 1px;
  border-radius: 50%; background: var(--accent); color: #fff; text-decoration: none;
}
.howto:active { background: var(--accent-dark); }
.exrx small { font-weight: 600; color: var(--ink-3); }
.circles { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.set {
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: #ececee; color: var(--ink-3); font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.set.hit { background: var(--hit-bg); color: var(--hit-fg); }
.set.short { background: var(--short-bg); color: var(--short-fg); }
.wbtn {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  font-size: 13px; font-weight: 700; color: var(--ink-2); padding: 4px 9px;
}
.warm-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.warm-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.warm-table tr:last-child td { border-bottom: none; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

.finishbtn {
  width: 100%; padding: 15px; margin-top: 12px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 800;
}
.finishbtn:disabled { background: #d9dadd; color: #fff; }

/* ---------- generic ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card h3 { font-size: 15px; margin-bottom: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.btn {
  border: none; border-radius: 10px; padding: 10px 16px; font-size: 15px;
  font-weight: 700; background: var(--ink); color: var(--on-ink);
}
.btn.sec { background: #ececee; color: var(--ink); }
.btn.danger { background: none; color: var(--accent); padding: 6px 8px; }
.btn.ghost { background: none; color: var(--ink-2); border: 1px solid var(--line); }
.btn.full { width: 100%; margin-top: 8px; }
.iconbtn { border: none; background: none; font-size: 17px; color: var(--ink-3); padding: 6px 8px; }

input, select {
  font-size: 16px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; width: 100%; background: var(--card); color: var(--ink);
}
label.f { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
label.f input, label.f select { margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- login ---------- */
.login { max-width: 340px; margin: 12vh auto 0; text-align: center; }
.login .logo { font-size: 40px; }
.login h1 { margin: 6px 0 22px; font-size: 24px; }
.login form { text-align: left; }
.err { color: var(--accent); font-size: 14px; margin: 8px 0; min-height: 18px; }

/* ---------- workout focus mode ---------- */
body.in-workout { padding-bottom: calc(env(safe-area-inset-bottom) + 28px); }
body.in-workout #tabbar { display: none; }
body.in-workout #resttimer { bottom: calc(env(safe-area-inset-bottom) + 14px); }

/* ---------- home ---------- */
/* quarter bar: read-only, one segment per week */
.weekmeta {
  display: flex; justify-content: space-between; align-items: baseline;
  margin: 0 2px 8px; font-size: 14px; color: var(--ink-2);
}
.weekmeta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.weekbar { display: flex; gap: 3px; height: 10px; margin: 0 2px 16px; }
.weekbar i { flex: 1; border-radius: 3px; background: #ececee; }
.weekbar i.done { background: var(--accent); }
.weekbar i.now { background: var(--accent); }
.daycard b { font-size: 17px; display: block; }
.daycard.next { border: 2px solid var(--accent); }
.daystat { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 15px; }
.daystat.done { color: var(--ink); cursor: pointer; }
.daystat.done .tick {
  width: 22px; height: 22px; border-radius: 50%; background: var(--good); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px;
}
.daystat.done > span:last-child { margin-left: auto; font-size: 20px; }
.startbtn {
  width: 100%; margin-top: 10px; padding: 13px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 800;
}

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 30;
}
#tabbar button {
  flex: 1; border: none; background: none; font-size: 11px; font-weight: 600;
  color: var(--ink-3); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
}
#tabbar button .ico { font-size: 16px; line-height: 1; }
#tabbar button.on { color: var(--accent); }

/* ---------- rest timer (corner circle, tap to dismiss) ---------- */
#resttimer {
  position: fixed; right: 14px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  width: 96px; height: 96px; border-radius: 50%; border: none;
  background: #17181a; z-index: 40; padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
}
#resttimer svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.rt-track { fill: none; stroke: #3a3c3f; stroke-width: 4; }
#rt-ring {
  fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 175.9; transition: stroke-dashoffset 1s linear;
}
#rt-time {
  position: relative; color: #fff; font-size: 30px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
/* rest over: flash the circle in the accent colour for a moment */
#resttimer.done { background: var(--accent); animation: rt-flash .5s ease-in-out 3; }
#resttimer.done .rt-track, #resttimer.done #rt-ring { stroke: rgba(255,255,255,.35); }
@keyframes rt-flash { 50% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(200,16,46,.25); } }
@media (prefers-reduced-motion: reduce) { #resttimer.done { animation: none; } }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 86vh; overflow-y: auto;
}
.sheet h2 { font-size: 18px; margin-bottom: 14px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet .actions .btn { flex: 1; }

/* weight stepper */
.stepper { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 10px 0 4px; }
.stepper button {
  width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); font-size: 24px; font-weight: 700; color: var(--ink);
}
.stepper .val { font-size: 30px; font-weight: 800; min-width: 110px; text-align: center; }
.stepper .stepval {
  font-size: 28px; font-weight: 800; width: 130px; text-align: center;
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 6px;
}

/* ---------- progress: full-width stat tiles ---------- */
.stat {
  background: var(--card); border-radius: var(--radius); padding: 18px 16px 16px;
  margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05); text-align: center;
}
.stat .lbl { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); font-weight: 700; }
.stat .big {
  font-size: 44px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat .big small { font-size: 17px; font-weight: 700; color: var(--ink-3); letter-spacing: 0; margin-left: 5px; }
.stat .delta { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.stat .delta b { color: var(--accent); }

/* ---------- my program (read-only) / choose ---------- */
.exrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.exrow:last-child { border-bottom: none; }
.exrow b { display: block; font-size: 15px; }
.exrow .m { font-size: 12px; color: var(--ink-3); }
.exrow .inc {
  border: none; border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 700;
  color: var(--accent); background: #ececee; white-space: nowrap;
}
.progcard {
  border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
  cursor: pointer; background: var(--card);
}
.progcard.on { border-color: var(--accent); }
.progcard b { font-size: 16px; display: block; }
.progcard small { font-size: 13px; color: var(--ink-2); display: block; margin-top: 3px; line-height: 1.4; }
.segrow button.on { background: var(--accent); color: #fff; }

/* ---------- summary ---------- */
.totals { display: flex; gap: 10px; margin-bottom: 12px; }
.totals > div {
  flex: 1; background: var(--bg); border-radius: 12px; padding: 12px 8px;
  text-align: center; display: flex; flex-direction: column; gap: 2px;
}
.totals b { font-size: 22px; font-weight: 800; }
.totals span { font-size: 12px; color: var(--ink-2); }

.sumrow { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.sumrow:last-child { border-bottom: none; }
.sumrow .up { color: var(--good); font-weight: 700; }
.sumrow .same { color: var(--ink-2); }

/* ---------- charts ---------- */
.chartwrap { overflow-x: auto; }
.chart text { font-family: inherit; }
.tip {
  position: fixed; background: var(--ink); color: var(--on-ink); padding: 6px 10px;
  border-radius: 8px; font-size: 13px; pointer-events: none; z-index: 60;
  transform: translate(-50%, -130%); white-space: nowrap;
}

/* ---------- history ---------- */
.sess { margin-bottom: 10px; }
.sess .h { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.sess .h b { font-size: 16px; }
.sess table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sess td { padding: 5px 2px; border-bottom: 1px solid var(--line); }
.sess tr:last-child td { border-bottom: none; }
.sess td.r { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* program editor */
.slotrow { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.slotrow:last-child { border-bottom: none; }
.slotrow .info { flex: 1; min-width: 0; }
.slotrow .info b { display: block; font-size: 15px; }
.slotrow .info span { font-size: 13px; color: var(--ink-2); }

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f2f3f4; --ink-2: #b9bdc2; --ink-3: #82878d;
    --line: #33363a; --bg: #131416; --card: #1e2023;
    --accent: #e8384f; --accent-dark: #c8102e; --good: #4cc26a;
    --on-ink: #131416;
    --hit-bg: #2e9e4f;  --hit-fg: #ffffff;
    --short-bg: #e6b800; --short-fg: #1a1400;
  }
  .set { background: #2b2e32; color: #82878d; }
  .weekbar i { background: #2b2e32; }
  .exrow .inc { background: #2b2e32; }
  .btn.sec, .stepper button { background: #2b2e32; }
  .finishbtn:disabled { background: #3a3d42; color: #82878d; }
  .badge { background: #2b2e32; color: var(--ink-2); }
  .badge.deload { background: #4a3b00; color: #ffd75e; }
  .meta { color: var(--ink-2); }
  /* light-tinted surfaces that were hardcoded for light mode */
  .tiercard.on { background: #2e1a1e; }
  .wlogged .ok { background: #1c3a26; }
  .vchip { background: #2b2e32; }
  .vchip.good { background: #1c3a26; color: var(--good); }
  .vchip.warn { background: #4a3b00; color: #ffd75e; }
  .vchip.bad { background: #4a1b1b; color: #ff7b72; }
  .vchip.grey { background: #2b2e32; color: var(--ink-3); }
  .hintbox { background: #3a2f10; border-color: #5a4a1a; color: #ffd75e; }
  .weekrow i.future { border-color: #4a4d52; }
  .stepdots i { background: #4a4d52; }
  .bigin::placeholder { color: #4a4d52; }
}

/* ---------- weight tracker ---------- */
.wring { display: flex; flex-direction: column; align-items: center; padding: 10px 0 14px; }
.wring .rlabel { font-size: 14px; color: var(--ink-2); margin-top: 8px; }
.wring .rlabel b { color: var(--ink); }
.bigin {
  display: block; width: 100%; text-align: center; border: 1.5px dashed var(--line);
  border-radius: 12px; height: 74px; font-size: 40px; font-weight: 800;
  color: var(--ink); background: none; letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.bigin::placeholder { color: #c3c8cd; }
.bigin:focus { outline: none; border-color: var(--accent); border-style: solid; }
.wcomment {
  display: block; width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; margin-top: 10px; background: var(--card);
  color: var(--ink);
}
.wlogged { text-align: center; padding: 22px 0 14px; }
.wlogged .ok {
  display: inline-flex; align-items: center; justify-content: center;
  width: 58px; height: 58px; border-radius: 50%; background: #e7f4ea;
  color: var(--good); font-size: 28px; font-weight: 800;
}
.wlogged h4 { font-size: 22px; font-weight: 800; margin-top: 10px; letter-spacing: -0.01em; }
.wlogged p { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.weekgrid { display: flex; flex-direction: column; gap: 7px; align-items: center; margin-top: 4px; }
.weekrow { display: flex; align-items: center; gap: 8px; }
.weekrow .wl { width: 30px; font-size: 10px; font-weight: 700; color: var(--ink-3); text-align: right; }
.weekrow i { width: 14px; height: 14px; border-radius: 50%; background: var(--good); display: block; }
.weekrow i.missed { background: var(--line); }
.weekrow i.backfilled { background: #a7d5b2; }
.weekrow i.today { background: var(--line); outline: 2px solid var(--accent); outline-offset: 1.5px; }
.weekrow i.logged.today { background: var(--good); }
.weekrow i.future { background: none; border: 1.5px dashed #d4d7da; }
.weekrow i.check { background: none; border: none; width: auto; height: auto; font-size: 14px; font-style: normal; line-height: 1; }
.vchip {
  display: inline-block; font-size: 12px; font-weight: 800; padding: 4px 12px;
  border-radius: 999px; background: #efeff1; color: var(--ink-2); white-space: nowrap;
}
.vchip.big { font-size: 15px; padding: 8px 18px; }
.vchip.good { background: #e7f4ea; color: var(--good); }
.vchip.warn { background: #fff3cd; color: #7a5a00; }
.vchip.bad { background: #fdeaea; color: #c0392b; }
.vchip.grey { background: #efeff1; color: var(--ink-3); }
.verdict-rate {
  font-size: 36px; font-weight: 800; letter-spacing: -0.02em; text-align: center;
  margin-top: 10px; font-variant-numeric: tabular-nums;
}
.stepdots { display: flex; gap: 6px; justify-content: center; padding: 2px 0 12px; }
.stepdots i { width: 7px; height: 7px; border-radius: 50%; background: #d4d7da; }
.stepdots i.on { background: var(--accent); }
.segrow { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.segrow button {
  flex: 1; text-align: center; padding: 10px 0; font-size: 14px; font-weight: 600;
  color: var(--ink-3); background: var(--card); border: none;
}
.segrow button.on { background: var(--accent); color: #fff; }
.tiercard {
  display: flex; gap: 10px; align-items: flex-start; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 11px 12px; margin-bottom: 8px; cursor: pointer;
}
.tiercard.on { border-color: var(--accent); background: #fdf3f4; }
.tiercard .radio { flex: none; width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid #c3c8cd; margin-top: 2px; }
.tiercard.on .radio { border: 5px solid var(--accent); }
.tiercard b { font-size: 14px; display: block; }
.tiercard b em { font-style: normal; font-weight: 700; color: var(--accent); font-size: 12px; float: right; font-variant-numeric: tabular-nums; }
.tiercard small { font-size: 12px; color: var(--ink-2); line-height: 1.35; display: block; }
.pledge { text-align: center; padding: 28px 14px 18px; }
.pledge .big { font-size: 42px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.pledge .big small { display: block; font-size: 15px; font-weight: 700; color: var(--ink-3); letter-spacing: 0; margin-top: 8px; }
.pledge p { font-size: 14px; color: var(--ink-2); margin-top: 14px; line-height: 1.5; }
.hintbox {
  background: #fff8e6; border: 1px solid #f2e3b3; border-radius: 12px;
  padding: 11px 12px; font-size: 13px; color: #7a5a00; margin-bottom: 10px;
}

/* Staging-only banner (app.js adds it when <html data-env="staging">). Sits just
   under the status bar, above content, never intercepts touches. */
.envbanner {
  position: fixed; top: env(safe-area-inset-top); left: 50%; transform: translateX(-50%);
  z-index: 36; pointer-events: none;
  padding: 2px 10px; border-radius: 0 0 8px 8px;
  background: #2a7f8f; color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .04em;
  white-space: nowrap;
}
