/**
 * Tonely - Music Theory App Styles
 * Mobile-first, dark theme design
 */

/* ==================== CSS Variables ==================== */
:root {
  /* Color Palette */
  --bg-primary: #1a1a1e;
  --bg-secondary: #2a2a2e;
  --accent-green: #4ADE80;
  --accent-green-dark: #22c55e;
  --text-primary: #ffffff;
  --text-secondary: #9ca3af;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;

  /* Layout */
  --header-height: 56px;
  --toolbar-height: 60px;
  --wheel-max-height: 45vh;

  /* Typography */
  --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-sm: 12px;
  --font-size-base: 14px;
  --font-size-md: 16px;
  --font-size-lg: 18px;

  /* Borders & Radius */
  --border-radius-sm: 0;
  --border-radius-md: 0;
  --border-radius-lg: 0;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-system);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  display: flex;
  flex-direction: column;
  touch-action: pan-x pan-y;
}

button {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

select {
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
  color: inherit;
}

/* ==================== Header ==================== */
.app-header {
  height: var(--header-height);
  background-color: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 var(--spacing-md);
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-selector {
  display: flex;
  justify-content: center;
}

.mode-selector select {
  font-size: var(--font-size-md);
  font-weight: 600;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--border-radius-md);
  background-color: rgba(255, 255, 255, 0.05);
  appearance: none;
  text-align: center;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.mode-selector select:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

/* ==================== Main Content ==================== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ==================== Wheel Container ==================== */
.wheel-container {
  width: 100%;
  max-height: var(--wheel-max-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
  flex-shrink: 0;
  box-sizing: border-box;
}

#wheelCanvas {
  width: 100%;
  height: auto;
  max-width: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

#wheelCanvas:active {
  cursor: grabbing;
}

/* ==================== Chord Progression Area ==================== */
.progression-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-md);
  background-color: var(--bg-primary);
}

.progression-section {
  margin-bottom: var(--spacing-lg);
}

.progression-section:last-child {
  margin-bottom: 0;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-md);
}

.section-label {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
}

/* Header Controls Container */
.header-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

/* Reorder Controls */
.reorder-controls {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.reorder-btn {
  width: 20px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  font-size: 10px;
  line-height: 1;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: 0;
}

.reorder-btn:hover:not(:disabled) {
  color: var(--accent-green);
  background: rgba(74, 222, 128, 0.15);
}

.reorder-btn:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* Preset Selector */
.preset-select {
  padding: 4px 8px;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M3 4.5L6 8l3-3.5H3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
  max-width: 120px;
}

.preset-select:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.preset-select:focus {
  outline: none;
  border-color: var(--accent-green);
}

.preset-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 8px;
}

.chord-slots {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
  align-items: center;
}

.chord-slot {
  background-color: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: var(--border-radius-md);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 60px;
  min-width: 70px;
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.chord-slot:hover {
  background-color: #3a3a3e;
  transform: translateY(-1px);
}

.chord-slot:active {
  transform: translateY(0);
}

.chord-slot.editing {
  border-color: var(--accent-green);
  background-color: rgba(74, 222, 128, 0.1);
}

.chord-slot.active {
  border-left: 4px solid var(--accent-green);
  padding-left: 10px;
}

.chord-name {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
}

.chord-slot.editing .chord-name {
  color: var(--accent-green);
}

/* Section Controls */
.section-controls {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.remove-section-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
  font-size: 18px;
  font-weight: 400;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  opacity: 0.6;
}

.remove-section-btn:hover {
  opacity: 1;
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

/* Repeat Controls */
.repeat-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: var(--spacing-sm);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius-sm);
  padding: 2px;
}

.repeat-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.repeat-btn:hover:not(:disabled) {
  color: var(--accent-green);
  background: rgba(74, 222, 128, 0.1);
}

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

.repeat-display {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--accent-green);
  min-width: 28px;
  text-align: center;
  padding: 0 var(--spacing-xs);
}

/* Chord Controls (add/remove) */
.chord-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: 8px;
}

.add-chord-btn,
.remove-chord-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.add-chord-btn:hover {
  color: var(--accent-green);
  border-color: var(--accent-green);
  background-color: rgba(74, 222, 128, 0.1);
}

.remove-chord-btn:hover:not(:disabled) {
  color: #ef4444;
  border-color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

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

/* Add Section Container */
.add-section-container {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-sm);
}

.section-type-select {
  flex: 0 0 auto;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--border-radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M3 4l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

.section-type-select:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.section-type-select:focus {
  outline: none;
  border-color: var(--accent-green);
}

/* Add Section Button */
.add-section-btn {
  flex: 1;
  padding: var(--spacing-md);
  background: transparent;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.add-section-btn:hover {
  border-color: var(--accent-green);
  color: var(--accent-green);
  background-color: rgba(74, 222, 128, 0.05);
}

/* Reset Button */
.reset-progressions-btn {
  flex: 0 0 auto;
  padding: var(--spacing-sm) var(--spacing-md);
  background: transparent;
  border: 2px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--border-radius-md);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.reset-progressions-btn:hover {
  border-color: #ef4444;
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

.chord-quality {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ==================== Playback Controls ==================== */
.playback-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-md);
  padding: var(--spacing-md);
  background: var(--bg-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.playback-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.playback-btn svg {
  width: 24px;
  height: 24px;
}

.playback-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.playback-btn:active {
  transform: scale(0.95);
}

.play-btn.playing {
  background: var(--accent-green);
  color: var(--bg-primary);
}

.play-btn.playing svg path {
  d: path("M6 4h4v16H6V4zm8 0h4v16h-4V4z"); /* Pause icon */
}

.loop-btn.active {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.loop-btn:not(.active) {
  opacity: 0.5;
}

.percussion-btn.active {
  color: var(--accent-green);
  border-color: var(--accent-green);
}

.percussion-btn:not(.active) {
  opacity: 0.5;
}

/* BPM Control */
.bpm-control {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--border-radius-md);
  padding: var(--spacing-xs);
}

.bpm-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.bpm-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.bpm-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 50px;
  padding: 0 var(--spacing-xs);
}

#bpmValue {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1;
}

.bpm-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Playing chord highlight */
.chord-slot.playing {
  border-color: var(--accent-green);
  background: rgba(74, 222, 128, 0.2);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.4);
  }
  to {
    box-shadow: 0 0 0 8px rgba(74, 222, 128, 0);
  }
}

/* ==================== Fretboard Area ==================== */
.fretboard-area {
  flex: 1;
  width: 100%;
  min-width: 0;
  overflow-y: auto;
  padding: 0;
  background-color: var(--bg-primary);
}

/* Scale Selector Container */
.scale-selector-container {
  width: calc(100% - 32px);
  max-width: 300px;
  margin: var(--spacing-sm) var(--spacing-md);
  position: relative;
}

/* Scale Selector Button */
.scale-selector-button {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-md);
  padding: 10px 12px;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
}

.scale-selector-button:hover {
  background: #3a3a3e;
}

.scale-selector-button:active {
  background: #2a2a2e;
}

.scale-indicator {
  width: 3px;
  height: 32px;
  background: var(--accent-green);
  border-radius: 0;
  margin-right: 10px;
  flex-shrink: 0;
}

.scale-info {
  flex: 1;
}

.scale-name {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.scale-type {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.2;
}

.scale-dropdown-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.scale-selector-button:hover .scale-dropdown-icon {
  color: var(--text-primary);
}

/* Scale Dropdown */
.scale-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
}

.scale-dropdown-item {
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.scale-dropdown-item:last-child {
  border-bottom: none;
}

.scale-dropdown-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.scale-dropdown-item.selected {
  background-color: rgba(74, 222, 128, 0.1);
}

.scale-dropdown-item.selected .scale-dropdown-name {
  color: var(--accent-green);
}

.scale-dropdown-name {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
}

.scale-dropdown-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: 1.3;
  margin-top: 2px;
}


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

/* Focus visible styles for keyboard navigation */
button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent-green);
  outline-offset: 2px;
}

/* ==================== Responsive Adjustments ==================== */
@media (min-width: 768px) {
  :root {
    --header-height: 64px;
    --toolbar-height: 70px;
    --wheel-max-height: 50vh;
  }
}

@media (min-width: 1024px) {
  .app-main {
    max-width: 100%;
    margin: 0 auto;
  }

  /* Center the wheel on larger screens but let fretboard use full width */
  .wheel-container {
    max-width: 600px;
    margin: 0 auto;
  }

  .fretboard-area {
    width: 100%;
    max-width: none;
  }

  .progression-area {
    max-width: 800px;
    margin: 0 auto;
  }
}

/* ==================== Touch & Interaction ==================== */
@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets on mobile */
  .header-btn,
  .toolbar-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ==================== Fretboard ==================== */
.fretboard {
  width: 100%;
  overflow-x: auto;
  padding: 0 var(--spacing-sm) var(--spacing-md);
}

.hfb-fretboard {
  display: flex;
  flex-direction: column;
  min-width: fit-content;
}

.hfb-main-row {
  display: flex;
}

.hfb-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  width: 24px;
  flex-shrink: 0;
}

.hfb-string-label {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--text-secondary);
  padding-right: 4px;
}

.hfb-frets-container {
  display: flex;
  flex: 1;
  background: linear-gradient(180deg, #252529 0%, #1e1e22 50%, #252529 100%);
  border-radius: var(--border-radius-md);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.hfb-fret {
  display: flex;
  flex-direction: column;
  position: relative;
}

.hfb-nut {
  width: 22px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.03);
}

/* Fret borders on cells only, not on fret numbers */
.hfb-fret:not(.hfb-nut) > .hfb-cell {
  border-right: 1px solid rgba(255, 255, 255, 0.12);
}

.hfb-nut > .hfb-cell {
  border-right: 2px solid rgba(255, 255, 255, 0.25);
}

.hfb-fret:not(.hfb-nut) {
  flex: 1;
  min-width: 32px;
}

.hfb-cell {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.hfb-string-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(90deg, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0.5) 50%, rgba(255,255,255,0.4) 100%);
  pointer-events: none;
}

/* Fret position markers (dots) */
.hfb-marker::before {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.hfb-double-marker::before {
  top: 25%;
}

.hfb-double-marker::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  left: 50%;
  top: 75%;
  transform: translate(-50%, -50%);
}

/* Scale notes */
.hfb-note {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 600;
  color: #fff;
  background: rgba(74, 222, 128, 0.7);
  position: relative;
  z-index: 2;
}

.hfb-note.hfb-root {
  width: 22px;
  height: 22px;
  font-size: 9px;
  background: var(--accent-green);
  color: var(--bg-primary);
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-green);
}

/* Fret numbers (inside each fret column) */
.hfb-fret-number {
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Responsive adjustments */
@media (min-width: 768px) {
  .hfb-labels {
    width: 28px;
  }

  .hfb-string-label {
    height: 34px;
    font-size: 13px;
  }

  .hfb-cell {
    height: 34px;
  }

  .hfb-nut {
    width: 28px;
  }

  .hfb-fret:not(.hfb-nut) {
    min-width: 50px;
  }

  .hfb-note {
    width: 24px;
    height: 24px;
    font-size: 10px;
  }

  .hfb-note.hfb-root {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .hfb-fret-number {
    font-size: 11px;
  }
}
