/**
 * Anatomy Canvas Styles
 * Interactive muscle visualization component
 */

.anatomy-canvas {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  background: transparent; /* Match page background */
  border-radius: 24px;
}

/* Controls */
.anatomy-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.gender-selector {
  display: flex;
  gap: 4px;
  background: rgba(40, 40, 40, 0.8);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.gender-btn {
  padding: 8px 20px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch target size */
}

.gender-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.05);
}

.gender-btn.active {
  background: linear-gradient(135deg, #ec4899, #f97316);
  color: white;
  box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3);
}

.view-selector {
  display: flex;
  gap: 4px;
  background: rgba(40, 40, 40, 0.8);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.view-btn {
  padding: 8px 20px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px; /* Touch target size */
}

.view-btn:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.05);
}

.view-btn.active {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}


/* Canvas Space */
.anatomy-space {
  position: relative;
  width: 100%;
  aspect-ratio: 596 / 842;
  background-color: #0c1222;
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.1);
  -webkit-tap-highlight-color: transparent;
}

.anatomy-body {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Prevent creating isolated stacking context so blend modes work with background */
  isolation: auto;
}

.silhouette-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.silhouette-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  /* Body silhouette - bright and visible */
  filter: invert(1) brightness(0.6) contrast(1.1);
  opacity: 0.7;
  pointer-events: none;
}

.muscles-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Muscle SVGs */
.muscle-svg {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: filter 0.2s ease, opacity 0.2s ease;
  pointer-events: auto; /* Ensure clickable */
  cursor: pointer;
}

/* Selected state - make muscle pop out */
.muscle-svg.selected {
  z-index: 10;
  transform: scale(1.03);
  transition: transform 0.15s ease, filter 0.15s ease;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
}


/* Minimal Recovery Controls */
.recovery-controls-minimal {
  display: flex !important;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin: 16px auto 12px;
  padding: 8px;
  max-width: 240px;
  z-index: 10;
  background: rgba(30, 30, 30, 0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.15);
  margin: 0 4px;
}

.icon-btn {
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0) scale(0.95);
}

.icon-btn.active {
  background: rgba(255, 255, 255, 0.15);
  color: #f97316;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.icon-btn.active::after {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: #f97316;
  border-radius: 50%;
}

/* Tooltip on hover */
.icon-btn::before {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 8px;
}

.icon-btn:hover::before {
  opacity: 1;
}

/* Hide old controls */
.recovery-controls {
  display: none !important;
}

/* Recovery Edit Overlay */
.recovery-edit-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.recovery-popup {
  background: rgba(30, 30, 30, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  animation: popup-fade-in 0.2s ease-out;
}

@keyframes popup-fade-in {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.popup-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: white;
}

.close-popup {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 44px; /* Larger touch target */
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.close-popup:hover {
  color: rgba(255, 255, 255, 0.9);
}

.popup-content {
  padding: 20px;
}

.recovery-slider-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recovery-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.recovery-info span:first-child {
  color: rgba(255, 255, 255, 0.7);
}

.recovery-percentage {
  font-size: 18px;
  font-weight: 700;
}

.recovery-slider {
  width: 100%;
  height: 44px; /* Big touch target height */
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  touch-action: none; /* KEY FIX: Prevents scrolling while dragging */
  margin: 10px 0;
  position: relative;
  z-index: 10;
}

/* Track styling */
.recovery-slider::-webkit-slider-runnable-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  border: none;
}

.recovery-slider::-moz-range-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  border: none;
}

/* Thumb styling */
.recovery-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 28px;
  width: 28px;
  border-radius: 50%;
  background: white;
  border: 4px solid #f97316; /* Orange ring */
  margin-top: -10px; /* Center on track: (8px track - 28px thumb) / 2 */
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.recovery-slider::-moz-range-thumb {
  height: 28px;
  width: 28px;
  border-radius: 50%;
  background: white;
  border: 4px solid #f97316;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

/* Active State */
.recovery-slider:active::-webkit-slider-thumb {
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.5);
  background: #fff;
}

.recovery-slider:active::-moz-range-thumb {
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.5);
  background: #fff;
}

/* Focus State */
.recovery-slider:focus {
  outline: none;
}

.recovery-slider:focus::-webkit-slider-thumb {
  border-color: #fb923c;
}

.hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  margin: 0;
  text-align: center;
}

/* Instructions */
.anatomy-instructions {
  text-align: center;
  margin-top: 16px;
}

.anatomy-instructions p {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
}

/* ============================================
   MUSCLE INDEX PANEL
   ============================================ */
.anatomy-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#muscle-index-panel {
  width: 100%;
  max-width: 300px;
  margin-top: 8px;
}

.muscle-panel-card {
  background: #1a1f2e;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.muscle-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.muscle-panel-header span {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-transform: capitalize;
}

.muscle-panel-header button {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #aaa;
  font-size: 20px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
}

.muscle-panel-header button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.muscle-panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.muscle-btn {
  display: block;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: all 0.15s ease;
}

.muscle-btn-primary {
  background: #3b82f6;
  color: #fff;
}

.muscle-btn-primary:hover {
  background: #2563eb;
}

.muscle-btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #ddd;
}

.muscle-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* Responsive */
@media (max-width: 640px) {
  .anatomy-canvas {
    padding: 16px;
    border-radius: 16px;
  }

  .anatomy-controls {
    justify-content: center;
  }

  .view-selector {
    justify-content: center;
  }

  .recovery-controls {
    flex-wrap: wrap;
    padding: 12px;
  }

  .recovery-btn {
    font-size: 13px;
    padding: 10px 16px;
    flex-grow: 1; /* Expand buttons to fill width */
    justify-content: center;
  }

  .muscle-index-panel {
    max-width: 100%;
    border-radius: 12px;
  }
}
