:root {
  --charcoal: #0d0e10; --graphite: #15171a; --slate: #1d2024; --inset: #0a0b0d;
  --signal: #f6c945; --ink: #f1eee6; --ink-2: #aaa9a4; --ink-3: #777974;
  --line: rgba(255,255,255,.09); --ready: #66c98a; --radius: 12px;
}
* { box-sizing: border-box; }
html { overscroll-behavior: none; overflow-x: hidden; }
body {
  margin: 0; overflow-x: clip;
  background: var(--charcoal); color: var(--ink);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", sans-serif;
  min-height: 100vh;
}

.topbar { height: 64px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.brand-mark { width: 20px; height: 20px; background: var(--signal); border-radius: 6px; display: grid; place-items: center; transition: background .2s; }
.brand-mark svg { width: 15px; height: 15px; display: block; }
.version { font: 10px ui-monospace, monospace; color: var(--ink-3); border-left: 1px solid var(--line); padding-left: 10px; }
.status { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.status span { width: 7px; height: 7px; border-radius: 50%; background: var(--ready); box-shadow: 0 0 0 4px rgba(102,201,138,.08); }
.status em { font-style: normal; }

main { display: grid; grid-template-columns: minmax(460px, 1fr) 400px; min-height: calc(100vh - 64px); }
.stage-panel { padding: 28px 32px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.stage-head { display: flex; align-items: end; justify-content: space-between; }
.eyebrow { font: 10px ui-monospace, monospace; letter-spacing: .16em; color: var(--signal); margin: 0 0 7px; }
h1 { font-size: 27px; letter-spacing: -.035em; margin: 0; font-weight: 620; }

.file-button, .export-box button { background: var(--signal); color: #17150b; border: 0; border-radius: 7px; padding: 11px 15px; font-size: 12px; font-weight: 700; cursor: pointer; }
.file-button input { display: none; }
.file-button:hover, .export-box button:hover:not(:disabled) { filter: brightness(1.07); }

.stage-wrap {
  position: relative;
  flex: 1; min-height: 480px;
  display: grid; place-items: center;
  background-color: #111316;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; padding: 20px;
}
.phone-stage {
  height: min(64vh, 660px);
  aspect-ratio: var(--ar, 9 / 16);
  max-width: 100%;
  background: #101114;
  position: relative; overflow: hidden;
  box-shadow: 0 18px 60px rgba(0,0,0,.42);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
}
/* Formats paysage : la largeur pilote, le ratio donne la hauteur */
.phone-stage.wide { width: min(100%, 1000px); height: auto; }
.phone-stage.checker {
  background-color: #6a6a6e;
  background-image: linear-gradient(45deg, #555 25%, transparent 25%), linear-gradient(-45deg, #555 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #555 75%), linear-gradient(-45deg, transparent 75%, #555 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.phone-stage video, .phone-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.phone-stage video { object-fit: cover; display: none; }
.phone-stage.showvideo video { display: block; }
.phone-stage canvas { pointer-events: none; }
.phone-stage.drag { outline: 2px solid var(--signal); outline-offset: -2px; }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 7px; color: var(--ink-2); text-align: center; padding: 0 20px 12%; }
.empty small { color: var(--ink-3); font-size: 11px; }
.loaded .empty { display: none; }
.empty-signal { height: 36px; display: flex; align-items: center; gap: 4px; margin-bottom: 9px; }
.empty-signal i { display: block; width: 3px; background: var(--signal); border-radius: 2px; animation: idlebar 1.4s ease-in-out infinite; }
.empty-signal i:nth-child(1), .empty-signal i:nth-child(5) { height: 10px; }
.empty-signal i:nth-child(2), .empty-signal i:nth-child(4) { height: 23px; animation-delay: .2s; }
.empty-signal i:nth-child(3) { height: 34px; animation-delay: .4s; }
@keyframes idlebar { 50% { transform: scaleY(.55); } }

.transport { display: flex; align-items: center; gap: 12px; background: var(--graphite); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 14px; }
.transport button { width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer; background: var(--signal); color: #17150b; font-size: 14px; }
.transport button:disabled { background: var(--slate); color: var(--ink-3); cursor: default; }
.transport .time { font: 12px ui-monospace, monospace; color: var(--ink-2); min-width: 88px; }
.transport input[type=range] { flex: 1; }
.filename { font-size: 11px; color: var(--ink-3); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.controls-panel { padding: 28px; background: var(--charcoal); overflow: auto; max-height: calc(100vh - 64px); }
.controls-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 22px; }
.text-button { border: 0; background: none; color: var(--ink-3); font-size: 11px; cursor: pointer; }
.text-button:hover { color: var(--ink); }

fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend { font-size: 12px; font-weight: 650; margin-bottom: 10px; padding: 0; }
.segments { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segments input { display: none; }
.segments label { height: 62px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; font-size: 10px; color: var(--ink-2); cursor: pointer; background: var(--graphite); }
.segments label:has(input:checked) { border-color: rgba(246,201,69,.75); color: var(--ink); background: rgba(246,201,69,.06); }
.segments.two { grid-template-columns: 1fr 1fr; margin-bottom: 14px; }
.segments.two label { height: 36px; flex-direction: row; font-size: 11px; }
.img-buttons { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.img-buttons .file-button { flex: 1; text-align: center; }
.file-button.ghost { background: transparent; color: var(--signal); border: 1px solid rgba(246,201,69,.42); }
.file-button.ghost:hover { filter: none; background: rgba(246,201,69,.06); }
.style-icon { width: 36px; height: 15px; display: block; background-repeat: no-repeat; }
.style-icon.bars { background: repeating-linear-gradient(90deg, var(--ink-2) 0 2px, transparent 2px 6px); clip-path: polygon(0 45%,10% 25%,20% 60%,30% 5%,40% 30%,50% 0,60% 48%,70% 15%,80% 55%,90% 28%,100% 45%,100% 55%,90% 72%,80% 45%,70% 85%,60% 52%,50% 100%,40% 70%,30% 95%,20% 40%,10% 75%,0 55%); }
.style-icon.dots { background: radial-gradient(circle, var(--ink-2) 1.5px, transparent 2px) 0 0 / 6px 6px; }
.style-icon.line { border-top: 2px solid var(--ink-2); transform: skewY(-12deg); margin-top: 7px; }

.control { margin-bottom: 16px; }
.control-label { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.control label { font-size: 12px; font-weight: 600; }
.control output { font: 10px ui-monospace, monospace; color: var(--ink-3); }
input[type=range] { width: 100%; appearance: none; height: 3px; background: var(--slate); border-radius: 3px; outline: 0; }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--signal); border: 4px solid var(--charcoal); box-shadow: 0 0 0 1px var(--signal); cursor: pointer; }
select { width: 100%; background: var(--graphite); color: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; font-size: 12px; outline: 0; }

.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 18px 0 14px; }
.color-row.single { grid-template-columns: 1fr; margin-top: 0; }
.color-row.disabled, .color-row.single.disabled { opacity: .38; pointer-events: none; }
.color-row > label { background: var(--graphite); border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; font-size: 10px; color: var(--ink-3); }
.color-row label span { display: flex; align-items: center; gap: 7px; margin-top: 8px; }
.color-row input { width: 22px; height: 22px; padding: 0; border: 0; background: none; }
.color-row b { font: 10px ui-monospace, monospace; color: var(--ink-2); }

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); background: var(--graphite); border-radius: 8px; padding: 11px 12px; margin: 0 0 10px; cursor: pointer; }
.toggle span { display: flex; flex-direction: column; gap: 3px; }
.toggle strong { font-size: 11px; }
.toggle small { font-size: 9px; color: var(--ink-3); }
.toggle input { display: none; }
.toggle i { flex-shrink: 0; width: 34px; height: 19px; border-radius: 12px; background: var(--slate); position: relative; transition: .18s; }
.toggle i:after { content: ""; position: absolute; width: 13px; height: 13px; left: 3px; top: 3px; background: var(--ink-3); border-radius: 50%; transition: .18s; }
.toggle input:checked + i { background: var(--signal); }
.toggle input:checked + i:after { transform: translateX(15px); background: #17150b; }

.export-box { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 20px; }
.export-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.export-head strong { font-size: 12px; }
.export-head select { width: 90px; }
.export-box button { width: 100%; height: 42px; }
.export-box button + button { margin-top: 7px; }
.export-box button.secondary { background: transparent; color: var(--signal); border: 1px solid rgba(246,201,69,.42); }
.export-box button:disabled { background: var(--slate); color: var(--ink-3); border-color: transparent; cursor: not-allowed; }
.export-meta { display: block; margin-top: 10px; font-size: 10px; color: var(--ink-3); line-height: 1.5; }
.progress { margin-top: 14px; }
.progress-bar { height: 4px; background: var(--slate); border-radius: 2px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0%; background: var(--signal); transition: width .15s; }
.progress small { display: block; margin-top: 7px; font-size: 10px; color: var(--ink-2); }
.progress .text-button { margin-top: 6px; }

/* Fenêtre de progression centrée sur l'aperçu */
.export-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(13,14,16,.72);
  backdrop-filter: blur(3px);
  border-radius: var(--radius);
}
.export-overlay[hidden] { display: none; }
.export-card {
  width: min(420px, 86%);
  background: var(--graphite);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
  text-align: left;
}
.export-card .eyebrow { margin-bottom: 16px; }
.ov-bar { height: 8px; background: var(--slate); border-radius: 4px; overflow: hidden; }
.ov-bar span { display: block; height: 100%; width: 0%; background: var(--signal); border-radius: 4px; transition: width .15s; }
.ov-row { display: flex; align-items: baseline; gap: 12px; margin-top: 12px; }
.ov-row b { font: 700 20px ui-monospace, monospace; color: var(--ink); }
.ov-row small { font-size: 11px; color: var(--ink-2); }
.export-card .text-button { margin-top: 14px; }

/* Pendant un export transparent : la vidéo disparaît de l'aperçu,
   on voit exactement ce qui part dans le fichier */
.phone-stage.novideo video { display: none !important; }

#errBanner { position: fixed; bottom: 0; left: 0; right: 0; background: #e5484d; color: #fff; padding: 10px 16px; font: 12px ui-monospace, monospace; z-index: 99; display: none; }

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .stage-panel { border-right: 0; }
  .controls-panel { border-top: 1px solid var(--line); max-height: none; }
  .stage-wrap { min-height: 420px; }
}

/* Mobile : la fenêtre d'export couvre l'écran, elle apparaît LÀ où on est
   (près du bouton d'export), pas cachée en haut de page */
@media (max-width: 900px) {
  .export-overlay { position: fixed; inset: 0; border-radius: 0; z-index: 70; }
}

/* Téléphones : une colonne serrée, rien ne déborde */
@media (max-width: 700px) {
  .topbar { padding: 0 14px; }
  .stage-panel { padding: 14px; gap: 12px; }
  .stage-head { flex-wrap: wrap; align-items: start; gap: 12px; }
  .stage-head h1 { font-size: 21px; }
  .stage-head .file-button { width: 100%; text-align: center; }
  .stage-wrap { padding: 12px; min-height: 340px; }
  .phone-stage { height: min(56vh, 520px); max-width: 100%; }
  .transport { flex-wrap: wrap; padding: 10px 12px; }
  .transport input[type=range] { flex: 1 1 100%; order: 3; }
  .filename { max-width: 40vw; }
  .controls-panel { padding: 18px 14px; }
  .export-card { padding: 18px 16px; }
}

/* Écrans tactiles : curseurs et cibles plus généreux */
@media (pointer: coarse) {
  input[type=range] { height: 6px; }
  input[type=range]::-webkit-slider-thumb { width: 24px; height: 24px; border-width: 5px; }
  .toggle i { width: 42px; height: 24px; }
  .toggle i:after { width: 16px; height: 16px; }
  .toggle input:checked + i:after { transform: translateX(18px); }
  .transport button { width: 46px; height: 46px; }
}
.export-card .dl-button { display: block; width: 100%; margin-top: 14px; background: var(--signal); color: #17150b; border: 0; border-radius: 7px; padding: 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.export-card .dl-button:hover { filter: brightness(1.07); }

/* Mini-aperçu flottant (mobile) : l'onde reste visible pendant les réglages */
#miniPreview {
  display: none;
  position: fixed; right: 10px; top: 72px;
  width: 158px; height: auto;
  border-radius: 12px;
  border: 2px solid rgba(246,201,69,.55);
  box-shadow: 0 12px 40px rgba(0,0,0,.65);
  z-index: 40; cursor: pointer;
  background-color: #6a6a6e;
  background-image: linear-gradient(45deg, #555 25%, transparent 25%), linear-gradient(-45deg, #555 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #555 75%), linear-gradient(-45deg, transparent 75%, #555 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
body.mini-on #miniPreview { display: block; }

/* Carte d'export sur petit écran : pourcentage en vedette, tout centré et aéré */
@media (max-width: 700px) {
  .export-overlay { padding: 18px; }
  .export-card { width: 100%; max-width: 380px; padding: 24px 20px 18px; text-align: center; }
  .export-card .eyebrow { text-align: center; font-size: 9px; letter-spacing: .1em; line-height: 1.6; margin-bottom: 18px; }
  .ov-bar { height: 10px; border-radius: 5px; }
  .ov-row { flex-direction: column; align-items: center; gap: 5px; margin-top: 16px; }
  .ov-row b { font-size: 34px; line-height: 1; }
  .ov-row small { font-size: 12px; line-height: 1.55; color: var(--ink-2); }
  .export-card .dl-button { margin-top: 12px; padding: 14px; font-size: 14px; }
  .export-card .text-button { margin-top: 14px; padding: 10px; font-size: 12px; width: 100%; }
}
