:root {
  --bg: #111318;
  --card-bg: #1b1e26;
  --border: #2c303a;
  --text: #ffffff;
  --text-body: #d1d5db;
  --text-meta: #9ca3af;
  --accent: #4f8cff;
  --accent-text: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-body);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

header {
  margin-bottom: 20px;
}

h1 {
  color: var(--text);
  font-size: 24px;
  margin: 4px 0;
}

h2 {
  color: var(--text);
  font-size: 19px;
  margin: 0 0 4px;
}

h3 {
  color: var(--text);
  font-size: 15px;
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta {
  color: var(--text-meta);
  font-size: 14px;
  margin: 0 0 2px;
}

.back {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

.phase-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.phase-tab {
  flex-shrink: 0;
  width: auto;
  padding: 8px 14px;
  margin-bottom: 0;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-meta);
  font-size: 14px;
}

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

footer {
  margin-top: 8px;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: inherit;
}

.block {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.exercise-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
}

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

.exercise:last-child {
  border-bottom: none;
}

.exercise-check {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.exercise.done .exercise-name {
  color: var(--text-meta);
  text-decoration: line-through;
}

.exercise.done .thumb {
  opacity: 0.5;
}

.progress-counter {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
}

.thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #0d0f14;
  cursor: pointer;
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-meta);
  text-align: center;
  border: 1px dashed var(--border);
  cursor: default;
}

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

.exercise-name {
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
}

.video-link {
  display: inline-block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  z-index: 100;
}

.lightbox img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: 8px;
}

.credits {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--text-meta);
}

.credits a {
  color: var(--text-meta);
}

.lightbox-caption {
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
}

ul {
  margin: 0;
  padding-left: 18px;
}

li {
  margin-bottom: 6px;
}

.history-list {
  padding-left: 0;
  list-style: none;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-header h3 {
  margin: 0;
}

.history-link {
  color: var(--accent);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
}

.history-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.history-entry:last-child {
  border-bottom: none;
}

.history-date {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.history-badge {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
}

.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 11px;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.heat-cell {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dashboard h3 {
  margin-bottom: 10px;
}

.stat-lines {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.stat-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-line .dot {
  width: 9px;
  height: 9px;
}

.stat-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.stat-line .meta {
  margin: 0;
}

button {
  display: block;
  width: 100%;
  padding: 14px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:last-child {
  margin-bottom: 0;
}

.reference-link {
  display: block;
  text-align: center;
  padding: 12px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

.tl-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tl-item {
  display: flex;
  gap: 12px;
}

.tl-label {
  flex: 0 0 52px;
  font-weight: 700;
  font-size: 14px;
}

.tl-text b {
  display: block;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
}

.tl-text span {
  font-size: 13px;
  color: var(--text-meta);
  line-height: 1.4;
}

.mech-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mech-card {
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 12px;
}

.mech-card b {
  display: block;
  color: var(--text);
  font-size: 14.5px;
  margin-bottom: 3px;
}

.mech-card span {
  display: block;
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.5;
}

.mech-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
}

.reference-note {
  text-align: center;
  margin-top: 4px;
}

.ic-grid {
  display: grid;
  gap: 3px;
  margin-top: 6px;
  align-items: center;
}

.ic-hh {
  text-align: center;
  font-size: 11px;
  color: var(--text-meta);
  font-weight: 600;
}

.ic-rowlabel {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  padding-right: 4px;
}

.ic-cell {
  aspect-ratio: 1;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ic-cell span {
  font-size: 12px;
  font-weight: 700;
}

.ic-note {
  margin-top: 10px;
}

/* ------------------------------------------------------------------
   Cycle protocol screens
   ------------------------------------------------------------------ */

.cycle-steps {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}

.cycle-steps-label {
  margin: 0 4px 0 0;
  font-size: 13px;
}

.cycle-step {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-body);
  font-size: 14px;
}

.cycle-step.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.slot-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}

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

.slot-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.role {
  color: var(--text-meta);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.slot-name {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
}

.slot-progress {
  flex-shrink: 0;
  color: var(--text-body);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.slot-row.has-done .slot-progress {
  color: var(--text);
  font-weight: 700;
}

.session-note {
  margin-top: 10px;
}

.link-row {
  display: flex;
  gap: 8px;
}

.link-row .reference-link {
  flex: 1;
  text-align: center;
}

/* --- Exercise screen --- */

.ex-header {
  margin: -20px -16px 12px;
  padding: 20px 16px 16px;
}

.ex-header .slot-top {
  margin: 10px 0 4px;
}

/* `contain`, not `cover`: these are instructional photos, and cropping them
   destroys the information. A square overhead-march shot loses the kettlebell
   off the top under `cover`, and the two-panel landmine press loses a panel. */
.ex-photo {
  display: block;
  width: 100%;
  height: 280px;
  object-fit: contain;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}

.ex-photo-empty {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text-meta);
  font-size: 14px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  width: auto;
  margin: 0;
  padding: 7px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-body);
  font-size: 14px;
}

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

.past-list,
.trend-list,
.bar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.past-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 2px 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

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

.past-date {
  grid-row: span 2;
  color: var(--text-meta);
  font-size: 13px;
}

.past-ex {
  color: var(--text-body);
}

.past-sets {
  color: var(--text-meta);
  font-variant-numeric: tabular-nums;
}

/* Sessions on the same exercise you picked today are the directly comparable
   ones — the rest are context, so only these get lifted. */
.past-row.same .past-ex,
.past-row.same .past-sets {
  color: var(--text);
  font-weight: 600;
}

/* --- Set logging --- */

.set-head,
.set-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) minmax(0, 1fr) 42px;
  gap: 6px;
  align-items: center;
}

.set-head {
  margin-bottom: 6px;
  color: var(--text-meta);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.set-head span:nth-child(2),
.set-head span:nth-child(3) {
  text-align: center;
}

.set-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.set-row {
  padding: 4px 0;
}

.set-no {
  color: var(--text-meta);
  font-size: 14px;
  text-align: center;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.step {
  width: 34px;
  height: 44px;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.num {
  min-width: 36px;
  flex: 1;
  height: 44px;
  padding: 0 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d0f14;
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

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

.num-wide {
  flex: 0 0 90px;
}

.tick {
  width: 42px;
  height: 44px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 18px;
}

.set-row.done .tick {
  background: #16a34a;
  border-color: #16a34a;
  color: #ffffff;
  font-weight: 700;
}

.set-row.done .num {
  color: var(--text-meta);
}

.set-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ghost {
  width: auto;
  flex: 1;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-body);
  font-size: 14px;
}

.primary-link {
  display: block;
  padding: 14px;
  border-radius: 10px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  font-weight: 700;
}

/* --- Cardio fields --- */

.field-label {
  margin-top: 18px;
}

.mode-toggle {
  display: flex;
  gap: 6px;
  margin: 12px 0 8px;
}

.mode-btn {
  flex: 1;
  width: auto;
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-body);
  font-size: 14px;
}

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

.stepper-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit {
  color: var(--text-meta);
  font-size: 14px;
}

.interval-grid,
.hr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.interval {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.interval .num {
  flex: none;
  width: 100%;
}

/* On a narrow phone the set row runs out of room and the number field gets
   crushed (41px at 375px wide, unreadable at 320px). Claw back the page and
   card padding and trim the steppers so the number you're actually reading
   mid-set stays the biggest thing in the row. */
@media (max-width: 400px) {
  #app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .block {
    padding-left: 10px;
    padding-right: 10px;
  }

  .ex-header {
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .set-head,
  .set-row {
    grid-template-columns: 20px minmax(0, 1fr) minmax(0, 1fr) 40px;
    gap: 4px;
  }

  .step {
    width: 30px;
  }

  .tick {
    width: 40px;
  }
}

/* --- Progress --- */

.trend {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.trend:last-child {
  border-bottom: none;
}

.trend-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.trend-name {
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.trend-best {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.spark {
  display: block;
  width: 100%;
  height: 40px;
  margin: 6px 0 4px;
}

.bar-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
}

.bar-label {
  color: var(--text-body);
}

.bar-track {
  height: 14px;
  border-radius: 7px;
  background: #0d0f14;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 7px;
}

.bar-value {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Rich history entries --- */

.log-entry {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.log-entry:last-child {
  border-bottom: none;
}

.log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.log-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  padding: 2px 0;
}

.log-ex {
  color: var(--text-body);
}

.log-line .meta {
  margin: 0;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* --- Last session line --- */

.last-session {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.last-session .meta {
  margin: 0;
}

.last-session strong {
  color: var(--text);
}

.last-session-link,
.edit-link {
  flex-shrink: 0;
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}

/* --- Session editor --- */

.edit-slot {
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.edit-slot.missing {
  opacity: 0.75;
}

.edit-slot .set-head {
  margin-top: 8px;
}

.chip.small {
  padding: 5px 10px;
  font-size: 13px;
}

.tick.remove {
  font-size: 20px;
  color: var(--text-meta);
}

.num-date,
.num-text {
  width: 100%;
  flex: none;
  text-align: left;
  padding: 0 10px;
}

.danger {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #f87171;
  background: transparent;
  color: #f87171;
  font-size: 15px;
  font-weight: 600;
}

.log-head .history-date {
  flex: 1;
}

.block-link {
  display: block;
  margin-bottom: 16px;
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
}

