/* Rythmn — un tableau de classe de solfège : ardoise verte, craie, feuille de partition. */
@font-face {
  font-family: 'Nunito';
  src: url('/fonts/nunito.woff2') format('woff2');
  font-weight: 400 900;
  font-display: swap;
}
@font-face {
  font-family: 'Caveat';
  src: url('/fonts/caveat.woff2') format('woff2');
  font-weight: 600 700;
  font-display: swap;
}

:root {
  --board: #1d3a32;
  --board-deep: #132823;
  --board-lift: #27493f;
  --chalk: #f3f0e4;
  --chalk-dim: rgba(243, 240, 228, 0.66);
  --chalk-faint: rgba(243, 240, 228, 0.16);
  --yellow: #f6d55c;
  --ok: #9ad9a9;
  --early: #8ecae6;
  --late: #f2a65a;
  --miss: #ef6f6c;
  --paper: #fffdf6;
  --ink: #1b2a26;
  --radius: 14px;
  --font: 'Nunito', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
  /* Écriture à la craie : marque et grands titres seulement. */
  --script: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
  /* Panneaux posés sur l'ardoise : assez opaques pour que les portées du fond ne gênent pas la lecture. */
  --slate: rgba(19, 40, 35, 0.9);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  /* Ardoise : un peu plus claire en haut à gauche, comme sous l'éclairage de la classe. */
  background:
    radial-gradient(ellipse 90% 60% at 20% 0%, rgba(243, 240, 228, 0.07), transparent 70%),
    radial-gradient(ellipse 80% 60% at 90% 100%, rgba(0, 0, 0, 0.28), transparent 70%),
    var(--board);
  background-attachment: fixed;
  color: var(--chalk);
  font: 400 17px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
/* Portées tracées à la craie derrière toutes les pages. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: url('/staff.svg') -120px 40px / 960px 600px repeat;
  opacity: 0.11;
  transition: opacity 0.6s ease;
}
/* Pendant le morceau, le fond s'efface presque : seule compte la zone de frappe. */
body:has(#play:not([hidden]))::before,
body:has(#view-playing:not([hidden]))::before { opacity: 0.035; }

h1, h2, h3, p { margin: 0; }
h1 {
  font-family: var(--script);
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.05;
  text-shadow: 0 0 1px rgba(243, 240, 228, 0.35);
}
h2 { font-size: 1.15rem; font-weight: 750; }
[hidden] { display: none !important; }
.dim { color: var(--chalk-dim); }
.small { font-size: 0.88rem; }
.num { font-variant-numeric: tabular-nums; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

.btn {
  border: 2px solid var(--chalk-faint);
  background: transparent;
  border-radius: 999px;
  padding: 0.55rem 1.1rem;
  font-weight: 650;
}
.btn:hover { border-color: var(--chalk-dim); }
.btn.primary { background: var(--yellow); border-color: var(--yellow); color: var(--ink); font-weight: 800; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.big { padding: 0.85rem 1.5rem; font-size: 1.1rem; }
.btn.small { padding: 0.3rem 0.8rem; }
.btn.danger { border-color: var(--miss); color: var(--miss); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--chalk-dim); text-decoration: underline; }

.field { display: grid; gap: 0.3rem; }
.field > span { font-weight: 650; font-size: 0.92rem; }
input:not([type]), input[type='text'], input[type='password'], input[type='number'], select {
  background: var(--board-deep);
  border: 2px solid var(--chalk-faint);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  width: 100%;
}
input:focus, select:focus { border-color: var(--yellow); outline: none; }
input[type='range'] { accent-color: var(--yellow); width: 100%; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; }
.check input { margin-top: 0.3rem; accent-color: var(--yellow); width: 1.05rem; height: 1.05rem; flex: none; }

.error { color: var(--miss); font-weight: 650; min-height: 1.4em; }
.panel {
  background: var(--slate);
  border: 1px solid rgba(243, 240, 228, 0.07);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.6);
}

/* Marque : le nom écrit à la craie jaune, précédé d'une croche. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.15em;
  font-family: var(--script);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  color: var(--yellow);
}
.brand::before {
  content: '';
  width: 0.8em;
  height: 0.8em;
  background: url('/note.svg') center / contain no-repeat;
  transform: translateY(-0.04em) rotate(-8deg);
}
.paper { background: var(--paper); color: var(--ink); border-radius: var(--radius); }

/* ---------- Partition ---------- */
.score-view { position: relative; overflow: auto; background: var(--paper); border-radius: var(--radius); }
.score-view .score-inner { position: relative; min-height: 80px; }
.score-view .measure-mark {
  position: absolute;
  background: rgba(246, 213, 92, 0.42);
  border-radius: 6px;
  pointer-events: none;
  transition: left 90ms linear, top 90ms linear, width 90ms linear;
}
.score-view .tap-mark {
  position: absolute;
  min-width: 3px;
  border-radius: 3px;
  background: #d9480f;
  pointer-events: none;
}
/* Appui long : la durée tenue apparaît comme une barre. */
.score-view .tap-mark.long { background: rgba(217, 72, 15, 0.35); border-left: 3px solid #d9480f; }
.score-view .tap-mark.done { animation: tap-fade 1.8s ease-out forwards; }
@keyframes tap-fade { 0%, 35% { opacity: 1; } 100% { opacity: 0; } }
.score-view .score-empty { color: #6b7772; padding: 1.5rem; text-align: center; }

/* ---------- Pulsation ---------- */
.transport { display: flex; align-items: center; gap: 0.9rem; }
.pulse {
  width: 1.1rem; height: 1.1rem; border-radius: 50%; flex: none;
  background: var(--chalk-faint);
}
.pulse.on { background: var(--chalk); }
.pulse.on.accent { background: var(--yellow); transform: scale(1.35); }
.progress { height: 6px; background: var(--chalk-faint); border-radius: 3px; overflow: hidden; flex: 1; }
.progress > i { display: block; height: 100%; width: 0; background: var(--yellow); }

/* ---------- Résultats ---------- */
.note-big { font-size: 4.2rem; font-weight: 850; line-height: 1; letter-spacing: -0.03em; }
.note-big small { font-size: 1.5rem; font-weight: 650; color: var(--chalk-dim); letter-spacing: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; }
.chip { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 650; }
.dot { width: 0.85rem; height: 0.85rem; border-radius: 50%; display: inline-block; flex: none; }
.dot.parfait { background: var(--ok); }
.dot.avance { background: var(--early); }
.dot.retard { background: var(--late); }
.dot.manque { background: transparent; border: 2px solid var(--miss); }
.dot.held, .dot.tenue { width: 1.7rem; border-radius: 0.45rem; }
.dot.tenue { background: var(--ok); }
/* Note longue mal tenue : la fin de la pastille est rouge. */
.dot.held-bad { background-image: linear-gradient(90deg, transparent 50%, var(--miss) 50%); }
.dot.trop { background: var(--miss); border-radius: 2px; transform: rotate(45deg) scale(0.8); }

.measures { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.measure-box {
  border: 1.5px solid var(--chalk-faint);
  border-radius: 9px;
  padding: 0.3rem 0.5rem 0.45rem;
  min-width: 3.4rem;
}
.measure-box.clean { border-color: rgba(154, 217, 169, 0.45); }
.measure-box b { display: block; font-size: 0.72rem; font-weight: 650; color: var(--chalk-dim); margin-bottom: 0.25rem; }
.measure-box .dots { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.board li {
  display: grid;
  grid-template-columns: 2.2rem minmax(5rem, 1fr) minmax(3rem, 2fr) 3.4rem;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: var(--board-lift);
}
.board li.me { outline: 2px solid var(--yellow); }
.board li.pick { cursor: pointer; }
.board li.pick:hover, .board li.selected { background: #315a4e; }
.board .rank { font-weight: 850; font-size: 1.15rem; }
.board li:first-child .rank { color: var(--yellow); }
.board .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .bar { height: 8px; border-radius: 4px; background: var(--chalk-faint); overflow: hidden; }
.board .bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.board .score { text-align: right; font-weight: 800; }

/* ---------- Élève ---------- */
.student { min-height: 100dvh; display: flex; flex-direction: column; }
.student .screen { flex: 1; display: flex; flex-direction: column; gap: 1.1rem; padding: 1.25rem; max-width: 34rem; width: 100%; margin: 0 auto; }
.student form { display: grid; gap: 1rem; margin-top: 0.5rem; }
/* Accueil élève : centré verticalement sur le téléphone, le formulaire posé sur l'ardoise. */
.student #join { justify-content: center; padding-bottom: 12vh; }
.student #join h1 { font-size: 2.9rem; }
.student #join form { background: var(--slate); border: 1px solid rgba(243, 240, 228, 0.07); border-radius: 20px; padding: 1.25rem; }
#code {
  text-transform: uppercase;
  letter-spacing: 0.4em;
  padding-left: 1.1rem;
  font-weight: 850;
  font-size: 1.9rem;
  text-align: center;
  color: var(--yellow);
}
#code::placeholder { color: rgba(246, 213, 92, 0.25); }

/* Hauteur fixe (flex: none) : sinon la partition s'étale de tout son long et pousse le pavé hors de l'écran. */
.student .screen.play { max-width: none; padding: 0.8rem; gap: 0.7rem; height: 100dvh; flex: none; min-height: 0; }
.play-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.play-head .title { font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play .score-view { flex: 0 1 38%; min-height: 110px; }
.pad {
  flex: 1;
  min-height: 12rem;
  border-radius: 28px;
  border: 3px dashed var(--chalk-faint);
  background: var(--slate);
  transition: background-color 60ms ease-out;
  display: grid;
  place-items: center;
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--chalk-dim);
  padding: 1rem;
}
.pad.live { border-style: solid; border-color: var(--yellow); color: var(--chalk); }
.pad.down { background: rgba(246, 213, 92, 0.28); color: var(--chalk); }
.pad.hit { background: var(--yellow); color: var(--ink); }
.pad small { font-size: 0.95rem; font-weight: 600; }
.pad .count { font-size: 6rem; line-height: 1; font-weight: 850; color: var(--yellow); }
.pad.small { min-height: 9rem; flex: none; font-size: 1.1rem; }

/* ---------- Professeur ---------- */
.prof { max-width: 78rem; margin: 0 auto; padding: 1.25rem; display: grid; gap: 1.1rem; }
.prof header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.prof header .brand { font-size: 2.4rem; }
.login {
  max-width: 25rem;
  margin: 10vh auto 2rem;
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--slate);
  border: 1px solid rgba(243, 240, 228, 0.07);
  border-radius: 20px;
  box-shadow: 0 20px 50px -25px rgba(0, 0, 0, 0.7);
}
@media (max-width: 30rem) { .login { margin: 4vh 16px 2rem; } }
.tabs { display: flex; gap: 0.3rem; background: rgba(0, 0, 0, 0.22); border-radius: 12px; padding: 0.25rem; }
.tabs .tab { flex: 1; background: none; border: 0; border-radius: 9px; padding: 0.55rem; color: var(--chalk-dim); font: inherit; font-weight: 700; cursor: pointer; }
.tabs .tab.active { background: var(--board-lift); color: var(--chalk); }
.tabs .tab[hidden] { display: none; }
.setup { display: grid; grid-template-columns: minmax(15rem, 19rem) minmax(0, 1fr) minmax(14rem, 18rem); gap: 1.1rem; align-items: start; }
@media (max-width: 62rem) { .setup { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 0.9rem; }
.row { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }

.songs { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.songs li { display: flex; align-items: center; gap: 0.4rem; border-radius: 10px; }
.songs li button.pick { flex: 1; text-align: left; background: none; border: 2px solid transparent; border-radius: 10px; padding: 0.5rem 0.65rem; font-weight: 650; }
.songs li button.pick small { display: block; font-weight: 500; font-size: 0.8rem; margin-top: 0.1rem; }
.songs li button.pick:hover { background: var(--board-lift); }
.songs li.selected button.pick { border-color: var(--yellow); background: var(--board-lift); }
.songs button.tool { background: none; border: 0; color: var(--chalk-dim); padding: 0.4rem 0.5rem; border-radius: 8px; }
.songs button.tool:hover { color: var(--chalk); }
.songs button.tool.del:hover { color: var(--miss); }
.songs select.move { max-width: 9rem; background: var(--board-lift); border: 1px solid var(--chalk-faint); border-radius: 8px; padding: 0.3rem; }
.songs li.folder { display: block; }
.songs li.label { padding: 0.5rem 0.65rem 0; }
.songs summary { display: flex; align-items: center; gap: 0.4rem; padding: 0.45rem 0 0.45rem 0.65rem; border-radius: 10px; cursor: pointer; font-weight: 750; list-style: none; }
.songs summary::-webkit-details-marker { display: none; }
.songs summary::before { content: '▸'; color: var(--chalk-dim); width: 0.9rem; }
.songs details[open] > summary::before { content: '▾'; }
.songs summary:hover { background: var(--board-lift); }
.songs summary .name { flex: 1; }
.songs details > .songs, .songs details > .empty { margin: 0.2rem 0 0.4rem 0.9rem; padding-left: 0.5rem; border-left: 2px solid var(--chalk-faint); }
.songs details > .empty { padding: 0.3rem 0.65rem; }
.drop { border: 2px dashed var(--chalk-faint); border-radius: 12px; padding: 0.9rem; text-align: center; }
.drop.over { border-color: var(--yellow); background: var(--board-lift); }

.join { display: grid; gap: 0.6rem; }
.join .qr { width: 9rem; height: 9rem; background: #fff; border-radius: 10px; padding: 4px; }
.join .qr svg, .join .qr img { width: 100%; height: 100%; display: block; }
.room-code { font-size: 3rem; font-weight: 900; letter-spacing: 0.14em; line-height: 1.1; color: var(--yellow); text-shadow: 0 0 1px rgba(246, 213, 92, 0.5); }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.players li { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.6rem; border-radius: 9px; background: var(--board-lift); font-weight: 650; }
.players li.off { opacity: 0.5; }
.players li .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players li.tapped { background: #3c6a5c; }
.players li button { background: none; border: 0; color: var(--chalk-dim); padding: 0 0.3rem; }
.players li button:hover { color: var(--miss); }

.stage { display: grid; grid-template-columns: minmax(0, 1fr) minmax(14rem, 18rem); gap: 1.1rem; align-items: start; }
@media (max-width: 62rem) { .stage { grid-template-columns: 1fr; } }
.stage .score-view { max-height: 62vh; }
.now { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.now .where { font-size: 2.4rem; font-weight: 850; line-height: 1.1; }
.now .where.count { color: var(--yellow); }

.results-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.1rem; align-items: start; }
@media (max-width: 62rem) { .results-grid { grid-template-columns: 1fr; } }

/* Mention discrète, en bas de page. */
.credit { font-family: var(--script); font-size: 1.05rem; color: var(--chalk-dim); opacity: 0.6; text-align: center; }
.student .credit { margin-top: auto; }

/* Liens vers les autres projets de l'auteur, sous la mention. */
.autres-projets { font-size: 0.82rem; color: var(--chalk-dim); text-align: center; opacity: 0.85; }
.autres-projets h2 { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.35rem; }
.autres-projets ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.autres-projets a { color: var(--chalk); font-weight: 700; text-decoration-color: var(--chalk-faint); text-underline-offset: 2px; }
.autres-projets a:hover { color: var(--yellow); text-decoration-color: currentColor; }
.login .autres-projets { border-top: 1px solid var(--chalk-faint); padding-top: 0.9rem; }

/* Bouton du son des frappes, pendant le morceau. */
.play-head .title { flex: 1; }
.mute {
  flex: none;
  border: 1.5px solid var(--chalk-faint);
  background: transparent;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--chalk-dim);
}
.mute.off { border-color: var(--late); color: var(--late); }
.pad .count + br + small { display: block; margin-top: 0.6rem; }

/* ---------- Plein écran (professeur) : la partition pour toute la classe ---------- */
body.big .prof { max-width: none; height: 100dvh; padding: 0.6rem 0.8rem; gap: 0.6rem; grid-template-rows: minmax(0, 1fr); }
body.big .prof > header,
body.big .prof > .credit,
body.big .setup > .panel,
body.big #settings > .field,
body.big #settings > .row,
body.big #settings > .check,
body.big #settings > #preview,
body.big .stage > .panel { display: none; }
body.big #settings { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem 1rem; padding: 0.6rem 0.9rem; }
body.big #settings .error:empty { display: none; }
.big-only { display: none; }
body.big .big-only { display: inline-block; }
body.big #view-results { overflow: auto; align-content: start; }
body.big .setup,
body.big .stage { grid-template-columns: minmax(0, 1fr); min-height: 0; height: 100%; }
body.big .setup > .stack,
body.big .stage > .stack { grid-template-rows: auto; grid-auto-rows: auto; min-height: 0; height: 100%; align-content: stretch; }
body.big .setup > .stack { grid-template-rows: auto auto minmax(0, 1fr); gap: 0.5rem; }
body.big .stage > .stack { grid-template-rows: auto auto minmax(0, 1fr); gap: 0.5rem; }
body.big .score-view { max-height: none; height: 100%; }
body.big .now .where { font-size: 3.2rem; }

/* ---------- Classement en gros sur l'écran du professeur ---------- */
.prof .results-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 62rem) { .prof .results-grid { grid-template-columns: 1fr; } }
.prof #leaderboard .board { font-size: clamp(1.3rem, 2.4vw, 2.1rem); gap: 0.3em; }
.prof #leaderboard .board.many { font-size: clamp(1.05rem, 1.6vw, 1.45rem); }
.prof #leaderboard .board li {
  grid-template-columns: 2.8em minmax(4em, 1fr) minmax(3em, 1.4fr) 3.6em;
  gap: 0.5em;
  padding: 0.4em 0.7em;
  border-radius: 0.5em;
}
.prof #leaderboard .board .bar { height: 0.4em; border-radius: 0.2em; }
/* Le podium ressort par la taille du texte ; les colonnes restent alignées d'une ligne à l'autre. */
.prof #leaderboard .board li:first-child { background: #315a4e; outline: 2px solid var(--yellow); padding-block: 0.55em; }
.prof #leaderboard .board li:first-child > :not(.bar) { font-size: 1.3em; }
.prof #leaderboard .board li:first-child .score { color: var(--yellow); }
.prof #leaderboard .board li:nth-child(2) > :not(.bar), .prof #leaderboard .board li:nth-child(3) > :not(.bar) { font-size: 1.12em; }
/* Sans détail ouvert, le classement seul, centré. */
.prof .results-grid.solo { grid-template-columns: minmax(0, 1fr); }
.prof .results-grid.solo #leaderboard .board { max-width: 60rem; margin: 0 auto; }
/* En plein écran, le classement encore plus gros, pour toute la classe. */
body.big .results-grid.solo #leaderboard .board { font-size: clamp(1.6rem, 3.4vw, 3rem); max-width: 70rem; }
body.big .results-grid.solo #leaderboard .board.many { font-size: clamp(1.2rem, 2.2vw, 2rem); }

@media (prefers-reduced-motion: reduce) {
  *, *::before { transition: none !important; }
}

/* Fenêtre de transcription d'un enregistrement */
dialog.sheet {
  width: min(52rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 1.5rem); overflow: auto;
  background: var(--slate); color: var(--chalk); border: 1px solid var(--chalk-faint); border-radius: var(--radius);
  padding: 1.2rem;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.sheet audio { width: 100%; }
dialog.sheet .score-view { max-height: 45vh; min-height: 120px; }
dialog.sheet .score-view { overflow-x: hidden; }
.row.nowrap { flex-wrap: nowrap; }

/* Téléphone : marges resserrées, en-tête compact */
@media (max-width: 40rem) {
  .prof { padding: 0.8rem; gap: 0.9rem; }
  .prof header { gap: 0.5rem; }
  .prof header .brand { font-size: 2rem; }
  .prof header .row { gap: 0.4rem; }
  .prof header .btn { padding: 0.4rem 0.8rem; font-size: 0.92rem; }
  .panel { padding: 0.9rem; }
  dialog.sheet { width: calc(100vw - 1rem); max-height: calc(100dvh - 1rem); padding: 0.9rem; }
}
#upload-error:empty { display: none; }
