/* ─── Design Tokens ─────────────────────────────────── */
:root {
  /* ── Fretty Palette ── */
  /* Backgrounds */
  --bg-page:         #0B0235;
  --bg-panel:        #15104A;
  --bg-panel-hover:  #1B1760;
  --bg-inset:        #110C3F;
  --bg-control:      #110C3F;
  --bg-panel-alt:    #1B1760;

  /* Text */
  --text-primary:    #FDFDFD;
  --text-secondary:  #C8D4FF;
  --text-hint:       #8FA3D9;
  --text-muted:      #8FA3D9;
  --text-disabled:   #6673A8;

  /* Borders */
  --border:          #2D2A6E;
  --border-bright:   #3D3A8E;
  --border-soft:     #24205A;
  --focus:           #079DF2;

  /* Blues — primary interactive (80% of UI color) */
  --blue-deep:       #03179E;
  --blue-bright:     #0462DE;
  --blue-sky:        #079DF2;
  --aqua:            #62EAF2;

  /* Brand accents — use sparingly (5%) */
  --brand-pink:      #EA185E;
  --brand-orange:    #F86623;
  --brand-gold:      #FAA311;
  --brand-yellow:    #FBD117;

  /* Gradients */
  --gradient-brand:  linear-gradient(135deg, #EA185E, #F86623, #FBD117);
  --gradient-cool:   linear-gradient(135deg, #03179E, #0462DE, #62EAF2);
  --gradient-cosmic: linear-gradient(180deg, #0B0235, #15104A, #1B1760);

  /* Legacy accent aliases — mapped to new palette */
  --accent-gold:     #FAA311;
  --accent-blue:     #079DF2;
  --accent-green:    #62EAF2;
  --accent-red:      #EA185E;
  --accent-purple:   #0462DE;
  --accent-teal:     #62EAF2;
  --accent-cyan:     #079DF2;

  /* Chord function colors */
  --fn-tonic:        #62EAF2;
  --fn-dominant:     #EA185E;
  --fn-subdominant:  #079DF2;
  --fn-other:        #0462DE;

  /* Fretboard */
  --fb-wood:         #5c3317;
  --fb-wood-light:   #7a4525;
  --fb-fret:         #b8b8c8;
  --fb-nut:          #e8e0c8;
  --fb-string:       #d4af37;
  --fb-inlay:        rgba(255,255,255,0.12);

  /* Note dots */
  --dot-selected:    #EA185E;
  --dot-tonic:       #62EAF2;
  --dot-scale:       rgba(7,157,242,0.45);
  --dot-dominant:    #FAA311;
  --dot-text:        #ffffff;

  --radius:          8px;
  --radius-sm:       4px;
  --gap:             12px;
  --font-mono:       'JetBrains Mono', 'Courier New', monospace;
  --font-display:    'Barlow Semi Condensed', 'IBM Plex Sans', sans-serif;

  /* Typography scale */
  --font-size-section-label: 0.8rem;
  --font-size-card-title:    0.93rem;
  --font-size-body:          0.85rem;
  --font-size-meta:          0.7rem;
  --line-height-body:        1.65;
  --line-height-meta:        1.45;
}

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

body {
  background: var(--bg-page);
  background-image: radial-gradient(ellipse at 50% 0%, #1B1760 0%, #0B0235 65%);
  color: var(--text-primary);
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

/* ─── Grain Texture Overlay (CSS-only, no SVG filter) ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.04;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.55) 1px, transparent 1px),
    radial-gradient(circle, rgba(255,255,255,0.35) 1px, transparent 1px);
  background-size: 24px 24px, 13px 13px;
  background-position: 0 0, 7px 11px;
}

/* ─── Dashboard Grid ────────────────────────────────── */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1400px;
  margin: 0 auto;
}

/* ─── Two-Column Body Layout ────────────────────────── */
.dashboard-body {
  display: grid;
  grid-template-columns: 640px 1fr;
  gap: var(--gap);
  align-items: start;
}

.dashboard-col-left {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  /* No max-height / overflow clipping — expanding panels (Harmony, Relationship)
     push content down naturally without covering the fretboard above them. */
}

.dashboard-col-right {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

@media (max-width: 1150px) {
  .dashboard-body {
    grid-template-columns: 1fr;
  }
}

/* ─── Header ────────────────────────────────────────── */
.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 12px;
}
.header-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-logo {
  height: 80px;
  width: auto;
  object-fit: contain;
}
.header-theory-btn { margin-left: 16px; }
.header-actions { display: flex; gap: 8px; }

/* ─── Panels ────────────────────────────────────────── */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}

/* Tier 1: primary instrument panels — elevated depth */
.panel-primary {
  box-shadow: 0 2px 14px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Tier 3: analysis/reference panels — recessed feel */
.panel-analysis {
  background: var(--bg-inset);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.35);
}

.section-label {
  font-family: Inter, system-ui, sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  font-variant: normal;
  letter-spacing: 0.06em;
  color: #7090c0;
  margin-bottom: 10px;
  display: block;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-collapse-header .panel-title-row {
  margin-bottom: 0;
}

/* Collapsible sub-headers match main panel title size */

.panel-title-row .section-label {
  margin-bottom: 0;
}

.panel-title-icon {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}
.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: var(--font-size-meta);
  color: var(--text-muted);
}
.key-placeholder {
  color: var(--text-hint);
  font-style: italic;
  font-size: 0.82rem;
}

/* ─── 4-Level Typography System ────────────────────── */
.card-title {
  font-size: var(--font-size-card-title);
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.body-text {
  font-size: var(--font-size-body);
  color: var(--text-primary);
  line-height: var(--line-height-body);
}
.meta-text {
  font-size: var(--font-size-meta);
  color: var(--text-secondary);
  line-height: var(--line-height-meta);
}

/* ─── Two-Column Rows (legacy, kept for compatibility) ── */
.two-col-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}
@media (max-width: 768px) {
  .two-col-row { grid-template-columns: 1fr; }
}

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-control);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--border); border-color: var(--border-bright); }

.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

.btn-accent {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
  font-weight: 600;
}
.btn-accent:hover { background: #2a8fd6; border-color: #2a8fd6; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border); }

.btn-danger {
  background: rgba(231,76,60,0.12);
  border-color: var(--accent-red);
  color: var(--accent-red);
}
.btn-danger:hover {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

.btn-outline {
  background: transparent;
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}
.btn-outline:hover, .btn-outline[data-active="true"] {
  background: var(--accent-blue);
  color: #fff;
}

.btn-active {
  background: var(--accent-gold) !important;
  border-color: var(--accent-gold) !important;
  color: #1a1a1a !important;
  font-weight: 700;
}

/* ─── Scale Type Buttons ────────────────────────────── */
.scale-type-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.scale-type-btn {
  padding: 3px 9px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--bg-control);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.scale-type-btn:hover { border-color: var(--accent-blue); color: var(--accent-blue); }
.scale-type-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
  font-weight: 600;
}

/* ─── Fretboard Controls ────────────────────────────── */

/* ── Move Shape row — centred strip directly below fretboard ── */
.move-shape-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 5px 12px 3px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-soft);
}

/* ── Icon bar — 3 equal columns: Tuning | Capo | Tone ── */
.shape-shift-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  padding: 4px 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-soft);
}

/* Left: Tuning */
.shape-shift-left {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
}

/* Centre: Capo */
.shape-shift-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* Right: Tone */
.shape-shift-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* Capo popover inner layout */
.capo-popover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  min-width: 230px;
}
.capo-pos-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.capo-remove-btn {
  background: transparent;
  border: 1px solid #e53e3e;
  color: #e53e3e;
  border-radius: 6px;
  padding: 4px 16px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.capo-remove-btn:hover {
  background: rgba(229, 62, 62, 0.15);
}

/* Capo icon button active glow — purple instead of gold */
#capo-icon-btn.open {
  outline: 2px solid #9333ea;
  outline-offset: 3px;
}

/* Capo Apply button highlights when pending capo differs from applied capo */
#btn-capo-apply.pending {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

.shape-shift-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.shape-shift-btn {
  background: var(--bg-raised, #1e1e3a);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  line-height: 1.6;
}
.shape-shift-btn:hover:not(:disabled) {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}
.shape-shift-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.shape-shift-pos {
  min-width: 44px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  background: var(--bg-card, #13132a);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
}

.fretboard-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-soft);
}
.tab-input-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.control-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.tab-input {
  background: var(--bg-control);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 5px 10px;
  width: 180px;
}
.tab-input:focus { outline: none; border-color: var(--accent-blue); }

.fretboard-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.scale-toggle-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ─── Chord Progression Chips ───────────────────────── */
.progression-section { padding: 10px 16px; }
.chord-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-height: 36px;
}
.chord-chips-empty { color: var(--text-hint); font-style: italic; font-size: 0.82rem; }

/* ─── Pattern Badge ─────────────────────────────────── */
.pattern-badge {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-top: 14px;
  margin-bottom: 6px;
  background: rgba(4,98,222,0.1);
  border: 1px solid rgba(4,98,222,0.3);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  line-height: 1.4;
}
.pattern-badge-icon { font-size: 0.9rem; }
.pattern-badge-name {
  font-weight: 700;
  color: var(--blue-sky);
}
.pattern-badge-genre {
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(7,157,242,0.15);
  color: var(--blue-sky);
  font-weight: 600;
}
.pattern-badge-examples {
  color: var(--text-secondary);
  font-style: italic;
}
.pattern-badge-desc {
  color: var(--text-muted);
  flex-basis: 100%;
  font-size: var(--font-size-meta);
}

.chord-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--bg-control);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.82rem;
  cursor: grab;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s, box-shadow 0.1s;
  font-weight: 600;
  user-select: none;
}
.chord-chip:active { cursor: grabbing; }
.chord-chip:hover { border-color: var(--accent-gold); color: var(--accent-gold); }
.chord-chip.active {
  background: var(--accent-gold);
  border-color: var(--accent-gold);
  color: #1a1a1a;
}
.chord-chip .chip-remove {
  font-size: 0.7rem;
  opacity: 0.5;
  cursor: pointer;
  margin-left: 2px;
}
.chord-chip .chip-remove:hover { opacity: 1; color: var(--accent-red); }

.chip-chord-name {
  display: block;
  line-height: 1.15;
  font-weight: 600;
}
.chip-numeral {
  display: block;
  font-size: 0.68em;
  font-weight: 400;
  opacity: 0.6;
  letter-spacing: 0.04em;
  line-height: 1;
}

/* Drag-to-reorder states */
.chord-chip.chip-dragging {
  opacity: 0.3;
  box-shadow: none !important;
}
/* Drop-target indicators — left/right edge highlight */
.chord-chip.chip-drop-before {
  box-shadow: -3px 0 0 0 var(--accent-teal);
}
.chord-chip.chip-drop-after {
  box-shadow: 3px 0 0 0 var(--accent-teal);
}
/* Drag handle icon — visible on hover */
.chip-drag-handle {
  font-size: 0.75rem;
  opacity: 0;
  color: var(--text-hint);
  transition: opacity 0.15s;
  pointer-events: none;
  flex-shrink: 0;
  line-height: 1;
}
.chord-chip:hover .chip-drag-handle { opacity: 0.55; }

/* ─── Scale Status Label ────────────────────────────── */
.scale-status-label {
  font-size: 0.72rem;
  color: var(--accent-teal);
  font-weight: 600;
  white-space: nowrap;
  display: none;
  align-items: center;
  gap: 4px;
}
.scale-status-label.visible { display: inline-flex; }
.scale-status-label::before { content: '↳'; opacity: 0.7; margin-right: 2px; }

/* ─── Form Template Select ─────────────────────────── */
.form-template-select {
  font-size: 0.72rem;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-control);
  color: var(--text-secondary);
  cursor: pointer;
  margin-left: auto;
}
.form-template-select:hover {
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

/* ─── Image-based action buttons (Add / Replace) ───── */
.btn-action-img {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  transition: opacity 0.15s, transform 0.12s;
}
.btn-action-img:hover { opacity: 0.88; transform: scale(1.03); }
.btn-action-img:active { opacity: 0.7; transform: scale(0.97); }
.btn-action-img-src {
  height: 46px;
  width: auto;
  display: block;
}
.btn-replace-img .btn-action-img-src {
  height: 42px;
}

/* ─── Panel Reveal Animation ────────────────────────── */
@keyframes panelReveal {
  from { opacity: 0; transform: translateY(-8px); filter: blur(2px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0);   }
}
.panel-reveal {
  animation: panelReveal 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Add-to-Progression Button Pulse ───────────────── */
@keyframes btnSuccess {
  0%   { filter: brightness(1) drop-shadow(0 0 0px rgba(7,157,242,0.0)); }
  40%  { filter: brightness(1.25) drop-shadow(0 0 8px rgba(7,157,242,0.8)); }
  100% { filter: brightness(1) drop-shadow(0 0 0px rgba(7,157,242,0.0)); }
}
.btn-pulse { animation: btnSuccess 0.5s ease-out; }

/* ─── Key Panel Glow on Key Change ──────────────────── */
@keyframes keyPanelGlow {
  0%   { box-shadow: 0 -3px 24px rgba(250,163,17,0),   0 2px 14px rgba(0,0,0,0.55); }
  35%  { box-shadow: 0 -3px 24px rgba(250,163,17,0.55), 0 2px 14px rgba(0,0,0,0.55); }
  100% { box-shadow: 0 -3px 24px rgba(250,163,17,0),   0 2px 14px rgba(0,0,0,0.55); }
}
.key-panel.key-glow {
  animation: keyPanelGlow 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── Drag-reorder: gap indicator ───────────────────── */
.chord-chip.chip-drop-before {
  box-shadow: -3px 0 0 0 var(--accent-teal);
  margin-left: 10px;
}
.chord-chip.chip-drop-after {
  box-shadow: 3px 0 0 0 var(--accent-teal);
  margin-right: 10px;
}

/* ─── Header separator before destructive buttons ───── */
.header-actions-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* ─── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-page); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* ─── PDF Export Modal ──────────────────────────────── */
.pdf-export-modal-box {
  width: min(480px, 95vw);
  max-height: 90vh;
}
.pdf-export-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}
.pdf-export-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pdf-export-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
}
.pdf-export-input {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s;
}
.pdf-export-input:focus { border-color: var(--focus); }
.pdf-export-divider {
  border-top: 1px solid var(--border-soft);
  margin: 2px 0;
}
.pdf-export-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pdf-export-option {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 1px;
  padding: 8px 10px;
  background: var(--bg-inset);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.pdf-export-option:hover {
  border-color: var(--border);
  background: var(--bg-panel-hover);
}
.pdf-export-option input[type="checkbox"] {
  grid-row: 1 / 3;
  align-self: center;
  accent-color: var(--focus);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
.pdf-option-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}
.pdf-option-desc {
  font-size: 0.75rem;
  color: var(--text-hint);
}
.pdf-export-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--border-soft);
  margin-top: 4px;
}

/* ── Site footer ── */
.site-footer {
  text-align: center;
  padding: 12px 16px;
  font-size: 11px;
  color: var(--text-muted, #9ca3af);
  border-top: 1px solid var(--border-soft, #2d2d4e);
  background: var(--bg-card, #12122a);
  margin-top: 24px;
}
