:root {
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #0284c7;
  --accent-text: #ffffff;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warn: #d97706;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --amrap: #7c3aed;
  --amrap-bg: #f3e8ff;
  --rehab: #0d9488;
  --rehab-bg: #ccfbf1;
  --indigo: #4f46e5;
  --pink: #db2777;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --tab-height: 68px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220;
    --bg-elevated: #141d2f;
    --text: #e8ecf3;
    --text-muted: #93a0b4;
    --border: #263349;
    --accent: #38bdf8;
    --accent-text: #06111f;
    --success: #4ade80;
    --success-bg: #133a20;
    --warn: #fbbf24;
    --danger: #f87171;
    --danger-bg: #3f1414;
    --amrap: #c084fc;
    --amrap-bg: #2c1a45;
    --rehab: #2dd4bf;
    --rehab-bg: #0f3d38;
    --indigo: #818cf8;
    --pink: #f472b6;
    --input-bg: #0f1826;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elevated: #141d2f;
  --text: #e8ecf3;
  --text-muted: #93a0b4;
  --border: #263349;
  --accent: #38bdf8;
  --accent-text: #06111f;
  --success: #4ade80;
  --success-bg: #133a20;
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-bg: #3f1414;
  --amrap: #c084fc;
  --amrap-bg: #2c1a45;
  --rehab: #2dd4bf;
  --rehab-bg: #0f3d38;
  --indigo: #818cf8;
  --pink: #f472b6;
  --input-bg: #0f1826;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(var(--tab-height) + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
  /* Weight/reps fields get double-tapped (to select-all and overwrite a
     prefilled value) more than any other field in the app — iOS Safari's
     native double-tap-to-zoom gesture fires on that, independent of any
     font-size fix for focus-zoom. Disabling it app-wide is safe since
     nothing here relies on double-tap for anything else. */
  touch-action: manipulation;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
  touch-action: manipulation;
}

/* iOS Safari auto-zooms the page on focusing any form control whose font-size
   computes below 16px. Setting it in absolute px (not rem) here guarantees
   that regardless of what any more specific rule elsewhere sets it to. */
input, select, textarea {
  font-size: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top, 0px)) 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.cycle-badge {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
}

.view-root {
  padding: 12px 16px 24px;
  max-width: 640px;
  margin: 0 auto;
}

.tab-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  height: var(--tab-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-height: 44px;
}

.tab-btn.active {
  color: var(--accent);
  font-weight: 600;
}

.tab-icon {
  font-size: 1rem;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.day-kicker {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 2px;
}

.section-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 18px 0 8px;
}

.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.set-row:last-child { border-bottom: none; }

.set-check {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-muted);
}

.set-check.done {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.set-row.amrap .set-check {
  border-color: var(--amrap);
}
.set-row.amrap .set-check.done {
  background: var(--amrap-bg);
  border-color: var(--amrap);
  color: var(--amrap);
}

.set-info {
  flex: 1;
  min-width: 0;
}

.set-weight {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.2;
}

.set-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.amrap-tag {
  color: var(--amrap);
  font-weight: 700;
}

.plate-strip {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.e1rm-line {
  font-size: 0.8rem;
  color: var(--amrap);
  font-weight: 600;
  margin-top: 4px;
  min-height: 1.1em;
}

.pr-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  min-height: 1.1em;
}

.set-input {
  width: 58px;
  height: 40px;
  text-align: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  font-size: 16px;
}

.accessory-block {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.accessory-block:last-child { border-bottom: none; }

.accessory-name {
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.accessory-target {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.accessory-cue {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  margin: -2px 0 8px;
}

/* Shared row style for checkbox-only accessories (no weight/reps to log,
   just a single done/not-done toggle). */
.rehab-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.rehab-row:last-child { border-bottom: none; }

.rehab-row .set-check {
  border-color: var(--rehab);
}
.rehab-row .set-check.done {
  background: var(--rehab-bg);
  border-color: var(--rehab);
  color: var(--rehab);
}

.rehab-name {
  font-weight: 600;
}

.accessory-sets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.accessory-set {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
}

.accessory-set-idx {
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 14px;
}

.accessory-set.completed {
  border-color: var(--success);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-bg);
}

.btn-ghost {
  background: none;
  border-color: transparent;
}

.btn-sm {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-block { width: 100%; }

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field input, .field select, .field textarea {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  padding: 8px 12px;
  font-size: 1rem;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.tm-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.tm-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.tm-tile-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.tm-tile-value {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 4px 0 8px;
}

.pill-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.pill-tabs::-webkit-scrollbar { display: none; }

.pill-tab {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 0.85rem;
  min-height: 40px;
}

.pill-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  justify-content: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.splash-hero {
  text-align: center;
  padding: 28px 20px;
}

.splash-kicker {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.splash-title {
  margin: 0 0 4px;
  font-size: 2rem;
}

.splash-other-days {
  padding: 4px 16px;
}

.splash-day-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 4px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--text);
  font-size: 0.95rem;
  text-align: left;
}
.splash-other-days .splash-day-row:last-child {
  border-bottom: none;
}

.splash-day-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.splash-day-name {
  flex: 1;
}

.splash-day-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  border-radius: 10px;
}

/* Adjacent-month days are still clickable (they can carry real sessions),
   so only the day number itself is dimmed — the dots stay at full strength
   so a session on a visible neighboring-month day is easy to read. */
.cal-cell.muted > span:first-child {
  color: var(--text-muted);
  opacity: 0.4;
}

.cal-cell.has-session {
  font-weight: 600;
}

.cal-cell.is-today {
  background: var(--bg);
  outline: 1px solid var(--border);
}

.cal-dots {
  display: flex;
  gap: 3px;
  min-height: 9px;
}

.cal-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

.session-detail-group {
  margin-bottom: 14px;
}

.session-detail-group h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.session-detail-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}
.session-detail-line:last-child { border-bottom: none; }

.session-detail-check {
  font-weight: 700;
}
.session-detail-check.yes { color: var(--success); }
.session-detail-check.no { color: var(--danger); }

.sync-status {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.sync-status-syncing { color: var(--accent); }
.sync-status-synced { color: var(--success); }
.sync-status-error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }

canvas.chart-canvas {
  display: block;
  max-width: 100%;
}

canvas.chart-canvas[hidden] {
  display: none;
}

.bw-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.bw-row:last-child { border-bottom: none; }

.empty-state {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 8px;
}

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

.rest-timer {
  position: fixed;
  bottom: calc(var(--tab-height) + env(safe-area-inset-bottom, 0px) + 12px);
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 4px;
}

.rest-timer-toggle {
  background: none;
  border: none;
  color: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 48px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rest-timer-label {
  font-size: 0.7rem;
  font-weight: 500;
  opacity: 0.85;
}

.rest-timer-cancel {
  background: rgba(0,0,0,0.12);
  border: none;
  color: inherit;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin-right: 4px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.modal-sheet {
  background: var(--bg-elevated);
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal-sheet { border-radius: 18px; }
}

.modal-sheet h2 {
  margin-top: 0;
}

.rest-quick-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.notes-field textarea {
  min-height: 72px;
  resize: vertical;
}

.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
  box-shadow: var(--shadow);
}
