/* Forma design system. Dark by default, light when the device asks for it.
   Type: system UI stack (SF Pro on iPhone), tabular numerals for every number. */

:root {
  color-scheme: dark light;

  --color-bg: #0e0f11;
  --color-surface: #17191c;
  --color-surface-raised: #1f2226;
  --color-line: #2b2f35;
  --color-text: #f2f3f5;
  --color-text-muted: #9aa1ab;
  --color-text-faint: #6b727c;
  --color-accent: #ff6b2c;
  --color-accent-pressed: #e85a1c;
  --color-on-accent: #160a04;
  --color-success: #3ddc97;
  --color-warning: #f5b841;
  --color-danger: #ff5a5f;
  --color-focus: #ffb38f;

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --text-2xl: 2rem;
  --text-3xl: 2.75rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;

  --radius-sm: 0.5rem;
  --radius-md: 0.875rem;
  --radius-lg: 1.25rem;
  --radius-pill: 999px;

  --tap-target: 2.75rem;
  --tabbar-height: 3.5rem;
  --content-max-width: 34rem;

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

  --duration-fast: 120ms;
  --duration-base: 220ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    --color-bg: #f5f5f2;
    --color-surface: #ffffff;
    --color-surface-raised: #ecebe7;
    --color-line: #dedcd6;
    --color-text: #15171a;
    --color-text-muted: #5b616a;
    --color-text-faint: #868b93;
    --color-accent: #e5531a;
    --color-accent-pressed: #c94511;
    --color-on-accent: #ffffff;
    --color-success: #138a5a;
    --color-warning: #a86b00;
    --color-danger: #c62f35;
    --color-focus: #e5531a;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0ms;
    --duration-base: 0ms;
  }
}

/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.45;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

a {
  color: inherit;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* App shell */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.app__main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4)
    calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-6));
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 0 var(--space-5);
}

.page-header__eyebrow {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

.page-header__title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

/* Bottom tab bar */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  padding: 0 calc(var(--safe-right) + var(--space-2)) var(--safe-bottom)
    calc(var(--safe-left) + var(--space-2));
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  border-top: 1px solid var(--color-line);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
}

.tabbar__item {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-height);
  color: var(--color-text-faint);
  font-size: 0.6875rem;
  font-weight: 600;
  text-decoration: none;
}

.tabbar__item svg {
  width: 1.5rem;
  height: 1.5rem;
}

.tabbar__item[aria-current="page"] {
  color: var(--color-accent);
}

.tabbar__item[aria-disabled="true"] {
  opacity: 0.45;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.card + .card {
  margin-top: var(--space-3);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.card__label {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card__title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* Numbers */
.metric {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.metric--xl {
  font-size: var(--text-3xl);
  line-height: 1;
}

.metric__unit {
  margin-left: 0.15em;
  color: var(--color-text-muted);
  font-size: 0.45em;
  font-weight: 600;
  letter-spacing: 0;
}

/* Empty states */
.empty {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out);
}

.button:active {
  transform: scale(0.97);
}

.button--primary {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.button--primary:active {
  background: var(--color-accent-pressed);
}

.button--ghost {
  background: transparent;
  border-color: var(--color-line);
}

.button--block {
  width: 100%;
  min-height: 3.25rem;
  font-size: var(--text-md);
}

.button--small {
  min-height: var(--tap-target);
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.field__label {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.field__input {
  width: 100%;
  min-height: 3.25rem;
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  /* 16px minimum stops iOS Safari from zooming into the field. */
  font-size: max(1rem, 16px);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.field__input:focus {
  border-color: var(--color-accent);
  outline: none;
}

.alert {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-danger) 14%, transparent);
  color: var(--color-text);
  font-size: var(--text-sm);
}

/* Status pill (sync / offline) */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 1.75rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
}

.status-pill::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-success);
}

.status-pill[data-state="offline"]::before {
  background: var(--color-warning);
}

.status-pill[data-state="pending"]::before {
  background: var(--color-accent);
}

/* Skeleton */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--color-surface-raised) 0%,
    var(--color-line) 50%,
    var(--color-surface-raised) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}

/* Auth screens */
.auth {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100dvh;
  max-width: 24rem;
  margin: 0 auto;
  padding: calc(var(--safe-top) + var(--space-6)) var(--space-5)
    calc(var(--safe-bottom) + var(--space-6));
}

.auth__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.auth__logo {
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-md);
}

.auth__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 750;
  letter-spacing: -0.02em;
}

.auth__subtitle {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.footer-actions {
  display: flex;
  justify-content: center;
  margin-top: var(--space-6);
}

/* ---------- Shared bits ---------- */
.muted {
  color: var(--color-text-muted);
}

.small {
  font-size: var(--text-sm);
}

.section {
  margin-top: var(--space-6);
}

.section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.section__title {
  margin-bottom: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section__link {
  color: var(--color-accent);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
}

.page-header__back {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap-target);
  margin-top: calc(var(--space-3) * -1);
  color: var(--color-accent);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
}

.page-header__back::before {
  content: "‹";
  margin-right: var(--space-1);
  font-size: 1.4em;
  line-height: 1;
}

.card--hero {
  padding: var(--space-5) var(--space-4);
}

.card__action {
  margin-top: var(--space-4);
}

.card .muted + .muted {
  margin-top: var(--space-1);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.5rem;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-raised);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  white-space: nowrap;
}

.badge--success {
  background: color-mix(in srgb, var(--color-success) 18%, transparent);
  color: var(--color-success);
}

.badge--pr {
  background: var(--color-accent);
  color: var(--color-on-accent);
  letter-spacing: 0.04em;
}

.note {
  color: var(--color-text-muted);
  white-space: pre-line;
}

.empty-state {
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.empty-state .muted {
  margin-top: var(--space-2);
}

/* Lists */
.list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  overflow: hidden;
}

.list__item + .list__item {
  border-top: 1px solid var(--color-line);
}

.list__item.empty {
  padding: var(--space-4);
}

.list__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 3.5rem;
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
}

.list__link:active {
  background: var(--color-surface-raised);
}

.list__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.list__title {
  font-weight: 650;
}

.list__meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.list__action {
  color: var(--color-accent);
  font-size: var(--text-sm);
  font-weight: 700;
}

.active-session {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent) 45%, transparent);
  color: var(--color-text);
  text-decoration: none;
}

.active-session__title {
  font-weight: 700;
}

.active-session__meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* History */
.set-summary {
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
}

.set-summary__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.25rem;
}

.set-summary__item--warmup {
  color: var(--color-text-muted);
}

.set-summary__label {
  width: 2.5rem;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.set-summary__value {
  font-size: var(--text-md);
}

.set-summary__note {
  flex-basis: 100%;
  padding-left: calc(2.5rem + var(--space-3));
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Analytics */
.week-dots {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--space-1);
  text-align: center;
}

.week-dots__week {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.week-dots__count {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-surface-raised);
  font-size: var(--text-sm);
}

.week-dots__count.is-complete {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.week-dots__label {
  color: var(--color-text-faint);
  font-size: 0.625rem;
}

.volume-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.volume-table th {
  width: 7.5rem;
  padding: var(--space-1) 0;
  font-weight: 500;
  text-align: left;
}

.volume-table__bar svg {
  display: block;
  width: 100%;
  height: 0.5rem;
}

.volume-table__count {
  width: 2rem;
  text-align: right;
}

.bar-track {
  fill: var(--color-surface-raised);
}

.bar-fill {
  fill: var(--color-accent);
}

/* Charts (server-rendered SVG) */
.chart {
  margin: 0;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart--empty {
  padding: var(--space-5) 0;
}

.chart__grid {
  stroke: var(--color-line);
  stroke-width: 1;
}

.chart__reference {
  stroke: var(--color-success);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chart__tick {
  fill: var(--color-text-faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.chart__line {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart__point {
  fill: var(--color-bg);
  stroke: var(--color-accent);
  stroke-width: 2;
}

.chart__dot {
  fill: var(--color-text-faint);
  opacity: 0.55;
}

/* ---------- Live session ---------- */
.app--session .app__main {
  padding-bottom: calc(var(--safe-bottom) + var(--space-7));
}

body.has-timer .app--session .app__main {
  padding-bottom: calc(var(--safe-bottom) + 7rem);
}

.session-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: color-mix(in srgb, var(--color-bg) 90%, transparent);
  border-bottom: 1px solid var(--color-line);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
}

.session-bar__back {
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  margin-left: calc(var(--space-2) * -1);
  color: var(--color-accent);
}

.session-bar__back svg {
  width: 1.5rem;
  height: 1.5rem;
}

.session-bar__title {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.session-bar__name {
  overflow: hidden;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-bar__elapsed {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.exercise-card {
  padding: var(--space-4) var(--space-3);
  scroll-margin-top: 4.5rem;
  transition: opacity var(--duration-base) var(--ease-out);
}

.exercise-card .card__header {
  align-items: flex-start;
  padding: 0 var(--space-1);
}

.exercise-card__heading {
  min-width: 0;
}

.exercise-card__target {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.exercise-card__progress {
  flex-shrink: 0;
  padding-top: 0.15rem;
  color: var(--color-text-faint);
  font-size: var(--text-sm);
}

.exercise-card.is-complete .exercise-card__progress {
  color: var(--color-success);
}

.exercise-card.is-skipped {
  opacity: 0.6;
}

.exercise-card > .muted,
.exercise-card__meta,
.suggestion {
  padding: 0 var(--space-1);
}

.exercise-card__meta {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.exercise-card__meta-label {
  color: var(--color-text-faint);
}

.suggestion {
  margin-top: var(--space-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 550;
}

.suggestion--increase {
  color: var(--color-accent);
}

.suggestion--increase::before {
  content: "↑ ";
  font-weight: 800;
}

.set-head,
.set-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1.25fr) minmax(0, 1fr) 3rem;
  align-items: center;
  gap: var(--space-1);
}

.set-head {
  margin-top: var(--space-3);
  padding: 0 0 var(--space-1);
  color: var(--color-text-faint);
  font-size: 0.6875rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
}

.set-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.set-row {
  padding: var(--space-1) 0;
  border-radius: var(--radius-md);
  transition: background-color var(--duration-base) var(--ease-out);
}

.set-row.is-next {
  background: var(--color-surface-raised);
}

.set-row.is-done {
  background: color-mix(in srgb, var(--color-success) 10%, transparent);
}

.set-row.is-warmup .stepper__value {
  color: var(--color-text-muted);
}

.set-row__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap-target);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.set-row__label .badge {
  min-height: 1rem;
  padding: 0 0.3rem;
  font-size: 0.5625rem;
}

.set-row__rir {
  color: var(--color-text-faint);
  font-size: 0.625rem;
}

.stepper {
  display: grid;
  grid-template-columns: var(--tap-target) minmax(0, 1fr) var(--tap-target);
  align-items: center;
  min-width: 0;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.stepper__button {
  width: var(--tap-target);
  height: var(--tap-target);
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.stepper__button:active {
  background: var(--color-surface-raised);
  color: var(--color-text);
}

.stepper__value {
  width: 100%;
  min-width: 0;
  height: var(--tap-target);
  padding: 0;
  border: 0;
  background: transparent;
  font-size: max(1.125rem, 16px);
  text-align: center;
}

.stepper__value:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}

.stepper__value::placeholder {
  color: var(--color-text-faint);
  font-weight: 500;
}

.set-row__check {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 2px solid var(--color-line);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-faint);
  touch-action: manipulation;
  transition: background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out), transform var(--duration-fast) var(--ease-out);
}

.set-row.is-next .set-row__check {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.set-row__check svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.set-row__check:active {
  transform: scale(0.92);
}

.set-row__check[aria-pressed="true"] {
  border-color: var(--color-success);
  background: var(--color-success);
  color: var(--color-bg);
}

.set-row.is-just-done .set-row__check {
  animation: check-pop 320ms var(--ease-out);
}

.set-row.is-new-record {
  animation: record-glow 1200ms var(--ease-out);
}

.set-row.is-new-record .badge--pr {
  animation: check-pop 420ms var(--ease-out);
}

@keyframes check-pop {
  0% {
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes record-glow {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-accent) 60%, transparent);
  }
  100% {
    box-shadow: 0 0 0 12px transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .set-row.is-just-done .set-row__check,
  .set-row.is-new-record,
  .set-row.is-new-record .badge--pr {
    animation: none;
  }
}

.set-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0 0 var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-3) 2.5rem;
}

.set-detail__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.set-detail__label {
  width: 2.25rem;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
}

.chips {
  display: flex;
  flex: 1;
  gap: var(--space-1);
}

.chip {
  flex: 1;
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  padding: 0;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-text-muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip--target {
  border-color: color-mix(in srgb, var(--color-accent) 50%, var(--color-line));
}

.chip[aria-checked="true"] {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.field__input--compact {
  flex: 1;
  min-height: var(--tap-target);
}

.field__textarea {
  min-height: 4.5rem;
  margin-top: var(--space-3);
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

.exercise-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.exercise-card__actions .button {
  flex: 1 1 auto;
  padding: 0 var(--space-3);
}

.discard-button {
  color: var(--color-danger);
}

/* Rest timer */
.rest-timer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  padding: 0 calc(var(--safe-right) + var(--space-3)) calc(var(--safe-bottom) + var(--space-3))
    calc(var(--safe-left) + var(--space-3));
  background: var(--color-surface);
  border-top: 1px solid var(--color-line);
  box-shadow: 0 -8px 24px rgb(0 0 0 / 0.25);
}

.rest-timer__bar {
  height: 3px;
  margin: 0 calc((var(--safe-right) + var(--space-3)) * -1) var(--space-3)
    calc((var(--safe-left) + var(--space-3)) * -1);
  background: var(--color-surface-raised);
}

.rest-timer__bar span {
  display: block;
  height: 100%;
  background: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left center;
}

.rest-timer__content {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: var(--content-max-width);
  margin: 0 auto;
}

.rest-timer__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.rest-timer__label {
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rest-timer__clock {
  font-size: var(--text-2xl);
  line-height: 1.1;
}

.rest-timer.is-over .rest-timer__clock,
.rest-timer.is-over .rest-timer__label {
  color: var(--color-accent);
}

.rest-timer__button {
  min-width: 4rem;
}

/* Bottom sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 0.55);
}

.sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: 85dvh;
  max-width: var(--content-max-width);
  margin: 0 auto;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--color-surface);
  animation: sheet-in var(--duration-base) var(--ease-out);
}

@keyframes sheet-in {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.sheet__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4) calc(var(--safe-bottom) + var(--space-5));
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__body .section__title {
  margin: var(--space-2) 0 0;
}

body.has-sheet {
  overflow: hidden;
}

.picker__list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.picker__option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 3.25rem;
  padding: var(--space-2) var(--space-4);
  border: 0;
  background: transparent;
  text-align: left;
}

.picker__option + .picker__option {
  border-top: 1px solid var(--color-line);
}

.picker__option:active {
  background: var(--color-surface-raised);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 4.25rem);
  z-index: 50;
  max-width: calc(100% - 2rem);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: var(--text-sm);
  font-weight: 650;
  transform: translateX(-50%);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.3);
}

/* Skeleton shapes */
.skeleton--title {
  width: 55%;
  height: 1.25rem;
  margin-bottom: var(--space-2);
}

.skeleton--line {
  width: 80%;
  height: 0.875rem;
  margin-bottom: var(--space-4);
}

.skeleton--row {
  height: var(--tap-target);
  margin-top: var(--space-2);
}

.status-pill[data-state="auth"]::before {
  background: var(--color-danger);
}

.status-pill[data-state="synced"]::before {
  background: var(--color-success);
}

/* ---------- Phase 3: body, plan, settings ---------- */
.flash-messages {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 50;
}

.toast--error {
  background: var(--color-danger);
  color: #fff;
}

.banner {
  margin-bottom: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-warning) 16%, transparent);
  font-size: var(--text-sm);
}

.weight-entry {
  margin-top: var(--space-4);
}

.weight-entry__row {
  display: grid;
  grid-template-columns: var(--tap-target) minmax(0, 1fr) var(--tap-target) auto;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.weight-entry__step {
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
}

.weight-entry__value {
  width: 100%;
  min-width: 0;
  height: 3.25rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  font-size: max(1.5rem, 16px);
  text-align: center;
}

.weight-entry__value:focus {
  border-color: var(--color-accent);
  outline: none;
}

.weight-entry__save {
  min-height: 3.25rem;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
}

.segmented__item {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0 var(--space-3);
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-decoration: none;
}

.segmented__item[aria-current="true"] {
  background: var(--color-surface);
  color: var(--color-text);
}

.chart__line--average {
  stroke: var(--color-accent);
}

.chart__point--average {
  display: none;
}

.chart__line--plan {
  stroke: var(--color-text-faint);
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
}

.chart__point--plan {
  display: none;
}

.chart__line--waist {
  stroke: var(--color-success);
}

.chart__point--waist {
  stroke: var(--color-success);
}

.chart__bar {
  fill: color-mix(in srgb, var(--color-accent) 75%, transparent);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.chart-legend__item::before {
  content: "";
  display: inline-block;
  width: 0.875rem;
  height: 0.25rem;
  margin-right: var(--space-1);
  border-radius: 2px;
  vertical-align: middle;
}

.chart-legend__item--average::before {
  background: var(--color-accent);
}

.chart-legend__item--raw::before {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--color-text-faint);
}

.chart-legend__item--plan::before {
  background: repeating-linear-gradient(90deg, var(--color-text-faint) 0 4px, transparent 4px 7px);
}

.chart-legend__item--goal::before {
  background: repeating-linear-gradient(90deg, var(--color-success) 0 4px, transparent 4px 7px);
}

.inline-form {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.inline-form .field__input {
  flex: 1;
  min-width: 0;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.stack-form .button {
  margin-top: var(--space-2);
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.disclosure {
  margin-top: var(--space-3);
}

.disclosure summary {
  display: flex;
  align-items: center;
  min-height: var(--tap-target);
  color: var(--color-accent);
  font-size: var(--text-sm);
  font-weight: 650;
  cursor: pointer;
}

.kv-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.kv-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 2.25rem;
  align-items: center;
  border-bottom: 1px solid var(--color-line);
}

.kv-list li:last-child {
  border-bottom: 0;
}

.list__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
}

.link-button {
  min-height: var(--tap-target);
  padding: 0 var(--space-2);
  border: 0;
  background: transparent;
  color: var(--color-danger);
  font-size: var(--text-xs);
  font-weight: 600;
}

.field__file {
  padding-top: 0.85rem;
}

.pose-picker,
.score-picker {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.pose-picker legend,
.score-picker legend {
  width: 100%;
  margin-bottom: var(--space-2);
}

.pose-picker__option,
.score-picker__option {
  flex: 1;
}

.pose-picker__option input,
.score-picker__option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.pose-picker__option span,
.score-picker__option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-weight: 650;
}

.pose-picker__option input:checked + span,
.score-picker__option input:checked + span {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.pose-picker__option input:focus-visible + span,
.score-picker__option input:focus-visible + span {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

.check-in {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.photo-grid__item {
  margin: 0;
}

.photo-grid__item img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
}

.photo-grid__item figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.compare-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-3);
  align-items: end;
}

.compare-form .button {
  grid-column: 1 / -1;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.compare-grid figure {
  margin: 0;
}

.compare-grid img,
.compare-grid__missing {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
}

.compare-grid__missing {
  display: grid;
  place-items: center;
  color: var(--color-text-faint);
}

.compare-grid figcaption {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-align: center;
}

.review__suggestion {
  font-size: var(--text-lg);
  font-weight: 650;
  line-height: 1.35;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin: var(--space-4) 0 0;
}

.metric-grid dt {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.metric-grid dd {
  margin: 0;
  font-size: var(--text-lg);
}

.phase-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  overflow: hidden;
}

.phase-list__item {
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid transparent;
}

.phase-list__item + .phase-list__item {
  border-top: 1px solid var(--color-line);
}

.phase-list__item.is-current {
  border-left-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 7%, transparent);
}

.phase-list__item.is-past {
  opacity: 0.55;
}

.phase-list__head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.phase-note {
  margin-top: var(--space-4);
  text-align: center;
}

.phase-note a {
  color: var(--color-accent);
}

.token-reveal__value {
  margin: var(--space-3) 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: max(0.875rem, 16px);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
}

.two-columns > * {
  min-width: 0;
}

input[type="date"].field__input {
  min-width: 0;
  max-width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

/* ---------- Phase 4: nutrition ---------- */
.page-header__title--small {
  font-size: var(--text-xl);
}

.day-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-left: calc(var(--space-2) * -1);
}

.day-nav__arrow {
  display: grid;
  place-items: center;
  width: 2rem;
  height: var(--tap-target);
  color: var(--color-accent);
  font-size: 1.5rem;
  text-decoration: none;
}

.rings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

.ring-block {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.ring {
  width: 100%;
  max-width: 9rem;
  transform: rotate(-90deg);
}

.ring__track {
  fill: none;
  stroke: var(--color-surface-raised);
  stroke-width: 9;
}

.ring__value {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 9;
  stroke-linecap: round;
  transition: stroke-dashoffset var(--duration-base) var(--ease-out);
}

.ring--protein .ring__value {
  stroke: var(--color-success);
}

.ring--over .ring__value {
  stroke: var(--color-danger);
}

.ring-block__text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  max-width: 9rem;
  margin: 0 auto;
  pointer-events: none;
}

.ring-block__value {
  font-size: var(--text-xl);
  line-height: 1;
}

.ring-block__unit {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.ring-block__caption {
  margin-top: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

.macro-bars {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.macro-bar {
  display: grid;
  grid-template-columns: 7.5rem 1fr auto;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.macro-bar__meter,
.water__meter {
  width: 100%;
  height: 0.5rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-surface-raised);
  -webkit-appearance: none;
  appearance: none;
}

.macro-bar__meter::-webkit-meter-bar,
.water__meter::-webkit-meter-bar {
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-surface-raised);
}

.macro-bar__meter::-webkit-meter-optimum-value,
.macro-bar__meter::-webkit-meter-suboptimum-value,
.water__meter::-webkit-meter-optimum-value,
.water__meter::-webkit-meter-suboptimum-value,
.water__meter::-webkit-meter-even-less-good-value {
  border-radius: var(--radius-pill);
  background: var(--color-accent);
}

.macro-bar__meter::-webkit-meter-even-less-good-value {
  border-radius: var(--radius-pill);
  background: var(--color-danger);
}

.macro-bar__meter::-moz-meter-bar,
.water__meter::-moz-meter-bar {
  border-radius: var(--radius-pill);
  background: var(--color-accent);
}

.macro-bar__value {
  font-size: var(--text-sm);
  white-space: nowrap;
}

.alert--warning {
  margin: var(--space-4) 0 0;
  background: color-mix(in srgb, var(--color-warning) 18%, transparent);
}

.quick-meals {
  display: flex;
  gap: var(--space-2);
  padding-bottom: var(--space-1);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.quick-meals::-webkit-scrollbar {
  display: none;
}

.quick-meal {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 9.5rem;
  max-width: 12rem;
  min-height: 4rem;
  padding: var(--space-3);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  text-align: left;
  scroll-snap-align: start;
  touch-action: manipulation;
}

.quick-meal:active {
  background: var(--color-surface-raised);
  transform: scale(0.98);
}

.quick-meal__name {
  font-weight: 700;
  line-height: 1.25;
}

.quick-meal__meta {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.water {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.card .water {
  margin-top: var(--space-4);
}

.section > .water,
.card.section > .water {
  margin-top: 0;
}

.water__info {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.water__value {
  font-size: var(--text-lg);
}

.water__add {
  min-width: 6rem;
}

.meal__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.meal__title {
  font-size: var(--text-lg);
  font-weight: 750;
}

.meal__totals {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.meal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.meal__save {
  flex-basis: 100%;
}

.meal__save summary {
  list-style: none;
}

.meal__save summary::-webkit-details-marker {
  display: none;
}

.entry__summary {
  display: flex;
  align-items: center;
  min-height: 3.25rem;
  padding: var(--space-2) var(--space-4);
  list-style: none;
  cursor: pointer;
}

.entry__summary::-webkit-details-marker {
  display: none;
}

.entry__form {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-3);
}

.entry__form .field__input {
  width: 6rem;
  min-height: var(--tap-target);
}

.meal-picker {
  display: flex;
  gap: var(--space-1);
  margin: 0 calc(var(--space-4) * -1) var(--space-3);
  padding: 0 var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}

.meal-picker__item {
  display: inline-flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-pill);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.meal-picker__item[aria-current="true"] {
  border-color: var(--color-accent);
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.search {
  position: sticky;
  top: calc(var(--safe-top) + var(--space-2));
  z-index: 5;
  margin-bottom: var(--space-3);
}

.search__input {
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.25);
}

.portions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.portion {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 3.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  text-align: left;
  touch-action: manipulation;
}

.portion:active {
  border-color: var(--color-accent);
  transform: scale(0.98);
}

.portion__label {
  font-weight: 700;
}

.portion__meta {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.amount__input {
  font-size: max(1.25rem, 16px);
}

.amount__live {
  grid-template-columns: repeat(4, 1fr);
}

.scanner__viewport {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 60dvh;
  border-radius: var(--radius-lg);
  background: #000;
}

.scanner__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner__frame {
  position: absolute;
  inset: 35% 10%;
  border: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 0.35);
}

.scanner__status {
  margin: var(--space-3) 0;
  color: var(--color-text-muted);
  text-align: center;
}
