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

:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #22263a;
  --border:      #2e334d;
  --text:        #e2e4f0;
  --text-muted:  #7880a0;
  --accent:      #6c8ef5;
  --accent-glow: rgba(108, 142, 245, 0.25);
  --root-color:  #f5856c;
  --root-glow:   rgba(245, 133, 108, 0.35);
  --overlay-bg:  rgba(108, 142, 245, 0.15);
  --selected-bg: #6c8ef5;
  --nut-width:      6px;
  --open-col-width: 80px; /* updated dynamically by JS */
  --cell-height:    40px;
  --dot-size:       28px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ── Header ──────────────────────────────────────────────────────────── */
header { margin-bottom: 32px; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--text-muted); margin-top: 4px; }
h2 { font-size: 15px; font-weight: 600; text-transform: uppercase;
     letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 14px; }

section { margin-bottom: 36px; }

/* ── Fretboard ───────────────────────────────────────────────────────── */
#fretboard-scroll { overflow-x: auto; padding-bottom: 8px; }

#fretboard-wrapper {
  display: grid;
  grid-template-columns: 28px 1fr;
  grid-template-rows: auto auto auto;
  gap: 0;
  /* min-width set dynamically in JS based on computed fret widths */
}

#string-labels {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
}
.string-label {
  height: var(--cell-height);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

#fretboard {
  grid-column: 2;
  grid-row: 2;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Nut (thick left border) — left position updated by JS via --open-col-width */
#fretboard::before {
  content: '';
  position: absolute;
  left: var(--open-col-width);
  top: 0; bottom: 0;
  width: var(--nut-width);
  background: #c8c0a8;
  z-index: 2;
  pointer-events: none;
}

#fret-markers {
  display: flex;
  order: 2;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

#strings { order: 1; }
.marker-cell {
  /* width set inline by JS */
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}
.marker-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
}

#strings { display: flex; flex-direction: column; }

.string-row {
  display: flex;
  position: relative;
}

/* String line — displayed order is e B G D A E (top to bottom) */
.string-row::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  pointer-events: none;
  z-index: 0;
  transform: translateY(-50%);
}
/* e (high, top row) = thinnest */
.string-row:nth-child(1)::after { height: 1px;   background: #a09888; }
.string-row:nth-child(2)::after { height: 1px;   background: #9a9080; }
.string-row:nth-child(3)::after { height: 1.5px; background: #807060; }
.string-row:nth-child(4)::after { height: 2px;   background: #6a5c50; }
.string-row:nth-child(5)::after { height: 2.5px; background: #5a5040; }
.string-row:nth-child(6)::after { height: 3px;   background: #4a3c30; }

.fret-cell {
  /* width set inline by JS */
  height: var(--cell-height);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  overflow: hidden;
  transition: background 0.1s;
}
/* Fret lines: only on non-open cells, right border only */
.fret-cell:not(.open-string) {
  border-right: 1px solid var(--border);
}
.fret-cell:last-child { border-right: none; }
/* Slight separator between open and fretted area */
.fret-cell.open-string { border-right: 1px solid #3a3f58; }
.fret-cell:hover .note-dot { transform: scale(1.15); }

.note-dot {
  width: var(--dot-size);
  height: var(--dot-size);
  border-radius: 50%;
  background: transparent;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(11px, calc(var(--dot-size) * 0.5), 15px);
  font-weight: 700;
  overflow: hidden;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  position: relative;
  z-index: 2;
}

/* Selected: user clicked this fret */
.fret-cell.selected .note-dot {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 10px var(--accent-glow);
}

/* Selected root note: highlighted in root color (free mode only; chord inline styles take precedence) */
.fret-cell.selected.is-root .note-dot {
  background: var(--root-color);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 0 10px var(--root-glow);
}

/* Chord ghost: pitch class belongs to a chord but fret not explicitly selected */
.fret-cell.chord-ghost .note-dot {
  background: color-mix(in srgb, var(--ghost-color, transparent) 14%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--ghost-color, transparent) 32%, transparent);
}

/* Overlay: scale dot, not selected */
.fret-cell.overlay .note-dot {
  background: var(--overlay-bg);
  border-color: var(--accent);
  color: var(--accent);
}
.fret-cell.overlay.root-dot .note-dot {
  background: var(--root-glow);
  border-color: var(--root-color);
  color: var(--root-color);
}

/* Fret numbers */
#fret-number-labels {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  margin-bottom: 6px;
}
.fret-num {
  /* width set inline by JS */
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.open-label { font-size: 10px; }

/* String labels align with string rows; pad bottom to account for marker row now at bottom */
#string-labels { padding-top: 0; padding-bottom: 20px; }

/* ── Fretboard controls ───────────────────────────────────────────────── */
#fretboard-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

#fret-count-control {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.fret-count-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 2px;
}
.fret-count-btn {
  padding: 4px 10px;
  font-size: 12px;
}
.fret-count-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) { background: var(--surface); border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: default; }

#show-intervals-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
}
#show-intervals-cb { accent-color: var(--accent); }

/* ── Tuning control ──────────────────────────────────────────────────── */
#tuning-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.tuning-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
#tuning-selects {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tuning-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 4px;
  font-size: 12px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
  text-align-last: center;
  min-width: 44px;
  transition: border-color 0.15s;
}
.tuning-select:hover,
.tuning-select:focus { outline: none; border-color: var(--accent); }

.tuning-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  align-self: center;
  flex-shrink: 0;
}

.tuning-preset {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.tuning-preset:hover,
.tuning-preset:focus { outline: none; border-color: var(--accent); color: var(--text); }

/* ── Chord palette bar (inside fretboard section, optional) ──────────── */
#chord-palette-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.chord-bar-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.chord-bar-optional { font-style: italic; }

#chord-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chord-slot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.chord-slot:hover { border-color: var(--chord-color); }
.chord-slot.active {
  border-color: var(--chord-color);
  background: color-mix(in srgb, var(--chord-color) 12%, var(--surface));
}

.chord-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chord-color);
  flex-shrink: 0;
}

.chord-clear-btn {
  margin-left: 3px;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}
.chord-clear-btn:hover { color: var(--text); background: var(--surface2); }

/* ── Note chips (chord-colored) ──────────────────────────────────────── */
#note-chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 32px; }
.note-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--chip-color, var(--border));
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ── Analysis results ─────────────────────────────────────────────────── */
#analysis-placeholder { color: var(--text-muted); }

#key-results {
  display: block;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.result-card:hover { border-color: var(--accent); }
.result-card.active {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 0 1px var(--accent);
}

.result-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
}

.score-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.score-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.result-meta {
  font-size: 12px;
  color: var(--text-muted);
}
.outside-notes {
  color: #f5856c;
  margin-top: 4px;
  font-size: 11px;
}

/* ── Section header (h2 + right-side toggle) ─────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 { margin-bottom: 0; }

/* Section title group: h2 + info button side by side */
.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
}
.section-title h2 { margin-bottom: 0; }

/* ── Info button ──────────────────────────────────────────────────────── */
.info-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  overflow: visible;
  line-height: 1;
}
.info-btn:hover { color: var(--accent); background: transparent; border-color: transparent; }
.info-btn::after {
  content: attr(data-info);
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  width: 260px;
  white-space: normal;
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: none;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  pointer-events: none;
}
.info-btn:hover::after { display: block; }

#pentatonic-toggle {
  font-size: 12px;
  padding: 4px 14px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
#pentatonic-toggle:hover { border-color: var(--accent); color: var(--text); }
#pentatonic-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Key results primary grid + modes disclosure ─────────────────────── */
.results-primary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.modes-disclosure { margin-top: 4px; }

.view-modes-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.view-modes-toggle:hover { border-color: var(--accent); color: var(--text); }

.modes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

/* ── Scale shapes — tabs / title ──────────────────────────────────────── */
#shapes-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.shape-tab { padding: 5px 14px; border-radius: 6px; font-size: 13px; }
.shape-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Title shown instead of tabs for non-pentatonic scales */
.shape-scale-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── Shape full-neck fretboard (mini-diagram aesthetic) ───────────────── */
.shape-fb-scroll { overflow-x: auto; padding-bottom: 6px; margin-bottom: 20px; }

.shape-fretboard-outer {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: fit-content;
}

/* Main grid: string-name column + fret columns, bordered like mini diagrams */
.shape-fretboard-grid {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

/* String name column */
.shape-fb-string-names {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface2);
  flex-shrink: 0;
}
.shape-fb-name-spacer {
  width: 24px;
  height: 20px; /* matches marker-cell height */
  border-top: 1px solid var(--border);
  background: var(--surface2);
}
.shape-fb-string-name {
  width: 24px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

/* Fret columns */
.shape-fb-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.shape-fb-col:last-child { border-right: none; }

/* Nut: thick right border on the open column */
.shape-fb-col.open-col { border-right: 5px solid #c8c0a8; }

/* Position marker row at bottom of each column */
.shape-fb-marker-cell {
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface2);
}

/* String cells — position:relative so the absolute string-line and z-indexed dot stack correctly */
.shape-fb-cell {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  z-index: 0;
}

/* String line always present — sits behind any dot via absolute positioning */
.shape-fb-string-line {
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 1px;
  background: var(--border);
  pointer-events: none;
}

/* Fret numbers above the grid */
.shape-fb-fret-nums {
  display: flex;
  margin-bottom: 4px;
}
/* Aligns fret numbers under fret columns, not under the string-name column */
.shape-fb-num-spacer {
  width: 24px;
  flex-shrink: 0;
}
.shape-fb-fret-num {
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Shape dots ───────────────────────────────────────────────────────── */
/* Active position — outlined dot with interval label */
.shape-dot {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}
.shape-dot.active-pos {
  width: min(28px, calc(100% - 2px));
  height: 28px;
  font-size: 12px;
  background: var(--overlay-bg);
  border: 1.5px solid var(--accent);
  color: var(--accent);
}
.shape-dot.active-pos.root {
  background: var(--root-glow);
  border-color: var(--root-color);
  color: var(--root-color);
}

/* Other positions — same size as active, muted colors, with label */
.shape-dot.other-pos {
  width: min(28px, calc(100% - 2px));
  height: 28px;
  font-size: 12px;
  background: transparent;
  border: 1.5px solid color-mix(in srgb, var(--text-muted) 50%, transparent);
  color: color-mix(in srgb, var(--text-muted) 70%, transparent);
  opacity: 0.55;
}
.shape-dot.other-pos.root {
  border-color: color-mix(in srgb, var(--root-color) 55%, transparent);
  color: color-mix(in srgb, var(--root-color) 70%, transparent);
  opacity: 0.65;
}

/* ── Pattern text ────────────────────────────────────────────────────── */
.shape-pattern-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: inline-block;
  min-width: 220px;
}
.pattern-label {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.shape-pattern-text pre {
  font-family: 'SF Mono', 'Fira Code', 'Menlo', monospace;
  font-size: 13px;
  line-height: 1.9;
  color: var(--text);
  white-space: pre;
}

/* ── Chord Progression ───────────────────────────────────────────────── */
.progression-chord-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.progression-chord-card {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--chord-color) 40%, var(--border));
  border-top: 3px solid var(--chord-color);
  border-radius: 8px;
  padding: 12px 18px;
  min-width: 90px;
  text-align: center;
}

.progression-chord-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--chord-color);
  margin-bottom: 6px;
  font-weight: 600;
}

.progression-chord-name {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.progression-chord-roman {
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
}

.progression-chord-roman.non-diatonic { color: var(--root-color); }

.progression-key-line {
  font-size: 14px;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.progression-key-label { flex-shrink: 0; }

.progression-key-line strong { color: var(--text); }

.progression-roman-string {
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  margin-left: 8px;
  letter-spacing: 0.05em;
}

/* ── Tab Import ───────────────────────────────────────────────────────────── */
#tab-import-section { margin-bottom: 36px; }

#tab-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 14px;
}
#tab-drop-zone:hover,
#tab-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
#tab-drop-zone p { color: var(--text-muted); font-size: 14px; margin: 0 0 4px; }
#tab-drop-zone label { color: var(--accent); cursor: pointer; text-decoration: underline; }
.tab-formats { font-size: 12px !important; }
#tab-file-input { display: none; }

#tab-text-row { display: flex; gap: 10px; align-items: flex-start; }
#tab-text-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'SF Mono', 'Fira Code', 'Menlo', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 10px 12px;
  resize: vertical;
  transition: border-color 0.15s;
}
#tab-text-input:focus { outline: none; border-color: var(--accent); }
#tab-text-input::placeholder { color: var(--text-muted); }

.tab-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid transparent;
}
.tab-status-loading {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
}
.tab-status-success {
  background: color-mix(in srgb, #4ABF6A 10%, var(--surface));
  border-color: color-mix(in srgb, #4ABF6A 30%, transparent);
  color: #4ABF6A;
}
.tab-status-error {
  background: color-mix(in srgb, var(--root-color) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--root-color) 30%, transparent);
  color: var(--root-color);
}

/* ── Utilities ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
