/* ============================================================
   Gym Log — mobile-first stylesheet
   Palette slots come from the validated data-viz reference set.
   Light values live on bare :root; dark values are redefined
   under both the OS media query and an explicit [data-theme].
   ============================================================ */

:root {
  color-scheme: light;

  /* surfaces & ink */
  --plane:        #ffffff;
  --surface:      #ffffff;
  --surface-2:    #f3f3f1;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;
  --hairline:     #e1e0d9;
  --axis:         #c3c2b7;
  --ring:         rgba(11, 11, 11, .10);

  /* categorical slots (validated: all-pairs PASS, light) */
  --series-1:     #2a78d6;
  --series-2:     #eb6834;
  --series-3:     #1baf7a;

  /* sequential blue ramp, for the consistency heatmap */
  --seq-0:        #f2f1ed;
  --seq-1:        #b7d3f6;
  --seq-2:        #6da7ec;
  --seq-3:        #2a78d6;
  --seq-4:        #184f95;

  --tabbar:       #2a78d6;

  /* stage behind the muscle maps (Analysis + PR) */
  --stage:        #ffffff;
  --stage-sil-2d: #2a2c37;   /* the artwork's own outline colour */
  --stage-sil:    #3b4354;
  --stage-dim:    #dfe4eb;   /* greyed-out muscles when a PR group is focused */
  --stage-glow:   1;
  --stage-ink:    #5b6475;

  /* status */
  --good:         #0ca30c;
  --good-text:    #006300;
  --critical:     #d03b3b;
  --warning:      #fab219;

  --radius:       14px;
  --radius-sm:    9px;
  --tap:          48px;

  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --tabbar:     #1c5cab;
    --plane:      #0d0d0d;
    --surface:    #1a1a19;
    --surface-2:  #232322;
    --ink:        #ffffff;
    --ink-2:      #c3c2b7;
    --ink-muted:  #898781;
    --hairline:   #2c2c2a;
    --axis:       #383835;
    --ring:       rgba(255, 255, 255, .10);

    --series-1:   #3987e5;
    --series-2:   #d95926;
    --series-3:   #199e70;

    --seq-0:      #232322;
    --seq-1:      #184f95;
    --seq-2:      #256abf;
    --seq-3:      #3987e5;
    --seq-4:      #86b6ef;

    --good-text:  #0ca30c;

    --stage:        #14171d;
    --stage-sil-2d: #4b5468;
    --stage-sil:    #4b5468;
    --stage-dim:    #2b313c;
    --stage-glow:   .3;
    --stage-ink:    #a9b2c3;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --tabbar:     #1c5cab;
  --plane:      #0d0d0d;
  --surface:    #1a1a19;
  --surface-2:  #232322;
  --ink:        #ffffff;
  --ink-2:      #c3c2b7;
  --ink-muted:  #898781;
  --hairline:   #2c2c2a;
  --axis:       #383835;
  --ring:       rgba(255, 255, 255, .10);

  --series-1:   #3987e5;
  --series-2:   #d95926;
  --series-3:   #199e70;

  --seq-0:      #232322;
  --seq-1:      #184f95;
  --seq-2:      #256abf;
  --seq-3:      #3987e5;
  --seq-4:      #86b6ef;

  --good-text:  #0ca30c;

  --stage:        #14171d;
  --stage-sil-2d: #4b5468;
  --stage-sil:    #4b5468;
  --stage-dim:    #2b313c;
  --stage-glow:   .3;
  --stage-ink:    #a9b2c3;
}

/* ───────────────────────── base ───────────────────────── */

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

html, body { overscroll-behavior-y: none; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--plane);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 17px; line-height: 1.2; }
h2 { font-size: 15px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); margin: 22px 0 8px; }

button { font-family: inherit; font-size: 16px; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ───────────────────────── chrome ───────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: calc(var(--safe-top) + 4px) 16px 4px;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-left { display: flex; align-items: center; gap: 2px; min-width: 0; }
.topbar-left h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#btn-back { min-width: 36px; height: 36px; margin-left: -10px; color: var(--series-1); }
#btn-back svg { display: block; }
#btn-settings { min-width: 36px; height: 36px; margin-right: -6px; color: var(--ink-muted); }
#btn-settings svg { width: 18px; height: 18px; }

/* ⋯ menu in the top bar (session detail) */
#btn-more { min-width: 36px; height: 36px; color: var(--series-1); }
.menu-sep { height: 1px; margin: 4px 6px; background: var(--hairline); }
.sort-menu button.menu-danger { color: var(--critical); font-weight: 600; }

/* session list: today's start card, week headers with a target meter, compact two-line rows */
/* solid blue call to action: clear and unmistakable */
.sess-start {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 14px; margin-bottom: 14px; cursor: pointer;
  border: 0; border-radius: var(--radius);
  background: var(--series-1); box-shadow: 0 6px 16px rgba(42, 120, 214, .25);
  color: #fff; font-size: 16px; font-weight: 650; text-align: left;
}
.sess-start:active { filter: brightness(.93); }
.sess-start-plus {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: rgba(255, 255, 255, .22); color: #fff; font-size: 20px; font-weight: 600; line-height: 1;
}
.sess-week {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 14px 2px 8px; font-size: 12px; color: var(--ink-muted);
}
.sess-week b { color: var(--ink); font-weight: 700; margin-right: 4px; }
.sess-week-meter { display: inline-flex; gap: 4px; flex: none; }
.sess-week-meter i { width: 8px; height: 8px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--hairline); }
.sess-week-meter i.on { background: var(--series-1); border-color: var(--series-1); }
.sess-week-meter.met i.on { background: var(--good); border-color: var(--good); }
.sess-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 10px 14px 10px 10px; margin-bottom: 8px;
  color: var(--ink);
}
.sess-item:active { background: var(--surface-2); }
.sess-day {
  width: 44px; flex: none; padding: 5px 0; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.05;
  background: var(--surface-2);
}
.sess-day span { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); }
.sess-day b { font-size: 18px; font-weight: 700; }
.sess-day.today { background: var(--series-1); }
.sess-day.today span, .sess-day.today b { color: #fff; }
.sess-main { flex: 1; min-width: 0; }
.sess-title { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.sess-pr { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; color: #b8860b; }
.sess-sub { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 12px; color: var(--ink-muted); white-space: nowrap; overflow: hidden; font-variant-numeric: tabular-nums; }
.sess-dots { display: inline-flex; align-items: center; gap: 3px; flex: none; }
.sess-dots em { font-style: normal; font-size: 11px; font-weight: 650; color: var(--ink-muted); margin-left: 1px; }
.sess-dots i { width: 9px; height: 9px; border-radius: 50%; }
.sess-vol { flex: none; text-align: right; font-size: 13px; font-weight: 650; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* rest timer: a small ring above the tab bar while you rest */
.rest-timer {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 46;
  bottom: calc(var(--safe-bottom) + 70px);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 6px; border: 0; border-radius: 999px; cursor: pointer;
  background: var(--ink); color: var(--plane);
  font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .25);
}
.rest-timer[hidden] { display: none; }
.rest-timer svg { width: 30px; height: 30px; transform: rotate(-90deg); }
.rest-timer .rt-track { fill: none; stroke: color-mix(in srgb, var(--plane) 25%, transparent); stroke-width: 4; }
.rest-timer .rt-fill { fill: none; stroke: var(--series-1); stroke-width: 4; stroke-linecap: round; transition: stroke-dasharray .25s linear; }
.rest-timer.done { background: var(--good); color: #fff; animation: restPulse .8s ease-in-out 3; }
.rest-timer.done .rt-track { stroke: rgba(255, 255, 255, .35); }
@keyframes restPulse { 50% { transform: translateX(-50%) scale(1.08); } }

/* static date header in the editor for today's session */
.edit-date-static { text-align: center; font-weight: 650; padding: 6px 0 12px; font-size: 17px; }
.ex-card .btn-done { margin: 0 14px 14px; width: calc(100% - 28px); }

/* read-mode session detail */
.session-stats.session-stats-blue {
  background: var(--series-1); border-color: var(--series-1);
  color: rgba(255, 255, 255, .82); justify-content: space-between;
  box-shadow: 0 6px 16px rgba(42, 120, 214, .25);
}
.session-stats.session-stats-blue b { color: #fff; }

/* key metrics of a session on one line */
#log-session-stats {
  flex-wrap: nowrap; white-space: nowrap; overflow: hidden;
  justify-content: space-between; gap: 8px; padding: 10px 14px;
  font-size: clamp(12px, 3.5vw, 14px);
}
#log-session-stats span { flex: none; }
.sort-menu-wrap { position: relative; }
/* variant used as a card title: dark ink, h2 size, menu opens under the left edge */
.sort-select-title { color: var(--ink); font-size: 15px; font-weight: 650; padding: 0; margin-left: 0; }
.sort-select-title::after { color: var(--series-1); opacity: 1; margin-left: 2px; }
.sort-menu-left { left: 0; right: auto; }
#card-bw-chart .card-head { margin-bottom: 0; }
.sort-select {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 36px; padding: 0 4px; border: 0; background: none;
  color: var(--series-1); font-weight: 600; font-size: 14px; cursor: pointer;
}
.sort-select #sort-label { display: inline-flex; align-items: center; gap: 3px; }
.sort-select svg { width: 20px; height: 20px; }
.sort-arrow { font-size: 15px; line-height: 1; }
.sort-opt { display: inline-flex; align-items: center; gap: 10px; }
.sort-ico { display: inline-flex; flex: none; color: var(--series-1); }
.sort-ico svg { width: 18px; height: 18px; }
.sort-select::after { content: "▾"; font-size: 12px; opacity: .7; transition: transform .15s; }
.sort-select[aria-expanded="true"]::after { transform: rotate(180deg); }
.sort-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  min-width: 228px; padding: 6px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .14);
  animation: fade .12s ease-out;
}
.sort-menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 40px; padding: 0 10px;
  border: 0; border-radius: 8px; background: none; text-align: left;
  font-size: 14px; font-weight: 500; color: var(--ink); cursor: pointer;
}
.sort-menu button:active { background: var(--surface-2); }
.sort-menu button.active { font-weight: 650; color: var(--series-1); }
.sort-check { visibility: hidden; font-weight: 700; }
.sort-menu button.active .sort-check { visibility: visible; }

/* session header: bold focus + regular "Session on <date>"; wraps to two lines when too long */
#screen-title.long { font-size: 15px; line-height: 1.2; white-space: normal; }
#screen-title.long .title-focus { font-weight: 700; white-space: nowrap; }
#screen-title.long .title-light { font-weight: 400; color: var(--ink-2); white-space: nowrap; }

.ex-card-read { position: relative; padding: 12px 14px 4px; cursor: pointer; }
.ex-card-read:active { background: var(--surface-2); }
/* small round toggle for a planned increase ("Rise") */
.rise-toggle {
  width: 30px; height: 30px; flex: none; padding: 0; cursor: pointer;
  display: grid; place-items: center; border-radius: 50%;
  border: 1.5px solid var(--hairline); background: transparent; color: var(--ink-muted);
}
.rise-toggle.active { border-color: #d4a017; background: #d4a017; color: #fff; }
.ex-pr { display: inline-flex; color: #b8860b; }
.ex-pr svg { width: 18px; height: 18px; }
.ex-trend { display: inline-flex; vertical-align: -2px; margin-left: 6px; }
.ex-trend.up { color: var(--good-text); }
.ex-trend.down { color: var(--critical); }
.ex-head-btns { display: flex; align-items: center; gap: 2px; flex: none; }
.gear-btn { color: var(--ink-muted); }
.gear-btn.active { color: var(--series-1); }
/* last time's sets as faint, tappable rows */
.set-row.set-ghost { opacity: .45; cursor: pointer; border-top-style: dashed; }
.set-row.set-ghost .set-idx { background: transparent; border: 1px dashed var(--axis); }
.set-row.set-ghost:active, .set-row.set-ghost.picked { opacity: .9; }
.set-row.set-ghost.picked .set-val { color: var(--series-1); }
/* line 1: small group chip + date/time top-left, pencil + Rise top-right */
.ex-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.ex-when { flex: none; margin: 0; }
.ex-chip {
  font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--chip-fg, var(--series-1));
  border: 1.5px solid var(--chip-fg, var(--series-1));
  background: transparent;
  padding: 1px 6px; border-radius: 999px; white-space: nowrap;
}
/* line 2: bold heading left, pencil + Rise right */
/* line 2: the heading owns the full card width; the buttons live only on line 1 */
.ex-row { display: block; }
.ex-row .ex-name { display: block; width: 100%; font-size: 16px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.ex-btns { flex: none; display: flex; align-items: center; gap: 6px; margin-left: auto; }
/* muscle-group colours */
.g-chest     { --chip-fg: #b3261e; --chip-bg: rgba(211, 59, 59, .13); }
.g-back      { --chip-fg: #1c5cab; --chip-bg: rgba(42, 120, 214, .13); }
.g-legs      { --chip-fg: #1b7a1b; --chip-bg: rgba(12, 163, 12, .14); }
.g-biceps    { --chip-fg: #5b3fc4; --chip-bg: rgba(112, 80, 220, .14); }
.g-triceps   { --chip-fg: #8a6200; --chip-bg: rgba(237, 161, 0, .20); }
.g-abs       { --chip-fg: #b5500f; --chip-bg: rgba(235, 104, 52, .15); }
.g-shoulders { --chip-fg: #0f766e; --chip-bg: rgba(20, 184, 166, .14); }
.g-forearms  { --chip-fg: #475569; --chip-bg: rgba(100, 116, 139, .15); }
:root[data-theme="dark"] .g-chest, :root[data-theme="dark"] .g-back, :root[data-theme="dark"] .g-legs,
:root[data-theme="dark"] .g-biceps, :root[data-theme="dark"] .g-triceps, :root[data-theme="dark"] .g-abs,
:root[data-theme="dark"] .g-shoulders, :root[data-theme="dark"] .g-forearms { filter: brightness(1.6) saturate(.9); }

.rise-btn {
  min-height: 30px; padding: 0 10px; flex: none;
  border: 1.5px solid var(--series-1); border-radius: 999px;
  background: transparent; color: var(--series-1);
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.rise-btn.active { background: var(--series-1); color: #fff; }
.ex-card.ex-card-rise {
  background: color-mix(in srgb, var(--series-1) 9%, var(--surface));
  border: 2px solid #d4a017;   /* golden edge marks a planned increase */
}
.ex-card-rise .ex-last, .ex-card-rise .step-btn, .ex-card-rise .set-idx { background: color-mix(in srgb, var(--series-1) 6%, var(--surface)); }
.ex-card-rise .read-row, .ex-card-rise .set-row { border-color: color-mix(in srgb, var(--series-1) 18%, var(--hairline)); }
.edit-btn {
  width: 30px; height: 30px; flex: none;
  border: 0; border-radius: 50%;
  background: var(--series-1); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.edit-btn:active { filter: brightness(.9); }
.ex-when { font-size: 12px; color: var(--ink-muted); margin-top: 3px; }
.read-rows { margin-top: 10px; }
.read-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}
.read-w { font-weight: 400; }
.read-reps { color: var(--ink-2); font-weight: 600; letter-spacing: .02em; }

.pill {
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--hairline); color: var(--ink-2);
  background: var(--surface);
}
.pill-synced  { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 40%, var(--hairline)); }
.pill-pending { color: var(--series-2); border-color: color-mix(in srgb, var(--series-2) 40%, var(--hairline)); }
.pill-local   { color: var(--ink-muted); }

.icon-btn {
  min-width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2);
  font-size: 20px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

#main {
  padding: 14px 16px calc(var(--safe-bottom) + 66px);
  max-width: 720px;
  margin: 0 auto;
}

.screen { display: none; }
.screen.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: var(--safe-bottom);
  background: var(--tabbar);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, .10);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 0 4px;
  border: 0; background: none; cursor: pointer;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  color: rgba(255, 255, 255, .62);
  transition: color .15s;
}
.tab-ico, .tab svg { width: 20px !important; height: 20px !important; flex: none; }
.tab.active { color: #fff; }
.tab.active .tab-ico { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .15)); }

/* ───────────────────────── buttons ───────────────────────── */

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--series-1); color: #fff; }
.btn-primary:active { filter: brightness(.92); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--hairline); }
.btn-ghost:active { background: var(--surface-2); }
.btn-block { width: 100%; margin-top: 10px; }
.btn-danger { color: var(--critical); }
.file-btn { cursor: pointer; }

.link-btn {
  border: 0; background: none; padding: 4px 2px;
  font-size: 13px; font-weight: 600; color: var(--series-1); cursor: pointer;
}

.chip {
  min-height: 36px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--hairline);
  background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--series-1); border-color: var(--series-1); color: #fff; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ───────────────────────── cards ───────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px;
}

.hint { margin: 6px 0 0; font-size: 13px; color: var(--ink-muted); }
.chart-note { margin: 8px 0 0; font-size: 12px; color: var(--ink-muted); }

.empty-state { text-align: center; padding: 30px 10px; color: var(--ink-muted); }
.empty-title { margin: 0; font-weight: 600; color: var(--ink-2); }
.empty-sub { margin: 4px 0 0; font-size: 14px; }

/* ───────────────────────── log screen ───────────────────────── */

.date-strip {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin-bottom: 12px;
}
.date-label {
  flex: 1; min-height: 40px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-weight: 650; cursor: pointer;
}
.visually-hidden-input {
  position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}

.session-stats {
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 12px;
  border: 1px solid var(--hairline); border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px; color: var(--ink-2);
}
.session-stats b { color: var(--ink); font-weight: 650; }

.ex-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.ex-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; padding: 12px 14px 8px;
}
.ex-name { font-weight: 650; font-size: 16px; }
.ex-group { font-size: 12px; color: var(--ink-muted); }
.ex-last {
  margin: 0 14px 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px; color: var(--ink-2);
}
.ex-last b { color: var(--ink); font-weight: 650; }
.ex-settings {
  margin: 0 14px 10px; width: calc(100% - 28px);
  min-height: 38px; padding: 0 10px;
  border: 1px dashed var(--hairline); border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-2); font-size: 13px;
  font-family: inherit;
}

.set-list { list-style: none; margin: 0; padding: 0 14px; }
.set-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}
.set-idx {
  width: 24px; height: 24px; flex: none;
  display: grid; place-items: center;
  border-radius: 7px; background: var(--surface-2);
  font-size: 12px; font-weight: 650; color: var(--ink-muted);
}
.set-val { flex: 1; font-weight: 600; }
.set-vol { font-size: 12px; color: var(--ink-muted); }
.set-pr {
  font-size: 11px; font-weight: 700; letter-spacing: .04em;
  color: var(--good-text);
}
.set-del {
  border: 0; background: none; color: var(--ink-muted);
  font-size: 20px; width: 34px; height: 34px; cursor: pointer;
}

.set-entry { display: flex; gap: 8px; align-items: flex-end; padding: 12px 14px 14px; flex-wrap: wrap; }
.entry-field { flex: 1 1 120px; min-width: 120px; }
.field-label {
  display: block; font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-muted); margin-bottom: 5px;
}

.stepper {
  display: flex; align-items: center; gap: 6px;
}
.step-btn {
  width: 42px; height: 46px; flex: none;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
  font-size: 22px; font-weight: 600; cursor: pointer;
}
.step-btn:active { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.step-input {
  flex: 1; min-width: 0; width: 100%; height: 46px;
  text-align: center;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 17px; font-weight: 650; font-family: inherit;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.step-input::-webkit-outer-spin-button,
.step-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit { font-size: 13px; color: var(--ink-muted); font-weight: 600; }

.btn-addset { flex: 1 1 100%; }

.per-side-note { font-size: 12px; color: var(--ink-muted); padding: 0 14px 10px; }

/* ───────────────────────── body screen ───────────────────────── */

.card-entry .stepper { margin-bottom: 10px; }
.entry-row { display: flex; gap: 8px; align-items: center; }
.date-input, .text-input {
  flex: 1; min-width: 0; height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 16px; font-family: inherit;
}

.text-input-block { display: block; width: 100%; margin-bottom: 14px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.field-pair .date-input { width: 100%; }
/* date fields show the app's own format ("Today", "Tue, 4 Nov"); the native input lies invisibly on top so a tap opens the system picker */
.date-wrap { position: relative; display: flex; align-items: center; }
.date-wrap .date-face { pointer-events: none; font-weight: 600; }
.date-wrap input[type="date"] {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0;
  border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-appearance: none; appearance: none;
}
.form-error { color: var(--critical); }

.tile-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 10px; margin-bottom: 14px;
}
.tile {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--radius); padding: 12px;
}
/* key numbers on blue, like the Scores area in Analysis; the tiles stay white on top */
.tile-row-blue {
  padding: 12px; border-radius: var(--radius);
  background: var(--series-1); box-shadow: 0 6px 16px rgba(42, 120, 214, .25);
}
.tile-row-blue:empty { display: none; }
.tile-row-blue .tile { border: 0; border-radius: var(--radius-sm); min-width: 0; }
/* sub line stays on one line: shrinks with the screen (≈10px at 320px, 11px from ~380px) */
.tile-row-blue .tile-sub {
  font-size: clamp(9.5px, 2.9vw, 11px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-label {
  font-size: 11px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .05em; color: var(--ink-muted);
}
.tile-value { font-size: 22px; font-weight: 680; letter-spacing: -.02em; margin-top: 2px; white-space: nowrap; }
.tile-label { white-space: nowrap; }
.tile-value.gain { color: var(--good-text); }
.tile-value.loss { color: var(--critical); }
.tile-sub { font-size: 12px; color: var(--ink-muted); }
.tile-sub.up { color: var(--series-2); }
.tile-sub.down { color: var(--good-text); }

.period-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 0; }
.period-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--hairline);
  border-radius: var(--radius-sm); background: var(--surface-2);
  font-size: 14px;
}
.period-row .period-dates { font-size: 12px; color: var(--ink-muted); }
.period-row .grow { flex: 1; }

/* ───────────────────────── charts ───────────────────────── */

.chart-box { position: relative; height: 240px; }
.chart-box-tall { height: 280px; }
.chart-box-sm { height: 170px; }

.select {
  width: 100%; height: var(--tap); margin-bottom: 12px;
  padding: 0 12px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 16px; font-family: inherit;
}

.table-view { margin-top: 12px; overflow-x: auto; }
#table-periods { margin-top: 4px; overflow: visible; }
.table-view table { border-collapse: collapse; width: 100%; font-size: 13px; }
.table-view th, .table-view td {
  text-align: right; padding: 6px 8px;
  border-bottom: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.table-view th { color: var(--ink-muted); font-weight: 650; }
.table-view th:first-child, .table-view td:first-child { text-align: left; }
.table-view td.td-del { padding: 0 0 0 6px; width: 36px; }
.del-btn {
  width: 36px; height: 34px; border: 0; background: none; cursor: pointer;
  color: var(--ink-muted); display: grid; place-items: center; border-radius: 8px;
}
.del-btn:active { color: var(--critical); background: var(--surface-2); }

/* ───────────────────────── analysis: summary + muscle map ───────────────────────── */

/* Area 1 — scores on blue (same treatment as the session summary box); tiles and details sit on it in white */
.scores-card {
  background: var(--series-1); border-color: var(--series-1);
  box-shadow: 0 6px 16px rgba(42, 120, 214, .25);
}
.scores-card .card-head h2 { color: #fff; }
.scores-window { font-size: 13px; color: rgba(255, 255, 255, .82); }
.score-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.score-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px; border-radius: var(--radius-sm);
  border: 0; background: var(--surface); color: var(--ink); cursor: pointer;
  font: inherit;
}
.score-tile.active { box-shadow: 0 0 0 3px rgba(255, 255, 255, .55); }

/* Area 2 — the period switch stands alone as the heading of everything below */
.period-head {
  margin: 22px 0 10px; padding-top: 14px;
  border-top: 1px solid var(--hairline);
}
.period-title { font-size: 19px; font-weight: 700; }
.score-ring { width: 64px; height: 64px; display: block; }
.score-ring-track { fill: none; stroke: var(--surface-2); stroke-width: 6; }
/* no data yet: dashed grey ring, muted dash instead of a number */
.score-tile.empty .score-ring-track { stroke: var(--hairline); stroke-dasharray: 4 5; }
.score-tile.empty .score-ring-num { fill: var(--ink-muted); }
.score-tile.empty .score-label { color: var(--ink-muted); }
.score-ring-fill { fill: none; stroke-width: 6; stroke-linecap: round; }
.score-ring-num { font-size: 19px; font-weight: 700; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; }
.score-label { font-size: 12px; font-weight: 650; color: var(--ink-2); }
.score-detail { margin-top: 10px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface); }
.score-part { margin-bottom: 10px; }
.score-part-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.score-part-head em { font-style: normal; font-weight: 500; color: var(--ink-muted); font-size: 11px; margin-left: 4px; }
.score-bar { height: 6px; border-radius: 999px; background: var(--surface-2); margin: 4px 0; overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 999px; }
.score-part p { margin: 0; font-size: 12px; color: var(--ink-2); line-height: 1.4; }
.score-note { margin: 0 0 8px; font-size: 12px; color: var(--ink-2); }
.score-tip {
  margin: 4px 0 0; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); font-size: 13px; line-height: 1.4; color: var(--ink);
}
.score-tip ul { margin: 4px 0 0; padding-left: 18px; }
.score-tip li + li { margin-top: 3px; }
.days-filter .chip { min-width: 40px; padding: 0 10px; }
.filter-row.disabled { opacity: .4; pointer-events: none; }
.goal-stepper { max-width: 320px; }
.goal-stepper .step-input::placeholder { color: var(--ink-muted); font-weight: 500; }


.body2d-status {
  position: absolute; inset: 0; display: grid; place-items: center; margin: 0;
  color: #7f93b3; font-size: 13px; font-weight: 600; pointer-events: none;
}
/* white stage in both themes; the selection outline is blue so it never reads as heat */
.body2d { border-radius: var(--radius-sm); background: var(--stage); padding: 8px 4px 6px; }
.body2d svg [id*="-silhouette-"] path { fill: var(--stage-sil-2d); }
.body2d-svg { position: relative; min-height: 200px; }
.body2d-svg svg {
  display: block; width: 100%; height: auto;
  --muscle-active: #2f5fd0; --muscle-hover: #b4bccb; --muscle-focus: #2f5fd0;
}
.body2d-info { margin: 6px 0 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--stage-ink); }
.body2d-info:empty { display: none; }
.credits a { color: inherit; text-decoration: underline; }
.body-legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 11px; color: var(--ink-muted); }
.body-legend-bar {
  flex: 1; height: 8px; border-radius: 999px;
  background: linear-gradient(90deg, #cfd9e6 0%, #fff0a8 6%, #ffd23f 25%, #ff9f1c 44%, #f2542d 63%, #c81d25 82%, #7a0b2e 100%);
}
/* two-option switch in a card head (muscle map colour scale) */
.seg { display: inline-flex; padding: 2px; border-radius: 999px; background: var(--surface-2); flex-shrink: 0; }
.seg button {
  min-height: 30px; padding: 0 12px; border: 0; border-radius: 999px;
  background: none; color: var(--ink-2); font-size: 12px; font-weight: 600; cursor: pointer;
}
.seg button.active { background: var(--series-1); color: #fff; }
.seg-row { margin-bottom: 8px; }
/* two columns of rows: name + value on top, a slim bar in the map colour below; tap = highlight on the map */
.body-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; margin-top: 12px; }
.body-group {
  display: flex; flex-direction: column; gap: 5px; min-width: 0;
  padding: 7px 10px 8px; border: 0; border-radius: 10px; background: var(--surface-2);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.body-group.active { box-shadow: inset 0 0 0 1.5px var(--series-1); }
.bg-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.bg-name { font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.bg-top b { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bg-bar { height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--ink) 8%, transparent); overflow: hidden; }
.bg-bar i { display: block; height: 100%; border-radius: 3px; min-width: 0; }
/* map: a highlighted group stays in colour, everything else fades */
.body2d-svg svg [data-selectable] path { transition: opacity .2s ease; }
.body2d-svg svg [data-dim] path { opacity: .18; }

/* ───────────────────────── PR tab ───────────────────────── */

/* The figure fills the tab; a tapped group zooms in and its records slide up over the lower part. */
/* The PR tab is pinned between the top bar and the tab bar (their real heights are measured
   by ui.js into --topbar-h / --tabbar-h). No viewport units: iOS home-screen apps size those
   differently from Safari, which pushed the tab bar up and left a white strip below it. */
#screen-pr.active {
  position: fixed; left: 0; right: 0; z-index: 1;
  top: var(--topbar-h, 54px); bottom: var(--tabbar-h, 52px);
  max-width: 720px; margin: 0 auto; padding: 12px 16px;
  display: flex; flex-direction: column;
}
html.no-page-scroll, html.no-page-scroll body { overflow: hidden; }
.pr-stage {
  position: relative; overflow: hidden;
  flex: 1 1 auto; min-height: 0;
  touch-action: pan-y;                       /* horizontal swipes belong to the figure */
  border-radius: var(--radius);
  background: var(--stage);                  /* white in light mode, deep slate in dark mode */
}
.pr-map { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; }
.pr-map svg { display: block; width: 100%; height: 100%; cursor: pointer; touch-action: pan-y; }
/* page dots: which side is showing */
.pr-dots { position: absolute; left: 0; right: 0; bottom: 10px; display: flex; justify-content: center; gap: 7px; pointer-events: none; }
.pr-dots i { width: 7px; height: 7px; border-radius: 50%; background: #cfd6e0; transition: background .2s, width .2s; }
.pr-dots i.on { background: var(--series-1); width: 16px; border-radius: 4px; }

/* softer slate outline instead of near-black */
.pr-map svg [id*="-silhouette-"] path { fill: var(--stage-sil); }
/* every group in its label colour, shaded light-to-dark (gradients and --grp are set by prmap.js) */
.pr-map svg path { transition: fill .25s ease, opacity .25s ease; }
.pr-map svg [data-group] path { fill: var(--grad, var(--grp)); }
/* a record in the last two weeks: soft pulsing glow; no record for weeks: faded */
.pr-map svg [data-fresh] { animation: prGlow 2.6s ease-in-out infinite; }
@keyframes prGlow {
  0%, 100% { filter: drop-shadow(0 0 1.5px var(--grp)); }
  50%      { filter: drop-shadow(0 0 7px var(--grp)) brightness(1.08); }
}
.pr-map svg [data-stale] { filter: saturate(.4) brightness(1.12); }
/* first visit: a light wave runs down the body (delays set per muscle by prmap.js) */
.pr-map.hint-wave svg [data-group] { animation: prWave .55s ease-in-out var(--wave-delay, 0ms) both; }
@keyframes prWave { 0%, 100% { filter: none; } 45% { filter: brightness(1.45) saturate(1.1); } }

/* focused: the body greys out, the chosen group keeps its colour */
.pr-map .pr-deco { transition: opacity .25s ease; }
.pr-map .pr-glow { opacity: var(--stage-glow); }
.pr-map.focused .pr-deco { opacity: .35; }
.pr-map.focused svg [id*="-silhouette-"], .pr-map.focused svg [id*="-silhouette-"] path,
.pr-map.focused svg [data-selectable="false"] path { opacity: .28; }
.pr-map.focused svg [data-selectable="true"]:not([data-focus]) path { fill: var(--stage-dim); }
.pr-map.focused svg [data-group] { animation: none; filter: none; }

/* frosted-glass sheet; drag the grabber down to close */
.pr-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  height: 70%; display: flex; flex-direction: column;     /* keep in sync with PANEL in prmap.js */
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.5); backdrop-filter: blur(18px) saturate(1.5);
  border-top: 1px solid color-mix(in srgb, var(--hairline) 70%, transparent);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 30px rgba(20, 30, 50, .14);
  transform: translateY(105%); transition: transform .34s cubic-bezier(.2, .8, .2, 1);
}
.pr-panel.open { transform: none; }
.pr-panel.dragging { transition: none; }
.pr-panel-head { padding: 6px 14px 6px; touch-action: none; cursor: grab; }
.pr-grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--axis); margin: 2px auto 8px; }
.pr-panel-title { display: flex; align-items: center; gap: 8px; }
.pr-panel-title .ex-chip { font-size: 12px; padding: 3px 10px; }
.pr-panel-count { font-size: 12px; color: var(--ink-muted); }
.pr-panel .pr-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 14px 12px; }
.pr-list { padding: 0 0 4px; }
/* one record per row: group-coloured accent, name (+ rise arrow), record */
.pr-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 10px 10px 12px; margin-top: 6px;
  border-radius: 12px; background: var(--surface);
  box-shadow: inset 3px 0 0 var(--grp, var(--series-1)), 0 1px 2px rgba(0, 0, 0, .05);
}
.pr-item { cursor: pointer; }
.pr-chev { flex: none; color: var(--ink-muted); font-size: 18px; transition: transform .2s; margin-left: -4px; }
.pr-ex.open .pr-chev { transform: rotate(90deg); }
.pr-ex.open .pr-item { border-radius: 12px 12px 0 0; }
.pr-ex-chart {
  background: var(--surface); border-radius: 0 0 12px 12px; padding: 4px 8px 8px;
  box-shadow: inset 3px 0 0 var(--grp, var(--series-1)), 0 1px 2px rgba(0, 0, 0, .05);
}
.pr-item-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.pr-item-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-rise { flex: none; color: #d4a017; }
.pr-item-val { text-align: right; flex: none; font-variant-numeric: tabular-nums; min-width: 70px; }
.pr-item-val b { display: block; font-size: 15px; font-weight: 650; }
.pr-item-val span { font-size: 12px; color: var(--ink-2); }
.pr-sep { font-style: normal; color: var(--axis); margin: 0 5px; }
.pr-item-val.pending b { color: var(--ink-muted); font-weight: 500; }

/* ───────────────────────── PR feed ───────────────────────── */

.pr-feed { display: flex; flex-direction: column; }
/* one line per record: exercise | weight | gain (no header row) */
.pr-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto 52px; align-items: baseline; column-gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--hairline);
  font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.pr-feed .pr-row:first-child { border-top: 0; }
.pr-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.pr-val { font-weight: 650; text-align: right; }
.pr-gain { color: var(--good-text); font-weight: 600; text-align: right; }
.pr-gain-new { color: var(--ink-muted); font-weight: 500; }

/* ───────────────────────── heatmap ───────────────────────── */

.heatmap {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 3px; overflow-x: auto; padding-bottom: 4px;
}
.hm-cell {
  width: 13px; height: 13px; border-radius: 3px;
  background: var(--seq-0);
}
.hm-0 { background: var(--seq-0); }
.hm-1 { background: var(--seq-1); }
.hm-2 { background: var(--seq-2); }
.hm-3 { background: var(--seq-3); }
.hm-4 { background: var(--seq-4); }
.heatmap-legend {
  display: flex; align-items: center; gap: 4px;
  margin-top: 10px; font-size: 11px; color: var(--ink-muted);
}
.hm-legend-label { margin: 0 4px; }

/* ───────────────────────── sheets & toast ───────────────────────── */

.backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(2px);
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  max-height: 86vh; display: flex; flex-direction: column;
  padding: 10px 16px calc(var(--safe-bottom) + 16px);
  background: var(--plane);
  border-top-left-radius: 18px; border-top-right-radius: 18px;
  border-top: 1px solid var(--hairline);
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0 10px;
}
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.search {
  width: 100%; height: var(--tap); margin-bottom: 10px;
  padding: 0 12px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  font-size: 16px; font-family: inherit;
}
.ex-list { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.ex-group-head {
  position: sticky; top: 0;
  padding: 8px 2px 4px;
  background: var(--plane);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-muted);
}
.ex-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; width: 100%;
  min-height: var(--tap); padding: 8px 12px; margin-bottom: 6px;
  border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  text-align: left; cursor: pointer;
}
.ex-item:active { background: var(--surface-2); }
.ex-item-sub { font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 66px); z-index: 90;
  padding: 10px 16px; border-radius: 999px;
  background: var(--ink); color: var(--plane);
  font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  animation: fade .18s ease-out;
}
