:root {
  --bg: #0B0F1A;
  --bg2: #131a2b;
  --card: #18203400;
  --line: rgba(255,255,255,.09);
  --txt: #F4F6FB;
  --mut: rgba(244,246,251,.6);
  --acc: #FF7A1A;
  --rec: #FF3B30;
  --ok: #3DDC97;
  --r: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--txt); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; overscroll-behavior: none; }
button, input, a.cta { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .4; cursor: default; }
small { color: var(--mut); font-weight: 500; }

/* ---------- barre du haut */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: rgba(11,15,26,.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top .title { font-weight: 700; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title .edit { font-size: .8em; opacity: .6; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; letter-spacing: .02em; font-size: 20px; }
.logo { width: 26px; height: 26px; border-radius: 50%; border: 5px solid var(--acc); position: relative; }
.logo::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--rec); }
.pill { font-size: 12px; padding: 5px 10px; border-radius: 99px; background: rgba(61,220,151,.12); color: var(--ok); white-space: nowrap; }
.icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; background: rgba(255,255,255,.06); flex: none; }

/* ---------- boutons principaux */
.cta {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 58px; padding: 14px 18px; border-radius: var(--r);
  font-weight: 800; font-size: 17px; text-decoration: none; cursor: pointer;
  transition: transform .12s;
}
.cta:active { transform: scale(.98); }
.cta.rec { background: linear-gradient(135deg, var(--acc), #ff5a1a); color: #fff; box-shadow: 0 10px 30px -10px rgba(255,122,26,.6); }
.cta.ghost { background: rgba(255,255,255,.06); border: 1px solid var(--line); }
.cta.small { min-height: 44px; font-size: 15px; width: auto; display: inline-flex; }
.recdot { width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 4px rgba(255,255,255,.3); }

/* ---------- accueil */
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + var(--safe-b)); }
.hero h1 { font-size: 30px; line-height: 1.1; margin: 12px 0 8px; letter-spacing: -.02em; }
.hero h1 em { font-style: normal; color: var(--acc); }
.hero p { color: var(--mut); margin: 0 0 20px; }
.home .cta + .cta { margin-top: 10px; }
h2 { font-size: 18px; margin: 28px 0 12px; display: flex; justify-content: space-between; align-items: baseline; }
h2 small { font-size: 12px; }
.matches { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.match { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--r); background: var(--bg2); border: 1px solid var(--line); cursor: pointer; }
.match:active { background: #1a2338; }
.m-main { flex: 1; min-width: 0; }
.m-title { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-meta { font-size: 13px; color: var(--mut); margin-top: 2px; }
.m-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.m-tags span { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: color-mix(in srgb, var(--c) 18%, transparent); }
.del { background: transparent; opacity: .55; }
.empty { text-align: center; color: var(--mut); padding: 32px 16px; border: 1px dashed var(--line); border-radius: var(--r); list-style: none; }

/* ---------- préparation */
.setup form { display: grid; gap: 16px; margin-top: 8px; }
.setup label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.setup input { width: 100%; padding: 15px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); font-size: 17px; font-weight: 500; outline: none; }
.setup input:focus { border-color: var(--acc); }
.tips { display: grid; gap: 8px; padding: 14px; border-radius: var(--r); background: rgba(255,122,26,.07); border: 1px solid rgba(255,122,26,.2); font-size: 14px; }
.hint { color: var(--mut); font-size: 14px; text-align: center; }

/* ---------- écran caméra */
.rec-screen { position: fixed; inset: 0; background: #000; overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.rec-screen video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.rec-screen.paused video { filter: grayscale(.8) brightness(.6); }
.rec-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l)); z-index: 3; }
.glass { background: rgba(0,0,0,.45); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: #fff; }
.rec-status { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 99px; background: rgba(0,0,0,.5); font-weight: 800; font-variant-numeric: tabular-nums; font-size: 18px; }
.rec-status .dot { width: 11px; height: 11px; border-radius: 50%; background: #888; }
.live .rec-status .dot { background: var(--rec); animation: blink 1s infinite; }
.paused .rec-status .dot { animation: none; background: #ffd23f; }
@keyframes blink { 50% { opacity: .25; } }

.rec-left { position: absolute; z-index: 3; display: grid; justify-items: center; gap: 6px; }
.bigrec { width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; display: grid; place-items: center; background: rgba(0,0,0,.2); }
.bigrec span { width: 56px; height: 56px; border-radius: 50%; background: var(--rec); transition: all .25s; }
.live .bigrec span { width: 30px; height: 30px; border-radius: 7px; }
.arm .bigrec { border-color: var(--rec); animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.main-label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; text-shadow: 0 1px 4px #000; }

.tagpad { position: absolute; z-index: 3; display: grid; gap: 8px; }
.tag {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 16px; color: #fff; font-weight: 800;
  background: color-mix(in srgb, var(--c) 30%, rgba(0,0,0,.55));
  border: 2px solid color-mix(in srgb, var(--c) 80%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  touch-action: manipulation;
}
.tag .e { font-size: 26px; line-height: 1; }
.tag .l { font-size: 15px; white-space: nowrap; }
.tag .n { position: absolute; top: -8px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--c); color: #111; font-size: 12px; display: grid; place-items: center; }
.tag .n:empty { display: none; }
.tag.hit { animation: hit .35s; }
@keyframes hit { 30% { transform: scale(.9); background: var(--c); } }

/* paysage (usage recommandé) : boutons en colonne à droite, REC à gauche */
@media (orientation: landscape) {
  .tagpad { right: calc(12px + var(--safe-r)); top: 64px; bottom: calc(12px + var(--safe-b)); grid-auto-rows: 1fr; width: min(210px, 30vw); }
  .tag { justify-content: flex-start; }
  .rec-left { left: calc(16px + var(--safe-l)); top: 50%; transform: translateY(-50%); }
}
/* portrait : boutons en bas */
@media (orientation: portrait) {
  .tagpad { left: 10px; right: 10px; bottom: calc(110px + var(--safe-b)); grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .tag { flex-direction: column; gap: 4px; padding: 10px 2px; }
  .tag .l { font-size: 11px; }
  .rec-left { left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); }
}

.flash { position: absolute; inset: 0; z-index: 2; pointer-events: none; box-shadow: inset 0 0 0 0 var(--c); }
.flash.go { animation: flash .5s; }
@keyframes flash { 0% { box-shadow: inset 0 0 0 14px var(--c); } 100% { box-shadow: inset 0 0 0 0 var(--c); } }
.rec-note { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 4; }
.rec-note .err { pointer-events: auto; background: rgba(0,0,0,.8); padding: 24px; border-radius: var(--r); text-align: center; max-width: 340px; display: grid; gap: 12px; }

/* ---------- toasts */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); top: calc(70px + var(--safe-t)); z-index: 50; display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-radius: 14px; background: rgba(20,26,42,.94); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: tin .2s ease-out; }
.toast span { flex: 1; font-size: 15px; }
.toast button { padding: 8px 12px; border-radius: 10px; background: rgba(255,255,255,.1); font-weight: 700; font-size: 14px; white-space: nowrap; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .25s; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

/* pendant le match, les toasts ne doivent jamais couvrir les boutons */
@media (orientation: landscape) {
  body.recording #toast-root { top: auto; bottom: calc(16px + var(--safe-b)); left: calc(120px + var(--safe-l)); transform: none; width: calc(100vw - 120px - min(210px, 30vw) - 40px - var(--safe-l) - var(--safe-r)); }
}

/* ---------- revue */
.review { padding-bottom: calc(110px + var(--safe-b)); }
.player { position: sticky; top: calc(67px + var(--safe-t)); z-index: 4; background: var(--bg); padding-bottom: 8px; }
.player video { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 14px; display: block; }
.timeline { position: relative; height: 34px; margin-top: 8px; border-radius: 8px; background: rgba(255,255,255,.06); cursor: pointer; overflow: hidden; }
.mk { position: absolute; top: 6px; bottom: 6px; border-radius: 4px; background: var(--c); min-width: 4px; }
.mk.off { opacity: .25; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; z-index: 2; pointer-events: none; }
.addbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; font-size: 14px; color: var(--mut); }
.addbar b { color: var(--txt); font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 6px; }
.chip { width: 44px; height: 44px; border-radius: 12px; font-size: 22px; background: color-mix(in srgb, var(--c) 22%, transparent); border: 1px solid color-mix(in srgb, var(--c) 60%, transparent); }
.chip:active { transform: scale(.92); }
.moments { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.moment { border-radius: 16px; background: var(--bg2); border: 1px solid var(--line); border-left: 4px solid var(--c); }
.moment.off { opacity: .5; }
.moment .row { display: flex; align-items: center; gap: 10px; padding: 8px; }
.mo-play { width: 48px; height: 48px; border-radius: 12px; background: color-mix(in srgb, var(--c) 22%, transparent); font-size: 24px; flex: none; position: relative; }
.mo-play::after { content: "▶"; position: absolute; right: 3px; bottom: 2px; font-size: 10px; opacity: .8; }
.mo-txt { flex: 1; display: grid; cursor: pointer; }
.mo-txt span { font-size: 13px; color: var(--mut); font-variant-numeric: tabular-nums; }
.mo-star { font-size: 22px; filter: grayscale(1); opacity: .35; width: 44px; height: 44px; }
.mo-star.on { filter: none; opacity: 1; }
.mo-inc { width: 44px; height: 44px; font-size: 20px; }
.edit-row { display: grid; gap: 10px; padding: 4px 12px 14px; }
.trim { display: flex; align-items: center; gap: 8px; }
.trim span { width: 48px; font-size: 13px; color: var(--mut); }
.trim button, .danger { padding: 10px 14px; border-radius: 10px; background: rgba(255,255,255,.07); font-weight: 700; font-size: 14px; }
.retag { display: flex; gap: 6px; }
.retag button { width: 44px; height: 40px; border-radius: 10px; font-size: 20px; border: 1px solid transparent; }
.retag button.cur { border-color: var(--c); background: color-mix(in srgb, var(--c) 20%, transparent); }
.danger { color: #ff6b81; justify-self: start; }
.sticky { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 35%); z-index: 6; }
.sticky .cta { max-width: 688px; margin: 0 auto; }

/* ---------- résumé */
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset { display: grid; gap: 4px; align-content: start; text-align: left; padding: 14px 12px; border-radius: var(--r); background: var(--bg2); border: 2px solid var(--line); }
.preset.on { border-color: var(--acc); background: rgba(255,122,26,.08); }
.preset .pe { font-size: 26px; }
.preset small { font-size: 12px; line-height: 1.3; }
.preset .cnt { font-size: 12px; font-weight: 800; color: var(--acc); margin-top: 4px; }
.opt { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; font-weight: 600; }
.opt input { width: 22px; height: 22px; accent-color: var(--acc); }
.summary { color: var(--mut); margin: 8px 0 16px; font-size: 14px; }
.summary b { color: var(--txt); }
.stage { margin-top: 16px; display: grid; gap: 10px; justify-items: center; }
.stage canvas { width: 100%; border-radius: 14px; background: #000; }
.bar { width: 100%; height: 8px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--acc), var(--rec)); transition: width .3s; }
.result { margin-top: 20px; display: grid; gap: 12px; }
.res-head { font-weight: 800; font-size: 18px; display: flex; justify-content: space-between; align-items: baseline; }
.result video { width: 100%; border-radius: 14px; background: #000; }
.res-actions { display: grid; gap: 10px; }
@media (max-width: 420px) { .presets { grid-template-columns: 1fr; } .preset { grid-template-columns: auto 1fr auto; align-items: center; } .preset small { grid-column: 2; } .preset .pe { grid-row: span 2; } .preset .cnt { grid-row: 1; grid-column: 3; } }

/* lecteur source caché du montage : "visible" pour que Safari décode */
.offscreen-video { position: fixed; left: 0; bottom: 0; width: 2px; height: 2px; opacity: .01; pointer-events: none; z-index: -1; }

/* ---------- compte */
.account { position: relative; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--acc), #ff5a1a); color: #fff; font-weight: 900; font-size: 17px; }
.menu { position: absolute; right: 0; top: 50px; min-width: 240px; background: #1a2236; border: 1px solid var(--line); border-radius: 16px; padding: 6px; box-shadow: 0 16px 40px rgba(0,0,0,.5); z-index: 20; display: grid; }
.menu-head { padding: 10px 12px; display: grid; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head small { overflow: hidden; text-overflow: ellipsis; }
.menu button { text-align: left; padding: 12px; border-radius: 10px; font-weight: 600; }
.menu button:hover, .menu button:active { background: rgba(255,255,255,.06); }
.hero .pill { display: inline-block; margin-bottom: 18px; }

/* ---------- connexion / inscription */
.auth { max-width: 420px; padding-top: calc(40px + var(--safe-t)); }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.auth-brand b { font-size: 26px; font-weight: 900; display: block; }
.logo.big { width: 48px; height: 48px; border-width: 8px; flex: none; }
.logo.big::after { inset: 7px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border-radius: 14px; background: var(--bg2); margin-bottom: 20px; }
.tabs button { padding: 12px; border-radius: 10px; font-weight: 700; color: var(--mut); }
.tabs button.on { background: rgba(255,255,255,.09); color: var(--txt); }
.auth form { display: grid; gap: 14px; }
.auth label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.auth input:not([type=checkbox]) { width: 100%; padding: 15px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); font-size: 17px; font-weight: 500; outline: none; }
.auth input:focus { border-color: var(--acc); }
.auth label.bad input { border-color: #ff4d6d; }
.pw { position: relative; display: block; }
.pw input { padding-right: 52px !important; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 42px; height: 42px; opacity: .6; }
.auth .check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.auth .check input { width: 22px; height: 22px; accent-color: var(--acc); flex: none; }
.auth .check.bad span { color: #ff6b81; }
.auth a { color: var(--acc); }
.privacy { font-size: 13px; line-height: 1.5; color: var(--mut); padding: 12px 14px; border-radius: 12px; background: var(--bg2); }
.privacy b { color: var(--txt); }
.form-err { color: #ff6b81; font-weight: 600; min-height: 1.2em; margin: 0; font-size: 14px; }
.hint.small { font-size: 12px; }

/* ---------- espace super admin */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 4px 0 16px; }
.stats div { padding: 14px 10px; border-radius: 16px; background: var(--bg2); border: 1px solid var(--line); text-align: center; display: grid; }
.stats b { font-size: 28px; font-weight: 900; }
.stats span { font-size: 12px; color: var(--mut); }
.admin-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.admin-tools input { flex: 1; min-width: 0; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 16px; outline: none; }
.users { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.user { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 16px; background: var(--bg2); border: 1px solid var(--line); }
.user.off { opacity: .55; }
.u-avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,122,26,.18); color: var(--acc); font-weight: 900; display: grid; place-items: center; flex: none; }
.u-main { flex: 1; min-width: 0; }
.u-name { font-weight: 800; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.u-email { font-size: 14px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; }
.u-meta { font-size: 12px; color: var(--mut); margin-top: 4px; }
.badge { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; background: rgba(61,220,151,.15); color: var(--ok); }
.badge.red { background: rgba(255,77,109,.15); color: #ff6b81; }
.u-toggle { padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.07); font-weight: 700; font-size: 13px; flex: none; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } .user { flex-wrap: wrap; } .u-toggle { margin-left: 52px; } }
