*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --fg: rgba(255, 255, 255, 0.92);
  --dim: rgba(255, 255, 255, 0.5);
  --faint: rgba(255, 255, 255, 0.32);
  --line: rgba(255, 255, 255, 0.12);
  --panel: rgba(8, 9, 14, 0.97);
  --accent: #ff6ad5;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Courier New", monospace;
}

html, body { height: 100%; }
body {
  background: #03040a;
  color: var(--fg);
  overflow: hidden;
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#c {
  position: fixed; inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

button { font: inherit; color: inherit; }

/* ── Intro ───────────────────────────────────────────────────────────── */
#intro {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(3, 4, 10, 0.55), rgba(3, 4, 10, 0.88));
  z-index: 50;
  cursor: pointer;
  transition: opacity 0.7s ease;
  padding: 16px;
}
body.started #intro { opacity: 0; pointer-events: none; }
.intro-card { max-width: 30rem; text-align: center; }
.intro-card h1 {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  font-weight: 300;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ff6ad5, #7af0ff 55%, #ffd36a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 1rem;
}
.intro-card p { color: rgba(255, 255, 255, 0.78); line-height: 1.55; font-size: 1rem; }
.intro-sub { margin-top: 0.4rem; color: var(--dim) !important; font-size: 0.9rem !important; }
.intro-go {
  display: inline-block; margin-top: 1.8rem;
  padding: 0.8rem 1.6rem; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 0.8rem; letter-spacing: 0.14em; text-transform: uppercase;
  animation: pulse 2.4s ease-in-out infinite;
}
.intro-credit { margin-top: 2.2rem; font-size: 0.72rem !important; color: var(--faint) !important; letter-spacing: 0.04em; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 rgba(255, 106, 213, 0); } 50% { box-shadow: 0 0 28px rgba(255, 106, 213, 0.35); } }

/* ── Boutons flottants ───────────────────────────────────────────────── */
#btn-panel, #btn-unhide {
  position: fixed; top: 14px; right: 14px; z-index: 30;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: opacity 0.25s, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
#btn-panel svg, #btn-unhide svg { width: 20px; height: 20px; }
#btn-panel:hover, #btn-unhide:hover { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.45); }
body.panel-open #btn-panel { opacity: 0; pointer-events: none; }
#btn-unhide { display: none; opacity: 0.25; }
body.ui-hidden.touch #btn-unhide { display: flex; }

/* ── REC ─────────────────────────────────────────────────────────────── */
#rec-dot {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  display: none; align-items: center; gap: 7px; z-index: 30;
  font: 600 0.72rem var(--mono); letter-spacing: 0.1em; color: #ff5a5a;
  background: rgba(0, 0, 0, 0.55); padding: 0.35rem 0.8rem; border-radius: 999px;
  pointer-events: none;
}
#rec-dot.active { display: flex; }
#rec-dot .dot { width: 8px; height: 8px; border-radius: 50%; background: #ff5a5a; animation: blink 1s ease-in-out infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.15; } }

/* ── Panneau ─────────────────────────────────────────────────────────── */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(340px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 0 1.2rem 2rem;
  display: flex; flex-direction: column; gap: 1.3rem;
  overflow-y: auto; overscroll-behavior: contain;
  z-index: 40;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  user-select: none;
}
body.panel-open #panel { transform: none; pointer-events: auto; }
body.touch #panel { width: min(400px, 100vw); padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }

#panel-header {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem 0 0.5rem;
  background: var(--panel);
}
#panel-header span { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
#btn-panel-close, .wm-close, #btn-help-close {
  background: none; border: none; color: var(--dim); font-size: 1.05rem;
  cursor: pointer; padding: 0.3rem 0.5rem; line-height: 1;
}
#btn-panel-close:hover, .wm-close:hover, #btn-help-close:hover { color: #fff; }

#panel-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem; }
.action-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.8rem;
  padding: 0.6rem 0.2rem 0.5rem;
  min-height: 68px;
  cursor: pointer; touch-action: manipulation;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
}
.action-icon {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.78);
  transition: background 0.18s, box-shadow 0.18s, color 0.18s;
}
.action-icon svg { width: 16px; height: 16px; display: block; }
.action-label { font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); white-space: nowrap; }
.action-btn:hover { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.26); transform: translateY(-1px); }
.action-btn:hover .action-icon { background: rgba(255, 255, 255, 0.14); box-shadow: 0 0 12px rgba(255, 255, 255, 0.3); color: #fff; }
.action-btn.recording { border-color: rgba(255, 90, 90, 0.6); background: rgba(255, 60, 60, 0.1); }
.action-btn.recording .action-icon { background: rgba(255, 60, 60, 0.3); border-color: #ff5a5a; color: #fff; }
body.touch .action-btn { min-height: 76px; }

.group { display: flex; flex-direction: column; gap: 1rem; }
.group-title {
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent); opacity: 0.85;
  padding-top: 0.9rem; border-top: 1px solid var(--line);
}

.setting { display: flex; flex-direction: column; gap: 0.42rem; }
.setting-name { display: flex; align-items: center; justify-content: space-between; font-size: 0.86rem; font-weight: 600; }
.setting-value { font: 0.72rem var(--mono); color: var(--dim); font-variant-numeric: tabular-nums; }
.setting-labels { display: flex; justify-content: space-between; font-size: 0.66rem; color: var(--faint); }

select {
  width: 100%;
  font: 0.85rem var(--font); color: #fff;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.55rem;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
}
select option { background: #111; color: #fff; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: rgba(255, 255, 255, 0.2); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 2px; background: rgba(255, 255, 255, 0.2); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -7px; border-radius: 50%; background: #fff; transition: box-shadow 0.12s; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border: none; border-radius: 50%; background: #fff; }
input[type="range"]:hover::-webkit-slider-thumb { box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); }
body.touch input[type="range"] { height: 32px; }
body.touch input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -12px; }
body.touch input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  flex: 1 1 auto;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 0.45rem 0.6rem;
  cursor: pointer; touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { color: #fff; border-color: rgba(255, 255, 255, 0.4); }
.chip.active { color: #000; background: #fff; border-color: #fff; }
body.touch .chip { padding: 0.65rem 0.6rem; }
.stepper { display: flex; gap: 0.35rem; }
.stepper .chip { flex: 0 0 auto; width: 2.6rem; font-size: 1rem; padding: 0.25rem 0; }

.toggle {
  position: relative; width: 38px; height: 22px; flex: 0 0 auto;
  border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06); cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 255, 255, 0.7);
  transition: transform 0.18s, background 0.18s;
}
.toggle.on { background: var(--accent); border-color: var(--accent); }
.toggle.on::after { transform: translateX(16px); background: #fff; }
.setting-toggle .setting-name span { font-weight: 500; }

#btn-defaults {
  align-self: flex-start; background: none; border: none;
  color: var(--dim); font-size: 0.75rem; text-decoration: underline; text-underline-offset: 3px;
  cursor: pointer;
}
#btn-defaults:hover { color: #fff; }

#shortcuts { display: flex; flex-direction: column; gap: 0.45rem; border-top: 1px solid var(--line); padding-top: 1rem; }
body.touch #shortcuts { display: none; }
.shortcut { display: flex; align-items: center; gap: 0.7rem; font-size: 0.7rem; color: rgba(255, 255, 255, 0.45); }
kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.9rem; padding: 0.12rem 0.4rem;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 0.3rem;
  font: 0.66rem var(--mono); color: rgba(255, 255, 255, 0.7); white-space: nowrap; flex-shrink: 0;
}

#credit, .help-credit { font-size: 0.68rem; line-height: 1.5; color: var(--faint); }
#credit a, .help-credit a { color: rgba(255, 255, 255, 0.6); text-underline-offset: 2px; }
#credit a:hover, .help-credit a:hover { color: #fff; }

/* ── Menu d'un fil ───────────────────────────────────────────────────── */
#wire-menu {
  position: fixed; z-index: 45; left: 0; top: 0;
  width: 244px;
  background: var(--panel);
  border: 1px solid hsla(var(--h, 320), 80%, 65%, 0.45);
  border-radius: 0.9rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 22px hsla(var(--h, 320), 90%, 60%, 0.15);
  padding: 0.6rem 0.75rem 0.8rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  opacity: 0; pointer-events: none; transform: scale(0.96);
  transition: opacity 0.15s, transform 0.15s;
}
body.wire-menu-open #wire-menu { opacity: 1; pointer-events: auto; transform: none; }
.wm-head { display: flex; align-items: center; justify-content: space-between; }
.wm-title { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: hsl(var(--h, 320), 85%, 72%); }
.wm-label { font-size: 0.64rem; color: var(--faint); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 0.1rem; }
.wm-hues { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.3rem; }
.wm-hue {
  aspect-ratio: 1; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent;
  background: radial-gradient(circle at 35% 35%, hsl(var(--h), 95%, 78%), hsl(var(--h), 85%, 52%));
}
.wm-hue.active { border-color: #fff; box-shadow: 0 0 10px hsla(var(--h), 90%, 60%, 0.8); }
.wm-btns { display: flex; gap: 0.35rem; margin-top: 0.2rem; }
.wm-delete:hover { background: rgba(255, 70, 90, 0.2); border-color: #ff5a6e; color: #fff; }
.wm-speeds .chip, .wm-modes .chip { padding-left: 0.3rem; padding-right: 0.3rem; }

/* ── Aide ────────────────────────────────────────────────────────────── */
#help {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
body.help-open #help { opacity: 1; pointer-events: auto; }
.help-card {
  width: min(460px, 100%); max-height: 100%; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 1rem;
  padding: 0.9rem 1.2rem 1.2rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.help-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); margin-bottom: 0.3rem; }
#help-list { display: flex; flex-direction: column; gap: 0.45rem; }
#help-list .shortcut { font-size: 0.8rem; color: rgba(255, 255, 255, 0.72); }
#help-list kbd { min-width: 6.5rem; }
.help-credit { margin-top: 0.6rem; }

/* ── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; top: 18px; z-index: 70;
  transform: translate(-50%, -8px);
  max-width: min(92vw, 560px);
  background: rgba(10, 11, 18, 0.92);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.55rem 1.1rem;
  font-size: 0.8rem; color: rgba(255, 255, 255, 0.88); text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  display: flex; gap: 0.6rem; align-items: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-input { flex: 1; min-width: 12rem; font: 0.72rem var(--mono); color: #fff; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 0.4rem; padding: 0.3rem 0.5rem; user-select: text; -webkit-user-select: text; }
body.recording-video #toast { top: 54px; }

#drop-hint {
  position: fixed; inset: 12px; z-index: 80;
  border: 2px dashed rgba(255, 255, 255, 0.5); border-radius: 1rem;
  display: none; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff; background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
body.drag-over #drop-hint { display: flex; }

/* ── Sauvegarde manuelle iOS de la vidéo ─────────────────────────────── */
#save-link {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 90;
  background: #fff; color: #000; border-radius: 999px;
  padding: 0.9rem 1.6rem; font-size: 0.85rem; font-weight: 700; text-decoration: none; white-space: nowrap;
  box-shadow: 0 4px 28px rgba(255, 255, 255, 0.3);
}

/* ── UI masquée (projection) ─────────────────────────────────────────── */
body.ui-hidden #btn-panel,
body.ui-hidden #rec-dot,
body.ui-hidden #toast:not(.show) { opacity: 0 !important; pointer-events: none !important; }
body.ui-hidden #panel { transform: translateX(100%) !important; pointer-events: none !important; }

@media (prefers-reduced-motion: reduce) {
  .intro-go { animation: none; }
}
