/* Dark stone + amber. Function over decoration -- this is read mid-set,
   one-handed, with sweaty hands, in bad gym lighting. */

:root {
  --stone-950: #0c0a09;
  --stone-900: #1c1917;
  --stone-850: #23201e;
  --stone-800: #292524;
  --stone-700: #44403c;
  --stone-600: #57534e;
  --stone-500: #78716c;
  --stone-400: #a8a29e;
  --stone-300: #d6d3d1;
  --stone-100: #f5f5f4;

  --amber-600: #d97706;
  --amber-500: #f59e0b;
  --amber-400: #fbbf24;
  --amber-300: #fcd34d;

  --red-700: #b91c1c;
  --red-600: #dc2626;
  --red-400: #f87171;
  --green-500: #22c55e;

  --bg: var(--stone-950);
  --surface: var(--stone-900);
  --surface-2: var(--stone-850);
  --line: var(--stone-800);
  --text: var(--stone-100);
  --muted: var(--stone-400);
  --accent: var(--amber-500);

  /* Thumb-sized. Do not shrink these. */
  --tap: 48px;
  --radius: 10px;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Keyboard/dialog focus in the palette, not the browser's blue.
   (showModal() autofocuses the first option in the swap sheet.) */
:focus-visible {
  outline: 2px solid var(--amber-500);
  outline-offset: 2px;
}

/* ---------- App chrome ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  font-size: 1.05rem;
  flex: 1;
  min-width: 0;
}

.week-pill {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--stone-950);
  background: var(--amber-500);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.week-pill.deload {
  background: var(--stone-300);
}

.save-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green-500);
  flex: none;
}
.save-dot[data-state='unsaved'],
.save-dot[data-state='read-failed'] {
  background: var(--red-600);
}
.save-dot[data-state='degraded'] {
  background: var(--amber-500);
}
.save-dot[data-state='saving'] {
  background: var(--stone-500);
}

main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Persistent failure banner ---------- */

.banner {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--red-700);
  color: #fff;
  padding: 12px 14px;
  display: grid;
  gap: 10px;
  border-bottom: 2px solid #fff3;
}

.banner[hidden] {
  display: none;
}

.banner strong {
  display: block;
  font-size: 0.98rem;
}

.banner p {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.35;
}

.banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.banner button {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid #fff6;
  background: #fff2;
  color: #fff;
  font-weight: 600;
  flex: 1 1 auto;
}

.banner button:active {
  background: #fff4;
}

/* ---------- Day / mode pickers ---------- */

.scroll-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 14px;
  scrollbar-width: none;
}
.scroll-row::-webkit-scrollbar {
  display: none;
}

/* Every chip the same size -- widths driven by session names made the row
   ragged and the wide chips crowded out the rest. The row scrolls. */
.day-chip {
  flex: 0 0 88px;
  width: 88px;
  min-height: var(--tap);
  padding: 6px 4px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  display: grid;
  place-items: center;
  line-height: 1.15;
  text-align: center;
}

.day-chip strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text);
}

.day-chip small {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.day-chip[aria-pressed='true'] {
  border-color: var(--amber-500);
  background: color-mix(in srgb, var(--amber-500) 16%, var(--surface));
}

.day-chip[data-done='true']::after {
  content: '✓';
  color: var(--green-500);
  font-size: 0.75rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px;
  margin-bottom: 16px;
}

.segmented button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.segmented button[aria-pressed='true'] {
  background: var(--amber-500);
  color: var(--stone-950);
}

/* ---------- Exercise cards ---------- */

.session-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 16px;
}

.exercise {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.exercise-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 4px;
}

.exercise-head h3 {
  font-size: 1rem;
  flex: 1;
  min-width: 0;
}

.sub-btn {
  flex: none;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--stone-700);
  background: var(--surface-2);
  color: var(--stone-300);
  font-size: 0.78rem;
  font-weight: 600;
}

.sub-btn[data-substituted='true'] {
  border-color: var(--amber-600);
  color: var(--amber-400);
}

.prescription {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 2px;
}

.target {
  font-size: 0.82rem;
  color: var(--amber-400);
  margin: 0 0 10px;
  font-weight: 600;
}

.note {
  font-size: 0.78rem;
  color: var(--stone-400);
  background: var(--surface-2);
  border-left: 3px solid var(--stone-600);
  padding: 7px 9px;
  border-radius: 0 6px 6px 0;
  margin: 0 0 10px;
}

.stall-flag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--stone-950);
  background: var(--amber-400);
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
}

/* Set rows. Never a dense multi-column grid on a phone. */
.set-row {
  display: grid;
  grid-template-columns: 46px 1fr 1fr;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.set-row.reps-only {
  grid-template-columns: 46px 1fr;
}

.set-row .set-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.field {
  position: relative;
}

.field input {
  width: 100%;
  min-height: var(--tap);
  /* 16px minimum: anything smaller makes iOS Safari zoom on focus. */
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 0 8px 0 8px;
  border-radius: 9px;
  border: 1px solid var(--stone-700);
  background: var(--stone-950);
  color: var(--text);
  appearance: none;
  -moz-appearance: textfield;
}

.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field input:focus {
  outline: 2px solid var(--amber-500);
  outline-offset: -1px;
  border-color: var(--amber-500);
}

.field input::placeholder {
  color: var(--stone-600);
}

.field .unit {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  color: var(--stone-600);
  pointer-events: none;
}

.field input:not(:placeholder-shown) + .unit {
  color: var(--stone-500);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
}

.checkbox-row input[type='checkbox'] {
  width: 26px;
  height: 26px;
  accent-color: var(--amber-500);
  flex: none;
}

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

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--stone-700);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 650;
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.btn.primary {
  background: var(--amber-500);
  border-color: var(--amber-500);
  color: var(--stone-950);
}

.btn.primary[data-complete='true'] {
  background: transparent;
  border-color: var(--green-500);
  color: var(--green-500);
}

.btn:active {
  filter: brightness(1.15);
}

.btn.danger {
  border-color: var(--red-700);
  color: var(--red-400);
}

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--stone-900) 96%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar button {
  min-height: 60px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  display: grid;
  gap: 2px;
  place-items: center;
}

.tabbar button span {
  font-size: 1.15rem;
  line-height: 1;
}

.tabbar button[aria-pressed='true'] {
  color: var(--amber-400);
}

/* ---------- Progression view ---------- */

.prog-exercise {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}

.prog-exercise h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.prog-row {
  display: grid;
  grid-template-columns: 62px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
}

.prog-row .wk {
  color: var(--muted);
  font-size: 0.78rem;
}

.prog-row .bar {
  height: 7px;
  border-radius: 4px;
  background: var(--amber-600);
  min-width: 3px;
}

.prog-row .val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- Review view ---------- */

/* One row per day. A 7-column grid is unusable on a phone -- this broke before. */
.weigh-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.weigh-row label {
  color: var(--muted);
  font-size: 0.82rem;
}

.metric-row {
  display: grid;
  grid-template-columns: 1fr 128px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.metric-row label {
  font-size: 0.88rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.card h2 {
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.stat-big {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  color: var(--muted);
  font-size: 0.78rem;
}

.report-preview {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  background: var(--stone-950);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px;
  max-height: 320px;
  overflow: auto;
  color: var(--stone-300);
}

.empty {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
  padding: 32px 16px;
}

/* ---------- Substitution sheet ---------- */

dialog.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  width: 100%;
  max-width: 720px;
  margin: auto auto 0;
}

dialog.sheet::backdrop {
  background: #000a;
}

.sheet-inner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}

.sheet-inner h2 {
  font-size: 1rem;
  margin-bottom: 4px;
}

.sheet-inner > p {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 14px;
}

.option {
  display: block;
  width: 100%;
  text-align: left;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  margin-bottom: 8px;
  font-size: 0.92rem;
}

.option[aria-pressed='true'] {
  border-color: var(--amber-500);
  color: var(--amber-400);
}

.option small {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

.option.blocked {
  opacity: 0.55;
  border-style: dashed;
  cursor: not-allowed;
  border-color: var(--red-700);
}

.option.blocked small {
  color: var(--red-400);
}

/* Rest countdown pill. Read at arm's length with the phone on the floor,
   so it is big, high-contrast and impossible to miss. */
.rest-pill {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 35;
  min-height: var(--tap);
  padding: 10px 26px;
  border-radius: 999px;
  border: 0;
  background: var(--amber-500);
  color: var(--stone-950);
  font-size: 1.15rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px #000a;
  white-space: nowrap;
}

.rest-pill[data-done='true'] {
  background: var(--green-500);
}

.rest-pill[hidden] {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--stone-100);
  color: var(--stone-950);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  z-index: 40;
  box-shadow: 0 8px 24px #0008;
}

.toast[hidden] {
  display: none;
}
