/* ==========================================================================
   Reusable components
   ========================================================================== */

/* --- Header -------------------------------------------------------------- */

.pagehead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0 18px;
}
.pagehead__sub { font-size: 13px; color: var(--text-2); margin-bottom: 3px; }

/* --- Card ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--line);
  padding: 16px;
}
.card--flush { padding: 0; overflow: hidden; }
.card + .card { margin-top: 12px; }

.section { margin-top: 26px; }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 0 2px;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 640;
  background: var(--surface-2);
  color: var(--text);
  transition: transform var(--fast) var(--ease), background var(--fast) var(--ease),
    opacity var(--fast) var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }

.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:active { background: var(--accent-press); }
.btn--ghost { background: transparent; color: var(--accent); min-height: 40px; padding: 0 10px; }
.btn--danger { background: transparent; color: var(--danger); }
.btn--block { display: flex; width: 100%; }
.btn--lg { min-height: 58px; font-size: 17px; border-radius: var(--r-lg); }

/* The hero CTA */
.cta {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 66px;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 18px;
  font-weight: 750;
  letter-spacing: 0.06em;
  box-shadow: 0 8px 22px var(--accent-soft);
  transition: transform var(--fast) var(--ease), background var(--fast) var(--ease);
}
.cta:active { transform: scale(0.975); background: var(--accent-press); }
.cta__icon { width: 20px; height: 20px; }

/* --- Bottom navigation --------------------------------------------------- */

.nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 560px;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--nav-h);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: color var(--fast) var(--ease);
}
.nav__item svg { width: 24px; height: 24px; }
.nav__item[aria-current="page"] { color: var(--accent); }
.nav__item:active { opacity: 0.55; }
.nav__dot {
  position: absolute;
  top: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* --- Streak -------------------------------------------------------------- */

.streak {
  display: flex;
  align-items: center;
  gap: 14px;
}
.streak__flame {
  width: 54px; height: 54px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--flame) 14%, transparent);
  font-size: 27px;
}
.streak__n { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.streak__unit { font-size: 15px; font-weight: 620; color: var(--text-2); margin-left: 6px; }
.streak__rule { font-size: 13px; color: var(--text-2); margin-top: 6px; line-height: 1.35; }

.weekgoal { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.weekgoal__top { display: flex; align-items: baseline; justify-content: space-between; }
.weekgoal__val { font-size: 14px; font-weight: 680; }
.weekdots { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 12px; }
.weekdot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.weekdot__label { font-size: 10px; font-weight: 620; color: var(--text-3); }
.weekdot__bead {
  width: 100%;
  max-width: 34px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1.5px solid var(--line);
  display: grid; place-items: center;
  color: var(--text-3);
  transition: transform var(--med) var(--ease), background var(--med) var(--ease);
}
.weekdot__bead svg { width: 15px; height: 15px; }
.weekdot--done .weekdot__bead {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}
.weekdot--today .weekdot__bead { border-color: var(--accent); border-width: 2px; }
.weekdot--today .weekdot__label { color: var(--accent); }

/* --- Heatmap ------------------------------------------------------------- */

.heat { }
.heat__scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.heat__grid { display: flex; gap: 4px; width: max-content; }
.heat__col { display: grid; grid-template-rows: repeat(7, 1fr); gap: 4px; }
.heat__cell {
  width: 13px; height: 13px;
  border-radius: 3.5px;
  background: var(--heat-0);
}
.heat__cell[data-lvl="1"] { background: var(--heat-1); }
.heat__cell[data-lvl="2"] { background: var(--heat-2); }
.heat__cell[data-lvl="3"] { background: var(--heat-3); }
.heat__cell[data-lvl="4"] { background: var(--heat-4); }
.heat__cell--today { box-shadow: 0 0 0 1.5px var(--text); }
.heat__cell--future { opacity: 0.25; }
.heat__months {
  display: flex;
  gap: 4px;
  width: max-content;
  margin-bottom: 6px;
  font-size: 10px;
  font-weight: 620;
  color: var(--text-3);
}
.heat__month { width: 13px; white-space: nowrap; }
.heat__legend {
  display: flex; align-items: center; gap: 5px;
  margin-top: 12px;
  font-size: 11px; color: var(--text-3);
}
.heat__legend .heat__cell { width: 11px; height: 11px; }

/* --- Chips (muscle selection) -------------------------------------------- */

.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 14px;
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1.5px solid var(--line);
  font-size: 16px;
  font-weight: 620;
  transition: transform var(--fast) var(--ease), border-color var(--fast) var(--ease),
    background var(--fast) var(--ease);
}
.chip:active { transform: scale(0.97); }
.chip__icon { width: 26px; height: 26px; color: var(--text-3); flex: 0 0 auto; }
.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.chip[aria-pressed="true"] .chip__icon { color: var(--accent); }
.chip[disabled] { opacity: 0.38; pointer-events: none; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: 13px; font-weight: 620; color: var(--text-2);
}
.pill--accent { background: var(--accent-soft); color: var(--accent); }
.pill__x { width: 14px; height: 14px; opacity: 0.7; }

/* --- Search -------------------------------------------------------------- */

.search {
  display: flex; align-items: center; gap: 8px;
  height: 46px;
  padding: 0 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: border-color var(--fast) var(--ease);
}
.search:focus-within { border-color: var(--accent); background: var(--surface); }
.search__icon { width: 18px; height: 18px; color: var(--text-3); flex: 0 0 auto; }
.search input { flex: 1; font-size: 16px; }
.search input::placeholder { color: var(--text-3); }
.search__clear { width: 22px; height: 22px; color: var(--text-3); flex: 0 0 auto; }

/* --- Exercise row -------------------------------------------------------- */

.exlist { display: flex; flex-direction: column; }
.exrow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: var(--surface);
  transition: background var(--fast) var(--ease);
}
.exrow + .exrow { border-top: 1px solid var(--line); }
.exrow:active { background: var(--surface-2); }
.exrow__meta { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.exrow__name { font-size: 16px; font-weight: 620; }
.exrow__add { width: 26px; height: 26px; color: var(--accent); flex: 0 0 auto; }
.exrow__badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  color: var(--accent); text-transform: uppercase;
}

.thumb {
  width: 52px; height: 52px;
  flex: 0 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid; place-items: center;
  border: 1px solid var(--line);
}
.thumb svg { width: 100%; height: 100%; }
.thumb--lg { width: 60px; height: 60px; border-radius: 14px; }

/* --- Set logging --------------------------------------------------------- */

.exercise {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: pop-in var(--med) var(--ease) both;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
.exercise + .exercise { margin-top: 12px; }
.exercise__head { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.exercise__title { font-size: 16px; font-weight: 680; }
.exercise__sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.exercise__menu { width: 34px; height: 34px; display: grid; place-items: center; color: var(--text-3); border-radius: 50%; flex: 0 0 auto; }
.exercise__menu:active { background: var(--surface-2); }

.prev {
  margin: 0 14px 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.prev__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prev__sets { font-size: 13px; color: var(--text-2); margin-top: 4px; line-height: 1.5; }
.prev__copy { font-size: 13px; font-weight: 680; color: var(--accent); padding: 4px 2px; }

.sets { padding: 0 8px 8px; }
.sets__header {
  display: grid;
  grid-template-columns: 38px 1fr 1fr 46px;
  gap: 6px;
  padding: 0 6px 6px;
  align-items: center;
}
.sets__header > * { text-align: center; }
.sets__header > :first-child { text-align: left; padding-left: 4px; }

.setrow-wrap { position: relative; overflow: hidden; border-radius: var(--r-sm); }
.setrow-wrap + .setrow-wrap { margin-top: 6px; }
/* Revealed only while a row is being swiped, so it can never bleed through
   the (semi-transparent) completed-row tint. */
.setrow-del {
  position: absolute; inset: 0 0 0 auto;
  width: 84px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger);
  border-radius: var(--r-sm);
  color: #fff; font-size: 14px; font-weight: 660;
  visibility: hidden;
}
.setrow-wrap--swiping .setrow-del { visibility: visible; }
.setrow {
  position: relative;
  display: grid;
  grid-template-columns: 38px 1fr 1fr 46px;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: transform var(--med) var(--ease), background var(--fast) var(--ease);
  will-change: transform;
}
.setrow--done { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.setrow__n {
  font-size: 14px; font-weight: 700; color: var(--text-3);
  padding-left: 4px;
}
.setrow--done .setrow__n { color: var(--accent); }
.setrow__field {
  height: 44px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid transparent;
  transition: border-color var(--fast) var(--ease);
}
.setrow__field:focus-within { border-color: var(--accent); background: var(--surface); }
.setrow__field input {
  width: 100%; height: 100%;
  text-align: center;
  font-size: 17px; font-weight: 660;
  font-variant-numeric: tabular-nums;
}
.setrow__field input::placeholder { color: var(--text-3); font-weight: 500; }
.setrow__check {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-3);
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease), color var(--fast) var(--ease);
}
.setrow__check svg { width: 21px; height: 21px; }
.setrow__check:active { transform: scale(0.9); }
.setrow--done .setrow__check { background: var(--accent); color: var(--accent-contrast); }

.addset {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--accent);
  font-size: 15px; font-weight: 680;
  transition: transform var(--fast) var(--ease);
}
.addset:active { transform: scale(0.98); }
.addset svg { width: 18px; height: 18px; }

/* --- Sticky action bar --------------------------------------------------- */

/* Sits directly ON TOP of the tab bar, never over it. */
.actionbar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom));
  width: 100%; max-width: 560px;
  z-index: 45;
  padding: 10px var(--pad);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
  animation: bar-in var(--med) var(--ease) both;
}
@keyframes bar-in { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }

/* --- Sheet / modal ------------------------------------------------------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.42);
  animation: fade-in var(--fast) var(--ease) both;
  display: flex; align-items: flex-end; justify-content: center;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-width: 560px;
  background: var(--elevated);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 10px var(--pad) calc(14px + var(--safe-bottom));
  animation: sheet-up var(--med) var(--ease) both;
  max-height: 86dvh; overflow-y: auto;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.sheet__grab {
  width: 36px; height: 5px; border-radius: 3px;
  background: var(--line-strong);
  margin: 0 auto 14px;
}
.sheet__title { font-size: 18px; font-weight: 700; text-align: center; }
.sheet__msg { font-size: 14px; color: var(--text-2); text-align: center; margin-top: 6px; }
.sheet__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

/* --- Segmented control --------------------------------------------------- */

.seg {
  display: flex;
  padding: 3px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  gap: 3px;
}
.seg__item {
  flex: 1;
  min-height: 34px;
  border-radius: 8px;
  font-size: 13px; font-weight: 620;
  color: var(--text-2);
  display: grid; place-items: center;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.seg__item[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
html[data-theme="dark"] .seg__item[aria-pressed="true"] { background: var(--surface-3); }

/* --- Scroll chip strip --------------------------------------------------- */

.strip {
  display: flex; gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 calc(-1 * var(--pad));
  padding: 2px var(--pad) 4px;
}
.strip__item {
  flex: 0 0 auto;
  height: 36px; padding: 0 14px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px; font-weight: 620; color: var(--text-2);
  display: grid; place-items: center;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease);
}
.strip__item[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}

/* --- Stats --------------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 10px;
  text-align: center;
}
.stat__v { font-size: 20px; font-weight: 760; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat__l { font-size: 11px; color: var(--text-2); margin-top: 3px; }

/* --- Empty state --------------------------------------------------------- */

.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 42px 20px;
}
.empty__icon {
  width: 62px; height: 62px; border-radius: 20px;
  background: var(--surface-2);
  display: grid; place-items: center; color: var(--text-3);
  margin-bottom: 16px;
}
.empty__icon svg { width: 30px; height: 30px; }
.empty__t { font-size: 17px; font-weight: 680; }
.empty__d { font-size: 14px; color: var(--text-2); margin-top: 6px; max-width: 260px; line-height: 1.45; }

/* --- Toast --------------------------------------------------------------- */

.toast-root {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  /* clears the sticky action bar on screens that have one */
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 92px);
  z-index: 80;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
  width: 100%;
  padding: 0 24px;
}
.toast {
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  font-size: 14px; font-weight: 600;
  padding: 11px 18px;
  border-radius: var(--r-full);
  box-shadow: var(--shadow-md);
  animation: toast-in var(--med) var(--ease) both;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
html[data-theme="dark"] .toast { background: rgba(240, 240, 245, 0.95); color: #000; }
.toast--out { animation: toast-out var(--fast) var(--ease) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.97); } }

/* --- Chart --------------------------------------------------------------- */

.chart { width: 100%; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart__line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart__area { fill: url(#chartGrad); }
.chart__dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.chart__dot--last { fill: var(--accent); }
.chart__grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 5; }
.chart__lbl { font-size: 10px; font-weight: 600; fill: var(--text-3); }
.chart__val { font-size: 11px; font-weight: 700; fill: var(--text-2); }

/* --- List rows ----------------------------------------------------------- */

.listrow {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 14px 16px;
  background: var(--surface);
  transition: background var(--fast) var(--ease);
}
.listrow + .listrow { border-top: 1px solid var(--line); }
.listrow:active { background: var(--surface-2); }
.listrow__chev { width: 18px; height: 18px; color: var(--text-3); flex: 0 0 auto; }

/* --- Generated exercise thumbnails --------------------------------------- */

.thumb { background: hsl(var(--h, 210) 58% 50% / 0.10); border-color: hsl(var(--h, 210) 40% 50% / 0.16); }
.thumb svg { color: hsl(var(--h, 210) 46% 44%); }
html[data-theme="dark"] .thumb { background: hsl(var(--h, 210) 55% 50% / 0.18); border-color: hsl(var(--h, 210) 40% 60% / 0.20); }
html[data-theme="dark"] .thumb svg { color: hsl(var(--h, 210) 68% 70%); }
