/* Styles partagés des pages du manuel (chapitre_*.html, teacher_lessons*.html). */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f4f0; color: #1a1a1a;
  min-height: 100vh; display: flex; flex-direction: column;
}
header {
  background: #1e2040; color: white;
  padding: 0.8rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.5rem;
}
header h1 { font-size: 1.05rem; font-weight: 600; }
header h1 a { color: inherit; text-decoration: none; }
header nav a {
  color: #9999cc; font-size: 0.85rem;
  text-decoration: none; margin-left: 1rem;
}
header nav a:hover { color: white; }
main {
  flex: 1; padding: 1.5rem 1rem;
  max-width: 860px; margin: 0 auto; width: 100%;
}
/* Pages de partie : colonne de contenu large de 210 mm, la largeur
   d'une page A4. Le calc ajoute les paddings de main (2×1rem) et du
   .card (2×1.4rem) pour que ce soit bien le contenu qui fasse
   210 mm. */
main.lesson-main { max-width: calc(210mm + 4.8rem); }
h2.page-title {
  font-size: 1.3rem; font-weight: 600; color: #1e2040;
  margin-bottom: 1rem;
}
.flash, .err {
  padding: 0.6rem 0.9rem; border-radius: 7px;
  font-size: 0.9rem; margin-bottom: 1rem;
}
.flash { background: #e0f5e0; border: 1px solid #66bb6a; color: #1b5e20; }
.err   { background: #fff5f5; border: 1px solid #fca5a5; color: #b71c1c; }

.card {
  background: white; border: 1px solid #e4e4e8;
  border-radius: 10px; padding: 1.2rem 1.4rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  margin-bottom: 1.2rem;
}
.card h3 { font-size: 1.05rem; color: #1e2040; margin-bottom: 0.3rem; }
.card h3 a { color: inherit; text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.card h3 form.inline { display: inline-block; margin-left: 0.5rem; }
.card p.desc { color: #666; font-size: 0.9rem; margin-bottom: 0.6rem; }

.lesson-list { list-style: none; }
.lesson-list li {
  padding: 0.45rem 0.2rem;
  border-top: 1px solid #f0f0f4;
  display: flex; align-items: center; gap: 0.5rem;
}
.lesson-list li:first-child { border-top: none; }
.lesson-list a { color: #3a3d7c; text-decoration: none; font-size: 0.95rem; }
.lesson-list a:hover { text-decoration: underline; }
.lock { font-size: 0.8rem; color: #999; }
.tag {
  font-size: 0.7rem; padding: 0.1rem 0.45rem; border-radius: 999px;
  border: 1px solid #d4d4dc; color: #666; white-space: nowrap;
}
.tag.draft { border-color: #e0b050; color: #9a6b00; background: #fdf6e3; }

.breadcrumb { font-size: 0.85rem; color: #888; margin-bottom: 0.8rem; }
.breadcrumb a { color: #3a3d7c; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.empty {
  background: white; border: 1px dashed #c4c4d4;
  border-radius: 10px; padding: 2rem; text-align: center; color: #666;
}

/* Contenu d'une partie (markdown rendu) */
.lesson-content { line-height: 1.65; font-size: 1rem; }
.lesson-content h1 { font-size: 1.5rem; color: #1e2040; margin: 1.4rem 0 0.6rem; }
.lesson-content h2 { font-size: 1.25rem; color: #1e2040; margin: 1.3rem 0 0.5rem; }
.lesson-content h3 { font-size: 1.05rem; color: #1e2040; margin: 1.1rem 0 0.4rem; }
.lesson-content p { margin: 0.6rem 0; }
.lesson-content ul, .lesson-content ol { margin: 0.6rem 0 0.6rem 1.4rem; }
.lesson-content blockquote {
  border-left: 3px solid #c9c9e6; padding: 0.2rem 0.9rem;
  color: #555; margin: 0.8rem 0; background: #fafaff;
}
.lesson-content code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: #f0eef4; padding: 0.1rem 0.35rem; border-radius: 4px;
  font-size: 0.9em;
}
.lesson-content pre {
  background: #f0eef4; padding: 0.8rem 1rem; border-radius: 8px;
  margin: 0.8rem 0;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.lesson-content pre code { background: none; padding: 0; }
.lesson-content table { border-collapse: collapse; margin: 0.8rem 0; }
.lesson-content th, .lesson-content td {
  border: 1px solid #ddd; padding: 0.4rem 0.7rem; font-size: 0.92rem;
}
.lesson-content th { background: #f0eef4; }
.lesson-content img { max-width: 100%; display: block; margin: 0.8rem auto; }
.lesson-content hr { border: none; border-top: 1px solid #e4e4e8; margin: 1.2rem 0; }

/* Partitions embarquées dans les parties (_score_embed.html) */
.score-embed { margin: 1rem 0; }
/* Dans la carte de partie, le cadre gravé ignore le padding horizontal
   de la carte (1.4rem), que le texte et la ligne de boutons respectent :
   la gravure garde ses 5 mm de marge sans rétrécir la musique. */
.lesson-card .score-embed .score-wrap { margin-left: -1.4rem; margin-right: -1.4rem; }
.score-embed .embed-audio {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.score-embed .embed-audio audio { flex: 1; min-width: 220px; height: 2.2rem; }
.score-embed .score-wrap {
  position: relative; display: block; line-height: 0;
  border: 1px solid #eee; border-radius: 8px; padding: 0.6rem;
  background: white;
}
.score-embed .score-wrap img { width: 100%; height: auto; display: block; }
.embed-error {
  background: #fff5f5; border: 1px solid #fca5a5; border-radius: 8px;
  padding: 0.9rem 1.1rem; color: #b71c1c; margin: 1rem 0;
  font-size: 0.9rem;
}
.embed-error pre {
  margin-top: 0.5rem; font-size: 0.8rem; white-space: pre-wrap;
  word-break: break-word; color: #7a1010;
}
.score-placeholder {
  border: 1px dashed #c4c4d4; border-radius: 8px;
  padding: 0.8rem 1rem; margin: 1rem 0; background: #fafaff;
}
.score-placeholder-label { font-size: 0.82rem; color: #777; margin-bottom: 0.5rem; }
.score-placeholder pre {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.8rem; color: #444;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

/* Blocs ```exercice : accordéon (un seul ouvert à la fois, cf. exfree.js) */
details.exfree {
  margin: 1.2rem 0; background: #fafaff;
  border: 1px solid #d8d8ea; border-radius: 10px;
}
details.exfree[open] { border-color: #8888cc; box-shadow: 0 2px 10px rgba(58,61,124,0.08); }
details.exfree summary {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.75rem 1rem; cursor: pointer; user-select: none;
  list-style: none;
}
details.exfree summary::-webkit-details-marker { display: none; }
details.exfree summary::before {
  content: "▸"; color: #3a3d7c; font-size: 0.9rem;
  transition: transform 0.15s; flex: none;
}
details.exfree[open] summary::before { transform: rotate(90deg); }
details.exfree summary:hover { background: #f0f0fb; border-radius: 10px; }
.exfree-chip {
  font-size: 0.7rem; font-weight: 700; color: #3a3d7c;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: #ebebff; border-radius: 999px; padding: 0.15rem 0.6rem;
}
.exfree-title { font-weight: 600; color: #1e2040; }
.exfree-hint { margin-left: auto; font-size: 0.8rem; color: #999; font-style: italic; }
details.exfree[open] .exfree-hint { display: none; }
.exfree-body { padding: 0 1rem 1rem; }
.exfree-body .exercise-widget { border: none; background: none; padding: 0; margin: 0; }
.exfree-loading { color: #888; font-size: 0.9rem; padding: 0.5rem 0; }
.exp-new { margin-left: auto; white-space: nowrap; }

/* Shortcodes */
.video-embed {
  position: relative; aspect-ratio: 16 / 9; margin: 1rem 0;
  border-radius: 8px; overflow: hidden; background: #000;
}
.video-embed iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0;
}
.sc-link { margin: 0.8rem 0; }
.sc-link a { color: #3a3d7c; word-break: break-all; }
.sc-error {
  border: 1px dashed #f0b4b4; border-radius: 8px; background: #fffafa;
  color: #b71c1c; font-size: 0.85rem; padding: 0.6rem 0.9rem; margin: 0.8rem 0;
}
.sc-note { color: #888; font-size: 0.85rem; font-style: italic; }
.exercise-slot {
  border: 1px solid #e4e4e8; border-radius: 8px; background: #fafaff;
  padding: 0.9rem 1.1rem; margin: 1rem 0;
}

/* Widget d'exercice inline (_exercise_widget.html) */
.exercise-widget {
  border: 1px solid #e4e4e8; border-radius: 8px; background: #fafaff;
  padding: 0.9rem 1.1rem; margin: 1rem 0;
}
.exercise-widget .exw-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.8rem;
}
.exercise-widget .exw-label {
  font-size: 0.72rem; font-weight: 600; color: #888;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.exercise-widget .exw-title { font-weight: 600; color: #1e2040; }
.exercise-widget .exw-audio {
  display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap;
  margin: 0.6rem 0;
}
.exercise-widget .exw-audio audio { flex: 1; min-width: 220px; height: 2.2rem; }
.exercise-widget .exw-wrap {
  position: relative; display: block; line-height: 0;
  border: 1px solid #eee; border-radius: 8px; padding: 0.6rem;
  background: white;
}
.exercise-widget .exw-wrap img { width: 100%; height: auto; display: block; }
.exercise-widget .exw-question {
  font-size: 0.95rem; font-weight: 600; color: #2a2a4a;
  margin: 0.8rem 0 0.7rem;
}
.exercise-widget .choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.6rem;
}
@media (max-width: 380px) { .exercise-widget .choice-grid { grid-template-columns: 1fr; } }
.exercise-widget .choice-btn {
  min-height: 52px;
  padding: 0.75rem 0.9rem; font-size: 1rem;
  background: #f8f8fc; border: 1.5px solid #ddd; border-radius: 8px;
  cursor: pointer; color: #2a2a4a; font-weight: 600;
  font-family: inherit;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background 0.12s, border-color 0.12s, color 0.12s,
              transform 0.05s, box-shadow 0.12s;
}
.exercise-widget .choice-btn:hover:not(:disabled) { background: #ebebff; border-color: #8888dd; }
.exercise-widget .choice-btn:active:not(:disabled) { transform: scale(0.97); }
.exercise-widget .choice-btn:disabled { cursor: default; }
.exercise-widget .choice-btn.reveal-correct,
.exercise-widget .choice-heptagon .choice-btn.reveal-correct {
  background: #d6f5d6; border-color: #4caf50; color: #1b5e20;
  box-shadow: 0 0 0 3px rgba(76,175,80,0.18);
}
.exercise-widget .choice-btn.reveal-wrong,
.exercise-widget .choice-heptagon .choice-btn.reveal-wrong {
  background: #ffe0e0; border-color: #e57373; color: #b71c1c;
}
.exercise-widget .reveal-line {
  margin-top: 0.8rem; font-size: 0.95rem; font-weight: 600;
  min-height: 1.3em; text-align: center; color: #666;
}

/* Frappe du rythme (widget inline) */
.exercise-widget .rhythm-tap {
  display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
}
.exercise-widget .tap-zone {
  width: 100%; padding: 1.6rem 1rem;
  background: linear-gradient(135deg, #3a3d7c, #5054a8);
  color: white; border-radius: 10px;
  font-size: 1.05rem; font-weight: 600;
  text-align: center; cursor: pointer; user-select: none;
  transition: transform 0.05s, background 0.12s;
}
.exercise-widget .tap-zone:active { transform: scale(0.97); background: #2e3170; }
.exercise-widget .tap-zone.armed { background: #2c8c4a; }
.exercise-widget .tap-zone.armed:active { background: #226f3a; }
.exercise-widget .tap-meta { font-size: 0.85rem; color: #666; min-height: 1.2em; }
.exercise-widget .tap-actions {
  display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center;
}
.exercise-widget .tap-viz { width: 100%; margin-top: 0.2rem; }
.exercise-widget .viz-summary { font-size: 0.92rem; margin-bottom: 0.6rem; text-align: center; color: #444; line-height: 1.5; }
.exercise-widget .viz-ok { color: #1b5e20; font-weight: 700; }
.exercise-widget .viz-ko { color: #b71c1c; font-weight: 700; }
.exercise-widget .viz-stat { color: #555; white-space: nowrap; }
.exercise-widget .viz-line { margin-bottom: 0.45rem; }
.exercise-widget .viz-line:last-child { margin-bottom: 0; }
.exercise-widget .viz-line-label { font-size: 0.72rem; color: #888; margin-bottom: 0.15rem; }
.exercise-widget .viz-track {
  position: relative; height: 54px; width: 100%;
  background: #f0f0f6; border: 1px solid #ddd; border-radius: 8px; overflow: hidden;
}
.exercise-widget .viz-tolband { position: absolute; top: 0; bottom: 0; background: rgba(76,175,80,0.12); }
.exercise-widget .viz-expected { position: absolute; top: 8px; bottom: 8px; width: 2px; margin-left: -1px; background: #8888aa; }
.exercise-widget .viz-tap { position: absolute; top: 50%; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-radius: 50%; }
.exercise-widget .viz-tap.hit { background: #2c8c4a; box-shadow: 0 0 0 2px rgba(44,140,74,0.25); }
.exercise-widget .viz-tap.miss { background: #e53935; box-shadow: 0 0 0 2px rgba(229,57,53,0.25); }
.exercise-widget .viz-legend { margin-top: 0.5rem; font-size: 0.75rem; color: #777; display: flex; gap: 0.9rem; justify-content: center; flex-wrap: wrap; }
.exercise-widget .viz-legend .lg::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 0.3rem; vertical-align: middle; }
.exercise-widget .lg-exp::before { background: #8888aa; }
.exercise-widget .lg-hit::before { background: #2c8c4a; border-radius: 50%; }
.exercise-widget .lg-miss::before { background: #e53935; border-radius: 50%; }
.oeuvre-card {
  border: 1px solid #e4e4e8; border-radius: 8px; background: #fafaff;
  padding: 0.9rem 1.1rem; margin: 1rem 0;
}
.oeuvre-title { font-weight: 600; color: #1e2040; }
.oeuvre-notes { color: #555; font-size: 0.9rem; margin-top: 0.3rem; }
.oeuvre-audio { margin: 0.5rem 0 1rem; }
.oeuvre-audio audio { width: 100%; max-width: 560px; display: block; }
.oeuvre-audio .yt-audio-btn {
  cursor: pointer; color: #3a3d7c; font-size: 0.9rem;
  background: #fff; border: 1px solid #c9cbe8; border-radius: 6px;
  padding: 0.25rem 0.7rem; margin-bottom: 0.3rem;
}
.oeuvre-audio .yt-audio-btn.playing { background: #eef0ff; font-weight: 600; }
.oeuvre-audio details.oeuvre-video summary {
  cursor: pointer; color: #3a3d7c; font-size: 0.9rem; user-select: none;
}
.oeuvre-audio details.oeuvre-video[open] summary { margin-bottom: 0.4rem; }
.embed-caption {
  font-weight: 600; color: #1e2040; font-size: 0.95rem;
  margin: 1rem 0 0.3rem;
}

.lesson-pager {
  display: flex; justify-content: space-between; gap: 0.6rem;
  margin: 1.2rem 0; flex-wrap: wrap;
}

/* Schémas LaTeX (blocs ```latex) */
.latex-embed { margin: 1rem 0; text-align: center; }
.latex-embed img { max-width: 100%; height: auto; }

/* Boutons */
.btn-primary {
  padding: 0.55rem 1.1rem; background: #3a3d7c; color: white;
  border: none; border-radius: 7px; font-weight: 600;
  cursor: pointer; font-family: inherit; font-size: 0.92rem;
  text-decoration: none; display: inline-block;
}
.btn-primary:hover { background: #2e3170; }
.btn-ghost {
  padding: 0.45rem 0.85rem; background: white;
  border: 1.5px solid #c4c4d4; border-radius: 7px;
  cursor: pointer; font-family: inherit; font-size: 0.85rem;
  color: #2a2a4a; text-decoration: none; display: inline-block;
}
.btn-ghost:hover { background: #ebebff; border-color: #8888dd; }
.btn-danger {
  padding: 0.45rem 0.85rem; background: white;
  border: 1.5px solid #f0b4b4; border-radius: 7px;
  cursor: pointer; font-family: inherit; font-size: 0.85rem;
  color: #b71c1c; text-decoration: none;
}
.btn-danger:hover { background: #fff0f0; }

/* Marqueur {{page}} : saut de page à l'impression. Visible dans l'aperçu de
   l'éditeur, invisible pour les lecteurs (.lesson-card), effectif en print. */
.page-break {
  display: flex; align-items: center; gap: 0.6rem;
  margin: 1.2rem 0; color: #b0b0c4; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
.page-break::before, .page-break::after {
  content: ""; flex: 1; border-top: 1px dashed #c4c4d4;
}
.lesson-card .page-break { display: none; }

/* Impression (papier A4) */
@media print {
  @page { size: A4; margin: 15mm; }
  body { display: block; background: white; min-height: 0; }
  header, .breadcrumb, .lesson-pager, .btn-primary, .btn-ghost, .btn-danger,
  .embed-audio, .beats-btn, .beat-mark, .score-cursor,
  details.exfree, .exercise-slot, .exercise-widget, .video-embed,
  .oeuvre-audio {
    display: none !important;
  }
  main { max-width: none; padding: 0; }
  .card {
    border: none; border-radius: 0; box-shadow: none;
    padding: 0; margin: 0;
  }
  /* la carte n'a plus de padding à l'impression : pas de débordement */
  .lesson-card .score-embed .score-wrap { margin-left: 0; margin-right: 0; }
  .score-embed .score-wrap { border: none; padding: 0; }
  .score-embed, .latex-embed, .oeuvre-card,
  .lesson-content img, .lesson-content table,
  .lesson-content blockquote, .lesson-content pre { break-inside: avoid; }
  .lesson-content h1, .lesson-content h2, .lesson-content h3,
  .embed-caption { break-after: avoid; }
  .page-break, .lesson-card .page-break {
    display: block; height: 0; margin: 0;
    visibility: hidden; break-after: page;
  }
  .page-break::before, .page-break::after { content: none; }
  a { color: inherit; text-decoration: none; }
}

/* Formulaires */
input[type="text"], input[type="number"], input[type="url"], select, textarea {
  padding: 0.5rem 0.7rem; font-size: 0.95rem;
  border: 1.5px solid #ddd; border-radius: 7px;
  font-family: inherit; background: white;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #3a3d7c; }
label.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: #444; }
label.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: #333; }
