/* CSS Custom Properties for consistent theming */
:root {
  --primary-color: #bb86fc;
  --primary-hover: #9c4dcc;
  --secondary-color: #03dac6;
  --accent-color: #ff0080;
  --accent-secondary: #00ffe7;
  --background-dark: #121212;
  --background-card: rgba(30, 30, 30, 0.95);
  --background-overlay: rgba(0, 0, 0, 0.8);
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --border-color: #444444;
  --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.2);
  --shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.3);
  --border-radius-small: 8px;
  --border-radius-medium: 12px;
  --border-radius-large: 16px;
  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* Prevent unwanted zoom on double-click */
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
  background: linear-gradient(
    135deg,
    var(--background-dark) 0%,
    #1a1a1a 25%,
    #2d2d2d 50%,
    #1a1a1a 75%,
    var(--background-dark) 100%
  );
  background-attachment: fixed;
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  position: relative;
  height: 100vh;
  width: 100vw;
}

#loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2em;
  z-index: 1000;
  background: var(--background-card);
  backdrop-filter: blur(20px);
  padding: 40px 60px;
  border-radius: var(--border-radius-large);
  text-align: center;
  box-shadow: var(--shadow-heavy);
  border: 1px solid rgba(255, 255, 255, 0.1);
  min-width: 300px;
}

#loading::before {
  content: "";
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto 20px;
  border: 3px solid var(--text-muted);
  border-top: 3px solid var(--primary-color);
  border-radius: 50%;
  animation: loading-spin 1s linear infinite;
}

@keyframes loading-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 0.5px;
  font-size: 1.3em;
  margin-bottom: 24px;
}

.loading-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
}

.loading-step {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius-small);
  border-left: 3px solid var(--text-muted);
  font-size: 0.9em;
  color: var(--text-secondary);
  transition: all var(--transition-normal);
}

.loading-step.active {
  border-left-color: var(--primary-color);
  background: rgba(187, 134, 252, 0.1);
  color: var(--primary-color);
  animation: loading-pulse 1.5s ease-in-out infinite;
}

.loading-step.completed {
  border-left-color: var(--secondary-color);
  background: rgba(3, 218, 198, 0.1);
  color: var(--secondary-color);
}

@keyframes loading-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.app-wrapper {
  display: none;
  position: relative;
  height: 100vh;
  width: 100vw;
}

.app-wrapper.visible {
  display: block;
}

.video-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

video,
canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Performance optimizations */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  perspective: 1000px;
  -webkit-perspective: 1000px;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  z-index: 1;
}

video {
  transform: scaleX(-1) translateZ(0); /* Mirror effect with GPU acceleration */
  -webkit-transform: scaleX(-1) translateZ(0);
}

/* Header overlay - REMOVED for clean production look */
.header-overlay {
  display: none !important;
}

/* Enhanced Mobile Responsiveness */
@media (max-width: 768px) {
  .container {
    padding: 5px;
  }

  /* Ensure video container takes full space on mobile */
  .video-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
  }

  /* Header adjustments for mobile */
  .header-overlay {
    top: 5px;
    padding: 8px 15px;
    max-width: calc(100vw - 20px);
    z-index: 10;
  }

  .main-title {
    font-size: 1.8em;
    line-height: 1.1;
  }

  .subtitle {
    font-size: 0.9em;
  }

  /* Workout info positioning for mobile */
  .workout-info {
    position: absolute !important;
    top: 5px !important;
    right: 5px !important;
    padding: 8px 12px;
    min-width: 100px;
    max-width: 45vw;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    backdrop-filter: none !important;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  #workout-name {
    font-size: 1em;
    margin-bottom: 3px;
  }

  #rep-counter,
  #sets-counter {
    font-size: 2.2em;
    margin: 4px 0;
  }

  .counters-container {
    gap: 8px;
  }

  #feedback {
    font-size: 0.75em;
    margin-top: 6px;
    line-height: 1.2;
  }

  /* Options panel mobile adjustments */
  .options-panel {
    top: 5px;
    left: 5px;
    padding: 8px 12px;
    min-width: 100px;
    max-width: 40vw;
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  .options-panel-title {
    font-size: 0.8em;
    margin-bottom: 8px;
  }

  /* Workout selection mobile layout - already handled by fixed positioning */
  .workout-selection {
    padding: 16px 12px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .workout-selection h3 {
    font-size: 0.85em;
    margin-bottom: 10px;
    text-align: center;
  }

  .workout-buttons {
    gap: 6px;
    justify-content: space-between;
  }

  .workout-btn {
    padding: 10px 8px;
    min-width: 60px;
    flex: 1;
    max-width: calc(25% - 5px);
    min-height: 60px;
  }

  .workout-icon {
    font-size: 1.3em;
  }

  .workout-name {
    font-size: 0.7em;
    margin-top: 2px;
  }

  /* User input mobile positioning */
  .user-input {
    bottom: 80px; /* Adjusted to be above the fixed bottom bar */
    left: 10px;
    padding: 8px 12px;
    min-width: 100px;
    max-width: calc(45vw - 15px);
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
    z-index: 10;
  }

  #usernameDisplay {
    font-size: 0.9em;
    margin-bottom: 10px;
  }

  .save-workout-button {
    padding: 10px 14px;
    font-size: 0.8em;
    min-height: 44px;
  }

  /* Leaderboard nav mobile */
  .leaderboard-nav {
    top: 85px;
    right: 10px;
    max-width: calc(50vw - 15px);
  }

  .nav-button {
    padding: 10px 14px;
    font-size: 0.8em;
    min-height: 44px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Loading screen mobile */
  #loading {
    padding: 30px 40px;
    min-width: 280px;
    font-size: 1.1em;
  }
}

/* Small to medium screens - ensure consistent positioning */
@media (min-width: 481px) and (max-width: 768px) {
  .workout-info {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    padding: 12px 16px;
    min-width: 120px;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    border-radius: 0 !important;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .workout-selection {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: transparent !important;
    backdrop-filter: none !important;
    border-top: none !important;
    box-shadow: none !important;
    z-index: 1000 !important;
  }

  .workout-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .workout-btn {
    width: 100%;
    max-width: none;
    flex: none;
    padding: 14px 12px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    min-height: 65px;
  }

  .workout-icon {
    font-size: 1.4em;
  }

  .workout-name {
    font-size: 0.75em;
    text-align: center;
  }

  .user-input {
    bottom: 80px; /* Positioned above the fixed bottom bar */
    left: 10px;
    right: auto;
    width: calc(45vw - 15px);
    max-width: 150px;
    background: transparent;
    border: none;
    border-radius: 0;
    backdrop-filter: none;
  }

  .workout-info {
    position: absolute !important;
    top: 10px !important;
    right: 10px !important;
    margin: 0 !important;
    width: auto !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    border-radius: 0 !important;
    padding: 8px 12px !important;
    min-width: 100px !important;
    max-width: 45vw !important;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  .options-panel {
    position: absolute !important;
    top: 10px !important;
    left: 10px !important;
    margin: 0 !important;
    width: auto !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    border-radius: 0 !important;
    padding: 8px 12px !important;
    min-width: 100px !important;
    max-width: 40vw !important;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  .leaderboard-nav {
    position: absolute !important;
    top: 100px !important;
    right: 20px !important;
    margin: 0 !important;
    z-index: 1001 !important;
    pointer-events: auto !important;
  }

  /* Reset app wrapper and video container */
  .app-wrapper {
    position: relative;
    padding: 0;
  }

  .video-container {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 1 !important;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
  #rep-counter,
  #sets-counter {
    font-size: 2em;
  }

  .workout-info {
    padding: 8px 12px;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    border-radius: 0 !important;
  }

  .workout-selection {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    padding: 12px 20px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: transparent !important;
    border-top: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    z-index: 1000 !important;
  }

  .user-input {
    bottom: 70px; /* Above the fixed bottom bar in landscape */
    padding: 8px 12px;
    background: transparent;
    border: none;
    box-shadow: none;
  }
}

.workout-info {
  position: absolute !important;
  top: 10px !important;
  right: 10px !important;
  z-index: 1001 !important; /* Higher than workout-selection to prevent overlay */
  background: transparent !important;
  backdrop-filter: none !important;
  padding: 12px 16px;
  border-radius: 0 !important;
  box-shadow: none !important;
  border: none !important;
  text-align: center;
  min-width: 120px;
  transition: all var(--transition-normal);
  overflow: visible;
  /* Ensure all interactive elements are accessible */
  pointer-events: auto !important;
}

.workout-info::before {
  display: none;
}

.workout-info:hover {
  background: transparent;
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

#workout-name {
  margin: 0 0 6px 0;
  color: var(--primary-color);
  font-size: 1.2em;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: capitalize;
}

.counter-label {
  font-size: 0.75em;
  color: rgb(196, 10, 180);
  margin-bottom: 4px;
  font-weight: 400;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* Counters container for side-by-side display */
.counters-container {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0;
  align-items: flex-start;
}

.counter {
  flex: 1;
  text-align: center;
  min-width: 70px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.counter-label {
  font-size: 0.65em;
  font-weight: 500;
  color: var(--primary-hover);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

#rep-counter,
#sets-counter {
  font-size: 2.8em;
  font-weight: 600;
  margin: 4px 0;
  color: var(--secondary-color);
  text-shadow: 0 0 15px rgb(153, 0, 158);
  line-height: 1;
  transition: all var(--transition-normal);
}

#sets-counter {
  color: var(--secondary-color);
  text-shadow: 0 0 15px rgba(153, 0, 158);
}

#rep-counter.pulse,
#sets-counter.pulse {
  transform: scale(1.1);
  text-shadow: 0 0 30px rgba(218, 3, 214, 0.6);
}

#feedback {
  font-size: 0.9em;
  font-weight: 400;
  min-height: 20px;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 0;
  background: transparent;
  border: none;
  transition: all var(--transition-normal);
}

#feedback.positive {
  color: var(--secondary-color);
  background: rgba(3, 218, 198, 0.1);
  border-color: var(--secondary-color);
}

#feedback.warning {
  color: #ffa726;
  background: rgba(255, 167, 38, 0.1);
  border-color: #ffa726;
}

#feedback.error {
  color: #f44336;
  background: rgba(244, 67, 54, 0.1);
  border-color: #f44336;
}

.workout-selection {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000; /* Lower than interactive panels but higher than video */
  background: transparent;
  backdrop-filter: none;
  padding: 12px 16px;
  border-radius: 0;
  text-align: center;
  box-shadow: none;
  border-top: none;
  width: 100%;
  /* Safe area support for devices with home indicators */
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  /* Ensure it doesn't interfere with other elements */
  pointer-events: auto;
  /* Prevent it from extending beyond its designated bottom area */
  max-height: 20vh;
  overflow: visible;
}

.workout-selection::before {
  display: none;
}

.workout-selection h3 {
  display: none; /* Hidden for clean native app look */
}

.workout-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 600px;
  margin: 0 auto;
}

.workout-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: none;
  padding: 12px 16px;
  border-radius: 0;
  cursor: pointer;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 70px;
  min-height: 50px;
  backdrop-filter: none;
  font-size: 0.85em;
  font-weight: 400;
  white-space: nowrap;
  text-transform: capitalize;
  letter-spacing: 0.3px;
  flex: 1;
  max-width: 100px;
}

.workout-btn::before {
  display: none;
}

.workout-icon {
  font-size: 1.6em;
  transition: filter var(--transition-normal);
  filter: grayscale(0.3);
}

.workout-name {
  font-size: 0.85em;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.workout-btn:hover {
  background: transparent;
  border-color: transparent;
  transform: none;
  box-shadow: none;
  color: rgba(255, 255, 255, 0.9);
}

.workout-btn:hover .workout-icon {
  transform: none;
  filter: grayscale(0);
}

.workout-btn.active {
  background: transparent;
  color: var(--primary-color);
  border-color: transparent;
  font-weight: 600;
  box-shadow: none;
  transform: none;
  text-shadow: 0 0 8px rgba(187, 134, 252, 0.6);
}

.workout-btn.active .workout-icon {
  filter: grayscale(0);
  transform: scale(1.05);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.workout-btn.active .workout-name {
  font-weight: 700;
}

.workout-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.3);
  background: transparent;
  border-color: transparent;
}

.workout-btn:active {
  transform: translateY(-1px);
}

.options-panel {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1001 !important; /* Higher than workout-selection to prevent overlay */
  background: transparent;
  backdrop-filter: none;
  border-radius: 0;
  padding: 12px 16px;
  box-shadow: none;
  border: none;
  color: var(--text-primary);
  min-width: 120px;
  transition: all var(--transition-normal);
  overflow: hidden;
  /* Ensure all interactive elements are accessible */
  pointer-events: auto !important;
}

.options-panel::before {
  display: none;
}

.options-panel:hover {
  background: transparent;
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

.options-panel:hover::before {
  display: none;
}

.options-panel-title {
  margin: 0 0 12px 0;
  font-size: 0.85em;
  font-weight: 500;
  color: rgba(250, 4, 246, 0.7);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.options-panel-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 8px 0;
  transition: color var(--transition-fast);
}

.options-panel-label:hover {
  color: var(--primary-color);
}

.options-panel-text {
  font-size: 0.55em;
  font-weight: 500;
}

.options-panel input[type="checkbox"] {
  width: 8px;
  height: 8px;
  accent-color: var(--primary-color);
  cursor: pointer !important;
  /* Force checkbox to be interactive */
  z-index: 999998 !important;
  position: relative !important;
  pointer-events: auto !important;
  touch-action: manipulation !important;
}

.pose-status-container {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.pose-status {
  font-size: 0.8em;
  font-weight: 400;
  padding: 4px 8px;
  border-radius: 0;
  background: transparent;
  border: none;
  transition: all var(--transition-fast);
  display: inline-block;
  width: 100px;
  text-align: center;
  box-sizing: border-box;
}

.pose-status.pose-detected {
  color: var(--secondary-color);
  background: rgba(3, 218, 198, 0.1);
  border-color: var(--secondary-color);
}

.pose-status.no-pose {
  color: #ffa726;
  background: rgba(255, 167, 38, 0.1);
  border-color: #ffa726;
}

.main-title {
  font-family: "Bangers", cursive;
  color: #ff0080;
  text-shadow: 2px 2px 0 #000, 4px 4px 0 #00ffe7;
  letter-spacing: 2px;
  font-size: 3.5em;
  margin-bottom: 0.1em;
}

.subtitle {
  font-family: "Pacifico", cursive;
  color: #00ffe7;
  font-size: 1.1em;
  margin-top: -0.5em;
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000;
}

.user-input {
  position: absolute;
  bottom: 100px; /* Positioned above the fixed bottom bar */
  left: 10px;
  z-index: 100;
  background: transparent;
  backdrop-filter: none;
  padding: 12px 16px;
  border-radius: 0;
  box-shadow: none;
  border: none;
  min-width: 120px;
  transition: all var(--transition-normal);
  overflow: hidden;
}

.user-input::before {
  display: none;
}

.user-input:hover {
  background: transparent;
  transform: none;
  box-shadow: none;
  border-color: transparent;
}

.user-input:hover::before {
  display: none;
}

.user-input-label {
  display: block;
  margin-bottom: 5px;
  color: #00ffe7;
}

.user-input-field {
  width: 100%;
  padding: 8px;
  border-radius: 5px;
  border: 1px solid #444;
  background-color: #333;
  color: #e0e0e0;
}

#usernameDisplay {
  margin: 0 0 10px 0;
  color: var(--secondary-color);
  text-shadow: 0 0 15px rgb(153, 0, 158);
  font-weight: 500;
  font-size: 0.9em;
  letter-spacing: 0.3px;
}

.save-workout-button {
  background: transparent;
  color: var(--secondary-color);
  text-shadow: 0 0 15px rgb(153, 0, 158);
  border: none;
  outline: none;
  padding: 8px 12px;
  border-radius: 0;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 400;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
  text-transform: none;
  letter-spacing: 0.3px;
}

.save-workout-button::before {
  display: none;
}

.save-workout-button:hover {
  background: transparent;
  color: rgba(255, 255, 255, 1);
  transform: none;
  box-shadow: none;
}

.save-workout-button:active {
  transform: translateY(-1px);
}

.save-workout-button:focus {
  outline: none;
  box-shadow: none;
  border: none;
}

.save-workout-button:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.save-workout-button:disabled::before {
  display: none;
}

/* REST BUTTON STYLES - Critical for interaction */
.rest-button,
#restBtn {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 8px 16px;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 500;
  transition: all var(--transition-normal);
  position: relative;
  z-index: 999999 !important; /* Ensure button is always clickable */
  pointer-events: auto !important;
  touch-action: manipulation !important;
  min-height: 44px;
  margin: 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rest-button:hover,
#restBtn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 1);
  border-color: rgba(255, 255, 255, 0.6);
  transform: translateY(-1px);
}

.rest-button:active,
#restBtn:active {
  transform: translateY(0);
  background: rgba(255, 255, 255, 0.2);
}

.rest-button:focus,
#restBtn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.5);
  border-color: var(--primary-color);
}

.rest-button.resting,
#restBtn.resting {
  background: var(--primary-color);
  color: var(--background-dark);
  border-color: var(--primary-color);
  animation: restingPulse 2s ease-in-out infinite;
}

@keyframes restingPulse {
  0%,
  100% {
    background: var(--primary-color);
  }
  50% {
    background: var(--primary-hover);
  }
}

/* UNIVERSAL REST BUTTON STYLES - Consolidated and simplified */

/* Leaderboard navigation button */
.leaderboard-nav {
  position: absolute;
  top: 100px;
  right: 20px;
  z-index: 100;
}

.nav-button {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: none;
  padding: 8px 12px;
  border-radius: 0;
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 400;
  transition: all var(--transition-normal);
  backdrop-filter: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0.3px;
  position: relative;
  overflow: hidden;
}

.nav-button::before {
  display: none;
}

.nav-button:hover {
  background: transparent;
  color: rgba(255, 255, 255, 1);
  transform: none;
  box-shadow: none;
}

.nav-button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(187, 134, 252, 0.3);
}

/* Enhanced animations and transitions */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInFromRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

@keyframes repCounterPulse {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.15);
    text-shadow: 0 0 30px rgba(3, 218, 198, 0.8);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes successGlow {
  0% {
    box-shadow: 0 0 5px rgba(3, 218, 198, 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(3, 218, 198, 0.8), 0 0 30px rgba(3, 218, 198, 0.4);
  }
  100% {
    box-shadow: 0 0 5px rgba(3, 218, 198, 0.3);
  }
}

@keyframes shakeError {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Apply simple animations to UI elements */
.app-wrapper.visible {
  animation: fadeIn 0.5s ease-out;
}

.workout-info,
.user-input,
.workout-selection,
.options-panel,
.leaderboard-nav {
  animation: fadeIn 0.3s ease-out;
}

/* Rep counter animation classes */
.rep-pulse {
  animation: repCounterPulse 0.4s ease-out;
}

.success-glow {
  animation: successGlow 1s ease-in-out;
}

.error-shake {
  animation: shakeError 0.5s ease-in-out;
}

/* Improved hover effects */
.workout-info:hover,
.user-input:hover,
.options-panel:hover {
  animation: none; /* Disable entrance animations on hover */
}

/* Enhanced focus styles for accessibility */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: var(--border-radius-small);
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Utility classes */
.hidden {
  display: none !important;
  opacity: 0;
  visibility: hidden;
}

.visible {
  display: flex !important;
  opacity: 1;
  visibility: visible;
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

.slide-in-right {
  animation: slideInFromRight 0.5s ease-out;
}

.slide-in-left {
  animation: slideInFromLeft 0.5s ease-out;
}

.slide-in-bottom {
  animation: slideInFromBottom 0.5s ease-out;
}

/* Error State Styling */
.error-message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(244, 67, 54, 0.95);
  color: white;
  padding: 20px 30px;
  border-radius: var(--border-radius-large);
  box-shadow: var(--shadow-heavy);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(244, 67, 54, 0.8);
  z-index: 1001;
  text-align: center;
  max-width: 400px;
  min-width: 300px;
}

.error-message h3 {
  margin: 0 0 12px 0;
  font-size: 1.2em;
  font-weight: 600;
}

.error-message p {
  margin: 0 0 20px 0;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.9);
}

.error-message button {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 10px 20px;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  font-weight: 500;
  transition: all var(--transition-normal);
  margin: 0 5px;
}

.error-message button:hover {
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
}

.error-message button.primary {
  background: white;
  color: #f44336;
  border-color: white;
}

.error-message button.primary:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* Camera permission error */
.camera-error {
  background: rgba(255, 193, 7, 0.95);
  border-color: rgba(255, 193, 7, 0.8);
  color: #1a1a1a;
}

.camera-error button {
  color: #1a1a1a;
  border-color: rgba(0, 0, 0, 0.2);
}

.camera-error button.primary {
  background: #1a1a1a;
  color: white;
  border-color: #1a1a1a;
}

/* Connection error */
.connection-error {
  background: rgba(156, 39, 176, 0.95);
  border-color: rgba(156, 39, 176, 0.8);
}

/* Success message */
.success-message {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(76, 175, 80, 0.95);
  color: white;
  padding: 16px 24px;
  border-radius: var(--border-radius-medium);
  box-shadow: var(--shadow-medium);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(76, 175, 80, 0.8);
  z-index: 1000;
  animation: slideInFromRight 0.5s ease-out;
  max-width: 300px;
}

.success-message.fade-out {
  animation: fadeOut 0.5s ease-out forwards;
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* Offline indicator */
.offline-indicator {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(158, 158, 158, 0.95);
  color: white;
  padding: 12px 20px;
  border-radius: var(--border-radius-medium);
  font-size: 0.9em;
  font-weight: 500;
  z-index: 1000;
  animation: slideInFromBottom 0.5s ease-out;
}

/* Performance warning */
.performance-warning {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 152, 0, 0.95);
  color: white;
  padding: 20px 30px;
  border-radius: var(--border-radius-large);
  box-shadow: var(--shadow-heavy);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 152, 0, 0.8);
  z-index: 1001;
  text-align: center;
  max-width: 400px;
}

.performance-warning h3 {
  margin: 0 0 12px 0;
  font-size: 1.1em;
  font-weight: 600;
}

.performance-warning p {
  margin: 0 0 20px 0;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95em;
}

/* Accessibility Improvements */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --background-dark: #000000;
    --background-card: rgba(0, 0, 0, 0.95);
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --border-color: #ffffff;
  }

  .workout-btn {
    border-width: 2px;
  }

  .save-workout-button {
    border: 2px solid var(--primary-color);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .loading-spinner {
    animation: none;
  }

  .loading-spinner::after {
    animation: none;
  }
}

/* Focus management */
.focus-trap {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: transparent;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--primary-color);
  color: var(--background-dark);
  padding: 8px;
  border-radius: var(--border-radius-small);
  text-decoration: none;
  font-weight: 600;
  z-index: 10000;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 6px;
}

/* Enhanced keyboard navigation */
[role="radiogroup"] {
  position: relative;
}

[role="radio"]:focus {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

/* Improved button states */
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:disabled:hover {
  transform: none !important;
  box-shadow: none !important;
}

/* ARIA live region styling */
[aria-live] {
  position: relative;
}

[aria-live="assertive"] {
  font-weight: 600;
}

/* Screen reader announcements */
.announcement {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Color blind friendly improvements */
@media (prefers-color-scheme: no-preference) {
  .workout-btn.active {
    border: 3px solid var(--background-dark);
  }

  #feedback.positive::before {
    content: "✓ ";
    color: var(--secondary-color);
  }

  #feedback.warning::before {
    content: "⚠ ";
    color: #ffa726;
  }

  #feedback.error::before {
    content: "✗ ";
    color: #f44336;
  }
}

/* Ensure minimum touch target size */
@media (pointer: coarse) {
  button,
  input[type="checkbox"] {
    min-height: 44px;
    min-width: 44px;
  }

  .workout-btn {
    min-height: 64px;
    min-width: 64px;
  }
}

/* Dynamic viewport unit support for mobile browsers */
@supports (height: 100dvh) {
  body {
    height: 100dvh;
  }

  .container {
    height: 100dvh;
  }

  .video-container {
    height: 100dvh;
  }

  .app-wrapper {
    height: 100dvh;
  }
}

/* Responsive font scaling */
@media (max-width: 320px) {
  :root {
    font-size: 14px;
  }
}

@media (min-width: 1200px) {
  :root {
    font-size: 18px;
  }
}

/* Safe area insets for devices with notches */
@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    .header-overlay {
      top: max(5px, env(safe-area-inset-top));
      padding-left: max(15px, env(safe-area-inset-left));
      padding-right: max(15px, env(safe-area-inset-right));
    }

    .workout-info {
      top: max(5px, env(safe-area-inset-top));
      right: max(5px, env(safe-area-inset-right));
    }

    .options-panel {
      top: max(5px, env(safe-area-inset-top));
      left: max(5px, env(safe-area-inset-left));
    }

    .workout-selection {
      padding-bottom: max(20px, env(safe-area-inset-bottom));
      padding-left: max(16px, env(safe-area-inset-left));
      padding-right: max(16px, env(safe-area-inset-right));
    }

    .user-input {
      bottom: max(120px, calc(120px + env(safe-area-inset-bottom)));
      left: max(10px, env(safe-area-inset-left));
    }

    .leaderboard-nav {
      right: max(10px, env(safe-area-inset-right));
    }
  }
}

/* Container queries for more precise responsive design */
@supports (container-type: inline-size) {
  .video-container {
    container-type: inline-size;
  }

  @container (max-width: 480px) {
    .workout-info {
      padding: 8px 12px;
    }

    #rep-counter,
    #sets-counter {
      font-size: 2em;
    }

    .counter-label {
      font-size: 0.6em;
    }
  }

  @container (min-width: 800px) {
    .workout-info {
      padding: 24px 28px;
    }

    #rep-counter,
    #sets-counter {
      font-size: 4.5em;
    }
  }
}

/* Additional fixes for text wrapping and layout issues */
@media (max-width: 320px), (max-height: 600px) {
  .counter-label {
    font-size: 0.55em;
    line-height: 1.1;
    margin-bottom: 2px;
  }

  .counters-container {
    gap: 8px;
  }

  .counter {
    min-width: 60px;
  }

  #rep-counter,
  #sets-counter {
    font-size: 2.2em;
    margin: 2px 0;
  }
}

/* Fullscreen mode specific fixes */
@media (max-width: 480px) and (orientation: portrait) {
  .workout-info {
    max-width: 40vw !important;
    padding: 6px 10px !important;
  }

  .counter-label {
    font-size: 0.5em !important;
    margin-bottom: 2px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .counter {
    min-width: 55px !important;
  }

  #rep-counter,
  #sets-counter {
    font-size: 2em !important;
    margin: 2px 0 !important;
  }
}

/* Landscape fullscreen fixes */
@media (max-height: 500px) and (orientation: landscape) {
  .workout-info {
    padding: 6px 10px !important;
    max-width: 35vw !important;
  }

  .counter-label {
    font-size: 0.5em !important;
    margin-bottom: 1px !important;
  }

  #rep-counter,
  #sets-counter {
    font-size: 1.8em !important;
    margin: 1px 0 !important;
  }

  .counters-container {
    gap: 6px !important;
  }
}

/* Save Button Styles */
.save-button,
#saveWorkoutBtn {
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  border: 2px solid rgba(34, 197, 94, 0.3);
  padding: 8px 16px;
  border-radius: var(--border-radius-small);
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 500;
  transition: all var(--transition-normal);
  margin-top: 8px;
}

.save-button:hover,
#saveWorkoutBtn:hover {
  background: rgba(34, 197, 94, 0.1);
  color: rgba(255, 255, 255, 1);
  border-color: rgba(34, 197, 94, 0.6);
  transform: translateY(-1px);
}

.save-button:active,
#saveWorkoutBtn:active {
  transform: translateY(0);
  background: rgba(34, 197, 94, 0.2);
}

.save-button:focus,
#saveWorkoutBtn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.5);
  border-color: #22c55e;
}

/* User Info Styles */
.user-info-container {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.username-display {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.8em;
  font-weight: 400;
}
