:root {
  --bg: #0b0d12;
  --stage: #06070a;
  --surface: #141821;
  --surface-2: #1b2030;
  --border: #262c3a;
  --text: #eef1f7;
  --muted: #8b93a7;
  --accent: #7c9cff;
  --accent-2: #b28cff;
  --accent-ink: #0b0d12;
  --trim: #ffd23f;
  --erotic-1: #ff4f7b;
  --erotic-2: #b0306a;
  --bar-bg: rgba(11, 13, 18, 0.86);
  --top-h: 56px;    /* mis à jour par le JS */
  --bottom-h: 70px; /* mis à jour par le JS */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] { display: none !important; }

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

button, label, a, input { font: inherit; color: inherit; touch-action: manipulation; }
button { -webkit-appearance: none; appearance: none; background: none; border: 0; padding: 0; cursor: pointer; }

/* ---------- Structure ---------- */
.app { position: fixed; inset: 0; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 10px) 6px calc(var(--safe-left) + 10px);
  min-height: calc(var(--safe-top) + 56px);
  background: var(--bar-bg);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 5;
}
.topbar-left, .topbar-right { display: flex; gap: 4px; flex: 1 0 44px; }
.topbar-right { justify-content: flex-end; }
.title {
  margin: 0;
  min-width: 0;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-align: center;
  text-wrap: balance; /* nom long : deux lignes équilibrées */
}
.title .nowrap { white-space: nowrap; }
@media (max-width: 359px) { .title { font-size: 12px; } }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.icon-btn:active { background: var(--surface-2); transform: scale(0.94); }

/* ---------- Scène ---------- */
.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--stage);
  touch-action: none;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(var(--top-h) + 24px) 24px 24px;
  text-align: center;
}
.empty-art {
  width: 96px;
  height: 96px;
  border-radius: 28px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #1e2433, #11141c);
  border: 1px solid var(--border);
  color: #7ee2a8;
}
.empty-art svg { width: 44px; height: 44px; stroke-width: 1.5; }
.empty-hint { margin: 0; color: var(--muted); font-size: 14px; max-width: 30ch; line-height: 1.45; }

.player { position: absolute; border-radius: 10px; overflow: hidden; background: #000; }
.player video, .player canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.player video { object-fit: fill; transition: filter 0.25s; }
.player.is-erotic video { filter: grayscale(1) contrast(1.08); }
#overlay { pointer-events: none; }

.badge-erotic {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: #fff;
  background: linear-gradient(135deg, var(--erotic-1), var(--erotic-2));
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bottom-h) + 14px);
  transform: translate(-50%, 20px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 24, 33, 0.92);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 4;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Barres du bas ---------- */
.bottom-bars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: var(--bar-bg);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px calc(var(--safe-right) + 14px) 10px calc(var(--safe-left) + 14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.panel-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.panel-row--wrap { flex-wrap: wrap; row-gap: 10px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.3; }

.text-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 16px; /* évite le zoom automatique d'iOS */
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.text-input:focus { border-color: var(--accent); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
  margin: 0 -14px;
  padding: 0 14px;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 18px;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s;
}
.chips button[aria-checked="true"] { border-color: var(--accent); background: var(--surface-2); }

.swatches { display: flex; gap: 6px; flex: 1 0 auto; padding: 3px; margin: -3px; }
.swatches button {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  transition: transform 0.12s;
}
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); transform: scale(1.05); }

.segmented {
  display: inline-flex;
  flex: none;
  padding: 3px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.segmented button {
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.segmented button[aria-checked="true"] { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.4); }

.slider { display: flex; align-items: center; gap: 12px; min-height: 36px; }
.slider-label { font-size: 13px; color: var(--muted); width: 52px; flex: none; }
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 36px;
  background: transparent;
  margin: 0;
  touch-action: pan-x;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 0; }

/* ---------- Découpe ---------- */
.trim { padding: 10px calc(var(--safe-right) + 18px) 4px calc(var(--safe-left) + 18px); }
.trim-labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 6px;
}
.trim-out { color: var(--text); font-weight: 650; }
.trim-out.is-erotic { color: var(--erotic-1); }

.track { position: relative; height: 46px; touch-action: none; }
.track-bg {
  position: absolute;
  left: 16px;  /* = largeur des poignées : la piste couvre exactement la durée */
  right: 16px;
  top: 5px;
  bottom: 5px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.06) 0 2px, transparent 2px 14px),
    var(--surface-2);
}
.track-sel {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 3px solid var(--trim);
  border-left-width: 16px;
  border-right-width: 16px;
  border-radius: 10px;
  background: rgba(255, 210, 63, 0.14);
  box-sizing: border-box;
  min-width: 32px;
}
.track.is-erotic .track-sel { border-color: var(--erotic-1); background: rgba(255, 79, 123, 0.16); }
.handle {
  position: absolute;
  top: 50%;
  width: 4px;
  height: 16px;
  margin-top: -8px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.55);
}
.handle--start { left: -10px; }
.handle--end { right: -10px; }
.playhead {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* ---------- Barre d'outils ---------- */
.toolbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px calc(var(--safe-right) + 8px) calc(var(--safe-bottom) + 6px) calc(var(--safe-left) + 8px);
}
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 58px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.tool svg { width: 26px; height: 26px; }
.tool:active { transform: scale(0.94); }
.tool[aria-pressed="true"] { color: var(--text); background: var(--surface-2); }
.tool[aria-pressed="true"] svg { color: var(--accent); }
.tool--erotic[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(135deg, var(--erotic-1), var(--erotic-2));
}
.tool--erotic[aria-pressed="true"] svg { color: #fff; fill: rgba(255, 255, 255, 0.35); }
.tool--save { color: var(--text); }
.tool--save svg { color: #7ee2a8; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-big { min-height: 54px; padding: 0 26px; font-size: 17px; border-radius: 16px; }
.btn-icon-only { width: 42px; padding: 0; }

/* ---------- Progression ---------- */
.busy {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
  animation: fade 0.2s ease;
}
.busy-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}
.busy-title { margin: 0; font-size: 17px; font-weight: 700; }
.busy-step { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.3em; font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.15s; }

/* ---------- Feuille du résultat ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  animation: fade 0.2s ease;
}
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: calc(100% - var(--safe-top) - 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 18px);
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  animation: slide-up 0.25s cubic-bezier(.2,.8,.2,1);
}
.sheet-grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 4px; }
.sheet h2 { margin: 0; font-size: 19px; text-align: center; }
.sheet-preview { flex: 1 1 auto; min-height: 0; display: flex; justify-content: center; }
.sheet-preview img {
  max-width: 100%;
  max-height: 40vh;
  max-height: 40dvh;
  border-radius: 12px;
  object-fit: contain;
  background: var(--stage);
  -webkit-touch-callout: default; /* appui long → « Ajouter à Photos » */
}
.sheet-info { margin: 0; text-align: center; font-size: 14px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sheet-hint { margin: 0; text-align: center; font-size: 13px; color: var(--muted); line-height: 1.4; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }
.sheet-actions .btn { width: 100%; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

@media (max-height: 640px) {
  .panel { gap: 6px; padding-top: 8px; }
  .tool { min-height: 50px; }
}
@media (min-width: 700px) {
  .panel > *, .trim > * { max-width: 600px; margin-left: auto; margin-right: auto; width: 100%; }
  .chips { margin: 0 auto; }
  .toolbar { grid-template-columns: repeat(3, 130px); justify-content: center; }
}
