/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  /* ── HomeFit Studio Brand Palette ─────────────────────────────── */

  /* Primary — Coral Orange */
  --color-primary: #FF6B35;
  --color-primary-dark: #E85A24;
  --color-primary-light: #FF8F5E;
  --color-primary-surface: #FFF3ED;

  /* Neutrals */
  --white: #ffffff;
  --off-white: #fafafb;
  --gray-50: #f3f4f6;
  --gray-100: #e5e7eb;
  --gray-200: #d1d5db;
  --gray-300: #9ca3af;
  --gray-400: #6b7280;
  --gray-500: #4b5563;
  --gray-600: #374151;
  --gray-700: #1f2937;
  --gray-800: #111827;
  --gray-900: #1a1a2e;
  --black: #0a0a0a;

  /* Text */
  --color-text-primary: #1a1a2e;
  --color-text-secondary: #6b7280;

  /* Semantic */
  --color-success: #22c55e;
  --color-success-light: #dcfce7;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  --color-error: #ef4444;
  --color-error-light: #fee2e2;

  /* Feature accents */
  --color-circuit: #14b8a6;
  --color-circuit-light: #ccfbf1;
  --color-circuit-dark: #0d9488;
  --color-rest: #64748b;
  --color-rest-light: #f1f5f9;
  --color-rest-surface: #e2e8f0;

  /* Dark mode surfaces */
  --color-dark-bg: #0f1117;
  --color-dark-surface: #1a1d27;
  --color-dark-surface-variant: #242733;
  --color-dark-border: #2e3140;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-card-hover: 0 2px 8px rgba(0,0,0,0.08), 0 8px 24px rgba(0,0,0,0.06);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Typography */
  --font-heading: 'Montserrat', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, monospace;

  /* Safe areas */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--white);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  height: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
  touch-action: pan-y;
}

/* === Loading Screen === */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  z-index: 100;
  transition: opacity var(--transition-normal);
}

.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  background: var(--color-primary);
  color: var(--white);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.02em;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.loading-text {
  color: var(--gray-500);
  font-size: 14px;
}

/* === Error Screen === */
.error-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  z-index: 90;
  padding: 32px;
}

.error-content {
  text-align: center;
  max-width: 300px;
}

.error-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  border: 2px solid var(--gray-300);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  color: var(--gray-400);
}

.error-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--gray-800);
}

.error-text {
  font-size: 14px;
  color: var(--gray-500);
  line-height: 1.6;
}

/* === App Layout === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  position: relative;
}

/* === Header === */
.header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--gray-100);
  background: var(--white);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
}

.header-brand {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

.header-client {
  font-size: 13px;
  color: var(--gray-500);
  font-weight: 500;
}

/* === Plan Bar === */
.plan-bar {
  flex-shrink: 0;
  padding: 16px 20px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.plan-title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.progress-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-400);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* === Progress Track === */
.progress-track {
  flex-shrink: 0;
  height: 2px;
  background: var(--gray-100);
  margin: 0 20px 4px;
  border-radius: 1px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 1px;
  transition: width var(--transition-slow);
  width: 0%;
}

/* === Card Viewport === */
.card-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  padding: 12px 0;
  touch-action: pan-y;
}

.card-track {
  display: flex;
  height: 100%;
  transition: transform var(--transition-slow);
  will-change: transform;
}

.card-track.is-swiping {
  transition: none;
}

/* === Exercise Card === */
.exercise-card {
  flex: 0 0 100%;
  width: 100%;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-normal);
}

/* === Media Area === */
.card-media {
  flex: 1;
  min-height: 0;
  background: var(--gray-50);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.card-media img,
.card-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Placeholder when no media */
.media-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  color: var(--gray-400);
}

.media-placeholder-icon {
  width: 64px;
  height: 64px;
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.media-placeholder-icon svg {
  width: 28px;
  height: 28px;
  stroke: var(--gray-300);
}

.media-placeholder-text {
  font-size: 13px;
  color: var(--gray-400);
}

/* Video play overlay */
.video-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.03);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.video-play-overlay:active {
  background: rgba(0,0,0,0.08);
}

.play-button {
  width: 56px;
  height: 56px;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  transition: transform var(--transition-fast);
}

.video-play-overlay:active .play-button {
  transform: scale(0.92);
}

.play-button svg {
  width: 22px;
  height: 22px;
  margin-left: 3px;
  fill: var(--gray-800);
}

.video-play-overlay.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* === Card Body === */
.card-body {
  flex-shrink: 0;
  padding: 20px;
}

.card-position {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-400);
  margin-bottom: 4px;
}

.card-exercise-name {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
  line-height: 1.25;
  margin-bottom: 12px;
}

/* Prescription pills */
.card-prescription {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.rx-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
}

.rx-pill-label {
  font-weight: 400;
  color: var(--gray-500);
}

/* Notes */
.card-notes {
  font-size: 14px;
  line-height: 1.6;
  color: var(--gray-600);
  padding: 12px 14px;
  background: var(--gray-50);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--gray-200);
}

/* === Navigation === */
.nav-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 16px;
  gap: 16px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--gray-800);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.nav-btn:active:not(:disabled) {
  background: var(--gray-50);
  transform: scale(0.97);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-btn-label {
  font-size: 14px;
}

/* Dots */
.nav-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex: 1;
  overflow: hidden;
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gray-200);
  transition: all var(--transition-normal);
  flex-shrink: 0;
}

.nav-dot.is-active {
  background: var(--color-primary);
  width: 18px;
  border-radius: 3px;
}

/* === Footer === */
.footer {
  flex-shrink: 0;
  text-align: center;
  padding: 0 20px 12px;
}

.footer-text {
  font-size: 12px;
  color: var(--gray-400);
}

/* === Swipe Hint === */
@keyframes swipe-hint {
  0% { transform: translateX(0); opacity: 1; }
  30% { transform: translateX(-20px); opacity: 1; }
  60% { transform: translateX(0); opacity: 1; }
  100% { opacity: 0; }
}

.swipe-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--gray-800);
  color: var(--white);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  animation: swipe-hint 2.5s ease forwards;
  animation-delay: 1s;
  opacity: 0;
  z-index: 10;
}

@keyframes swipe-hint-appear {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.swipe-hint {
  animation: swipe-hint-appear 0.3s ease 1s forwards, swipe-hint 2.5s ease 1.5s forwards;
}

.swipe-hint svg {
  width: 14px;
  height: 14px;
}

/* === Responsive adjustments === */
@media (min-width: 480px) {
  .exercise-card {
    padding: 0 32px;
  }

  .plan-bar {
    padding-left: 32px;
    padding-right: 32px;
  }

  .progress-track {
    margin-left: 32px;
    margin-right: 32px;
  }

  .header-inner {
    padding-left: 32px;
    padding-right: 32px;
  }

  .nav-bar {
    padding-left: 32px;
    padding-right: 32px;
  }
}

/* === Rest Card === */
.rest-card {
  background: linear-gradient(160deg, var(--color-rest-light) 0%, var(--color-rest-surface) 40%, #c5d3dc 100%);
  border-color: #bcc9d1;
}

.rest-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  text-align: center;
}

.rest-icon {
  width: 80px;
  height: 80px;
  color: #5a7a8a;
  opacity: 0.8;
}

.rest-icon svg {
  width: 100%;
  height: 100%;
}

.rest-title {
  font-size: 28px;
  font-weight: 700;
  color: #3d5a6a;
  letter-spacing: -0.02em;
}

.rest-duration {
  font-size: 48px;
  font-weight: 800;
  color: #2c4a5a;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.rest-next-up {
  font-size: 14px;
  color: #5a7a8a;
  font-weight: 500;
  margin-top: 8px;
}

/* === Circuit Bar === */
.circuit-bar {
  flex-shrink: 0;
  background: var(--color-circuit-dark);
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 6px 16px;
  letter-spacing: 0.02em;
}

/* === Workout Timer Mode === */

/* Start Workout floating button */
.start-workout-btn {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--color-primary);
  color: var(--white);
  border: none;
  border-radius: 100px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(255,107,53,0.3);
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.start-workout-btn:active {
  transform: translateX(-50%) scale(0.95);
}

.start-workout-btn svg {
  width: 20px;
  height: 20px;
}

/* Timer overlay — centered over card viewport */
.timer-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 140px;
  height: 140px;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.timer-overlay-bg {
  position: absolute;
  inset: -10px;
  background: rgba(0,0,0,0.35);
  border-radius: 50%;
  filter: blur(16px);
}

.timer-ring {
  position: absolute;
  width: 120px;
  height: 120px;
}

.timer-ring-progress {
  transition: stroke 0.3s ease, stroke-dashoffset 0.3s linear;
}

.timer-text {
  position: relative;
  font-size: 36px;
  font-weight: 700;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 1;
}

/* Play gate — full viewport overlay between exercises */
.play-gate {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.25);
  -webkit-tap-highlight-color: transparent;
}

.play-gate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.play-gate-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--white);
  color: var(--gray-900);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  transition: transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.play-gate-btn:active {
  transform: scale(0.92);
}

.play-gate-btn svg {
  width: 36px;
  height: 36px;
  margin-left: 4px;
}

.play-gate-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

/* Rest countdown overlay (over the card viewport in workout mode) */
.rest-countdown {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
}

.rest-countdown-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rest-countdown-time {
  font-size: 72px;
  font-weight: 800;
  color: var(--white);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 12px rgba(0,0,0,0.3);
  line-height: 1;
}

.rest-countdown-next {
  font-size: 16px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Pause / Resume button */
.pause-btn {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.5);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 26;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all var(--transition-fast);
}

.pause-btn:active {
  transform: translateX(-50%) scale(0.92);
}

.pause-btn svg {
  width: 20px;
  height: 20px;
}

/* Workout complete overlay */
.workout-complete {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.workout-complete-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 40px;
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
  max-width: 300px;
}

.workout-complete-icon {
  width: 64px;
  height: 64px;
  color: var(--color-success);
}

.workout-complete-icon svg {
  width: 100%;
  height: 100%;
}

.workout-complete-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.02em;
}

.workout-complete-time {
  font-size: 16px;
  color: var(--gray-500);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.workout-close-btn {
  margin-top: 8px;
  padding: 12px 32px;
  background: var(--color-primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.workout-close-btn:active {
  transform: scale(0.97);
}

/* Desktop: constrain to phone-like width */
@media (min-width: 640px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-100);
  }

  #app {
    max-width: 430px;
    width: 100%;
    height: 100%;
    max-height: 932px;
    background: var(--white);
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    overflow: hidden;
    position: relative;
  }

  .loading-screen,
  .error-screen {
    border-radius: var(--radius-xl);
  }

  /* Keep workout overlays inside the app container on desktop */
  .workout-complete {
    position: absolute;
  }
}
