:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101411;
  --surface: #171d18;
  --surface-2: #202821;
  --line: #344036;
  --text: #f4f7f2;
  --muted: #aab5aa;
  --accent: #b7f36b;
  --accent-text: #17200f;
  --danger: #ff9c96;
  --upper: #6ec8ff;
  --lower: #f0c14a;
  --full: #c9a0ff;
  --cardio: #8b9cff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5ef;
  --surface: #ffffff;
  --surface-2: #e6ebe1;
  --line: #c5d0bf;
  --text: #172017;
  --muted: #5b685c;
  --accent: #4f8d14;
  --accent-text: #f7ffe9;
  --danger: #c23d35;
  --upper: #2f8ec4;
  --lower: #c48a10;
  --full: #8a5cc4;
  --cardio: #4d5fd6;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}

.brand,
.nav-button,
.text-button,
.icon-button {
  border: 0;
  background: transparent;
}

.brand {
  padding: 8px 0;
  font-weight: 800;
  font-size: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

nav {
  display: flex;
  gap: 4px;
}

.theme-toggle {
  width: 40px;
  font-size: 20px;
}

.nav-button {
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
}

.nav-button.active {
  color: var(--text);
  background: var(--surface-2);
}

main {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: 28px 16px calc(40px + env(safe-area-inset-bottom));
}

.view[hidden] {
  display: none;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 22px;
  font-size: clamp(28px, 8vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.035em;
}

h2 {
  margin-bottom: 8px;
  font-size: 18px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted,
.optional,
.data-card p {
  color: var(--muted);
}

.optional {
  font-weight: 400;
}

.template-grid {
  display: grid;
  gap: 12px;
}

.template-button,
.wide-button,
.small-button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 750;
}

.template-button {
  min-height: 76px;
  padding: 18px;
  text-align: left;
  background: var(--surface);
  font-size: 19px;
}

.template-button:active,
.wide-button:active,
.small-button:active {
  transform: translateY(1px);
}

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

.secondary {
  color: var(--text);
  background: var(--surface-2);
}

.danger-button {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

#start-summary {
  margin-top: 18px;
}

.resume-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 18px;
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent);
  text-align: left;
}

.resume-button[hidden] {
  display: none;
}

.resume-button span {
  font-size: 12px;
  font-weight: 650;
}

.session-heading {
  display: flex;
  align-items: start;
  gap: 12px;
}

.session-heading h1 {
  margin-bottom: 5px;
}

.draft-status {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  padding: 8px 4px;
  color: var(--muted);
}

.session-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
  background: var(--bg);
}

input,
select {
  min-height: 46px;
  padding: 10px;
}

textarea {
  padding: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

.exercise-list {
  display: grid;
  gap: 12px;
}

.exercise-card,
.data-card,
.history-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.exercise-card {
  padding: 12px;
}

.exercise-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.exercise-header > div:first-child {
  flex: 1;
}

.exercise-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.exercise-name {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 7px 8px;
  border-color: transparent;
  background: transparent;
  font-weight: 800;
  font-size: 17px;
}

.exercise-unit {
  flex: 0 0 68px;
  width: 68px;
  min-height: 36px;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 800;
}

.progression-note {
  display: block;
  min-height: 17px;
  padding-left: 8px;
  color: var(--accent);
  font-size: 12px;
}

.progression-note.is-up {
  color: var(--accent);
}

.progression-note.is-same {
  color: var(--muted);
}

.progression-note.is-down {
  color: var(--danger);
}

.exercise-actions {
  display: flex;
}

.icon-button {
  width: 34px;
  min-height: 40px;
  padding: 0;
  color: var(--muted);
  font-size: 18px;
}

.remove-exercise {
  color: var(--danger);
  font-size: 24px;
}

.set-grid {
  display: grid;
  grid-template-columns: 32px minmax(60px, 0.85fr) minmax(74px, 1fr) minmax(82px, 1.1fr);
  align-items: center;
  gap: 7px;
}

.set-grid-heading {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.set-row + .set-row {
  margin-top: 8px;
}

.set-number {
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.set-row input {
  min-height: 52px;
  padding: 8px;
  text-align: center;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.set-row .actual-reps {
  min-height: 58px;
  border-color: #586a59;
  font-size: 24px;
  font-weight: 850;
}

.set-row .actual-reps::placeholder {
  color: var(--muted);
  font-weight: 600;
  opacity: 0.75;
}

.wide-button {
  width: 100%;
  margin-top: 14px;
  padding: 12px 16px;
}

.add-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.cardio-card strong {
  display: block;
  min-height: 40px;
  padding: 7px 8px;
  font-size: 17px;
}

.cardio-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 10px;
}

.cardio-details-label {
  grid-column: 1 / -1;
}

.notes-label {
  margin-top: 20px;
}

.result-breakdown {
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
}

.review-tabs,
.stat-range {
  display: flex;
  gap: 6px;
  margin-bottom: 18px;
}

.review-tab {
  flex: 1;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 750;
}

.review-tab.active {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent);
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 40px 1fr 40px auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.calendar-toolbar h1 {
  margin: 0;
  text-align: center;
  font-size: 26px;
}

.calendar-toolbar .icon-button {
  font-size: 28px;
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}

.chip-upper { color: #0b2230; background: var(--upper); }
.chip-lower { color: #2a2108; background: var(--lower); }
.chip-full { color: #241536; background: var(--full); }
.chip-cardio { color: #12162c; background: var(--cardio); }
.chip-unknown { color: var(--text); background: var(--surface-2); }

html[data-theme="light"] .chip-upper,
html[data-theme="light"] .chip-lower,
html[data-theme="light"] .chip-full,
html[data-theme="light"] .chip-cardio {
  color: #fff;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.cal-day {
  min-height: 72px;
  padding: 5px 4px;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  text-align: left;
}

.cal-day.empty {
  background: transparent;
  border-color: transparent;
}

.cal-day.today {
  border-color: var(--accent);
}

.cal-day.selected {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.cal-day-number {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 800;
}

.cal-day .chip {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#calendar-day-detail {
  margin-top: 16px;
}

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

.stat-card {
  padding: 14px;
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.stat-card .stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.score-head {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.score-head-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.score-head h2 {
  margin: 0;
}

.score-head .muted {
  margin: 0;
}

.score-avg-stat {
  flex: 0 0 auto;
  text-align: right;
}

.score-avg-stat .stat-value {
  font-size: 28px;
  font-weight: 850;
  letter-spacing: -0.04em;
  line-height: 1;
}

.score-avg-stat .stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.week-bars {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  gap: 8px;
  min-height: 148px;
  margin: 8px 0 4px;
}

.week-col {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  min-height: 148px;
}

.week-col-bars {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  min-height: 118px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: end;
  gap: 2px;
  min-width: 0;
}

.bar-count {
  color: var(--text);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.bar {
  width: 12px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}

.week-bars.is-dense .bar {
  width: 8px;
}

.week-bars.is-dense .week-col-bars {
  gap: 2px;
}

.bar-upper { background: var(--upper); }
.bar-lower { background: var(--lower); }
.bar-full { background: var(--full); }
.bar-cardio { background: var(--cardio); }

.week-col-label {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.balance-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.balance-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 68px;
  align-items: center;
  gap: 8px;
}

.balance-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  font-size: 13px;
  font-weight: 750;
}

.balance-tag {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.balance-row.is-most .balance-tag {
  color: var(--accent);
}

.balance-row.is-none .balance-name,
.balance-row.is-none .balance-value {
  color: var(--muted);
}

.balance-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.balance-bar {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: var(--accent);
}

.balance-row.is-light .balance-bar,
.balance-row.is-none .balance-bar {
  background: color-mix(in srgb, var(--accent) 40%, var(--muted));
}

.balance-value {
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.balance-summary {
  margin: 12px 0 0;
  font-size: 12px;
}

.muscle-grid {
  display: grid;
  gap: 10px;
}

.muscle-card {
  padding: 12px;
}

.muscle-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 800;
}

.muscle-delta {
  color: var(--muted);
  font-size: 12px;
}

.muscle-delta.up { color: var(--accent); }
.muscle-delta.down { color: var(--danger); }

.spark {
  display: flex;
  align-items: end;
  gap: 4px;
  height: 56px;
}

.spark i {
  flex: 1;
  min-height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--surface-2);
}

.spark i.current {
  background: var(--accent);
}

.spark-labels {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.spark-labels span {
  flex: 1;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-caption {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 650;
}

.muscle-progress .chart-caption {
  margin: 2px 0 6px;
}

.muscle-empty {
  margin: 10px 0 0;
  font-size: 12px;
}

.muscle-progress {
  margin-top: 10px;
}

.exercise-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.exercise-tab {
  max-width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 750;
  text-align: left;
}

.exercise-tab.active {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent);
}

.weight-chart {
  min-height: 120px;
}

.weight-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.weight-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.weight-dot {
  fill: var(--accent);
}

.weight-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.weight-axis {
  fill: var(--muted);
  font-family: inherit;
  font-size: 9px;
  font-weight: 700;
}

.weight-point-label {
  fill: var(--text);
  font-family: inherit;
  font-size: 9px;
  font-weight: 800;
}

.weight-chart-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.weight-chart-meta .up { color: var(--accent); }
.weight-chart-meta .down { color: var(--danger); }

.score-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.45;
}

.score-avg {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.score-dot-upper { fill: var(--upper); }
.score-dot-lower { fill: var(--lower); }
.score-dot-full { fill: var(--full); }
.score-dot-unknown { fill: var(--muted); }

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px 10px;
  padding: 14px;
}

button.history-item {
  appearance: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

button.history-item:hover,
button.history-item:focus-visible {
  border-color: var(--accent);
}

.history-title {
  font-weight: 800;
}

.history-meta,
.history-notes {
  color: var(--muted);
  font-size: 13px;
}

.history-score {
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
  color: var(--accent);
  font-weight: 850;
}

.history-chevron {
  grid-row: 1 / span 2;
  grid-column: 3;
  align-self: center;
  color: var(--muted);
  font-size: 22px;
  font-weight: 650;
}

.history-notes {
  grid-column: 1 / -1;
  white-space: pre-wrap;
}

#session-detail-meta {
  margin-bottom: 4px;
}

.session-detail-body {
  display: grid;
  gap: 12px;
}

#delete-session {
  margin-top: 8px;
}

#delete-session[hidden] {
  display: none;
}

.session-detail-notes {
  margin: 0;
  white-space: pre-wrap;
}

.readonly-card .exercise-header {
  margin-bottom: 8px;
}

.readonly-card strong {
  font-size: 17px;
}

.readonly-set {
  min-height: 44px;
  padding: 6px 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.readonly-set .actual-reps {
  color: var(--accent);
  font-size: 20px;
  font-weight: 850;
}

.data-card {
  margin-bottom: 12px;
  padding: 16px;
}

.data-card .wide-button {
  margin-top: 4px;
}

.data-card .wide-button + .wide-button,
.data-card .wide-button + .file-button,
.data-card .file-button + .wide-button {
  margin-top: 8px;
}

.github-form {
  display: grid;
  gap: 12px;
  margin: 12px 0;
}

.github-repo-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.file-button {
  display: grid;
  place-items: center;
  color: var(--text);
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

code {
  color: var(--text);
}

dialog {
  width: min(calc(100% - 32px), 480px);
  padding: 20px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

dialog::backdrop {
  background: rgb(0 0 0 / 70%);
}

#delete-session-label {
  margin-bottom: 0;
  font-weight: 650;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 8px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(24px, calc(16px + env(safe-area-inset-bottom)));
  min-width: min(calc(100% - 32px), 260px);
  padding: 12px 18px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: 0 10px 28px rgb(0 0 0 / 28%);
  text-align: center;
  transform: translateX(-50%);
}

.toast[hidden] {
  display: none;
}

.small-button {
  min-height: 42px;
  padding: 8px 18px;
}

@media (min-width: 680px) {
  main {
    padding-top: 42px;
  }

  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .exercise-card {
    padding: 16px;
  }

  .set-grid {
    grid-template-columns: 42px minmax(90px, 0.75fr) minmax(110px, 1fr) minmax(130px, 1fr);
  }

  .muscle-grid {
    grid-template-columns: 1fr;
  }
}
