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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #111827;
  color: #ffffff;
  line-height: 1.5;
  min-height: 100vh;
}

/* ===== Layout ===== */
.main-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem;
}

.controls-wrapper {
  width: 100%;
  max-width: 80rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.fretboard-wrapper {
  width: 100%;
  max-width: 80rem;
  overflow-x: auto;
}

.fretboard-svg {
  width: 100%;
}

.chords-wrapper {
  width: 100%;
  max-width: 80rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

/* ===== Buttons ===== */
.btn {
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: background-color 0.15s;
}

.btn-primary {
  background-color: #2563eb;
  color: #ffffff;
}

.btn-primary:hover {
  background-color: #1d4ed8;
}

.btn-secondary {
  background-color: #374151;
  color: #ffffff;
}

.btn-secondary:hover {
  background-color: #4b5563;
}

.btn-ghost {
  background: none;
  color: #9ca3af;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
}

.btn-ghost:hover {
  color: #ffffff;
}

/* ===== Forms ===== */
.form-select {
  background-color: #1f2937;
  color: #ffffff;
  border: 1px solid #4b5563;
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  appearance: auto;
}

.form-select-full {
  width: 100%;
  background-color: #1f2937;
  color: #ffffff;
  border: 1px solid #4b5563;
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  appearance: auto;
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ===== Chord Chips ===== */
.chord-chip {
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #111827;
  padding: 0.75rem;
  border: 2px solid transparent;
}

.chord-chip--highlighted {
  border: 2px solid #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

.chord-chip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.chord-chip-title {
  font-weight: 700;
}

.chord-chip-remove {
  margin-left: 0.5rem;
  color: #374151;
  font-weight: 700;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.chord-chip-remove:hover {
  color: #000000;
}

.chord-chip-intervals {
  font-size: 0.75rem;
  line-height: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

/* ===== Key Preview Chips ===== */
.key-preview-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #111827;
}

.key-preview-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background-color: #111827;
  border: 1px solid #374151;
  border-radius: 0.5rem;
  padding: 1.5rem;
  width: 24rem;
  max-width: 100%;
}

.modal-title {
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ===== Modal Form Elements ===== */
.form-group {
  margin-bottom: 1rem;
}

.form-group-spaced {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.form-label {
  color: #9ca3af;
  font-size: 0.875rem;
  display: block;
  margin-bottom: 0.25rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-col {
  flex: 1;
}

.string-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.string-label {
  color: #9ca3af;
  font-size: 0.875rem;
  width: 4rem;
}

.string-select {
  flex: 1;
}

/* ===== LiveView internals ===== */
[data-phx-session], [data-phx-teleported-src] {
  display: contents;
}

/* ===== Flash Messages ===== */
.flash-group {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 100;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.flash-info {
  background-color: #065f46;
  color: #d1fae5;
  border: 1px solid #047857;
}

.flash-error {
  background-color: #7f1d1d;
  color: #fecaca;
  border: 1px solid #991b1b;
}

.flash-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  opacity: 0.5;
  font-size: 1.25rem;
  line-height: 1;
  margin-left: auto;
}

.flash-close:hover {
  opacity: 1;
}

/* ===== Section Label ===== */
.section-label {
  color: #9ca3af;
  font-size: 0.875rem;
  display: block;
  margin-bottom: 0.5rem;
}

/* ===== Footer ===== */
.site-footer {
  text-align: center;
  padding: 1.5rem 1rem;
  margin-top: 2rem;
  border-top: 1px solid #374151;
  color: #9ca3af;
  font-size: 0.75rem;
}

.site-footer p {
  margin-bottom: 0.25rem;
}

.site-footer a {
  color: #9ca3af;
  text-decoration: none;
  transition: color 0.15s;
}

.site-footer a:hover {
  color: #ffffff;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Key Suggestions ===== */
.key-suggestions-wrapper {
  width: 100%;
  max-width: 80rem;
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.text-muted {
  color: #6b7280;
  font-size: 0.875rem;
}

.key-suggestions-loading {
  color: #6b7280;
  font-size: 0.875rem;
  padding: 0.5rem 0;
}

/* --- Key Suggestion Cards --- */
.key-card {
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 16rem;
  flex: 1 1 16rem;
}

.key-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3), 0 4px 12px rgba(59, 130, 246, 0.15);
  background-color: #24344d;
}

.key-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.key-card-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f1f5f9;
}

.key-card-score {
  font-size: 0.75rem;
  font-weight: 600;
  color: #22c55e;
  background-color: rgba(34, 197, 94, 0.12);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  white-space: nowrap;
}

.key-card-score--partial {
  color: #eab308;
  background-color: rgba(234, 179, 8, 0.12);
}

.key-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.key-card-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #111827;
}

.key-card-arrow {
  font-size: 0.75rem;
  color: #3b82f6;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* --- Collapsed Modes Row --- */
.key-modes-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.key-modes-toggle {
  background: none;
  border: 1px solid #334155;
  border-radius: 9999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: #94a3b8;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.key-modes-toggle:hover {
  border-color: #3b82f6;
  color: #3b82f6;
}

.key-modes-expanded {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* --- Multi-Key Suggestions --- */
.multi-key-group {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.multi-key-group:last-of-type {
  border-bottom: none;
}

.multi-key-group-label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9ca3af;
  margin-bottom: 0.5rem;
}

.multi-key-your-chords {
  margin-top: 0.5rem;
  padding-left: 0.5rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.multi-key-your-chords-label {
  font-size: 0.75rem;
  color: #6b7280;
  margin-right: 0.25rem;
}

.multi-key-unmatched {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(107, 114, 128, 0.08);
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.multi-key-unmatched-label {
  font-size: 0.75rem;
  color: #6b7280;
  margin-right: 0.25rem;
}

.chord-chip--unmatched {
  opacity: 0.5;
  filter: grayscale(1);
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  background: #4b5563;
  color: #d1d5db;
}

/* ===== Tab Toggle (Segmented Control) ===== */
.tab-toggle {
  display: inline-flex;
  background-color: #1f2937;
  border: 1px solid #374151;
  border-radius: 0.375rem;
}

.tab-toggle-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  color: #9ca3af;
  white-space: nowrap;
}

.tab-toggle-btn:first-child {
  border-radius: 0.375rem 0 0 0.375rem;
}

.tab-toggle-btn:last-child {
  border-radius: 0 0.375rem 0.375rem 0;
}

.tab-toggle-btn--active {
  background-color: #2563eb;
  color: #ffffff;
}

.tab-toggle-btn--active:hover {
  background-color: #1d4ed8;
}

.tab-toggle-btn:not(.tab-toggle-btn--active):hover {
  background-color: #374151;
  color: #ffffff;
}

/* ===== Analyzer Fretboard ===== */
.analyzer-note-circle {
  fill: #4FC3F7;
  stroke: #ffffff;
  stroke-width: 2;
  cursor: pointer;
  transition: fill 0.15s;
}

.analyzer-note-circle:hover {
  fill: #29B6F6;
}

.analyzer-note-text {
  fill: #1a1a1a;
  font-size: 9px;
  font-weight: bold;
  text-anchor: middle;
  pointer-events: none;
}

.analyzer-position {
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.analyzer-position:hover {
  opacity: 0.3;
}

/* ===== Clear Button ===== */
.btn-clear {
  background-color: #374151;
  color: #9ca3af;
  border: 1px solid #4b5563;
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-clear:hover {
  background-color: #4b5563;
  color: #ffffff;
  border-color: #6b7280;
}

/* ===== Analysis Results ===== */
.analyzer-results {
  width: 100%;
  max-width: 80rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.analyzer-empty {
  color: #6b7280;
  font-size: 0.875rem;
  padding: 1rem 0;
  text-align: center;
}

.analyzer-single-note {
  color: #e5e7eb;
  font-size: 1rem;
  padding: 0.5rem 0;
}

.analyzer-interval {
  color: #e5e7eb;
  font-size: 0.95rem;
  padding: 0.5rem 0;
}

/* --- Analysis Cards --- */
.analysis-card {
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: 0.5rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.analysis-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.3);
}

.analysis-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.analysis-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #f1f5f9;
}

.analysis-card-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.analysis-badge--exact {
  color: #22c55e;
  background-color: rgba(34, 197, 94, 0.12);
}

.analysis-badge--partial {
  color: #eab308;
  background-color: rgba(234, 179, 8, 0.12);
}

.analysis-badge--incomplete {
  color: #3b82f6;
  background-color: rgba(59, 130, 246, 0.12);
}

.analysis-card-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.analysis-note-item {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.analysis-note-item strong {
  color: #f1f5f9;
}

.analysis-card-intervals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #94a3b8;
}

.analysis-card-inversion {
  font-size: 0.8rem;
  color: #6b7280;
  font-style: italic;
}

.analysis-card-bass {
  font-size: 0.8rem;
  color: #94a3b8;
}

.analysis-card-bass strong {
  color: #e5e7eb;
}

/* ===== Piano Keyboard ===== */
.piano-wrapper {
  width: 100%;
  max-width: 80rem;
  overflow-x: auto;
}

.piano-svg {
  width: 100%;
  display: block;
}

.piano-key-rect {
  cursor: default;
}

.piano-key--white .piano-key-rect {
  fill: #fafafa;
  stroke: #4b5563;
  stroke-width: 1;
}

.piano-key--black .piano-key-rect {
  fill: #1f2937;
  stroke: #111827;
  stroke-width: 1;
}

.piano-key-marker {
  stroke: #111827;
  stroke-width: 1;
  pointer-events: none;
}

.piano-note-label {
  fill: #1a1a1a;
  font-size: 11px;
  font-weight: bold;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.piano-wrapper--interactive .piano-key {
  cursor: pointer;
  outline: none;
}

.piano-wrapper--interactive .piano-key-rect {
  cursor: pointer;
}

.piano-wrapper--interactive .piano-key:focus .piano-key-rect {
  stroke: #4FC3F7;
  stroke-width: 3;
}

.piano-wrapper--interactive .piano-key--selected .piano-key-rect {
  stroke: #4FC3F7;
  stroke-width: 2;
}

/* ===== Desktop: min-width for fretboard and piano SVGs ===== */
@media (min-width: 1280px) {
  .fretboard-svg,
  .piano-svg {
    min-width: 900px;
  }
}

/* ===== Collapsible Secondary Controls ===== */
.controls-secondary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.controls-more-btn {
  display: none;
}

/* ===== Modal Handle (mobile bottom sheet grab bar) ===== */
.modal-handle {
  display: none;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 1279px) {
  .main-container {
    padding: 0.75rem;
    gap: 1rem;
  }

  .controls-row {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .controls-row .btn,
  .controls-row .form-select,
  .controls-row select,
  .controls-row button {
    min-height: 44px;
    min-width: 44px;
  }

  /* Secondary controls hidden by default on mobile; JS.toggle sets inline
     display:flex to show when 'More' is clicked */
  .controls-secondary {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-top: 0.75rem;
  }

  /* 'More' button visible only on mobile */
  .controls-more-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 700;
    background-color: #374151;
    color: #ffffff;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
    transition: background-color 0.15s;
  }

  .controls-more-btn:hover {
    background-color: #4b5563;
  }

  /* ===== Modal Bottom Sheets ===== */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    border-radius: 0.75rem 0.75rem 0 0 0;
    margin-bottom: 0;
  }

  .modal-handle {
    display: block;
    width: 2.5rem;
    height: 0.25rem;
    background-color: #4b5563;
    border-radius: 9999px;
    margin: 0 auto 1rem auto;
  }
}
