:root {
  --accent: #c8102e;
  --accent-dark: #a00d25;
  --ink: #17181a;
  --ink-2: #5b6067;
  --ink-3: #9aa0a7;
  --line: #e6e8ea;
  --bg: #f7f7f8;
  --card: #ffffff;
  --good: #1a7f37;
  --radius: 14px;
  --tabbar-h: 64px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
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); }

#app { max-width: 560px; margin: 0 auto; padding: 0 14px 20px; }

/* ---------- 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; }
.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.done { background: var(--accent); color: #fff; }
.set.miss { background: var(--accent-dark); color: #ffd6dd; }
.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: #fff;
}
.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; }

/* ---------- home ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 12px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 700;
  flex: 0 0 auto;
}
.chip.now { border-color: var(--ink-3); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.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;
}

/* ---------- 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; }

/* ---------- summary ---------- */
.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: #fff; 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;
  }
  .set { background: #2b2e32; color: #82878d; }
  .btn.sec, .stepper button { background: #2b2e32; }
  .badge { background: #2b2e32; color: var(--ink-2); }
  .badge.deload { background: #4a3b00; color: #ffd75e; }
  .meta { color: var(--ink-2); }
}
