:root {
  --clr-bg: #f0f2f5;
  --clr-surface: #ffffff;
  --clr-primary: #4361ee;
  --clr-primary-dark: #3451d1;
  --clr-exercise: #e63946;
  --clr-exercise-dark: #c1121f;
  --clr-rest: #4cc9f0;
  --clr-rest-dark: #0096c7;
  --clr-warning: #f4a261;
  --clr-success: #2dc653;
  --clr-strength: #7b2d8b;
  --clr-strength-dark: #6a1a78;
  --clr-text: #1a1a2e;
  --clr-text-muted: #6c757d;
  --clr-border: #dee2e6;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: 0.2s ease;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100vh;
  transition: background-color 0.5s ease;
}

/* ─── Workout body states ─── */
body.state-exercise {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255,80,80,0.35) 0%, transparent 65%),
    linear-gradient(135deg, #c1121f 0%, #8b0000 100%);
}
body.state-rest {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(120,220,255,0.35) 0%, transparent 65%),
    linear-gradient(135deg, #0096c7 0%, #023e8a 100%);
}
body.state-warning {
  background:
    radial-gradient(ellipse at 50% 30%, rgba(255,220,120,0.35) 0%, transparent 65%),
    linear-gradient(135deg, #f4a261 0%, #c77b28 100%);
}

/* ─── Layout helpers ─── */
.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 40px;
  max-width: 640px;
  margin: 0 auto;
}

/* ─── Page header (back button + title) ─── */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 24px;
}
.page-header h1 { flex: 1; font-size: 1.4rem; font-weight: 700; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn--primary   { background: var(--clr-primary);  color: #fff; }
.btn--primary:hover { background: var(--clr-primary-dark); }

.btn--danger    { background: var(--clr-exercise); color: #fff; }
.btn--danger:hover { background: var(--clr-exercise-dark); }

.btn--strength  { background: var(--clr-strength); color: #fff; }
.btn--strength:hover { background: var(--clr-strength-dark); }

.btn--ghost {
  background: transparent;
  color: var(--clr-text-muted);
  border: 1.5px solid var(--clr-border);
}
.btn--ghost:hover { background: var(--clr-border); }

.btn--icon {
  background: transparent;
  color: var(--clr-text-muted);
  border: none;
  padding: 8px;
  font-size: 1.2rem;
  border-radius: 50%;
  width: 40px; height: 40px;
}
.btn--icon:hover { background: var(--clr-border); }

.btn--back {
  background: var(--clr-surface);
  color: var(--clr-text);
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition);
}
.btn--back:hover { background: var(--clr-border); }

/* ─── Card (surface box) ─── */
.card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  width: 100%;
}

/* ─── Copyright ─── */
.copyright {
  font-size: 0.75rem;
  color: var(--clr-text-muted);
  margin-top: auto;
  padding-top: 32px;
  font-style: italic;
}
.copyright a { color: var(--clr-text-muted); }

/* ─── Input ─── */
.input {
  font-family: var(--font);
  font-size: 1rem;
  padding: 10px 14px;
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition);
  background: var(--clr-surface);
  color: var(--clr-text);
  width: 100%;
}
.input:focus { border-color: var(--clr-primary); }

/* ══════════════════════════════════════════
   HOME PAGE
══════════════════════════════════════════ */
.home-body { background: var(--clr-bg); }

.home-page {
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Header */
.home-header { text-align: center; }
.home-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--clr-text);
}
.home-title-accent { color: #f4a261; }
.home-subtitle { color: var(--clr-text-muted); margin-top: 4px; font-size: 0.95rem; }

/* Hero */
.home-hero {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  aspect-ratio: 16/9;
}
.home-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.home-hero-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to right, rgba(0,0,0,0.62) 45%, transparent 100%);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.home-hero-line {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  line-height: 1.2;
}
.home-hero-accent { color: #f4a261; }
.home-hero-sub {
  margin-top: 10px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.82);
  max-width: 200px;
  line-height: 1.5;
}

/* Cards */
.home-cards {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.home-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--clr-text);
  transition: transform var(--transition), box-shadow var(--transition);
}
.home-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.home-card:active { transform: scale(0.97); }
.home-card--full { grid-column: 1 / -1; }

.home-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.home-card-icon--blue   { background: #dbeafe; }
.home-card-icon--red    { background: #fee2e2; }
.home-card-icon--purple { background: #ede9fe; }

.home-card-body { flex: 1; }
.home-card-title {
  font-weight: 700;
  font-size: 1rem;
}
.home-card--blue   .home-card-title { color: var(--clr-primary); }
.home-card--red    .home-card-title { color: var(--clr-exercise); }
.home-card--purple .home-card-title { color: var(--clr-strength); }

.home-card-sub  { font-size: 0.8rem; color: var(--clr-text-muted); margin-top: 1px; }
.home-card-desc { font-size: 0.8rem; color: var(--clr-text-muted); margin-top: 4px; line-height: 1.4; }
.home-card-arrow { font-size: 1.4rem; color: var(--clr-border); flex-shrink: 0; }

/* Progress CTA */
.home-progress-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  background: var(--clr-surface);
  border: 1.5px solid var(--clr-border);
  border-radius: 99px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--clr-text);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), box-shadow var(--transition);
}
.home-progress-btn:hover { background: var(--clr-bg); box-shadow: var(--shadow); }

/* ══════════════════════════════════════════
   WORKOUT PAGE
══════════════════════════════════════════ */
.workout-card {
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.workout-mode-badge {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 99px;
  background: rgba(0,0,0,0.08);
}

.workout-exercise-name {
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
}

.workout-exercise-desc {
  font-size: 0.95rem;
  color: #444;
  text-align: center;
  line-height: 1.5;
}

.workout-countdown {
  font-size: 5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--clr-exercise);
  transition: color 0.3s;
}

body.state-rest .workout-countdown { color: var(--clr-rest-dark); }
body.state-warning .workout-countdown { color: var(--clr-warning); }

.workout-next {
  font-size: 0.9rem;
  color: var(--clr-text-muted);
}

/* Progress bar */
.progress-bar-wrap {
  width: 100%;
  height: 8px;
  background: rgba(0,0,0,0.1);
  border-radius: 99px;
  overflow: hidden;
  margin: 4px 0;
}
#progress-bar {
  height: 100%;
  background: var(--clr-primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* Exercise list */
#exercise-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  list-style: none;
  padding: 0;
  margin: 4px 0;
}
#exercise-list li {
  font-size: 0.78rem;
  padding: 4px 10px;
  background: rgba(0,0,0,0.06);
  border-radius: 99px;
}
#exercise-list li.current-exercise {
  background: var(--clr-exercise);
  color: #fff;
  font-weight: 700;
}
#exercise-list li.completed {
  text-decoration: line-through;
  opacity: 0.5;
}

/* Workout controls */
.workout-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  margin-top: 4px;
}
.workout-controls .btn { flex: 1; min-width: 100px; }

/* End screen overlay */
.end-screen {
  position: fixed;
  inset: 0;
  background: rgba(44, 198, 83, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  animation: fadeIn 0.4s ease;
}
.end-screen h2 { font-size: 2rem; color: #fff; font-weight: 800; }
.end-screen p  { color: rgba(255,255,255,0.85); font-size: 1.1rem; }
.end-emoji { font-size: 4rem; }

@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ══════════════════════════════════════════
   STRENGTH PAGE
══════════════════════════════════════════ */
.session-date {
  font-size: 0.85rem;
  color: var(--clr-text-muted);
  margin-bottom: 8px;
  align-self: flex-start;
}

.exercise-checklist {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.exercise-item {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}

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

.exercise-item-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.exercise-item-prev {
  font-size: 0.78rem;
  color: var(--clr-text-muted);
  margin-bottom: 10px;
}

.exercise-item-prev .improved { color: var(--clr-success); font-weight: 600; }
.exercise-item-prev .declined { color: var(--clr-exercise); font-weight: 600; }

.sets-display {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  min-height: 28px;
}

.set-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--clr-bg);
  border: 1.5px solid var(--clr-border);
  border-radius: 99px;
  padding: 3px 10px;
  font-size: 0.88rem;
  font-weight: 600;
}

.set-badge .remove-set {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--clr-text-muted);
  font-size: 0.9rem;
  padding: 0;
  line-height: 1;
}

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

.log-set-row .input {
  width: 90px;
  text-align: center;
}

/* ─── Editor panel (slide-in) ─── */
.editor-panel {
  position: fixed;
  inset: 0;
  background: var(--clr-surface);
  z-index: 200;
  overflow-y: auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.25s ease;
}
.editor-panel.hidden { display: none; }

@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.editor-panel h2 { font-size: 1.3rem; font-weight: 700; }

.editor-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.editor-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--clr-bg);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.editor-item-name { flex: 1; font-weight: 600; }

.editor-item-actions { display: flex; gap: 4px; }

.editor-add {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

/* ══════════════════════════════════════════
   PROGRESS PAGE
══════════════════════════════════════════ */
.progress-section { width: 100%; }
.progress-section + .progress-section { margin-top: 28px; }

.exercise-progress-card {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
  margin-bottom: 12px;
}

.exercise-progress-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
}

.sparkline-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 60px;
}

.sparkline-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.sparkline-bar {
  width: 100%;
  background: var(--clr-primary);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.3s ease;
}

.sparkline-label {
  font-size: 0.68rem;
  color: var(--clr-text-muted);
  text-align: center;
}

.sparkline-val {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--clr-text);
}

.progress-best {
  font-size: 0.82rem;
  color: var(--clr-text-muted);
  margin-top: 10px;
}
.progress-best strong { color: var(--clr-success); }

.empty-state {
  text-align: center;
  color: var(--clr-text-muted);
  padding: 40px 20px;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ══════════════════════════════════════════
   CARDIO EDITOR PAGE
══════════════════════════════════════════ */
.routine-editor-list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.routine-item {
  background: var(--clr-surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.routine-item-info { flex: 1; }
.routine-item-name { font-weight: 600; }
.routine-item-duration { font-size: 0.82rem; color: var(--clr-text-muted); margin-top: 2px; }

.routine-item-duration input {
  width: 52px;
  padding: 4px 6px;
  font-size: 0.85rem;
  border: 1.5px solid var(--clr-border);
  border-radius: 4px;
  text-align: center;
  font-family: var(--font);
}

.routine-add-form {
  background: var(--clr-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.routine-add-form .row { display: flex; gap: 8px; }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 480px) {
  .workout-exercise-name { font-size: 1.4rem; }
  .workout-countdown { font-size: 4rem; }
  .home-header h1 { font-size: 1.6rem; }
}

@media (max-height: 700px) {
  #exercise-list { display: none; }
}
