/* Drag & Drop MIDI Styling */

/* Drag Handle Container */
.drag-handles-container {
  display: flex;
  gap: 0.75rem;
  margin: 1rem 0;
}

/* Individual Drag Handle */
.drag-handle {
  flex: 1;
  height: 80px;
  /* Reserve border space to avoid layout shift on hover */
  border: 3px solid transparent;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(var(--color-rgb), 0.05);
  user-select: none;
  position: relative;

}

/* Status dot for download state */
.drag-handle .status-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px; 
  height: 8px; 
  border-radius: 999px; 
  background: #bbb;
}

/* Downloaded = enabled + green */
.drag-handle.is-downloaded {
  background: #0a7a33;      /* green */
  border-color: #0a7a33;
  color: #fff;
  cursor: grab;
  opacity: 1;
  pointer-events: auto;
}

.drag-handle.is-downloaded:active {
  cursor: grabbing;
}

.drag-handle.is-downloaded .status-dot {
  background: #b6f2c9;
}

/* Downloading state */
.drag-handle.is-downloading {
  cursor: progress;
  opacity: .8;
  pointer-events: auto;
}

/* Drag Handle Content */
.drag-handle-icon {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.drag-handle-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0;
}

.drag-handle-subtitle {
  font-size: 0.75rem;
  opacity: 0.7;
  margin: 0;
}

/* Drag Handle States */
.drag-handle:hover {
  cursor: pointer;
  background: rgba(var(--color-rgb), 0.1);
  /* Keep reserved transparent border to avoid layout shift */
  border-color: transparent;
}

/* Melody Section Styles */
.melody-section {
  background: var(--foreground);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  margin: 1rem 0;
  transition: all 0.3s ease;
}

.melody-section.loading {
  position: relative;
  overflow: hidden;
}

.melody-section.loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(var(--color-rgb), 0.1), transparent);
  animation: loading-shimmer 2s infinite;
}

@keyframes loading-shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.melody-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.melody-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.melody-tabs {
  display: flex;
  gap: 0.5rem;
}

.melody-tab {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--background-light);
  color: var(--text-color);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.melody-tab:hover {
  background: var(--background);
  border-color: var(--color);
}

.melody-tab.active {
  background: var(--color);
  color: white;
  border-color: var(--color);
}

.melody-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color);
  border-radius: 1px;
}

.melody-content {
  position: relative;
}

.melody-tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.melody-tab-content.active {
  display: block;
}

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

.melody-generate-section {
  text-align: center;
  padding: 2rem 1rem;
}

.melody-generate-header {
  margin-bottom: 2rem;
}

.melody-generate-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.melody-generate-subtitle {
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.7;
}

.melody-generate-btn {
  background: var(--color);
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(var(--color-rgb), 0.3);
}

.melody-generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(var(--color-rgb), 0.4);
}

.melody-generate-btn:active {
  transform: translateY(0);
}

.melody-generate-btn.loading {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.melody-generate-btn.loading .melody-generate-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* .melody-results-container {
  min-height: 200px;
} */

.melody-results-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-color);
  opacity: 0.6;
  text-align: center;
}

.melody-results-empty i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.melody-results-empty span {
  font-size: 1rem;
  font-weight: 500;
}

/* Melody Results Grid */
.melody-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.melody-result-card {
  background: var(--background-light);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.melody-result-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  border-color: var(--color);
}

.melody-result-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--color);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.melody-result-card:hover::before {
  transform: scaleX(1);
}

.melody-result-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color);
  margin-bottom: 0.5rem;
}

.melody-result-description {
  font-size: 0.9rem;
  color: var(--text-color);
  opacity: 0.8;
}

.melody-modifier-tag {
  display: inline-block;
  background: rgba(var(--color-rgb), 0.1);
  color: var(--color);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid rgba(var(--color-rgb), 0.2);
}

/* Downloaded handle hover effects */
.drag-handle.is-downloaded:hover {
  background: #0d8a3a; /* slightly darker green */
  border-color: #0d8a3a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(10, 122, 51, 0.3);
}

/* Overlay smaller dashed border with rounded corners on hover */
.drag-handle:hover::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-sizing: border-box;
  pointer-events: none;
  border: 2px dashed var(--color); /* smaller dashes */
}

.drag-handle:active,
.drag-handle.dragging {
  cursor: pointer;
  opacity: 0.7;
  transform: scale(0.98);
}

/* Drag Handle Focus (for accessibility) */
.drag-handle:focus {
  outline: 2px solid var(--color);
  outline-offset: 2px;
}

/* Chord Handle Specific */
.drag-handle--chords {
  /* Chord-specific styling can be added here */
}

/* Bass Handle Specific */
.drag-handle--bass {
  /* Bass-specific styling can be added here */
}

/* Melody Handle Specific */
.drag-handle--melody {
  /* Melody-specific styling can be added here */
}

/* Hide text elements in melody handle on hover */
.drag-handle--melody:hover .drag-handle-title,
.drag-handle--melody:hover .drag-handle-subtitle {
  opacity: 0;
  pointer-events: none;
}

/* Hide text elements and icon during loading */
.drag-handle--melody.loading .drag-handle-title,
.drag-handle--melody.loading .drag-handle-subtitle,
.drag-handle--melody.loading .drag-handle-icon {
  opacity: 0;
  pointer-events: none;
}

/* Hide text elements and icon when melodies are present */
.drag-handle--melody.has-results .drag-handle-title,
.drag-handle--melody.has-results .drag-handle-subtitle,
.drag-handle--melody.has-results .drag-handle-icon {
  opacity: 0;
  pointer-events: none;
}

/* Hide generate button during loading */
.drag-handle--melody.loading .melody-generate-container {
  display: none;
}

/* Show centered spinner during loading */
/* Animated border glow for melody handle during generation */
.drag-handle--melody.loading {
  position: relative;
  isolation: isolate;
  overflow: visible;
}

.drag-handle--melody.loading .melody-glow {
  position: absolute;
  inset: -2px;
  border-radius: 8px;
  overflow: hidden;
  pointer-events: none;
  z-index: -1;
}

.drag-handle--melody.loading .melody-glow-bg {
  --glow-color: oklch(0.85 0.37 145.75);
  animation: spin 3s linear infinite;
  aspect-ratio: 1;
  background: conic-gradient(in oklch longer hue, var(--glow-color), var(--glow-color));
  left: 50%;
  position: absolute;
  top: 50%;
  translate: -50% -50%;
  width: 150%;
}

.drag-handle--melody.loading .melody-white-clip {
  position: absolute;
  background: var(--foreground);
  filter: blur(6px);
  border-radius: 8px;
  width: 100%;
  height: 100%;
  pointer-events: none;
  inset: 1px;
}

.drag-handle--melody.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 3px solid rgba(var(--color-rgb), 0.3);
  border-top: 3px solid var(--color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 10;
}

/* Melody generate button container */
.melody-generate-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

/* Show generate button on hover */
.drag-handle--melody:hover .melody-generate-container {
  opacity: 1;
  pointer-events: auto;
}

/* Melody generate button */
.melody-generate-btn {
  background: var(--color);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  cursor: pointer;
  transform: scale(0.9);
  border: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.melody-generate-btn:hover {
  background: var(--color);
  opacity: 0.9;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(var(--color-rgb), 0.3);
}

/* Show button with scale animation on container hover */
.drag-handle--melody:hover .melody-generate-btn {
  transform: scale(1);
}

/* Melody generate button icon */
.melody-generate-icon {
  font-size: 1rem;
}

/* Loading state for melody generate button */
.melody-generate-btn.loading {
  opacity: 0.8;
  pointer-events: none;
}

.melody-generate-btn.loading .melody-generate-icon,
.melody-generate-btn.loading span {
  display: none;
}

.melody-generate-btn.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid white;
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Melody results grid container */
.melody-results-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

/* Bass results grid container - same as melody */
.bass-results-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

/* Show results when melodies are generated */
.drag-handle--melody.has-results .melody-results-container {
  display: grid;
  opacity: 1;
  pointer-events: auto;
}

/* Hide generate button when results are shown */
.drag-handle--melody.has-results .melody-generate-container {
  display: none;
}

/* Show results when basslines are generated */
.drag-handle--bass.has-results .bass-results-container {
  display: grid;
  opacity: 1;
  pointer-events: auto;
}

/* Default state: show text, hide grid */
.drag-handle--bass.has-results .bass-results-container {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.drag-handle--bass.has-results .drag-handle-title,
.drag-handle--bass.has-results .drag-handle-subtitle,
.drag-handle--bass.has-results .drag-handle-icon {
  opacity: 1;
  pointer-events: auto;
}

/* Hover state: hide text, show grid */
.drag-handle--bass.has-results:hover .bass-results-container {
  display: grid;
  opacity: 1;
  pointer-events: auto;
}

.drag-handle--bass.has-results:hover .drag-handle-title,
.drag-handle--bass.has-results:hover .drag-handle-subtitle,
.drag-handle--bass.has-results:hover .drag-handle-icon {
  opacity: 0;
  pointer-events: none;
}

/* Individual melody result card */
.melody-result-card {
  background: var(--color);
  color: white;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.6rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: all 0.3s ease;
  cursor: pointer;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.melody-result-card:hover {
  background: var(--color);
  opacity: 0.9;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(var(--color-rgb), 0.3);
}

/* Melody result title - large number in center */
.melody-result-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  margin: 0;
  opacity: 1;
  transition: opacity 0.3s ease;
  position: absolute;
  top: 50%;
  color: var(--white-color);

  left: 50%;
  transform: translate(-50%, -50%);
}

/* Melody result description - hidden by default */
.melody-result-description {
  font-size: 0.5rem;
  opacity: 0;
  line-height: 1.1;
  margin: 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  transition: opacity 0.3s ease;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  padding: 0.5rem;
  box-sizing: border-box;
}

/* Show description on hover, hide title */
.melody-result-card:hover .melody-result-title {
  opacity: 0;
}

.melody-result-card:hover .melody-result-description {
  opacity: 0.9;
}

/* Melody card downloading state */
.melody-result-card.downloading {
  pointer-events: none;
  opacity: 0.7;
}

.melody-result-card.downloading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 10;
}

.melody-result-card.downloading .melody-result-title,
.melody-result-card.downloading .melody-result-description {
  opacity: 0;
}

/* Melody card show content state */
.melody-result-card.show-content .melody-result-title {
  opacity: 0;
}

.melody-result-card.show-content .melody-result-description {
  opacity: 0.9;
}

/* Melody modifier tag styling */
.melody-modifier-tag {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  width: 100%;
  height: 100%;
  font-size: 0.55rem;
  font-weight: 600;
  text-align: center;
}

.melody-modifier-tag i {
  font-size: 0.65rem;
  opacity: 0.9;
}

/* All modifier tags use the same styling - no background color modifications */

/* Simplified melody description container - just shows the tag */
.melody-result-description {
  font-size: 0.5rem;
  opacity: 0;
  line-height: 1.1;
  margin: 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  transition: opacity 0.3s ease;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  padding: 0.5rem;
  box-sizing: border-box;
}

/* Three handles layout optimization */
.drag-handles-container:has(.drag-handle--melody) {
  gap: 0.5rem;
}

.drag-handles-container:has(.drag-handle--melody) .drag-handle {
  min-width: 0; /* Allow handles to shrink if needed */
}

/* Responsive Design */
@media (max-width: 768px) {
  .drag-handles-container {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .drag-handle {
    height: 70px;
  }
  
  .drag-handle-icon {
    font-size: 1.25rem;
  }
  
  .drag-handle-title {
    font-size: 0.85rem;
  }
  
  .drag-handle-subtitle {
    font-size: 0.7rem;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .drag-handle {
    background: rgba(var(--color-rgb), 0.1);
  }
  
  .drag-handle:hover {
    background: rgba(var(--color-rgb), 0.15);
  }
}

/* Animation for drag feedback */
@keyframes dragPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.drag-handle.drag-start {
  animation: dragPulse 0.3s ease-in-out;
}

/* Loading state (for future prefetch functionality) */
.drag-handle.loading {
  opacity: 0.6;
  pointer-events: none;
}

.drag-handle.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--color);
  border-top: 2px solid transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Tooltip styling */
.drag-handle[title] {
  position: relative;
}

/* Accessibility improvements */
.drag-handle:focus-visible {
  outline: 2px solid var(--color);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .drag-handle {
    border-width: 3px;
  }
  
  .drag-handle:hover {
    border-width: 4px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .drag-handle {
    transition: none;
  }
  
  .drag-handle.drag-start {
    animation: none;
  }
  
  .drag-handle.loading::after {
    animation: none;
  }
}

.drag-handle--melody:hover .melody-generate-btn {
  width: 80%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.prog-info-btn {
  margin-bottom: 6px;
}