/* App styles. System fonts only: the app loads nothing from another origin (REQ-41).
   Screens fit 360 to 430 CSS px without sideways scrolling, and every control is at least 44 x 44 CSS px (A-8). */
:root {
  color-scheme: light dark;
  --space: 16px;
  --tap: 44px;
  --radius: 10px;
  --line: color-mix(in srgb, currentColor 25%, transparent);
  --accent: #1f6feb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  line-height: 1.4;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-wrap: anywhere;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  padding: var(--space);
}

.app-name {
  margin: 0;
  font-size: 1.5rem;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-main {
  padding: 0 var(--space) var(--space);
}

h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

/* Controls: at least 44 x 44, 16 px text so iOS doesn't zoom in. */
button,
input,
select,
textarea {
  font: inherit;
  font-size: 16px;
  min-height: var(--tap);
  min-width: var(--tap);
  max-width: 100%;
  border-radius: var(--radius);
}

input,
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: Canvas;
  color: CanvasText;
}

button {
  padding: 10px 16px;
  border: 1px solid var(--line);
  background: ButtonFace;
  color: ButtonText;
  cursor: pointer;
}

button.primary {
  width: 100%;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

form,
fieldset {
  display: grid;
  gap: 12px;
}

fieldset {
  margin: 0 0 var(--space);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}

legend {
  padding: 0 4px;
  font-weight: 600;
}

.field {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.field > label,
.label {
  font-weight: 600;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pair-part {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pair-part input,
.set-field input {
  flex: 1 1 auto;
  min-width: var(--tap);
}

/* A unit label beside a number box stays whole on one line at 360 to 430 px (REQ-45, D-27): the body lets long
   text break anywhere, so unit labels opt out and never shrink. */
.unit-label,
.set-unit {
  flex: none;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

.error {
  margin: 0;
  color: #c62828;
  font-weight: 600;
}

.hint {
  margin: 0;
  opacity: 0.85;
}

.notice {
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.notice-warn {
  border-left-color: #c62828;
  background: color-mix(in srgb, #c62828 12%, transparent);
}

.card {
  display: grid;
  gap: 8px;
  padding: var(--space);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.program-week {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.8;
}

.exercises {
  margin: 0;
  padding-left: 1.25rem;
  display: grid;
  gap: 6px;
}

.exercise {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 8px;
}

.exercise-name {
  font-weight: 600;
}

.finisher {
  margin: 0;
}

/* Workout, history and past workouts (M07). Everything stays in the page flow, so the rest timer never covers the
   set rows, the swap controls or the finish button. */
.stack {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.exercise-block {
  min-width: 0;
}

.exercise-title {
  margin: 0;
  font-size: 1.1rem;
}

.exercise-plan,
.warmups,
.exercise-cue,
.suggestion p {
  margin: 0;
}

.suggestion {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.suggestion-weight {
  font-size: 1.25rem;
  font-weight: 700;
}

.exercise-cue {
  padding: 8px 10px;
  border-left: 4px solid var(--line);
}

.exercise-actions,
.swap-scope,
.rest-actions,
.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swap-menu {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.swap-options {
  display: grid;
  gap: 6px;
}

.swap-option {
  text-align: left;
}

.swap-option[aria-pressed="true"],
.set-done[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.set-rows {
  display: grid;
  gap: 8px;
}

.set-row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.set-row .row-error {
  grid-column: 1 / -1;
}

.set-number {
  font-weight: 600;
}

.set-field {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.set-unit {
  font-size: 0.85rem;
  opacity: 0.8;
}

.set-row-done input {
  border-color: var(--accent);
}

.rest-timer {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
}

.rest-line,
.rest-done {
  margin: 0;
}

.rest-remaining {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* The done state stands alone where the phone can't vibrate (D-9, R-3). */
.rest-timer-done {
  border-color: #2e7d32;
  background: color-mix(in srgb, #2e7d32 18%, transparent);
}

.rest-done {
  font-size: 1.25rem;
  font-weight: 700;
}

.history-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
}

.history-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 8px;
}

.history-date {
  font-variant-numeric: tabular-nums;
}

.history-detail {
  font-size: 0.9rem;
  opacity: 0.85;
}

/* Weigh-ins, the targets card and the check-in (M08). */
.average {
  margin: 0;
  font-size: 1.1rem;
}

.average-value,
.target-value {
  font-weight: 700;
}

.weigh-in-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.weigh-in-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.weigh-in-item .error {
  grid-column: 1 / -1;
}

.weigh-in-date {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.target {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 8px;
  margin: 0;
}

.target-label {
  font-weight: 600;
}

.card p {
  margin: 0;
}

.notice p + button {
  margin-top: 8px;
}

/* Progress (M09). Charts are drawn by the app as inline SVG and scale to the card's width. Weigh-ins are hollow
   circles and averages a solid line with filled squares, so they differ in shape as well as colour. */
.chart {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  overflow: hidden;
}

.chart-axis {
  stroke: currentColor;
  stroke-opacity: 0.5;
  stroke-width: 1;
}

.chart-grid {
  stroke: currentColor;
  stroke-opacity: 0.2;
  stroke-dasharray: 3 3;
}

.chart-label {
  fill: currentColor;
  font-size: 11px;
}

.chart-circle {
  fill: Canvas;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-line {
  fill: none;
  stroke: #c2410c;
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.chart-square {
  fill: #c2410c;
}

.series-strength .chart-line {
  stroke: var(--accent);
}

.series-strength .chart-square {
  fill: var(--accent);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
}

.chart-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-mark {
  display: inline-block;
  flex: none;
}

.legend-circle {
  width: 10px;
  height: 10px;
  border: 2px solid var(--accent);
  border-radius: 50%;
}

.legend-line {
  position: relative;
  width: 22px;
  height: 3px;
  background: #c2410c;
}

.legend-line::after {
  content: "";
  position: absolute;
  top: -3px;
  left: 8px;
  width: 6px;
  height: 6px;
  background: #c2410c;
}

.muscle-head,
.muscle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.5rem 5.5rem;
  align-items: center;
  gap: 4px 8px;
}

.muscle-head {
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0.8;
}

.muscle-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.muscle-name {
  font-weight: 600;
}

.muscle-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.muscle-range {
  font-variant-numeric: tabular-nums;
}

.muscle-outside {
  grid-column: 1 / -1;
  font-weight: 700;
  color: #c62828;
}

.muscle-row-outside {
  padding: 4px 6px;
  border-left: 4px solid #c62828;
}

/* Offline and install (M10): the "New version ready" prompt above every screen, the tab note on setup and home, and
   the version and storage lines in settings. */
.app-update:empty {
  display: none;
}

.update-prompt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin: 0 var(--space) var(--space);
  padding: 10px 12px;
  border-left: 4px solid var(--accent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.update-text {
  margin: 0;
  font-weight: 600;
}

.update-reload {
  flex: none;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.tab-note {
  margin: 0 0 var(--space);
}

.settings-line {
  margin: 0;
}

/* Backup and restore (M11): the backup section, the home reminder, and the import preview and delete-all
   confirmations, which take the screen's place until they're answered. */
.backup-reminder {
  margin: 0 0 var(--space);
}

button.danger {
  border-color: #c62828;
  background: #c62828;
  color: #fff;
  font-weight: 600;
}

.summary-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 1.25rem;
}

[data-test="import-preview"] p,
[data-test="delete-all-dialog"] p,
[data-test="data-unreadable"] p {
  margin: 0;
}
