:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-strong: #fdfcf7;
  --ink: #18202f;
  --muted: #667085;
  --line: #e3e7df;
  --accent: #19666a;
  --accent-strong: #0f4f53;
  --accent-soft: #d8eeee;
  --warm: #b85c38;
  --gold: #e8b653;
  --danger: #b42318;
  --shadow: 0 16px 42px rgba(24, 32, 47, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(25, 102, 106, 0.11), transparent 240px),
    var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  width: min(100%, 740px);
  min-height: 100vh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(86px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 2px 14px;
}

.topbar h1,
.section-head h2,
.dialog-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 28px;
  line-height: 1.1;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 14px;
}

.section-head h2 {
  font-size: 22px;
  line-height: 1.2;
}

.panel,
.chart-panel,
.metric-strip {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(227, 231, 223, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  margin-bottom: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field.compact {
  gap: 6px;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 0 12px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(25, 102, 106, 0.15);
}

.date-input,
.select-pill {
  min-height: 40px;
  width: auto;
  max-width: 164px;
  border-radius: 999px;
  font-size: 14px;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr 46px;
  gap: 8px;
}

.category-strip {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
  padding: 0 0 4px;
  scrollbar-width: none;
}

.category-strip::-webkit-scrollbar {
  display: none;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  padding: 0 12px;
  white-space: nowrap;
}

.category-chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.icon-button {
  display: inline-grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
}

.icon-button.muted {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.exercise-list {
  display: grid;
  gap: 8px;
  max-height: 262px;
  margin-top: 12px;
  overflow: auto;
  padding-right: 2px;
}

.exercise-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 11px 12px;
  text-align: left;
}

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

.exercise-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.exercise-item strong,
.history-card strong {
  display: block;
  line-height: 1.25;
}

.exercise-item small,
.selected-exercise p,
.history-card small,
.chart-title-row span,
.settings-row small,
.muted-text {
  color: var(--muted);
}

.tag {
  border-radius: 999px;
  background: #f0f3ec;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
  white-space: nowrap;
}

.entry-panel.disabled {
  opacity: 0.65;
}

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

.selected-exercise h3 {
  margin: 0 0 4px;
  font-size: 20px;
}

.selected-exercise p {
  margin: 0;
  font-size: 13px;
}

.small-button,
.secondary-button,
.primary-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.small-button {
  flex: 0 0 auto;
  background: #edf3f3;
  color: var(--accent-strong);
  padding: 0 12px;
}

.secondary-button {
  background: #eef1eb;
  color: var(--ink);
  padding: 0 14px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
}

.primary-button:disabled,
.secondary-button:disabled,
.small-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button.full {
  width: 100%;
}

.set-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 58px 38px;
  gap: 8px;
  align-items: center;
}

.set-grid-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 0 4px 7px;
}

.set-rows {
  display: grid;
  gap: 8px;
}

.set-row input {
  min-height: 44px;
  text-align: center;
}

.set-row .set-index {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #f3f4ef;
  font-weight: 800;
}

.remove-set {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: #fff1ed;
  color: var(--danger);
}

.remove-set svg {
  width: 18px;
  height: 18px;
}

.entry-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding-top: 12px;
}

.history-filter {
  box-shadow: none;
}

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

.history-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 13px;
  box-shadow: 0 10px 26px rgba(24, 32, 47, 0.08);
}

.history-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.history-card ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.history-card li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid #edf0e9;
  padding-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.history-card li > span:first-child {
  min-width: 0;
}

.history-entry-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.history-card .edit-session,
.history-card .delete-session {
  border: 0;
  background: transparent;
  font-weight: 800;
  padding: 0;
}

.history-card .edit-session {
  color: var(--accent-strong);
}

.history-card .delete-session {
  color: var(--danger);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-bottom: 12px;
}

#chartExerciseSelect {
  max-width: 248px;
}

.chart-browser {
  display: grid;
  gap: 12px;
}

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

.chart-browser-head strong {
  display: block;
  line-height: 1.25;
}

.chart-browser-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.chart-category-strip {
  margin-top: 0;
}

.chart-exercise-list {
  display: grid;
  max-height: 296px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-exercise-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  border: 0;
  border-bottom: 1px solid #edf0e9;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
}

.chart-exercise-row:last-child {
  border-bottom: 0;
}

.chart-exercise-row.active {
  background: var(--accent-soft);
}

.chart-exercise-copy {
  min-width: 0;
}

.chart-exercise-copy strong {
  display: block;
  overflow: hidden;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-exercise-copy small {
  display: block;
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-row-stats {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 6px;
  justify-content: end;
}

.chart-row-stats em {
  border-radius: 999px;
  background: #f0f3ec;
  color: var(--accent-strong);
  font-size: 12px;
  font-style: normal;
  font-weight: 850;
  padding: 5px 7px;
  white-space: nowrap;
}

.metric-strip div {
  display: grid;
  gap: 4px;
  min-width: 0;
  background: #fff;
  padding: 13px 10px;
}

.metric-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-strip strong {
  overflow: hidden;
  font-size: 18px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-panel {
  padding: 14px 12px 10px;
  margin-bottom: 12px;
}

.chart-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-title-row h3,
.panel-title {
  margin: 0;
  font-size: 16px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.settings-list {
  display: grid;
  gap: 8px;
}

.auth-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.auth-panel.signed-in {
  background: var(--surface-strong);
}

.oauth-actions {
  display: grid;
  gap: 10px;
}

.oauth-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 850;
}

.oauth-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.settings-row {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 13px;
  text-align: left;
}

.settings-row span {
  font-weight: 850;
}

.settings-row.danger span {
  color: var(--danger);
}

.file-row {
  position: relative;
  cursor: pointer;
}

.file-row input {
  position: absolute;
  inset: 0;
  cursor: pointer;
  opacity: 0;
}

.muscle-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.muscle-chip {
  border-radius: 999px;
  background: #edf3f3;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 10px;
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 740px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(227, 231, 223, 0.95);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.tab {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 12px;
  font-weight: 800;
}

.tab svg {
  width: 21px;
  height: 21px;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

dialog {
  width: min(calc(100% - 28px), 520px);
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.38);
}

.dialog-card {
  display: grid;
  gap: 12px;
  max-height: min(88vh, 760px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow);
}

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

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  display: none;
  max-width: 520px;
  margin: 0 auto;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.empty-state {
  border: 1px dashed #cdd5cc;
  border-radius: var(--radius);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 22px;
  }

  .topbar {
    padding-top: 24px;
  }

  .panel,
  .chart-panel {
    padding: 18px;
  }
}

@media (max-width: 370px) {
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .date-input,
  .select-pill {
    max-width: none;
    width: 100%;
  }

  .chart-exercise-row {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .chart-row-stats {
    justify-content: start;
  }

  .entry-actions {
    grid-template-columns: 1fr;
  }

  .oauth-actions {
    grid-template-columns: 1fr;
  }

  .metric-strip strong {
    font-size: 16px;
  }
}
