/* Partitions : feuille de style unique, sans framework. */

:root {
  --bg: #fbfaf7;
  --fg: #1f1d1a;
  --muted: #6b665e;
  --line: #e4e0d8;
  --accent: #b4441f;      /* accords */
  --accent-soft: #f6e9e2;
  --chorus-bg: #f3f1ec;
  --link: #1f5f8b;
  --invalid-fg: #8f0d1c;  /* accord invalide */
  --invalid-bg: #fbd5d9;
  --lyric-size: 1.05rem;
  --row: 1.4;             /* hauteur d'une rangée accord ou paroles */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1917;
    --fg: #ece9e3;
    --muted: #a19b91;
    --line: #34312c;
    --accent: #f0915f;
    --accent-soft: #3a2a21;
    --chorus-bg: #24221f;
    --link: #82bde6;
    --invalid-fg: #ffb3bb;
    --invalid-bg: #5a1b22;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- En-tête du site ----------------------------------------------------- */

header.site {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .25rem 1.25rem;
  /* Bordure sur toute la largeur de l'écran ; contenu limité à 60rem
     (un peu plus large que la page) grâce aux marges intérieures. */
  padding: .75rem max(1rem, calc((100% - 60rem) / 2 + 1rem));
  border-bottom: 1px solid var(--line);
}
header.site .brand { font-weight: 700; font-size: 1.15rem; color: var(--fg); }
header.site nav { display: flex; gap: 1rem; }

main { max-width: 52rem; margin: 0 auto; padding: 1rem 1rem 4rem; }

/* --- Édition (administrateur) --------------------------------------------- */

header.site .admin { display: flex; align-items: baseline; gap: 1rem; margin-left: auto; }
header.site .admin form { display: inline; margin: 0; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
button.link:hover { text-decoration: underline; }
.admin-links { display: flex; gap: 1rem; margin: .25rem 0; font-size: .9rem; }

form.editor, form.login, form.confirm { display: flex; flex-direction: column; gap: .5rem; }
form.login { max-width: 20rem; }
form.editor label, form.login label { font-size: .85rem; color: var(--muted); }
form.editor textarea {
  width: 100%;
  min-height: 60vh;
  box-sizing: border-box;
  padding: .5rem;
  font: 14px/1.45 ui-monospace, "DejaVu Sans Mono", Menlo, Consolas, monospace;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
}
form.login input[type=password] { font: inherit; background: var(--bg); color: var(--fg); padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 4px; }
form .actions { display: flex; align-items: baseline; gap: 1rem; margin: .25rem 0; }
form button:not(.link):not(.star) { font: inherit; padding: .4rem 1rem; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
form button.danger { border-color: #c0392b; color: #c0392b; }
.error { border-left: 3px solid #c0392b; padding: .25rem .75rem; background: rgba(192, 57, 43, .1); }
.error ul { margin: .25rem 0; padding-left: 1.2rem; }

h1 { font-size: 1.6rem; line-height: 1.25; margin: .5rem 0 .25rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .35rem; }

/* --- Listes --------------------------------------------------------------- */

.browse, .kind, .empty { color: var(--muted); }
.kind { margin: .75rem 0 0; font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }

ul.songs, ul.groups { list-style: none; padding: 0; margin: 1rem 0; }
ul.songs li, ul.groups li { border-bottom: 1px solid var(--line); }
ul.songs a, ul.groups a { display: block; padding: .6rem .25rem; color: var(--fg); }
ul.songs li { display: flex; align-items: center; }
ul.songs li > a { flex: 1; min-width: 0; }

/* --- Favoris ---------------------------------------------------------------- */

.star { color: #e8b923; font-size: 1.2rem; line-height: 1; padding: 0 .35rem; flex: none; }
.star-form { display: contents; }
button.star { background: none; border: 0; margin: 0; padding: .45rem .35rem; font-family: inherit; cursor: pointer; }
/* Étoile « transparente » : contour seul. */
.star.off { color: transparent; -webkit-text-stroke: 1.2px var(--muted); }
button.star.off:hover, button.star.off:focus-visible { -webkit-text-stroke-color: #e8b923; }
button.star:not(.off):hover { opacity: .75; }
button.star[aria-busy="true"] { opacity: .5; cursor: progress; }
button.star.error { -webkit-text-stroke-color: #c0392b; color: transparent; }
@supports not (-webkit-text-stroke: 1px black) {
  .star.off { color: var(--muted); }
}
.title-row { display: flex; align-items: baseline; gap: .25rem; margin: .5rem 0 .25rem; }
.title-row h1 { margin: 0; }
.title-row .star { font-size: 1.5rem; }
ul.songs .a, ul.groups .n { color: var(--muted); font-size: .9rem; margin-left: .35rem; }

/* --- Page chanson : en-tête ------------------------------------------------- */

.song-head { margin-bottom: 1.5rem; }
.song-head .meta { margin: 0 0 .5rem; display: flex; flex-wrap: wrap; gap: .35rem .75rem; align-items: baseline; }
.song-head .style {
  font-size: .8rem; padding: .05rem .5rem; border-radius: 1rem;
  border: 1px solid var(--line); color: var(--muted);
}
.badges { margin: 0 0 .75rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.badges:empty { display: none; }
.badge { font-size: .9rem; padding: .15rem .6rem; border-radius: .35rem; background: var(--chorus-bg); }
.badge.capo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.key { font-weight: 600; color: var(--accent); }

.transpose { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.transpose[hidden] { display: none; }
.transpose .label { color: var(--muted); font-size: .9rem; margin-right: .25rem; }
.transpose button {
  font: inherit; min-width: 2.75rem; min-height: 2.25rem; padding: 0 .6rem;
  border: 1px solid var(--line); border-radius: .4rem; background: var(--bg); color: var(--fg);
  cursor: pointer;
}
.transpose button:hover { border-color: var(--accent); }
.transpose .reset { font-size: .85rem; }
.transpose .notation-label { margin-left: .75rem; }
.transpose .notation { display: inline-flex; gap: .2rem; }
.transpose button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.transpose .offset { min-width: 2.5rem; text-align: center; font-weight: 600; color: var(--accent); }

/* --- Sections --------------------------------------------------------------- */

.block { margin: 0 0 1.5rem; }
.block.chorus {
  background: var(--chorus-bg);
  border-left: 3px solid var(--accent);
  padding: .6rem .9rem;
  border-radius: 0 .4rem .4rem 0;
}
.block.bridge { border-left: 3px dashed var(--line); padding-left: .9rem; }
.gap { height: .8rem; }
.comment { font-style: italic; color: var(--muted); margin: .25rem 0; }

/* --- Lignes accords + paroles ------------------------------------------------
   Chaque mot (.w) est insécable ; chaque segment (.seg) est une colonne à deux
   rangées de même hauteur : l'accord au-dessus, le texte en dessous. Les
   segments sont alignés par le haut, donc toutes les paroles d'une ligne
   tombent sur la même rangée. */

.line { font-size: var(--lyric-size); margin: 0 0 .15rem; }
.w { white-space: nowrap; }
.seg { display: inline-flex; flex-direction: column; vertical-align: top; }
.ch, .ly { display: block; line-height: var(--row); min-height: calc(var(--row) * 1em); white-space: pre; }
.ch { color: var(--accent); font-weight: 700; font-size: .92em; }
.ch:not(:empty) { padding-right: .3em; }  /* écarte deux accords rapprochés */
.line:not(.has-chords) .ch { display: none; }

/* --- Grilles ---------------------------------------------------------------- */

.grid-row { display: flex; flex-wrap: wrap; align-items: center; margin: 0 0 .25rem; }
.measure {
  display: inline-flex; min-width: 7.5rem; padding: .2rem .5rem;
  border-left: 2px solid var(--muted);
}
.measure:last-child, .measure:has(+ .grid-note) { border-right: 2px solid var(--muted); }
.beat { flex: 1 0 auto; min-width: 1.6rem; padding-right: .35em; font-weight: 700; color: var(--accent); }
.beat.hold { color: var(--muted); font-weight: 400; }
.grid-note { margin-left: .6rem; color: var(--muted); font-style: italic; }

@media print {
  header.site, .transpose, .admin-links, .star-form, .star { display: none; }
  .block { break-inside: avoid; }
}

/* Accord ou tonalité invalide : montré tel quel, jamais transposé ni traduit.
   Fond et soulignement ondulé le distinguent des accords (déjà colorés). */
.c.invalid, .key.invalid {
  color: var(--invalid-fg); background: var(--invalid-bg);
  text-decoration: underline wavy; text-underline-offset: .15em;
  border-radius: .2rem; padding: 0 .2em;
}
