:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --input-bg: #e2e8f0;
  --blue: #2b9af3;
  --blue-soft: #e0f2fe;
  --purple: #7c3aed;
  --purple-soft: #c084fc;
  --green: #22c55e;
  --green-soft: #dcfce7;
  --orange: #f59e0b;
  --orange-soft: #fef3c7;
}

body.theme-dark {
  --bg: #0f172a;
  --card: #1e293b;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --border: #334155;
  --input-bg: #334155;
  --blue: #38bdf8;
  --blue-soft: rgba(56, 189, 248, 0.18);
  --purple: #a855f7;
  --purple-soft: #7e22ce;
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.22);
  --orange: #f59e0b;
  --orange-soft: rgba(245, 158, 11, 0.25);
  background: #020617;
  color: var(--ink);
}

body.theme-dark .modal-sheet {
  background: #1e293b;
  color: #f8fafc;
  border-top: 1px solid #334155;
}
body.theme-dark .aw-input {
  background: #334155;
  color: #f8fafc;
}
body.theme-dark .aw-input:focus {
  background: #0f172a;
  border-color: var(--blue);
}
body.theme-dark .set-badge:not(.warmup),
body.theme-dark .check-btn:not(.done),
body.theme-dark .add-set-bar {
  background: #334155;
  color: #f8fafc;
}
body.theme-dark .icon-pill {
  background: rgba(56, 189, 248, 0.16);
  color: #38bdf8;
}
body.theme-dark .ex-row {
  border-bottom-color: #334155;
}
body.theme-dark .bg-choice-label {
  background: #1e293b;
  color: #f8fafc;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #e2e8f0;
  color: var(--ink);
}

/* Mobile-First App Container (Centered like iPhone on desktop, full width on mobile) */
.app-shell {
  max-width: 540px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  padding-bottom: 88px;
  position: relative;
  box-shadow: 0 0 32px rgba(15, 23, 42, 0.12);
}

.page-pad {
  padding: 1rem 1.15rem;
}

.page-title {
  font-size: 2rem;
  font-weight: 800;
  margin: 0.25rem 0 1rem;
  letter-spacing: -0.02em;
}

/* Alerts */
.toast {
  margin: 0.75rem 1.15rem 0;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
}
.toast-ok {
  background: #dcfce7;
  color: #15803d;
}
.toast-err {
  background: #fee2e2;
  color: #b91c1c;
}

/* Cards */
.w-card {
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.w-card-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.w-card-title {
  font-size: 1.08rem;
  font-weight: 700;
  margin: 0;
}

.w-card-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

/* Buttons & Pills */
.btn-blue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.78rem 1.2rem;
  border-radius: 11px;
  border: none;
  text-decoration: none;
  cursor: pointer;
  width: 100%;
}
.btn-blue:hover {
  background: #1a88e0;
}

.btn-green {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.48rem 1.1rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--blue-soft);
  color: #0284c7;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: none;
  text-decoration: none;
  cursor: pointer;
}

.icon-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #eef2ff;
  color: var(--blue);
  width: 36px;
  height: 30px;
  border-radius: 999px;
  border: none;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}

/* Profile Bar Chart (IMG_6038.PNG) */
.bar-chart-wrap {
  position: relative;
  padding-top: 0.5rem;
}
.bar-goal-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 0.2rem;
}
.bar-goal-line::before {
  content: "";
  flex: 1;
  height: 1.5px;
  background: #d8b4fe;
}
.bars-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.5rem;
  align-items: end;
  height: 135px;
  padding: 0 0.25rem;
  border-bottom: 1px solid #f1f5f9;
}
.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.bar-fill {
  width: 20px;
  border-radius: 6px 6px 3px 3px;
  background: var(--purple-soft);
  transition: height 0.2s;
}
.bar-fill.hit-goal {
  background: var(--purple);
}
.bars-labels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  text-align: center;
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 0.45rem;
}

/* Templates 2-Column Grid (IMG_6040.PNG) */
.templates-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.template-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 155px;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  position: relative;
  overflow: hidden;
}
.template-card:hover {
  border-color: var(--blue);
  transform: translateY(-1px);
}
.template-card.has-custom-bg {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.22);
}
.template-card.has-custom-bg .template-card-title {
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}
.template-card.has-custom-bg .template-card-preview {
  color: #e2e8f0;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.template-card.has-custom-bg .template-card-date {
  color: #cbd5e1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
}
.template-card.has-custom-bg .icon-pill {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  backdrop-filter: blur(4px);
}
.template-card-title {
  font-size: 1.05rem;
  font-weight: 800;
  margin: 0 0 0.35rem;
  line-height: 1.25;
}
.template-card-preview {
  font-size: 0.84rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.template-card-date {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Custom Theme Picker Grid on Profile Page */
.bg-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
}
.bg-choice-card {
  position: relative;
  border: 2.5px solid #e2e8f0;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: #0f172a;
  transition: border-color 0.15s, transform 0.12s;
  display: flex;
  flex-direction: column;
}
.bg-choice-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.bg-choice-card.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(43, 154, 243, 0.25);
}
.bg-choice-thumb {
  width: 100%;
  height: 68px;
  object-fit: cover;
  display: block;
}
.bg-choice-label {
  background: #ffffff;
  color: var(--ink);
  font-size: 0.73rem;
  font-weight: 700;
  padding: 0.35rem 0.4rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Exercises List (IMG_6039.PNG) */
.ex-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid #f1f5f9;
}
.ex-icon {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}
.ex-info {
  flex: 1;
  min-width: 0;
}
.ex-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 0.15rem;
}
.ex-sub {
  font-size: 0.88rem;
  color: var(--muted);
}
.ex-best {
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

/* Active Workout Table & Inline Countdown Rest Timers (IMG_6042.PNG) */
.aw-ex-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--blue);
  margin: 1.15rem 0 0.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.aw-set-header,
.aw-set-row {
  display: grid;
  grid-template-columns: 40px 1fr 74px 66px 38px 28px;
  gap: 0.4rem;
  align-items: center;
  text-align: center;
}
/* Wider Rest Timer Column during Template Builder Setup */
.builder-set-header,
.builder-set-row {
  display: grid;
  grid-template-columns: 38px 1fr 70px 64px 92px;
  gap: 0.45rem;
  align-items: center;
  text-align: center;
}
.del-set-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: #ef4444;
  font-size: 1.05rem;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0.75;
}
.del-set-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  opacity: 1;
}
.bg-del-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: rgba(239, 68, 68, 0.92);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.bg-del-btn:hover {
  background: #dc2626;
}
/* Active Workout Screen with Custom Background Image */
.active-workout-screen {
  min-height: 100vh;
  background: var(--card);
}
.active-workout-screen.has-workout-bg {
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
.active-workout-screen.has-workout-bg .aw-ex-card {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 16px;
  padding: 0.85rem 0.9rem;
  margin-bottom: 1.15rem;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.16);
}
body.theme-dark .active-workout-screen.has-workout-bg .aw-ex-card {
  background: rgba(15, 23, 42, 0.84);
  border-color: rgba(255, 255, 255, 0.14);
}
.aw-set-header {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.45rem;
}
.aw-set-row {
  padding: 0.25rem 0.2rem;
  border-radius: 10px;
  transition: background 0.15s;
}
.aw-set-row.done {
  background: var(--green-soft);
}
.set-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 28px;
  border-radius: 8px;
  background: #e2e8f0;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  border: none;
  text-decoration: underline;
}
.set-badge.warmup {
  background: var(--orange-soft);
  color: #d97706;
}
.prev-text {
  font-size: 0.92rem;
  color: #94a3b8;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.aw-input {
  width: 100%;
  background: #e2e8f0;
  border: 1.5px solid transparent;
  border-radius: 8px;
  padding: 0.35rem 0.25rem;
  font-size: 0.98rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
}
.aw-input:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
}
.check-btn {
  width: 34px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: #e2e8f0;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.check-btn.done {
  background: var(--green);
  color: #fff;
}

/* Inline Rest Timer Divider Line (2:00 / 1:00 between sets in IMG_6042.PNG) */
.rest-divider {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.3rem 0;
  position: relative;
}
.rest-line {
  flex: 1;
  height: 3px;
  background: #e0f2fe;
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}
.rest-line-fill {
  height: 100%;
  width: 0%;
  background: var(--blue);
  transition: width 0.25s linear;
}
.rest-time-pill {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--blue);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
}
.rest-time-pill.running {
  background: var(--blue);
  color: #fff;
  padding: 0.15rem 0.6rem;
}
.rest-time-pill.finished {
  background: var(--green);
  color: #fff;
}

.add-set-bar {
  width: 100%;
  background: #e2e8f0;
  color: var(--ink);
  border: none;
  border-radius: 8px;
  padding: 0.45rem;
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 0.35rem;
}

/* Modal Overlay (IMG_6041.PNG) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.modal-backdrop.open {
  display: flex;
}
.modal-sheet {
  background: #fff;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  border-radius: 22px 22px 0 0;
  padding: 1.15rem 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Fixed 5-Tab Bottom Navigation Bar (Matches IMG_6038..6041 + Custom Banner Pictures) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  background: #27272a;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 0.38rem 0.3rem 0.48rem;
  z-index: 100;
  border-top: 1px solid #3f3f46;
}
.bottom-nav.has-custom-banner .nav-tab {
  color: #e4e4e7;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.bottom-nav.has-custom-banner .nav-tab.active {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.35rem 0.2rem;
  border-radius: 10px;
  color: #a1a1aa;
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
}
.nav-tab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.nav-tab.active {
  background: #52525b;
  color: #ffffff;
}
