:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #1a4480);
  --button: var(--tg-theme-button-color, #1a4480);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, #f6f7f9);
  --separator: var(--tg-theme-section-separator-color, #e5e5e5);
  --accent: var(--tg-theme-accent-text-color, #1a4480);
  --danger: #d32f2f;
  --success: #2e7d32;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px 14px 32px;
}

button { font: inherit; cursor: pointer; border: none; }
input[type="text"] { font: inherit; }

/* ---- Screens ---- */
.screen { display: flex; flex-direction: column; gap: 12px; }

/* ---- Home ---- */
.home .week-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 8px;
}
.home .week-notes { color: var(--hint); font-size: 13px; line-height: 1.4; }
.home .break-note {
  background: #fff8e1;
  border-left: 3px solid #f9a825;
  color: #5d4037;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.home .break-note:empty { display: none; }

.workout-card {
  background: var(--section-bg);
  border-radius: 12px;
  padding: 14px 16px;
}
.workout-name { font-size: 18px; font-weight: 600; }
.workout-meta { font-size: 13px; color: var(--hint); margin: 4px 0 12px; }
.exercise-list {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 14px;
}
.exercise-list .row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--separator);
}
.exercise-list .row:last-child { border-bottom: none; }
.exercise-list .ex-row-name { flex: 1; }
.exercise-list .ex-row-meta { color: var(--hint); font-size: 12px; }

/* ---- Buttons ---- */
.primary {
  background: var(--button);
  color: var(--button-text);
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 16px;
}
.primary:active { opacity: 0.8; }
.primary.big { padding: 18px; font-size: 18px; }

.ghost {
  background: transparent;
  color: var(--link);
  font-size: 14px;
  padding: 10px;
}
.ghost.small { font-size: 13px; }

/* ---- Exercise screen ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
}
.topbar .icon {
  background: var(--section-bg);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
}
.progress { flex: 1; }
.progress-bar { height: 6px; background: var(--section-bg); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.2s; }
.progress-text { font-size: 12px; color: var(--hint); margin-top: 3px; text-align: center; }

.ex-card {
  background: var(--section-bg);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.ex-images {
  display: flex; gap: 8px; justify-content: center;
  margin-bottom: 8px;
}
.ex-images img {
  max-height: 180px; max-width: 48%;
  background: white; border-radius: 8px; padding: 4px;
}
.ex-images.single img { max-width: 80%; }
.ex-images.no-image {
  height: 80px;
  align-items: center;
  color: var(--hint);
  font-size: 13px;
}
.ex-name {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}
.ex-target-line {
  color: var(--hint);
  font-size: 13px;
  margin-bottom: 8px;
}
.ex-tips {
  text-align: left;
  font-size: 12px;
  color: var(--hint);
  line-height: 1.4;
}
.ex-tips ul { padding-left: 18px; }

.set-section {
  display: flex; flex-direction: column; gap: 10px;
}
.set-dots {
  display: flex; gap: 8px; justify-content: center;
}
.set-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--separator);
  border: 2px solid transparent;
}
.set-dot.done { background: var(--success); }
.set-dot.current { background: transparent; border-color: var(--accent); }
.set-dot.skipped { background: var(--hint); }

.suggestion-line {
  text-align: center;
  font-size: 12px;
  color: var(--hint);
  min-height: 16px;
}
.suggestion-line strong { color: var(--accent); }

.inputs {
  display: flex; gap: 10px;
}
.input-group { flex: 1; }
.input-label { font-size: 12px; color: var(--hint); text-align: center; margin-bottom: 4px; }

.stepper {
  display: flex; align-items: stretch;
  background: var(--section-bg);
  border-radius: 10px;
  overflow: hidden;
}
.stepper button {
  background: transparent;
  width: 44px;
  font-size: 22px;
  color: var(--accent);
}
.stepper button:active { background: rgba(0,0,0,0.05); }
.stepper input {
  flex: 1; min-width: 0;
  background: transparent;
  border: none; outline: none;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.rpe-row {
  background: var(--section-bg);
  border-radius: 10px;
  padding: 10px;
}
.rpe-label { font-size: 12px; color: var(--hint); text-align: center; margin-bottom: 6px; }
.rpe-buttons { display: flex; gap: 6px; }
.rpe-buttons button {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 4px;
  font-weight: 600;
  font-size: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.rpe-buttons button:active { background: var(--accent); color: var(--button-text); }
.rpe-buttons button span {
  font-size: 10px;
  font-weight: 400;
  color: var(--hint);
}
.rpe-buttons button:active span { color: var(--button-text); }

.rest-timer {
  background: var(--section-bg);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.rest-label { font-size: 12px; color: var(--hint); }
.rest-time {
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.rest-timer.expired .rest-time { color: var(--success); }

.ex-actions {
  display: flex; justify-content: space-between; gap: 8px;
  padding-top: 4px;
}
.skip-set-btn {
  align-self: center;
  padding: 6px 12px;
  margin-top: -4px;
}

/* ---- Summary ---- */
.summary { text-align: center; }
.summary h1 { margin: 16px 0; font-size: 24px; }
.summary h2 { margin: 16px 0 8px; font-size: 16px; text-align: left; }
.summary-stats {
  display: flex; gap: 12px; justify-content: center;
  margin: 12px 0;
}
.stat {
  flex: 1;
  background: var(--section-bg);
  border-radius: 10px;
  padding: 14px;
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11px; color: var(--hint); margin-top: 2px; }
.summary-sets {
  text-align: left;
  font-size: 13px;
  display: flex; flex-direction: column; gap: 4px;
}
.summary-sets .group { background: var(--section-bg); border-radius: 8px; padding: 8px 12px; }
.summary-sets .group .group-name { font-weight: 600; margin-bottom: 4px; }
.summary-sets .set-line { color: var(--hint); font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.85); color: white;
  padding: 10px 16px; border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  animation: toast-in 0.2s;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
