:root {
  --bg: #0a0a0c;
  --bg-2: #14141a;
  --fg: #f5f5f7;
  --fg-dim: #9a9aa2;
  --accent: #ff3d8a;
  --accent-2: #6c5cff;
  --rainbow: linear-gradient(
    90deg,
    #ff3b30 0%,
    #ff9500 18%,
    #ffcc00 36%,
    #34c759 54%,
    #00c7ff 72%,
    #af52de 100%
  );
  --radius: 14px;
  --shadow: 0 24px 60px -10px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    Helvetica, Arial, "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
  min-height: 100vh; /* fallback */
  min-height: 100dvh; /* iOS Safari : évite layout shift barre adresse */
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 18px 32px;
  gap: 18px;
  background:
    radial-gradient(circle at 20% -10%, rgba(108, 92, 255, 0.18), transparent 50%),
    radial-gradient(circle at 110% 110%, rgba(255, 61, 138, 0.16), transparent 55%),
    var(--bg);
}

/* ===== Top bar ===== */

.topbar {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-flag {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(255, 61, 138, 0.4));
}

.brand-name {
  background: var(--rainbow);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-size: 18px;
}

.brand-sep {
  color: var(--fg-dim);
}

.brand-mode {
  color: var(--fg-dim);
  font-weight: 500;
  font-size: 14px;
}

.rec-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 59, 48, 0.12);
  border: 1px solid rgba(255, 59, 48, 0.4);
  color: #ff5e54;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rec-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff3b30;
  box-shadow: 0 0 10px #ff3b30;
  animation: rec-blink 1s infinite;
}

@keyframes rec-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

/* ===== Stage ===== */

.stage-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.stage {
  position: relative;
  width: min(360px, 90vw);
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  isolation: isolate;
}

#stage-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#webcam,
#playback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: -1;
  opacity: 0;
  pointer-events: none;
}

#playback {
  position: absolute;
  z-index: 5;
  opacity: 1;
  background: #000;
}

/* ===== Panel ===== */

.panel {
  width: 100%;
  max-width: 480px;
  background: var(--bg-2);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status {
  margin: 0;
  text-align: center;
  font-size: 14px;
  color: var(--fg-dim);
  line-height: 1.45;
  min-height: 20px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions-result {
  grid-template-columns: 1fr 1fr;
}

.actions-result .btn-tiktok {
  grid-column: 1 / -1;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--fg);
  background: rgba(255, 255, 255, 0.06);
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--rainbow);
  color: #fff;
  box-shadow: 0 8px 24px -6px rgba(255, 61, 138, 0.55);
}

.btn-primary:hover {
  box-shadow: 0 10px 32px -6px rgba(255, 61, 138, 0.7);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
}

.btn-tiktok {
  background: linear-gradient(135deg, #25f4ee 0%, #fe2c55 100%);
  color: #fff;
  box-shadow: 0 8px 24px -6px rgba(254, 44, 85, 0.5);
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--fg-dim);
  line-height: 1.5;
}

.hint code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
}

/* ===== Empty state / errors ===== */

.error {
  color: #ff7b6e;
}

@media (max-width: 380px) {
  .actions {
    grid-template-columns: 1fr;
  }
  .actions-result {
    grid-template-columns: 1fr;
  }
}

/* ===== Share button ===== */
.btn-share-big {
  width: 100%;
  padding: 15px;
  font-size: 18px;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #7c3aed, #a855f7, #ff3d8a, #ff6ec7, #a855f7, #7c3aed);
  background-size: 300% 100%;
  animation: share-shimmer 5s linear infinite;
  box-shadow: 0 6px 22px -4px rgba(168, 85, 247, 0.6);
  transition: filter 0.15s, transform 0.15s;
}
.btn-share-big:hover { filter: brightness(1.1); transform: translateY(-2px); }

@keyframes share-shimmer {
  0%   { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

/* ===== Share panel (desktop fallback: download + platform links) ===== */
.share-panel {
  margin-top: 12px;
  padding: 14px 16px;
  background: rgba(255,255,255,0.07);
  border-radius: 16px;
  text-align: center;
}
.share-panel-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin: 0 0 10px;
}
.share-platforms {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.share-plat-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  color: #fff;
  transition: transform 0.15s, filter 0.15s;
}
.share-plat-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.share-plat-btn.tiktok  { background: #111; border: 1px solid #69C9D0; }
.share-plat-btn.reels   { background: linear-gradient(135deg, #f09433, #dc2743, #bc1888); }
.share-plat-btn.shorts  { background: #ff0000; }
.share-plat-btn.snap    { background: #FFFC00; color: #111; }

/* ===== Share modal ===== */
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.share-modal[hidden] { display: none; }
.share-modal-card {
  background: #16162a;
  border-radius: 24px;
  padding: 28px 22px 22px;
  width: 100%;
  max-width: 340px;
  position: relative;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.07);
}
.share-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255,255,255,0.08);
  border: none;
  color: rgba(255,255,255,0.55);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.share-modal-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
.share-modal-title {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  text-align: center;
  margin: 0 0 18px;
}
.share-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.share-modal-plat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 18px 10px 14px;
  border-radius: 18px;
  border: none;
  cursor: pointer;
  font-weight: 800;
  font-size: 14px;
  color: #fff;
  transition: transform 0.15s, filter 0.15s;
}
.share-modal-plat:hover { transform: translateY(-3px); filter: brightness(1.12); }
.share-modal-plat .plat-icon { font-size: 30px; }
.share-modal-plat.tiktok  { background: #111; border: 1.5px solid #69C9D0; }
.share-modal-plat.reels   { background: linear-gradient(145deg,#f09433,#dc2743,#bc1888); }
.share-modal-plat.shorts  { background: #ff0000; }
.share-modal-plat.snap    { background: #FFFC00; color: #111; }
.share-modal-hint {
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin: 0 0 12px;
}
.share-modal-native {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 11px 14px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  outline: none;
  transition: background 0.15s, color 0.15s;
}
.share-modal-native:hover { background: rgba(255,255,255,0.1); color: rgba(255,255,255,0.8); }
.share-modal-native:focus-visible { outline: 2px solid rgba(255,255,255,0.3); outline-offset: 2px; }
.share-modal-plat:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
.share-modal-close:focus-visible { outline: 2px solid rgba(255,255,255,0.5); outline-offset: 2px; }
.share-modal-plat .plat-label { display: block; }
