:root {
  --bg: #0f1012;
  --card: #1a1c20;
  --line: #2a2d33;
  --text: #f2f3f5;
  --muted: #8d939e;
  --accent: #f5a524;
  --accent-ink: #1a1203;
  --bad: #ef5350;
  --good: #4cc38a;
  --tabs-h: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px
           calc(env(safe-area-inset-bottom) + var(--tabs-h) + 96px);
}

h1 { font-size: 28px; margin: 4px 0 16px; letter-spacing: -0.02em; }
h2 { font-size: 19px; margin: 0; }
h3.section { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 4px 10px; }
p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; margin: 12px 4px; }
.link { color: var(--accent); font-size: 15px; padding: 6px 0; }
.danger { color: var(--bad); }

.primary {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 15px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 17px;
}
.primary:active { opacity: 0.8; }

.secondary {
  display: block;
  width: 100%;
  padding: 13px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  font-weight: 600;
  margin-bottom: 10px;
}

/* Plan list on the home card */
.plan { list-style: none; margin: 14px 0 0; padding: 0; }
.plan li {
  display: grid;
  grid-template-columns: 1fr auto 84px;
  gap: 10px;
  align-items: baseline;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.plan li strong { text-align: right; font-variant-numeric: tabular-nums; }
.plan .sr { color: var(--muted); font-size: 14px; }
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(239, 83, 80, 0.16);
  color: var(--bad);
  vertical-align: 2px;
}
.badge.ok { background: rgba(76, 195, 138, 0.16); color: var(--good); }

/* Active workout */
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--line);
  font-size: 20px;
  line-height: 1;
}
.stepper button:active { background: #3a3e46; }
.stepper .val {
  min-width: 78px;
  text-align: center;
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.sets { display: flex; gap: 8px; margin: 14px 0 4px; }
.set {
  flex: 1;
  max-width: 60px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: var(--muted);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.set.done { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.set.miss { background: transparent; border-color: var(--bad); color: var(--bad); }

details { margin-top: 10px; }
summary { color: var(--muted); font-size: 14px; padding: 4px 0; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::before { content: "＋ "; }
details[open] summary::before { content: "－ "; }
.warm { list-style: none; margin: 6px 0 0; padding: 0; font-size: 14px; color: var(--muted); }
.warm li { display: grid; grid-template-columns: 58px 1fr auto; gap: 8px; padding: 4px 0; font-variant-numeric: tabular-nums; }
.warm li span:last-child { text-align: right; color: var(--text); }

/* Rest timer */
#rest {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + var(--tabs-h) + 10px);
  max-width: 536px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #24272d;
  border: 1px solid #3a3e46;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
#rest[hidden] { display: none; }
#rest .clock { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 78px; }
#rest .clock.go { color: var(--good); }
#rest .msg { flex: 1; font-size: 13px; color: var(--muted); }
#rest .x { width: 36px; height: 36px; font-size: 20px; color: var(--muted); }

/* Tabs */
#tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(15, 16, 18, 0.94);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1;
  height: var(--tabs-h);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
#tabs button.on { color: var(--accent); }

/* History */
.hist-lines { margin-top: 10px; font-size: 15px; }
.hist-lines div { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.hist-lines span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }

/* Progress */
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 8px 14px;
  border-radius: 99px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
svg.chart { display: block; width: 100%; height: auto; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; text-align: center; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }

/* Settings */
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 3px; }
.seg button { padding: 7px 16px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
select {
  font: inherit;
  color: var(--text);
  background: var(--line);
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
}
.lift-set { padding: 12px 0; border-top: 1px solid var(--line); }
.lift-set:first-of-type { border-top: 0; padding-top: 4px; }
.lift-set .sub { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; color: var(--muted); font-size: 14px; }
.rules { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.rules li { margin: 5px 0; }
