:root {
  --primary: #ff3d7f;
  --secondary: #7c4dff;
  --bg: #12101f;
  --text: #ffffff;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bg-image: none;
  --glass: color-mix(in srgb, var(--bg) 70%, transparent);
  --surface: color-mix(in srgb, var(--text) 7%, transparent);
  --surface-2: color-mix(in srgb, var(--text) 12%, transparent);
  --line: color-mix(in srgb, var(--text) 14%, transparent);
  --muted: color-mix(in srgb, var(--text) 62%, transparent);
  --radius: 22px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.ico { flex-shrink: 0; display: block; }

/* ---------- fond ---------- */
#video {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform: scaleX(-1) scale(1.12);
  filter: blur(22px) saturate(1.15) brightness(.5);
}
.backdrop {
  position: fixed; inset: 0;
  background:
    radial-gradient(1100px 700px at 0% 0%, color-mix(in srgb, var(--primary) 26%, transparent), transparent 65%),
    radial-gradient(900px 700px at 100% 100%, color-mix(in srgb, var(--secondary) 26%, transparent), transparent 65%),
    color-mix(in srgb, var(--bg) 62%, transparent);
}
body.has-bg-image .backdrop {
  background: linear-gradient(color-mix(in srgb, var(--bg) 20%, transparent), color-mix(in srgb, var(--bg) 45%, transparent)), var(--bg-image) center / cover no-repeat;
}

/* ---------- écrans ---------- */
#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  opacity: 0; visibility: hidden; transform: translateY(12px);
  transition: opacity .4s var(--ease), transform .4s var(--ease), visibility 0s .4s;
  padding: 32px;
}
.screen.active { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.screen-head { position: absolute; top: 32px; left: 32px; right: 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.screen-title { font-size: clamp(26px, 3.4vw, 46px); font-weight: 700; letter-spacing: -.02em; margin: 0; text-align: center; }
.head-spacer { width: 140px; }
.center-col { display: flex; flex-direction: column; align-items: center; gap: 26px; text-align: center; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .22em; font-size: 14px; font-weight: 700; color: var(--muted); }

/* ---------- boutons ---------- */
.cta {
  border: 0; border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff; font-weight: 700; letter-spacing: .01em;
  box-shadow: 0 14px 40px -12px color-mix(in srgb, var(--primary) 70%, transparent);
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  transition: transform .15s var(--ease), filter .15s;
}
.cta:active { transform: scale(.97); }
.cta:disabled { filter: grayscale(.8) brightness(.7); cursor: not-allowed; }
.cta-lg { font-size: 24px; padding: 22px 30px; width: 100%; }
.cta-sm { font-size: 19px; padding: 15px 28px; }
.btn-ghost {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 13px 24px; font-size: 18px; font-weight: 600; text-decoration: none; color: var(--text);
  display: inline-flex; align-items: center; gap: 10px; transition: background .15s;
}
.btn-ghost.small { padding: 8px 16px 8px 12px; font-size: 15px; }
.btn-ghost:active { background: var(--surface-2); }

/* ---------- accueil ---------- */
.welcome-inner { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 1100px; }
.brand-logo { max-height: 20vh; max-width: 55vw; object-fit: contain; margin-bottom: 10px; filter: drop-shadow(0 8px 30px rgba(0,0,0,.3)); }
#welcome-title { font-size: clamp(48px, 7.5vw, 120px); font-weight: 800; letter-spacing: -.035em; margin: 0; line-height: .95; }
#welcome-subtitle { font-size: clamp(18px, 2vw, 28px); margin: 6px 0 36px; color: var(--muted); font-weight: 400; }
.shutter { position: relative; width: 168px; height: 168px; border-radius: 50%; border: 0; background: none; padding: 0; }
.shutter-ring { position: absolute; inset: 0; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--text) 75%, transparent); animation: ring 2.4s var(--ease) infinite; }
.shutter-core {
  position: absolute; inset: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center; color: #fff;
  box-shadow: 0 20px 60px -10px color-mix(in srgb, var(--primary) 70%, transparent);
  transition: transform .2s var(--ease);
}
.shutter:active .shutter-core { transform: scale(.92); }
@keyframes ring { 0% { transform: scale(1); opacity: .9; } 70% { transform: scale(1.22); opacity: 0; } 100% { opacity: 0; } }
.start-text { font-size: clamp(18px, 1.8vw, 24px); font-weight: 600; margin: 18px 0 0; letter-spacing: .02em; }
.camera-error { position: absolute; bottom: 40px; background: #b3261e; color: #fff; padding: 14px 22px; border-radius: 14px; max-width: 80vw; text-align: center; }

/* ---------- formats ---------- */
.format-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 270px)); gap: 24px; justify-content: center; width: 100%; max-width: 1240px; }
.format-card {
  background: var(--glass); backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 22px 26px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: transform .2s var(--ease), border-color .2s;
}
.format-card:active { transform: scale(.97); border-color: var(--primary); }
.format-card h3 { margin: 14px 0 0; font-size: 25px; font-weight: 700; }
.format-card p { margin: 0; color: var(--muted); font-size: 16px; text-align: center; }
.fmt-illu { width: 150px; height: 150px; color: var(--text); }
.fmt-illu .accent { fill: url(#fmtgrad); stroke: none; }

/* ---------- live ---------- */
#screen-live { flex-direction: row; align-items: stretch; gap: 24px; padding: 24px; }
.stage-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.stage { position: relative; max-width: 100%; max-height: 100%; border-radius: var(--radius); overflow: hidden; box-shadow: 0 30px 90px -20px rgba(0,0,0,.7); background: #000; }
#live-canvas { display: block; max-width: 100%; max-height: calc(100vh - 48px); }
.stage.mirror #live-canvas { transform: scaleX(-1); }
.stage-hud { position: absolute; top: 18px; left: 18px; right: 18px; display: flex; justify-content: space-between; pointer-events: none; }
.hud-pill { background: rgba(10,10,14,.6); backdrop-filter: blur(10px); padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 20px; display: inline-flex; align-items: center; gap: 10px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #ff3b30; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }
.countdown { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.count-num { position: relative; width: min(42vh, 340px); height: min(42vh, 340px); display: flex; align-items: center; justify-content: center; font-size: min(26vh, 220px); font-weight: 800; color: #fff; text-shadow: 0 10px 50px rgba(0,0,0,.5); animation: count 1s var(--ease) forwards; font-variant-numeric: tabular-nums; }
.count-num svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.count-num circle { fill: none; stroke: #fff; stroke-width: 4; stroke-dasharray: 302; stroke-dashoffset: 0; animation: sweep 1s linear forwards; opacity: .9; }
.count-smile { font-size: min(10vh, 90px); font-weight: 800; color: #fff; text-shadow: 0 10px 50px rgba(0,0,0,.5); animation: count .6s var(--ease) forwards; }
@keyframes count { 0% { transform: scale(1.4); opacity: 0; } 18% { transform: scale(1); opacity: 1; } 85% { opacity: 1; } 100% { transform: scale(.92); opacity: 0; } }
@keyframes sweep { to { stroke-dashoffset: 302; } }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
.thumbs { position: absolute; bottom: 18px; left: 18px; display: flex; gap: 10px; }
.thumbs img { height: 78px; border-radius: 10px; border: 3px solid #fff; box-shadow: 0 6px 20px rgba(0,0,0,.4); animation: pop .3s var(--ease); }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
.fx-loading { position: absolute; bottom: 18px; right: 18px; font-size: 15px; font-weight: 600; }

.panel {
  width: 400px; flex-shrink: 0;
  background: var(--glass); backdrop-filter: blur(20px);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.format-label { font-weight: 700; font-size: 20px; }
.tabs { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 999px; }
.tabs button { flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 11px 6px; font-weight: 700; font-size: 15px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .2s, color .2s; }
.tabs button.active { background: var(--text); color: var(--bg); }
.tab-body { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-content: start; padding: 2px; }
.chip { border: 0; background: none; padding: 0; display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chip .sw {
  width: 100%; aspect-ratio: 1; border-radius: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: var(--surface) center / cover; color: var(--muted);
  outline: 3px solid transparent; outline-offset: 2px; transition: outline-color .15s;
}
.chip .sw.contain { background-size: contain; background-repeat: no-repeat; background-origin: content-box; padding: 6px; }
.chip .sw canvas, .chip .sw img { width: 100%; height: 100%; display: block; object-fit: cover; }
.panel.mirror .chip .sw canvas.live { transform: scaleX(-1); }
.chip.active { color: var(--text); }
.chip.active .sw { outline-color: var(--primary); }
.toggle-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-radius: 16px; background: var(--surface); font-weight: 600; font-size: 17px; }
.toggle-row .lbl { display: inline-flex; align-items: center; gap: 10px; }
.switch { width: 58px; height: 32px; border-radius: 999px; background: var(--surface-2); position: relative; border: 0; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); }
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(26px); }
.section-label { grid-column: 1 / -1; margin: 6px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; }
#screen-live.capturing .panel { opacity: .35; pointer-events: none; }

/* ---------- traitement ---------- */
.spinner { width: 84px; height: 84px; border-radius: 50%; border: 6px solid var(--surface-2); border-top-color: var(--primary); animation: spin 1s linear infinite; }
.spinner.small { width: 16px; height: 16px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
#processing-text { margin: 0; font-weight: 600; }
.progress { width: 360px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width .2s; }

/* ---------- résultat ---------- */
#screen-result { flex-direction: row; gap: 32px; padding: 32px; align-items: stretch; }
.result-media { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.result-media img { max-width: 100%; max-height: calc(100vh - 64px); border-radius: 14px; box-shadow: 0 30px 90px -20px rgba(0,0,0,.75); animation: pop .5s var(--ease); }
.result-side { width: 420px; flex-shrink: 0; display: flex; flex-direction: column; gap: 18px; background: var(--glass); backdrop-filter: blur(20px); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; overflow-y: auto; }
.result-title { margin: 6px 0 0; font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.qr-box { background: #fff; color: #111; border-radius: 18px; padding: 14px; display: flex; gap: 16px; align-items: center; }
.qr-box img { width: 150px; height: 150px; display: block; flex-shrink: 0; }
.qr-text { display: flex; flex-direction: column; gap: 6px; font-size: 16px; }
.qr-text strong { font-size: 18px; }
.qr-text span { color: #555; }
.share-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.share-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 16px 16px; display: flex; align-items: center; gap: 12px; font-weight: 600; font-size: 18px; transition: background .15s; }
.share-btn .ico { color: var(--primary); }
.share-btn:active { background: var(--surface-2); }
.share-btn:disabled { opacity: .4; }
.upload-state { margin: 0; text-align: center; color: var(--muted); min-height: 1.2em; }
.result-footer { margin-top: auto; display: flex; justify-content: space-between; gap: 12px; }

/* ---------- merci ---------- */
.done-mark { width: 150px; height: 150px; }
.done-mark circle { fill: none; stroke: var(--primary); stroke-width: 5; stroke-dasharray: 327; stroke-dashoffset: 327; }
.done-mark path { fill: none; stroke: var(--text); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 80; stroke-dashoffset: 80; }
#screen-thanks.active .done-mark circle { animation: draw .7s var(--ease) forwards; }
#screen-thanks.active .done-mark path { animation: draw .45s .45s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
#thanks-text { font-size: clamp(40px, 6vw, 88px); font-weight: 800; letter-spacing: -.03em; margin: 0; }

/* ---------- modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(8px); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 20px; z-index: 20; }
body.vk-open .modal { padding-top: 2vh; }
.modal-card { width: min(720px, 100%); max-height: 90vh; overflow-y: auto; background: color-mix(in srgb, var(--bg) 92%, #fff 8%); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: 0 30px 90px rgba(0,0,0,.6); }
body.vk-open .modal-card { max-height: calc(100vh - 430px); }
.modal-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.modal-icon { width: 48px; height: 48px; border-radius: 14px; background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.modal-card h2 { margin: 0; font-size: 28px; font-weight: 700; }
#terms h2 { margin-bottom: 16px; }
.fields { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 16px; color: var(--muted); }
.field input, .field select {
  font: inherit; font-size: 24px; font-weight: 500; padding: 14px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); outline: none; user-select: text;
}
.field select option { color: #111; }
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.phone-row { display: flex; gap: 10px; }
.phone-row select { width: 130px; }
.phone-row input { flex: 1; min-width: 0; }
.check { display: flex; gap: 14px; align-items: flex-start; font-size: 17px; font-weight: 400; line-height: 1.45; padding: 4px 0; }
.check input { width: 28px; height: 28px; flex-shrink: 0; accent-color: var(--primary); margin: 0; }
.check a { color: var(--primary); font-weight: 600; }
.form-error { color: #ff6b81; font-weight: 600; min-height: 1.2em; margin: 12px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 18px; }
.terms-text { white-space: pre-wrap; line-height: 1.6; font-size: 17px; color: var(--muted); }
.tech-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- clavier virtuel ---------- */
.vk { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #17171c; padding: 12px; transform: translateY(105%); transition: transform .25s var(--ease); display: flex; flex-direction: column; gap: 8px; box-shadow: 0 -10px 40px rgba(0,0,0,.5); }
.vk.open { transform: none; }
.vk-row { display: flex; gap: 8px; justify-content: center; }
.vk-key { flex: 1; max-width: 96px; height: 70px; border: 0; border-radius: 12px; background: #34343c; color: #fff; font-size: 27px; font-weight: 500; display: flex; align-items: center; justify-content: center; }
.vk-key:active { background: var(--primary); }
.vk-space { max-width: 420px; flex: 5; font-size: 19px; }
.vk-ok { background: var(--primary); max-width: 160px; flex: 2; font-size: 22px; font-weight: 700; }
.vk-back, .vk-shift, .vk-mode, .vk-abc { background: #4a4a55; max-width: 130px; flex: 1.5; font-size: 21px; }
.vk-shift.active { background: #fff; color: #111; }
.vk-domain { max-width: 210px; font-size: 17px; background: #26262e; }

/* ---------- divers ---------- */
.toast { position: fixed; left: 50%; top: 28px; transform: translate(-50%, -160%); background: #fff; color: #111; padding: 16px 26px; border-radius: 999px; font-weight: 700; font-size: 19px; z-index: 40; transition: transform .35s var(--ease); box-shadow: 0 10px 40px rgba(0,0,0,.35); max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #ff4d6d; color: #fff; }
.net-status { position: fixed; right: 14px; bottom: 10px; font-size: 13px; font-weight: 600; color: var(--muted); z-index: 5; display: flex; align-items: center; gap: 6px; }
.net-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #34c759; }
.net-status.offline::before { background: #ff9f0a; }
.hotspot { position: fixed; top: 0; left: 0; width: 90px; height: 90px; z-index: 50; }

/* ---------- écran vertical (borne portrait / tablette) ---------- */
@media (orientation: portrait) {
  #screen-live, #screen-result { flex-direction: column; padding: 16px; gap: 16px; }
  .panel, .result-side { width: 100%; }
  .tab-body { grid-template-columns: repeat(4, 1fr); max-height: 26vh; }
  #live-canvas { max-height: 55vh; }
  .result-media img { max-height: 50vh; }
  .head-spacer { display: none; }
}
