/* ------- Base ------- */
:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --border: #e4e4ea;
  --text: #1c1c24;
  --text-muted: #6e6e7a;
  --accent: #5b5bd6;
  --accent-soft: #ececfb;
  --danger: #c0392b;
  --major: #9a6b00;
  --major-soft: #faf1d9;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 20, 40, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141419;
    --surface: #1e1e26;
    --border: #2e2e3a;
    --text: #ececf1;
    --text-muted: #9a9aa8;
    --accent: #8484e8;
    --accent-soft: #26264a;
    --major: #e3b95c;
    --major-soft: #3a3120;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

code {
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ------- Header ------- */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem 2rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

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

.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
}

.year-select {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ------- Section titres/artistes communs ------- */
.commons {
  max-width: 1200px;
  margin: 0 auto 0.5rem;
  padding: 0 2rem;
}

.commons-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1.2rem;
}

.commons-card h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.commons-card .chips + h2 { margin-top: 0.8rem; }

.commons-card .h2-all { color: var(--accent); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.85rem;
}

.chip .flags { margin-left: 0.3em; }

/* Titres/artistes présents dans tous les pays : mise en avant */
.chip-all {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ------- Colonnes pays ------- */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
  max-width: 1200px;
  margin: 1rem auto;
  padding: 0 2rem;
}

.country-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.country-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}

.country-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.country-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: wait; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { color: #fff; opacity: 0.9; }

/* ------- Liste des titres ------- */
.track-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  max-height: 65vh;
  overflow-y: auto;
}

.track {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
}

.track:hover { background: var(--accent-soft); }

.track .rank {
  width: 1.6rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

.track img,
.track .artwork-fallback {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: cover;
}

.track .artwork-fallback {
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}

.track .info { min-width: 0; }

.track .title {
  font-size: 0.92rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track .artist {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track .track-right {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.track .common-badge { font-size: 0.75rem; }

/* Bouton d'écoute YouTube (recherche dans un nouvel onglet) */
.yt-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.yt-link:hover {
  background: #e62117;
  color: #fff;
}

.track .yt-link {
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.track:hover .yt-link,
.track .yt-link:focus-visible { opacity: 1; }

/* Sur tactile (pas de survol), le bouton reste toujours visible */
@media (hover: none) {
  .track .yt-link { opacity: 1; }
}

.dialog-head .yt-link {
  vertical-align: middle;
  margin-left: 0.35rem;
}

.track .badge-all {
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.4rem;
}

/* ------- Résumé harmonique compact ------- */
.harmony {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.harmony-key {
  font-size: 0.68rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0.02rem 0.35rem;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.harmony-key.major {
  background: var(--major-soft);
  color: var(--major);
}

.harmony .degree {
  font-size: 0.65rem;
  font-family: ui-monospace, Consolas, monospace;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.02rem 0.3rem;
  line-height: 1.5;
}

.harmony .chord-count {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.track .streams-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}

.track .streams {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.track .streams-total {
  font-size: 0.68rem;
  color: var(--text-muted);
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  padding: 2rem 1.1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.error-state { color: var(--danger); }

/* ------- Dialog d'analyse ------- */
.track-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.5rem;
  width: min(560px, 92vw);
}

.track-dialog::backdrop { background: rgba(10, 10, 20, 0.45); }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-head .artist { color: var(--text-muted); margin: 0.1rem 0 0; }

.close-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
}

.key-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 0.15rem 0.6rem;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.chord-badge {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  margin-left: 0.4rem;
}

.sections-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.sections-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.sections-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.sections-table .chords { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
.sections-table .roman { color: var(--accent); font-weight: 600; }

.analysis-notes {
  margin-top: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-style: italic;
}

.analysis-disclaimer {
  margin-top: 0.9rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.dialog-actions { margin-top: 1rem; display: flex; gap: 0.6rem; }

.spinner-text { color: var(--text-muted); font-size: 0.9rem; }

/* ------- Footer ------- */
.site-footer {
  max-width: 1200px;
  margin: 1.5rem auto 2rem;
  padding: 0 2rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 640px) {
  .site-header, .columns, .commons, .site-footer { padding-left: 1rem; padding-right: 1rem; }
}
