/* Music Line Rider — thème sombre "studio". UI en français. */

:root {
  --bg: #0a0b10;
  --panel: rgba(20, 23, 32, 0.92);
  --panel-solid: #14171f;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8eaf2;
  --text-dim: #9aa2b4;
  --accent: #4f8cff;
  --accent-glow: rgba(79, 140, 255, 0.5);
  --danger: #ff5a5f;
  --ok: #35d6a4;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Stage ─────────────────────────────────────────────── */
#stage { position: fixed; inset: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* Curseur masqué après quelques secondes d'inactivité pendant la lecture */
body.cursor-hidden,
body.cursor-hidden * { cursor: none !important; }

/* ── Écran de démarrage ────────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 0%, #161a26 0%, #070810 70%);
}
.splash-card {
  max-width: 460px; padding: 34px 30px; text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.splash-card h1 {
  margin: 0 0 14px; font-size: 30px; letter-spacing: 2px; font-weight: 800;
}
.splash-card h1 span { color: var(--accent); }
.splash-card h1 span:last-of-type { color: var(--text); }
.splash-sub { color: var(--text-dim); font-size: 14px; line-height: 1.55; margin: 0 0 18px; }
.splash-steps { text-align: left; padding-left: 0; list-style: none; margin: 0 0 22px; }
.splash-steps li { font-size: 13px; color: var(--text-dim); line-height: 1.5; margin-bottom: 8px; }
.splash-steps b { color: var(--accent); }
#btn-start {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 13px 34px; font-size: 15px; font-weight: 700; letter-spacing: 1px;
  box-shadow: 0 0 24px var(--accent-glow);
}
#btn-start:hover { filter: brightness(1.1); }
.splash-note { color: var(--text-dim); font-size: 11px; margin: 12px 0 0; }

/* ── Barre d'outils ────────────────────────────────────── */
#toolbar {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px; backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.tool {
  width: 40px; height: 40px; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 9px; color: var(--text-dim);
}
.tool svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.tool.active { background: var(--accent); color: #fff; box-shadow: 0 0 16px var(--accent-glow); }
.tool.on { color: var(--accent); }
.tool.danger:hover { background: rgba(255, 90, 95, 0.15); color: var(--danger); }
.tool:disabled { opacity: 0.3; cursor: default; }
.tb-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* ── Barre de note ─────────────────────────────────────── */
#note-bar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px; backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); max-width: calc(100vw - 40px);
}
/* .nb-head : transparent en layout desktop (display:contents), devient la
   poignée de la feuille sur téléphone. */
.nb-head { display: contents; }
#nb-toggle {
  display: none; width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: rgba(255, 255, 255, 0.06); color: var(--text-dim);
  place-items: center;
}
#nb-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round; transition: transform 0.2s ease; }
body.note-open #nb-toggle svg { transform: rotate(180deg); }

.nb-context { display: flex; flex-direction: column; gap: 2px; min-width: 96px; }
#nb-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
#nb-current { font-size: 17px; font-weight: 700; }
#nb-deselect, #nb-delete {
  align-self: flex-start; margin-top: 2px;
  background: rgba(255, 255, 255, 0.06); border: 0; color: var(--text-dim);
  border-radius: 6px; font-size: 11px; padding: 2px 7px; line-height: 1.4;
}
#nb-deselect:hover, #nb-delete:hover { background: rgba(255, 255, 255, 0.14); color: var(--text); }

/* clavier */
.keyboard { display: flex; gap: 3px; }
.key {
  width: 26px; height: 44px; border: 1px solid var(--border); border-radius: 0 0 5px 5px;
  background: #e9ecf5; color: #1b1e28; font-size: 10px; font-weight: 700;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px;
}
.key.sharp { background: #23262f; color: #cdd3e0; height: 36px; width: 22px; }
.key:hover { filter: brightness(1.08); }
.key.active { background: var(--accent); color: #fff; box-shadow: 0 0 14px var(--accent-glow); }
.key.sharp.active { background: var(--accent); }

.nb-octave { display: flex; align-items: center; gap: 4px; }
.nb-octave button {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05); color: var(--text); font-size: 15px; line-height: 1;
}
.nb-octave button:hover { background: rgba(255, 255, 255, 0.12); }
#oct-val { min-width: 14px; text-align: center; font-weight: 700; }
#vel-val { min-width: 32px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.nb-cap { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-right: 1px; }

#nb-preview {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.04);
  color: var(--text); border-radius: 7px; padding: 6px 10px; font-size: 11px; white-space: nowrap;
}
#nb-preview:hover { background: rgba(255, 255, 255, 0.12); }

/* ── Panneau effets ────────────────────────────────────── */
#panel {
  position: absolute; right: 12px; top: 14px;
  display: flex; align-items: flex-start; gap: 8px;
}
#panel-toggle {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#panel-toggle:hover { background: rgba(255, 255, 255, 0.12); }
#panel-toggle svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
#panel.collapsed #panel-toggle { color: var(--text-dim); }
#panel-body {
  width: 256px; padding: 14px 15px 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#panel.collapsed #panel-body { display: none; }
#panel h2 { margin: 0 0 10px; font-size: 13px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--text-dim); }
#panel h2.panel-h2b { margin: 18px 0 10px; padding-top: 12px; border-top: 1px solid var(--border); }
#panel h3 { margin: 14px 0 6px; font-size: 12px; color: var(--accent); }
#panel select {
  background: rgba(255, 255, 255, 0.06); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px; font-size: 11px; font-family: inherit; width: 100%;
}
.grid-hint { font-size: 10px; color: var(--text-dim); line-height: 1.5; margin: 8px 0 0; }
label.fx { display: grid; grid-template-columns: 52px 1fr 46px; align-items: center; gap: 7px; margin: 7px 0; }
label.fx span { font-size: 11px; color: var(--text-dim); }
label.fx em { font-size: 10px; color: var(--text-dim); text-align: right; font-style: normal; white-space: nowrap; }
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.12); outline: none;
  width: 100%; min-width: 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent-glow); cursor: pointer;
}
input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--accent); cursor: pointer;
}
.panel-foot { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
#save-status { font-size: 11px; color: var(--ok); }
.panel-foot .hint { display: block; margin-top: 6px; font-size: 10px; color: var(--text-dim); line-height: 1.5; }
.panel-foot .hint.touch-only { display: none; }
body.touch .panel-foot .hint:not(.touch-only) { display: none; }
body.touch .panel-foot .hint.touch-only { display: block; }

/* ── Transport ─────────────────────────────────────────── */
#transport {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 16px; backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); width: min(640px, calc(100vw - 40px));
}
.tp-row { display: flex; align-items: center; gap: 10px; }
.tp-buttons { justify-content: center; gap: 5px; }
#transport button {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05); color: var(--text);
  display: grid; place-items: center; flex: none;
}
#transport button:hover { background: rgba(255, 255, 255, 0.12); }
#transport button svg {
  width: 16px; height: 16px; display: block; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
#transport button svg .f, #transport button svg rect.f { fill: currentColor; stroke: none; }
#btn-fullscreen .fs-out { display: none; }
#btn-fullscreen.active .fs-in { display: none; }
#btn-fullscreen.active .fs-out { display: inline; }
#btn-play { width: 38px; height: 38px; }
#btn-play svg { width: 18px; height: 18px; }
#btn-play.playing { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 0 16px var(--accent-glow); }
#btn-follow.active, #btn-slowmo.active, #btn-onion.active, #btn-simflag.active {
  background: var(--accent); color: #fff; border-color: transparent;
}
.tp-sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; flex: none; }
/* #tp-more : transparent sur desktop, popover sur téléphone (voir @media). */
#tp-more { display: contents; }
#transport #btn-more { display: none; }   /* > #transport button */
#time, #time-total { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
#time { min-width: 52px; }
#time-total { min-width: 52px; text-align: right; }
#timeline-wrap { position: relative; flex: 1; display: flex; align-items: center; }
#timeline { width: 100%; }
#tl-flag {
  position: absolute; top: -1px; transform: translateX(-50%);
  width: 0; height: 0; pointer-events: none;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 7px solid var(--accent);
  filter: drop-shadow(0 0 4px var(--accent-glow));
}

/* ── Bouton "œil" (masquer les contrôles) — tactile ────── */
#btn-zen-touch {
  display: none;
  position: absolute; right: 12px; bottom: 20px; z-index: 16;
  width: 38px; height: 38px; border-radius: 10px; place-items: center;
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  backdrop-filter: blur(10px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
#btn-zen-touch svg { width: 19px; height: 19px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
body.touch #btn-zen-touch { display: grid; }
body.zen #btn-zen-touch { color: var(--accent); }

/* ── Fond des feuilles coulissantes (téléphone) ────────── */
#sheet-backdrop {
  display: none; position: fixed; inset: 0; z-index: 24;
  background: rgba(4, 5, 9, 0.5); backdrop-filter: blur(1px);
}

/* ── Toast générique (gestes, orientation) ─────────────── */
#toast {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 32px)); text-align: center;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); font-size: 12.5px; line-height: 1.5; padding: 10px 16px;
  border-radius: 14px; backdrop-filter: blur(10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 30;
}
#toast.show { opacity: 1; }

/* glisser-déposer d'un fichier de projet */
body.drag-over::after {
  content: 'Déposer le projet .json ici';
  position: fixed; inset: 12px; z-index: 999;
  display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 16px;
  background: rgba(10, 14, 26, 0.55);
  color: var(--text); font-weight: 700; font-size: 15px; letter-spacing: 0.02em;
  pointer-events: none;
}

/* ── Mode zen (Tab / œil) : plus que le canevas + l'animation ── */
#toolbar, #note-bar, #panel, #transport, #btn-zen-touch {
  transition: opacity 0.25s ease, transform 0.25s ease;
}
body.zen #toolbar   { opacity: 0; pointer-events: none; transform: translate(-16px, -50%); }
body.zen #note-bar  { opacity: 0; pointer-events: none; transform: translate(-50%, -16px); }
body.zen #panel     { opacity: 0; pointer-events: none; transform: translateX(16px); }
body.zen #transport { opacity: 0; pointer-events: none; transform: translate(-50%, 16px); }

#zen-hint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text-dim); font-size: 12px; padding: 7px 14px; border-radius: 999px;
  backdrop-filter: blur(10px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 20;
  max-width: calc(100vw - 32px); text-align: center;
}
#zen-hint.show { opacity: 1; }

/* ══ Cibles agrandies dès qu'on pointe au doigt ══════════ */
@media (pointer: coarse) {
  .tool { width: 46px; height: 46px; }
  .tool svg { width: 23px; height: 23px; }
  #panel-toggle, #btn-zen-touch { width: 44px; height: 44px; }
  #transport button { width: 44px; height: 44px; }
  #btn-play { width: 52px; height: 52px; }
  .key { width: 30px; height: 54px; font-size: 11px; }
  .key.sharp { width: 26px; height: 44px; }
  .nb-octave button { width: 34px; height: 34px; font-size: 17px; }
  #nb-toggle { width: 40px; height: 40px; }
  #nb-preview { padding: 9px 13px; font-size: 12px; }
  #nb-deselect, #nb-delete { padding: 5px 10px; font-size: 12px; }
}

/* ══ Tablette : disposition desktop, quelques ajustements ══ */
@media (max-width: 900px) {
  #panel-body { width: min(260px, calc(100vw - 40px)); }
  /* note-bar : occupe la largeur entre le bord et la colonne engrenage,
     le clavier défile horizontalement pour absorber le manque de place. */
  #note-bar {
    left: 10px; right: 58px; transform: none; max-width: none;
    gap: 9px; padding: 7px 10px;
  }
  #note-bar #keyboard {
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    flex: 1 1 auto; min-width: 40px;
  }
  #note-bar #keyboard::-webkit-scrollbar { display: none; }
  .key { flex: none; }
}

/* ══ Téléphone (portrait étroit OU paysage court) : interface
      repensée en bandeaux + feuilles coulissantes ══ */
@media (max-width: 600px), (max-height: 520px) and (pointer: coarse) {
  /* Barre d'outils : bandeau horizontal défilable en haut.
     right: 58px pour laisser la colonne engrenage + œil libre. */
  #toolbar {
    left: 8px; right: 58px; top: 8px; transform: none;
    flex-direction: row; gap: 3px; padding: 5px;
    max-width: none; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; border-radius: 12px;
  }
  #toolbar::-webkit-scrollbar { display: none; }
  .tb-sep { width: 1px; height: 26px; margin: 0 3px; align-self: center; flex: none; }

  /* Bouton œil : sous l'engrenage (le transport occupe le bas) */
  #btn-zen-touch { top: 60px; bottom: auto; }

  /* Note-bar : pastille repliée en haut, feuille dépliée en bas */
  #note-bar {
    top: 74px; left: 50%; right: auto; transform: translateX(-50%);
    flex-direction: column; align-items: stretch; gap: 10px;
    max-width: calc(100vw - 16px); padding: 8px 10px;
  }
  .nb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  #nb-toggle { display: grid; }
  .nb-context { flex-direction: row; align-items: baseline; gap: 8px; min-width: 0; }
  /* replié : on ne montre que la poignée */
  body:not(.note-open) #note-bar > :not(.nb-head) { display: none; }

  body.note-open #note-bar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; transform: none;
    max-width: none; width: 100%; z-index: 25;
    border-radius: 16px 16px 0 0; padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
    max-height: 62dvh; overflow-y: auto;
  }
  body.note-open #keyboard {
    overflow-x: auto; scrollbar-width: none; padding-bottom: 4px;
    justify-content: flex-start;
  }
  body.note-open #keyboard::-webkit-scrollbar { display: none; }
  body.note-open .nb-octave { justify-content: center; }
  body.note-open #nb-preview { width: 100%; text-align: center; }

  /* Panneau réglages : engrenage en place, corps en feuille basse */
  #panel { right: 12px; top: 14px; }
  #panel:not(.collapsed) #panel-body {
    position: fixed; inset: auto 0 0 0; width: 100%; z-index: 25;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(14px + env(safe-area-inset-bottom));
    max-height: 74dvh; overflow-y: auto;
  }

  /* Fond sombre quand une feuille est ouverte */
  body.note-open #sheet-backdrop,
  body.panel-open #sheet-backdrop { display: block; }

  /* Transport : barre pleine largeur en bas */
  #transport {
    left: 0; right: 0; bottom: 0; transform: none; width: 100%;
    border-radius: 14px 14px 0 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    gap: 6px;
  }
  .tp-row { gap: 7px; }
  .tp-buttons { justify-content: space-between; gap: 3px; }
  #time-total { display: none; }
  #time { min-width: 44px; font-size: 11px; }
  .tp-buttons > .tp-sep { display: none; }
  #transport #btn-more { display: grid; }
  #tp-more {
    display: none;
    position: absolute; bottom: calc(100% + 8px); right: 8px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
    padding: 8px; gap: 6px; flex-wrap: wrap; width: min(232px, calc(100vw - 24px));
    justify-content: center; backdrop-filter: blur(10px);
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5); z-index: 26;
  }
  body.tp-more-open #tp-more { display: flex; }
  #tp-more .tp-sep { display: none; }

  /* Splash compact */
  .splash-card { padding: 26px 20px; }
  .splash-card h1 { font-size: 24px; }
  .splash-steps li { font-size: 12.5px; }

  /* Zen sur téléphone : on pousse les barres hors écran proprement */
  body.zen #toolbar   { transform: translateY(-130%); }
  body.zen #note-bar  { transform: translate(-50%, -130%); }
  body.zen #transport { transform: translateY(130%); }
  body.zen #panel     { transform: translateX(130%); }
}

/* La puce tactile du splash n'apparaît que sur écran tactile */
.splash-touch { display: none; }
body.touch .splash-touch { display: list-item; }
