* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: var(--tg-theme-bg-color, #18181b);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #232328);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --link: var(--tg-theme-link-color, #67a8ff);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --section-header: var(--tg-theme-section-header-text-color, var(--hint));
  --destructive: var(--tg-theme-destructive-text-color, #ef4444);
  --accent: var(--tg-theme-accent-text-color, #67a8ff);
  --separator: rgba(255,255,255,0.08);
  --success: #10b981;
  --warning: #f59e0b;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Helvetica Neue", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

#app { min-height: 100vh; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--hint);
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
  padding: 14px 16px 12px;
  z-index: 10;
}
.header-title {
  font-size: 13px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.header-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.header-name { font-size: 17px; font-weight: 600; }
.header-stats {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}
.header-stat strong { color: var(--text); font-weight: 600; }

/* ===== Routines list ===== */
.routines {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.routine-card {
  background: var(--bg-secondary);
  border-radius: 14px;
  padding: 16px;
  cursor: pointer;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.05s ease;
}
.routine-card:active { transform: scale(0.98); }
.routine-name { font-size: 17px; font-weight: 600; }
.routine-meta { font-size: 13px; color: var(--hint); }
.routine-notes { font-size: 13px; color: var(--hint); margin-top: 4px; }

/* ===== Workout screen ===== */
.exercises {
  padding: 8px 16px 120px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.exercise {
  background: var(--bg-secondary);
  border-radius: 14px;
  padding: 14px;
}
.exercise-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}
.exercise-name { font-size: 16px; font-weight: 600; }
.exercise-meta { font-size: 12px; color: var(--hint); }
.exercise-history {
  font-size: 12px;
  color: var(--hint);
  margin: 6px 0 10px;
  font-variant-numeric: tabular-nums;
}
.exercise-target {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
  background: rgba(103, 168, 255, 0.10);
  padding: 6px 8px;
  border-radius: 6px;
}

/* ===== Photo row ===== */
.photo-row {
  margin: 12px 16px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 12px;
}
.photo-row-label {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 8px;
}
.photo-buttons {
  display: flex;
  gap: 8px;
}
.photo-btn {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--separator);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}
.photo-btn:active { background: rgba(255,255,255,0.05); }
.photo-status {
  margin-top: 8px;
  font-size: 12px;
  color: var(--hint);
  min-height: 14px;
  font-variant-numeric: tabular-nums;
}

/* ===== Set row ===== */
.set {
  display: grid;
  grid-template-columns: 28px 1fr 1fr 44px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.set-num {
  font-size: 13px;
  color: var(--hint);
  text-align: center;
  font-weight: 500;
}
.set-input {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border-radius: 10px;
  overflow: hidden;
  height: 44px;
}
.set-input button {
  width: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  user-select: none;
}
.set-input button:active { background: rgba(255,255,255,0.08); }
.set-input input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  outline: none;
  width: 100%;
  padding: 0;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.set-input input::-webkit-outer-spin-button,
.set-input input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.set-input-label {
  font-size: 10px;
  color: var(--hint);
  text-transform: uppercase;
  align-self: center;
  margin-right: 4px;
}

.set-check {
  width: 44px;
  height: 44px;
  border: 2px solid var(--separator);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.set-check:active { transform: scale(0.92); }
.set.done .set-check {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.set.done .set-input input { color: var(--hint); }
.set.done { opacity: 0.85; }

/* ===== Rest timer ===== */
.rest-timer {
  position: fixed;
  bottom: calc(76px + env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  background: var(--button);
  color: var(--button-text);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  z-index: 5;
  box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}
.rest-timer.warning { background: var(--warning); }
.rest-timer-time {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.rest-timer-skip {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

/* ===== Bottom action ===== */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent 0%, var(--bg) 30%);
  z-index: 6;
}
.action-bar button {
  width: 100%;
  height: 52px;
  border-radius: 12px;
  border: none;
  background: var(--button);
  color: var(--button-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.action-bar button.danger { background: var(--destructive); }
.action-bar button:active { opacity: 0.85; }

/* ===== Summary ===== */
.summary {
  padding: 24px 16px 120px;
  text-align: center;
}
.summary-title { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.summary-stats {
  display: flex;
  justify-content: space-around;
  background: var(--bg-secondary);
  border-radius: 14px;
  padding: 18px;
  margin: 16px 0;
}
.summary-stat-value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-stat-label { font-size: 12px; color: var(--hint); margin-top: 2px; }
.summary-text { color: var(--hint); margin: 16px 0; line-height: 1.5; }

/* ===== Misc ===== */
.back-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  padding: 0;
  cursor: pointer;
  font-weight: 400;
}
.error {
  padding: 16px;
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 12px;
  margin: 16px;
  color: var(--text);
}
