:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --field: #f0efec;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --s1: #2a78d6;
  --s2: #eb6834;
  --danger: #d03b3b;
  --good: #006300;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --raised: #222221;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --field: #2c2c2a;
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --danger: #e66767;
    --good: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --raised: #222221; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.1); --field: #2c2c2a; --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --danger: #e66767; --good: #0ca30c;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
/* bottom padding leaves room for the tab bar and the rest timer above it */
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; padding: 0 16px calc(150px + env(safe-area-inset-bottom)); }
#app.focus { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 28px 0 10px; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  margin: 0 -16px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.top .title { flex: 1; min-width: 0; font-weight: 650; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person { display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--ink); font: inherit; font-weight: 650; font-size: 17px; padding: 6px 0; cursor: pointer; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 700; }
.sync { width: 10px; height: 10px; border-radius: 50%; border: 0; padding: 0; background: var(--good); cursor: pointer; flex: none; }
.sync.pending, .sync.syncing { background: var(--accent); }
.sync.offline { background: var(--muted); }
.sync.error { background: var(--danger); }
.icon-btn { border: 0; background: none; color: var(--ink); font: inherit; font-size: 22px; line-height: 1; padding: 6px 8px; margin-left: -8px; cursor: pointer; }
.banner { margin: 6px 0 4px; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, transparent); font-size: 14px; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabs a { flex: 1; max-width: 180px; text-align: center; padding: 10px 0; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px; border-radius: 10px; }
.tabs a.on { color: var(--ink); background: var(--field); }

/* ---------- buttons & fields ---------- */
button { font: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 0;
  background: var(--field); color: var(--ink); font-weight: 650; font-size: 16px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn.danger { color: var(--danger); background: none; }
.btn:active { transform: scale(0.98); }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid transparent; border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.hero { padding: 20px; margin-top: 8px; }
.hero .eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.hero h1 { font-size: 32px; font-weight: 750; margin: 4px 0 6px; }
.hero .moves { color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }
.hero .btn { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.alt { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.alt .label { font-size: 14px; color: var(--muted); margin-right: 2px; }
.acc { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer; margin-top: 12px; color: var(--ink); font: inherit; }
.acc .name { font-weight: 650; }
.acc .sub { font-size: 14px; color: var(--muted); }
.acc .go { margin-left: auto; color: var(--muted); font-size: 20px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--border); }
.list a, .list .item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.list .when { width: 64px; flex: none; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.list .what { flex: 1; min-width: 0; }
.list .what .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-key { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--s1); }
.dot-key.s2 { background: var(--s2); }

/* ---------- workout ---------- */
.w-head { display: flex; gap: 8px; align-items: center; margin: 4px 0 12px; }
.top input[type="date"] { width: auto; flex: none; min-height: 36px; padding: 6px 10px; font-size: 14px; }
.move { padding: 14px 14px 12px; }
.move .head { display: flex; align-items: baseline; gap: 8px; }
.move .head h3 { font-size: 18px; font-weight: 700; flex: 1; }
.move .target { font-size: 13px; color: var(--muted); }
.move .x { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 0 4px; cursor: pointer; }
.move .last { font-size: 13px; color: var(--muted); margin-top: 3px; }
.sets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.set { border: 0; border-radius: 8px; background: var(--field); color: var(--ink); padding: 6px 10px; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; }
.set .i { color: var(--muted); font-weight: 500; margin-right: 4px; font-size: 12px; }
.set.editing { outline: 2px solid var(--accent); }
.set .note { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 4px; }
.entry { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: center; margin-top: 10px; }
.entry .times { color: var(--muted); }
.entry input { text-align: center; font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.entry .btn { min-height: 44px; padding: 0 16px; }
.entry-actions { display: flex; gap: 8px; margin-top: 8px; }
.add-move { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- progress ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.tile .delta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.chart-card { padding: 14px 12px 8px; }
.chart-card .head { display: flex; align-items: baseline; gap: 8px; padding: 0 4px 6px; }
.chart-card .head h3 { font-size: 15px; font-weight: 650; flex: 1; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); padding: 2px 4px 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: var(--field); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; color: var(--ink-2); padding: 4px 10px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.note { font-size: 13px; color: var(--muted); margin-top: 10px; }
details.table { margin: 4px 4px 4px; font-size: 13px; color: var(--ink-2); }
details.table summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--border); font-size: 13px; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }

svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .axis { stroke: var(--axis); stroke-width: 1; }
svg .guide { stroke: var(--axis); stroke-width: 1; }
svg .tick { fill: var(--muted); font-size: 10px; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-variant-numeric: tabular-nums; }
svg path.s1 { fill: var(--s1); }
svg path.s2 { fill: var(--s2); }
svg path.ln { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .dot { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
svg .dot.hollow { fill: var(--surface); stroke: var(--s1); stroke-width: 2; }
svg .hit { fill: transparent; cursor: default; }
svg.spark { width: 72px; height: 22px; flex: none; }
svg.spark polyline { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
svg.spark circle { fill: var(--s1); }
svg.cal { display: block; width: 100%; height: auto; }
svg .cell.empty { fill: var(--field); }
svg .cell.s1 { fill: var(--s1); }
svg .cell.s2 { fill: var(--s2); }
.tip {
  position: fixed; z-index: 50; display: none; pointer-events: none; max-width: 260px; white-space: pre-line;
  background: var(--raised); color: var(--ink); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.mv-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: var(--ink); text-decoration: none; }
.mv-row .what { flex: 1; min-width: 0; }
.mv-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.mv-row .val small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }

/* ---------- plan ---------- */
.group { padding: 12px; }
.group .g-head { display: flex; gap: 6px; align-items: center; }
.group .g-head .n { width: 26px; text-align: center; color: var(--muted); font-weight: 700; }
.group .g-head input { font-weight: 650; }
.item { display: grid; grid-template-columns: 1fr 92px auto; gap: 6px; margin-top: 6px; align-items: center; }
.item input { min-height: 40px; padding: 8px 10px; font-size: 15px; }
.mini { border: 0; background: none; color: var(--muted); font-size: 16px; min-width: 32px; min-height: 36px; cursor: pointer; border-radius: 8px; }
.mini:disabled { opacity: 0.3; }
.mv-meta { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.mv-meta .what { flex: 1; min-width: 0; font-size: 15px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid label { display: block; font-size: 13px; color: var(--ink-2); }
.form-grid label input, .form-grid label select { margin-top: 4px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- sheets & sign-in ---------- */
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 80dvh; overflow: auto; }
.sheet h3 { font-size: 17px; margin-bottom: 12px; }
.sheet .list { margin-bottom: 12px; }
.sheet .list button { all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; cursor: pointer; }
.signin { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px; text-align: center; padding: 24px 8px; }
.signin h1 { font-size: 40px; font-weight: 800; }
.signin .gbtn { display: flex; justify-content: center; min-height: 44px; }
.signin form { display: flex; gap: 8px; max-width: 360px; margin: 0 auto; width: 100%; }
.err { color: var(--danger); font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

/* ---------- rest timer ---------- */
#rest { position: fixed; left: 0; right: 0; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 7; display: flex; justify-content: center; padding: 0 16px; pointer-events: none; }
#rest[hidden] { display: none; }
body.tabs-on #rest { bottom: calc(72px + env(safe-area-inset-bottom)); }
.rest-bar {
  pointer-events: auto; position: relative; overflow: hidden; width: 100%; max-width: 528px;
  display: flex; align-items: baseline; gap: 8px; padding: 12px 10px 12px 16px;
  border-radius: 14px; background: var(--raised); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.rest-fill { position: absolute; left: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 18%, transparent); transition: width 0.25s linear; }
.rest-label, .rest-time, .rest-of, .rest-x { position: relative; }
.rest-label { font-weight: 600; color: var(--ink-2); }
.rest-time { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rest-of { color: var(--muted); font-variant-numeric: tabular-nums; }
.rest-x { margin-left: auto; align-self: center; border: 0; background: none; color: var(--muted); font-size: 18px; padding: 4px 8px; cursor: pointer; }
.rest.over .rest-bar { background: #c62f2f; border-color: transparent; color: #fff; animation: pulse 0.9s ease-in-out infinite alternate; }
.rest.over .rest-label, .rest.over .rest-of, .rest.over .rest-x { color: #fff; }
.rest.over .rest-fill { display: none; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.8; } }
@media (prefers-reduced-motion: reduce) { .rest.over .rest-bar { animation: none; } }

/* ---------- desktop ---------- */
@media (hover: hover) {
  .btn:hover { filter: brightness(1.06); }
  .list a:hover, .sheet .list button:hover, .chip:hover, .set:hover { background: var(--field); }
  .tabs a:hover { color: var(--ink); }
}
@media (min-width: 900px) {
  #app { max-width: 720px; }
  .tabs a { max-width: 200px; }
  .hero h1 { font-size: 38px; }
}

/* ---------- record of the workout ---------- */
.rec-line { margin-top: 8px; font-size: 14px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record { margin-bottom: 12px; }
.rec-top { display: flex; gap: 14px; align-items: center; }
.cover { width: 92px; height: 92px; flex: none; border-radius: 8px; object-fit: cover; background: var(--field); }
.cover.blank { display: grid; place-items: center; font-size: 32px; color: var(--muted); }
.rec-meta { min-width: 0; }
.rec-meta .eyebrow { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.rec-artist { font-weight: 700; font-size: 17px; margin-top: 2px; }
.rec-title { font-style: italic; font-size: 16px; color: var(--ink-2); }
.rec-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.rec-links .chip { text-decoration: none; }
.chip.ghost { background: none; color: var(--muted); }
.writeup { margin-top: 12px; font-size: 15px; line-height: 1.5; color: var(--ink-2); max-height: 6em; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 45%, transparent); mask-image: linear-gradient(to bottom, #000 45%, transparent); }
.writeup.open { max-height: none; -webkit-mask-image: none; mask-image: none; }
.writeup p + p { margin-top: 10px; }
.writeup .by { font-size: 13px; color: var(--muted); font-style: italic; }
.more { border: 0; background: none; color: var(--accent); font: inherit; font-size: 14px; font-weight: 600; padding: 6px 0 0; cursor: pointer; }
@media (min-width: 900px) { .cover { width: 120px; height: 120px; } }
