* { box-sizing: border-box; }

:root {
  --bg: #12141a;
  --card: #1c1f28;
  --border: #2c3040;
  --text: #e8eaf0;
  --muted: #8a90a4;
  --accent: #ff5e3a;
  --accent2: #3ad1ff;
  --crop: #ffd23a;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }

header { text-align: center; padding: 14px 12px 2px; }
header h1 { margin: 0; font-size: 22px; letter-spacing: 2px; }
header h1 span { color: var(--accent); }
header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

main { max-width: 1100px; margin: 0 auto; padding: 10px 10px 70px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 12px; font-size: 15px; color: var(--accent2); }

/* ---- encart repliable ---- */
.card-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.card-toggle .chev { font-size: 11px; color: var(--muted); transition: transform .15s; }
.card.collapsed { padding-top: 10px; padding-bottom: 10px; margin-bottom: 8px; }
.card.collapsed .card-toggle { margin-bottom: 0; }
.card.collapsed .card-toggle .chev { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }
.card-summary {
  display: none; margin-left: auto; min-width: 0;
  font-size: 13px; font-weight: 400; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card.collapsed .card-summary { display: block; }

.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, monospace; }
.hint { color: var(--muted); font-size: 12px; }
.error { color: #ff6b6b; white-space: pre-wrap; }

/* ---- boutons : gros tap targets ---- */
button {
  background: var(--border); color: var(--text); border: none;
  border-radius: 8px; padding: 10px 14px; cursor: pointer; font-size: 14px;
  min-height: 42px; touch-action: manipulation;
}
button:hover { background: #3a3f55; }
button.big { font-size: 17px; padding: 12px 20px; }
#playBtn { min-width: 64px; font-size: 20px; }
button.primary { background: var(--accent); font-weight: 600; }
button.primary:hover { background: #ff7657; }
button:disabled { opacity: .5; cursor: default; }
button.active { background: var(--accent2); color: #04222e; }
button.active:hover { background: #6cdcff; }

/* ---- sources ---- */
.sources-row { display: flex; flex-direction: column; gap: 16px; }
.source { width: 100%; }
.dropzone {
  display: flex; align-items: center; justify-content: center;
  min-height: 96px; padding: 14px; text-align: center;
  border: 2px dashed var(--border); border-radius: 10px;
  cursor: pointer; color: var(--muted); transition: border-color .15s, color .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); color: var(--text); }
.dropzone.loaded { border-style: solid; border-color: var(--accent2); color: var(--text); }
.source label { display: block; margin-bottom: 6px; font-size: 14px; }
select {
  width: 100%; padding: 12px; border-radius: 8px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  font-size: 16px; /* 16px : évite le zoom auto d'iOS au focus */
}

.track-upload {
  display: inline-block; margin-top: 10px; padding: 6px 2px;
  font-size: 14px; color: var(--accent2);
  cursor: pointer; text-decoration: underline dotted;
}
.track-upload:hover { color: #6cdcff; }

/* ---- barres de progression ---- */
.upload-progress { margin-top: 10px; display: flex; align-items: center; gap: 10px; }
.bar { flex: 1; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---- bloc vidéo sticky : reste visible pendant qu'on règle en dessous ---- */
/* Les vidéos sont verticales dans ~90 % des cas : la vidéo tient sa propre
   colonne (sticky) et les réglages vivent à côté / en dessous. */
.video-sticky {
  position: sticky; top: 0; z-index: 30;
  background: var(--card);
  padding: 4px 0 8px; margin: -4px 0 8px;
}
.video-wrap { text-align: center; margin-bottom: 8px; }
.video-frame { position: relative; display: inline-block; border-radius: 8px; overflow: hidden; max-width: 100%; }
video { display: block; max-width: 100%; max-height: 38vh; background: #000; object-fit: contain; }

/* plein écran natif */
.video-frame:fullscreen video { max-height: 100vh; width: 100vw; height: 100vh; object-fit: contain; }
.video-frame:fullscreen #fsControls { display: flex; }
.video-frame:fullscreen #fullscreenBtn, .video-frame:fullscreen #theaterBtn { bottom: 64px; }

/* faux plein écran (iPhone : pas de requestFullscreen) */
.video-frame.fake-fs {
  position: fixed; inset: 0; z-index: 1000; border-radius: 0;
  background: #000; display: flex; align-items: center; justify-content: center;
  max-width: none;
}
.video-frame.fake-fs video { max-width: 100%; width: 100%; height: 100%; max-height: none; object-fit: contain; }
.video-frame.fake-fs #fsControls { display: flex; }
.video-frame.fake-fs #fullscreenBtn, .video-frame.fake-fs #theaterBtn { bottom: 72px; }

#tintOverlay { position: absolute; inset: 0; pointer-events: none; }

#fullscreenBtn, #theaterBtn {
  position: absolute; bottom: 8px; z-index: 2;
  background: rgba(0,0,0,.55); font-size: 18px; line-height: 1; padding: 10px 12px;
  min-height: 44px;
}
#fullscreenBtn { right: 8px; }
#theaterBtn { right: 60px; }
#fullscreenBtn:hover, #theaterBtn:hover { background: rgba(0,0,0,.8); }

/* mode agrandi (pleine largeur, pas plein écran) */
#editor.theater .video-frame { display: block; width: 100%; }
#editor.theater video { width: 100%; max-height: 55vh; }

/* contrôles en plein écran */
#fsControls {
  display: none; position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  align-items: center; gap: 12px; padding: 14px 14px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.85));
}
#fsControls .fs-mix { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 420px; font-size: 13px; color: var(--muted); }

/* ---- mini-mixer collé à la vidéo ---- */
.mini-mixer {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  max-width: 720px; margin: 0 auto; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font-size: 12px; color: var(--muted);
}
.mini-mixer input[type=range] { flex: 1; min-width: 80px; }
.mini-mixer .mm-val { color: var(--text); min-width: 52px; text-align: center; }
.mini-mixer .mm-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

/* ---- transport & sync ---- */
.transport {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.transport .spacer { flex: 1; }
.nudges { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.nudges button {
  min-height: 40px; min-width: 44px; padding: 8px 6px;
  font-size: 11px; letter-spacing: -1px; line-height: 1;
}
#offsetInput {
  width: 92px; padding: 8px 6px; text-align: center;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; font-size: 16px;
}
#offsetInput:focus { border-color: var(--accent); outline: none; }

/* ---- waveform ---- */
.wave-help {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; margin: 6px 0;
}
.zoom-btns { margin-left: auto; display: flex; gap: 6px; }
.zoom-btns button { min-height: 38px; min-width: 44px; padding: 6px 10px; font-weight: 700; font-size: 16px; }

#waveWrap { position: relative; user-select: none; }
#waveCanvas {
  width: 100%; height: 200px; display: block;
  background: #0d0f14; border: 1px solid var(--border); border-radius: 8px;
  touch-action: none; cursor: grab;
}

/* ---- scrollbar / minimap de la waveform ---- */
#waveScroll {
  position: relative; height: 16px; margin-top: 6px;
  background: #0d0f14; border: 1px solid var(--border); border-radius: 8px;
  touch-action: none; cursor: pointer; overflow: hidden;
}
#waveScroll.full { cursor: default; opacity: .5; }
#waveScrollThumb {
  position: absolute; top: 2px; bottom: 2px; left: 0; width: 100%;
  background: rgba(58,209,255,.3); border: 1px solid rgba(58,209,255,.7);
  border-radius: 6px; cursor: grab;
}
#waveScrollThumb:hover { background: rgba(58,209,255,.42); }
#waveScroll.full #waveScrollThumb { cursor: default; }
#waveScroll.grabbing, #waveScroll.grabbing #waveScrollThumb { cursor: grabbing; }
#waveScrollPlayhead {
  position: absolute; top: 0; bottom: 0; width: 1.5px; margin-left: -0.75px;
  background: #ff3a3a; pointer-events: none;
}

/* ---- calages suggérés ---- */
.cand-row {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px; color: #4dff88; font-size: 13px;
}
#candList {
  display: flex; gap: 6px; flex-wrap: nowrap;
  /* flex item en .cand-row row : sans min-width:0 la liste s'étale au lieu de défiler */
  flex: 1 1 auto; min-width: 0;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  scrollbar-width: thin; scrollbar-color: rgba(77,255,136,.4) transparent;
}
#candList::-webkit-scrollbar { height: 6px; }
#candList::-webkit-scrollbar-track { background: transparent; }
#candList::-webkit-scrollbar-thumb {
  background: rgba(77,255,136,.4); border-radius: 3px;
}
#candList .cand {
  font-family: ui-monospace, monospace; font-size: 13px; padding: 8px 10px;
  background: rgba(77,255,136,.12); border: 1px solid rgba(77,255,136,.4);
  color: #bdf5d2; min-height: 40px;
  flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start;
}
#candList .cand:hover { background: rgba(77,255,136,.25); }
#candList .cand.current { background: #4dff88; border-color: #4dff88; color: #08301a; font-weight: 700; }
#candList .cand small { opacity: .65; margin-left: 5px; }

/* ---- crop ---- */
.crop-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px;
  color: var(--crop); font-size: 13px;
}
.crop-row .mono { color: var(--text); }

/* ---- mix ---- */
.mix-grid { display: flex; flex-direction: column; gap: 20px; }
.mix-control { width: 100%; }
.mix-control > label { display: block; margin-bottom: 8px; font-size: 14px; }
.slider-row { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
input[type=range] { flex: 1; height: 36px; accent-color: var(--accent); margin: 0; }

/* ---- rendu ---- */
#renderBtn { width: 100%; }
.download {
  display: block; text-align: center; margin-top: 14px; padding: 14px 20px;
  background: var(--accent2); color: #04222e; font-weight: 700;
  border-radius: 8px; text-decoration: none; font-size: 16px;
}

/* ---- écrans larges ---- */
@media (min-width: 760px) {
  header { padding: 24px 16px 8px; }
  header h1 { font-size: 28px; }
  main { padding: 16px; }
  .card { padding: 18px 20px; }
  .card h2 { font-size: 17px; }
  .sources-row { flex-direction: row; gap: 24px; }
  .source { flex: 1; min-width: 280px; width: auto; }
  .dropzone { min-height: 110px; }

  /* vidéo verticale : colonne dédiée à gauche, réglages à droite */
  .edit-layout { display: flex; gap: 20px; align-items: stretch; }
  .video-col { flex: 0 0 clamp(240px, 30vw, 360px); }
  .ctrl-col { flex: 1; min-width: 0; }
  .video-sticky { top: 8px; }
  video { max-height: min(74vh, 640px); }

  #editor.theater .edit-layout { display: block; }
  #editor.theater .video-col { width: auto; }
  #editor.theater video { max-height: 78vh; }
  #waveCanvas { height: 220px; }
  .mix-grid { flex-direction: row; gap: 28px; }
  .mix-control { flex: 1; min-width: 260px; width: auto; }
  #renderBtn { width: auto; }
  .download { display: inline-block; }
  .cand-row { flex-direction: row; align-items: flex-start; gap: 10px; }
}
