:root {
  --color-bg: #f7f7f9;
  --color-card: #ffffff;
  --color-text: #1c1c1e;
  --color-text-secondary: #6b6b70;
  --color-text-tertiary: #8e8e93;
  --color-border: #e5e5ea;
  --color-primary: #2563eb;
  --color-success: #34c759;
  --color-danger: #e33b3b;

  --shade-q0: var(--color-bg);
  --shade-q1: #dbeafe;
  --shade-q2: #93c5fd;
  --shade-q3: #3b82f6;
  --shade-q4: #16a34a;

  --radius-sm: 7px;
  --radius-md: 10px;
  --radius-lg: 14px;

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

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, system-ui, BlinkMacSystemFont, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

.screen-header,
.protocol-header,
.tracker-header {
  padding: calc(var(--safe-top) + 14px) 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-btn, .stats-btn, .tracker-link {
  background: none; border: none; cursor: pointer; font-size: 18px;
  color: var(--color-primary); padding: 4px 8px;
}

.tracker-link {
  margin: 16px;
  padding: 12px;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  text-align: center;
  font-weight: 500;
}

.sheet { display: none; position: fixed; inset: 0; z-index: 100; }
.sheet.active { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.sheet-content {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--color-card);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 24px);
  max-height: 80vh; overflow-y: auto;
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--color-border); border-radius: 2px;
  margin: 0 auto 12px;
}

[hidden] { display: none !important; }

.date-line { margin: 0; font-size: 13px; color: var(--color-text-secondary); font-weight: 500; }
.day-summary { margin: 4px 0 0; font-size: 13px; color: var(--color-primary); font-weight: 600; }

.tiles-container { display: flex; flex-direction: column; gap: 10px; padding: 16px; flex: 1; }

.tile {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--color-card);
  border: none; border-radius: var(--radius-lg);
  text-align: left; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  font-family: inherit; color: var(--color-text);
}
.tile.done .tile-name { color: var(--color-text-secondary); text-decoration: line-through; }
.tile-icon { font-size: 26px; }
.tile-body { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.tile-name { font-size: 15px; font-weight: 600; }
.tile-sub { font-size: 12px; color: var(--color-text-secondary); }
.tile-check { font-size: 18px; color: var(--color-success); }
.mini-bar { display: block; height: 4px; background: var(--color-border); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.mini-bar-fill { display: block; height: 100%; background: var(--color-primary); border-radius: 2px; }

.protocol-title { font-size: 14px; font-weight: 600; flex: 1; }
.progress-strip {
  display: flex; gap: 3px;
  padding: 0 16px 18px;
}
.pip {
  flex: 1; height: 3px; border-radius: 2px;
  background: var(--color-border); border: none; padding: 6px 0;
  cursor: pointer;
}
.pip.done { background: var(--color-success); }
.pip.current { background: var(--color-primary); }

.step-content {
  flex: 1; padding: 0 16px 16px; overflow-y: auto;
}
.step-footer {
  padding: 12px 16px calc(var(--safe-bottom) + 16px);
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
}
.done-btn {
  width: 100%; padding: 14px;
  background: var(--color-primary); color: white;
  border: none; border-radius: var(--radius-lg);
  font-size: 15px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}

.prompt { padding: 12px 0; }
.prompt-title { margin: 0 0 12px; font-size: 22px; font-weight: 700; line-height: 1.2; }
.prompt-body {
  margin: 0; padding: 14px 16px;
  background: var(--color-card); border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.55; color: var(--color-text);
}
.prompt-body.multi p { margin: 0 0 8px; }
.prompt-body.multi p:last-child { margin-bottom: 0; }
.duration-input {
  display: flex; align-items: center; gap: 12px;
  background: var(--color-card); border-radius: var(--radius-md);
  padding: 12px 16px; margin-top: 12px;
}
.duration-input span { font-size: 14px; font-weight: 500; }
.duration-input input {
  flex: 1; border: none; background: transparent;
  font-size: 18px; font-family: inherit;
  font-variant-numeric: tabular-nums; -webkit-appearance: none;
}

/* ---- mobility-timed renderer ---- */
.ex-gif {
  background: var(--color-border); border-radius: var(--radius-md);
  aspect-ratio: 16 / 10;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; margin-bottom: 14px;
}
.ex-gif img { width: 100%; height: 100%; object-fit: cover; }
.gif-placeholder { color: var(--color-text-tertiary); font-size: 13px; }

.ex-name { margin: 0 0 4px; font-size: 19px; font-weight: 700; line-height: 1.2; }
.ex-meta { margin: 0 0 14px; font-size: 12px; color: var(--color-text-secondary); }

.side-toggle {
  display: flex; background: var(--color-border); border-radius: 8px; padding: 2px;
  margin-bottom: 14px;
}
.side-btn {
  flex: 1; background: transparent; border: none; padding: 8px;
  border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer;
  color: var(--color-text-secondary); font-family: inherit;
}
.side-btn.active { background: var(--color-card); color: var(--color-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.timer-display {
  text-align: center; font-size: 56px; font-weight: 200;
  font-variant-numeric: tabular-nums; line-height: 1; margin: 8px 0;
}
.timer-controls { display: flex; gap: 8px; margin-bottom: 14px; }
.timer-btn {
  flex: 1; background: var(--color-card); border: none;
  padding: 10px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; color: var(--color-primary);
  font-family: inherit; cursor: pointer;
}

.ex-cues {
  background: var(--color-card); border-radius: var(--radius-md);
  padding: 10px 12px; font-size: 12px; color: #4b4b50; line-height: 1.5;
  margin-bottom: 12px;
}

/* ---- mobility-reps renderer ---- */
.reps-target {
  text-align: center; padding: 24px 0;
  margin-bottom: 14px;
}
.reps-num { font-size: 64px; font-weight: 300; color: var(--color-primary); font-variant-numeric: tabular-nums; }
.reps-label { display: block; font-size: 14px; color: var(--color-text-secondary); margin-top: 4px; }

/* ---- strength-sets renderer ---- */
.sets-list { background: var(--color-card); border-radius: var(--radius-md); overflow: hidden; margin-bottom: 12px; }
.set-row {
  display: flex; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid #f0f0f3; font-size: 13px;
}
.set-row:last-child { border-bottom: none; }
.set-num { font-weight: 600; width: 56px; font-size: 12px; }
.set-prescription { flex: 1; color: var(--color-text-secondary); font-size: 12px; }
.set-state { color: var(--color-text-secondary); font-size: 11px; }
.set-row.done { background: #f0fdf4; }
.set-row.done .set-state { color: var(--color-success); font-weight: 600; }
.set-row.current { background: #eff6ff; border-left: 3px solid var(--color-primary); padding-left: 9px; }
.set-row.current .set-state { color: var(--color-primary); font-weight: 600; }

.rest-banner {
  background: #fff7e6; border: 1px solid #fde9c6;
  border-radius: var(--radius-md);
  padding: 10px 12px; margin-bottom: 12px;
  font-size: 12px; color: #92400e; text-align: center;
}
.rest-time { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 4px 0; }
.rest-target { color: #b45309; font-size: 12px; }
.rest-skip {
  display: block; margin: 6px auto 0;
  background: none; border: none; color: #b45309; font-weight: 500; font-size: 12px;
  cursor: pointer; font-family: inherit;
}

/* ---- rounds-counter renderer ---- */
.rounds-area { display: flex; flex-direction: column; align-items: center; padding: 16px 0; }
.rounds-ring {
  width: 200px; height: 200px;
  background: var(--color-card);
  border: 6px solid var(--color-primary); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
  font-family: inherit;
}
.rounds-count { font-size: 64px; font-weight: 300; color: var(--color-primary); font-variant-numeric: tabular-nums; line-height: 1; }
.rounds-of { font-size: 13px; color: var(--color-text-secondary); margin-top: 4px; }
.rounds-hint { font-size: 12px; color: var(--color-text-tertiary); font-style: italic; margin: 12px 0 0; }

/* ---- toast notification ---- */
.app-toast {
  position: fixed; bottom: calc(var(--safe-bottom) + 16px);
  left: 16px; right: 16px;
  background: #1c1c1e; color: white;
  padding: 12px 16px; border-radius: var(--radius-md);
  font-size: 13px; text-align: center;
  z-index: 200;
  opacity: 0; transform: translateY(20px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.app-toast.show { opacity: 1; transform: translateY(0); }

.tracker-title { flex: 1; font-size: 16px; font-weight: 700; }
.tracker-content { padding: 0 16px 24px; flex: 1; overflow-y: auto; }

.month-nav {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--color-card); padding: 10px 14px;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.month-name { font-size: 15px; font-weight: 600; }
.month-arrow {
  background: none; border: none; color: var(--color-primary);
  font-size: 16px; padding: 4px 8px; cursor: pointer;
}

.cal-box {
  background: var(--color-card);
  padding: 8px 8px 12px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin-bottom: 14px;
}
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 4px; }
.cal-weekdays div { text-align: center; font-size: 10px; color: var(--color-text-tertiary); font-weight: 500; padding: 4px 0; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-day {
  aspect-ratio: 1; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 500; color: var(--color-text);
  display: flex; align-items: center; justify-content: center;
  background: var(--shade-q0); cursor: pointer; font-family: inherit;
}
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.future { background: transparent; color: var(--color-text-tertiary); cursor: default; }
.cal-day.past-empty { color: var(--color-text-tertiary); }
.cal-day.q1 { background: var(--shade-q1); color: #1e40af; }
.cal-day.q2 { background: var(--shade-q2); color: white; }
.cal-day.q3 { background: var(--shade-q3); color: white; }
.cal-day.q4 { background: var(--shade-q4); color: white; }
.cal-day.today { border-color: var(--color-text); border-width: 2px; font-weight: 700; }
.cal-day.selected { border-color: var(--color-primary); border-width: 2px; }

.legend {
  display: flex; gap: 8px; justify-content: center; align-items: center;
  margin-top: 8px; font-size: 10px; color: var(--color-text-secondary);
}
.legend-swatch {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
}
.legend-swatch.q0 { background: var(--shade-q0); }
.legend-swatch.q1 { background: var(--shade-q1); }
.legend-swatch.q2 { background: var(--shade-q2); }
.legend-swatch.q3 { background: var(--shade-q3); }
.legend-swatch.q4 { background: var(--shade-q4); }

.day-detail {
  background: var(--color-card); border-radius: var(--radius-md);
  padding: 12px 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.day-detail-header {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #f0f0f3;
}
.day-detail-date { font-size: 14px; font-weight: 600; }
.day-detail-pct { font-size: 13px; color: var(--color-primary); font-weight: 600; }
.detail-row {
  display: flex; align-items: center; padding: 7px 0; font-size: 13px;
}
.d-icon { margin-right: 10px; font-size: 16px; }
.d-name { flex: 1; }
.d-status { font-size: 12px; }
.d-status.done { color: var(--color-success); font-weight: 600; }
.d-status.partial { color: var(--color-primary); font-weight: 600; }
.d-status.miss { color: var(--color-text-tertiary); }

.streak-block {
  display: flex; justify-content: space-around; align-items: center;
  background: var(--color-bg); border-radius: var(--radius-md);
  padding: 14px; margin-bottom: 14px;
}
.streak-block > div { text-align: center; flex: 1; }
.streak-num { font-size: 30px; font-weight: 700; line-height: 1; }
.streak-label { font-size: 11px; color: var(--color-text-secondary); margin-top: 4px; }
.streak-divider { width: 1px; height: 36px; background: var(--color-border); }

.pp-summary-title {
  font-size: 11px; color: var(--color-text-secondary);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  margin: 6px 0 8px;
}
.pp-summary { display: flex; flex-direction: column; gap: 2px; }
.pp-row { display: flex; align-items: center; padding: 8px 4px; font-size: 13px; }
.pp-icon { margin-right: 10px; font-size: 18px; }
.pp-name { flex: 1; }
.pp-count { font-variant-numeric: tabular-nums; color: var(--color-text-secondary); font-size: 12px; }
