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

:root {
  --bg: #03060c;
  --panel: 8, 13, 22;
  --ink: 214, 230, 242;
  --line: 160, 200, 230;
  --accent: 143, 208, 240;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: rgb(var(--ink));
  overflow: hidden;
  position: fixed;
  inset: 0;
  font: 12px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

#fluid-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#fluid-canvas { touch-action: none; }

/* Vidéo quasi invisible mais DANS l'écran : Safari iOS peut suspendre une vidéo muette
   hors écran ou à opacité nulle, et MediaPipe ne recevrait plus d'images. Aperçu en vignette si activé. */
#webcam-video {
  position: fixed;
  width: 4px;
  height: 3px;
  right: 0;
  bottom: 0;
  opacity: 0.01;
  pointer-events: none;
  transform: scaleX(-1);
  object-fit: cover;
}
body.show-preview #webcam-video {
  right: 14px; bottom: 14px;
  width: 200px; height: 150px;
  opacity: 0.8;
  z-index: 3;
  border-radius: 8px;
  border: 1px solid rgba(var(--line), 0.18);
  filter: grayscale(1) contrast(1.05);
}

#status {
  position: fixed;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
  font: 11px/1 ui-monospace, Menlo, monospace;
  color: rgba(var(--ink), 0.4);
  white-space: nowrap;
  transition: opacity 0.6s;
}
#status.faded { opacity: 0; }

#hint {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  pointer-events: none;
  font: 11px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 1px;
  color: rgba(var(--ink), 0.55);
  opacity: 0;
  transition: opacity 0.6s;
  white-space: nowrap;
}
#hint.on { opacity: 1; }

#rec-dot {
  position: fixed;
  top: 12px; right: 56px;
  z-index: 10;
  display: none;
  align-items: center;
  gap: 6px;
  font: 11px/1 ui-monospace, Menlo, monospace;
  color: #ff6b6b;
}
#rec-dot .dot { width: 8px; height: 8px; border-radius: 50%; background: #ff4d4d; animation: blink 1s infinite; }
body.recording #rec-dot { display: flex; }
@keyframes blink { 50% { opacity: 0.2; } }

#gear-btn {
  position: fixed;
  top: 10px; right: 12px;
  z-index: 30;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(var(--line), 0.15);
  background: rgba(var(--panel), 0.55);
  color: rgba(var(--ink), 0.8);
  font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
#gear-btn:hover { color: rgb(var(--accent)); }

/* ── Panneau ───────────────────────────────────────── */
#panel {
  position: fixed;
  top: 10px; right: 10px;
  z-index: 40;
  width: 272px;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 14px 14px;
  background: rgba(var(--panel), 0.72);
  border: 1px solid rgba(var(--line), 0.1);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(28px) saturate(1.3);
  -webkit-backdrop-filter: blur(28px) saturate(1.3);
  transform: translateX(0);
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1), opacity 0.35s;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--line), 0.2) transparent;
}
body.panel-closed #panel { transform: translateX(calc(100% + 20px)); opacity: 0; pointer-events: none; }
body:not(.panel-closed) #gear-btn { opacity: 0; pointer-events: none; }
body.ui-hidden #gear-btn { display: none; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(var(--line), 0.08);
}
.panel-title {
  font: 500 9px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 3px;
  color: rgba(var(--ink), 0.45);
}
#panel-close {
  background: none; border: 0;
  color: rgba(var(--ink), 0.5);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
}
#panel-close:hover { color: rgb(var(--ink)); }

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}
.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px 6px;
  border-radius: 8px;
  border: 1px solid rgba(var(--line), 0.08);
  background: rgba(var(--line), 0.04);
  color: rgba(var(--ink), 0.65);
  font-size: 9.5px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.act[hidden] { display: none; }
.act .ico { font-size: 13px; line-height: 1; }
.act:hover { background: rgba(var(--line), 0.09); color: rgb(var(--ink)); }
.act.on { color: rgb(var(--accent)); border-color: rgba(var(--accent), 0.35); background: rgba(var(--accent), 0.08); }
body.recording #btn-rec { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.4); }

.sec { padding-top: 12px; margin-top: 10px; border-top: 1px solid rgba(var(--line), 0.07); }
.sec-title {
  display: flex;
  justify-content: space-between;
  font: 500 9px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(var(--ink), 0.4);
  margin-bottom: 9px;
}
.sec-title.sub { margin-top: 14px; }
.sec-val { color: rgba(var(--accent), 0.9); letter-spacing: 1px; }

#palettes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pal {
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(var(--line), 0.12);
  cursor: pointer;
  position: relative;
  outline-offset: 2px;
}
.pal.on { outline: 1.5px solid rgba(var(--accent), 0.9); }
.pal span {
  position: absolute; left: 6px; bottom: 4px;
  font-size: 9px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.ctrl { margin-bottom: 8px; }
.ctrl label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(var(--ink), 0.7);
  margin-bottom: 3px;
}
.ctrl label output { color: rgba(var(--ink), 0.45); font-variant-numeric: tabular-nums; }
.ctrl input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
.ctrl input[type=range]::-webkit-slider-runnable-track { height: 2px; background: rgba(var(--line), 0.18); border-radius: 2px; }
.ctrl input[type=range]::-moz-range-track { height: 2px; background: rgba(var(--line), 0.18); border-radius: 2px; }
.ctrl input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: rgb(var(--accent));
  border: 0;
}
.ctrl input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: rgb(var(--accent)); border: 0; }

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 11px;
  color: rgba(var(--ink), 0.7);
  cursor: pointer;
}
.toggle input { display: none; }
.toggle .sw {
  width: 28px; height: 16px;
  border-radius: 8px;
  background: rgba(var(--line), 0.16);
  position: relative;
  transition: background 0.2s;
  flex: none;
}
.toggle .sw::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: rgba(var(--ink), 0.7);
  transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .sw { background: rgba(var(--accent), 0.45); }
.toggle input:checked + .sw::after { transform: translateX(12px); background: rgb(var(--accent)); }

.seg { display: flex; gap: 4px; margin-bottom: 9px; }
.seg-label { font-size: 11px; color: rgba(var(--ink), 0.7); margin-bottom: 4px; }
.seg button {
  flex: 1;
  padding: 4px 0;
  border-radius: 6px;
  border: 1px solid rgba(var(--line), 0.1);
  background: rgba(var(--line), 0.04);
  color: rgba(var(--ink), 0.6);
  font-size: 10.5px;
  cursor: pointer;
}
.seg button.on { color: rgb(var(--accent)); border-color: rgba(var(--accent), 0.4); background: rgba(var(--accent), 0.08); }

.legend { list-style: none; margin: 6px 0 4px; }
.legend li { font-size: 10.5px; color: rgba(var(--ink), 0.5); margin-bottom: 3px; }
.legend b { font-weight: 500; color: rgba(var(--ink), 0.78); }
.note { font-size: 10px; color: rgba(var(--ink), 0.38); margin-top: 6px; }

.keys {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 5px 8px;
  align-items: center;
  font-size: 10.5px;
  color: rgba(var(--ink), 0.5);
}
kbd {
  font: 10px/1 ui-monospace, Menlo, monospace;
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid rgba(var(--line), 0.15);
  color: rgba(var(--ink), 0.75);
  text-align: center;
}
.reset {
  width: 100%;
  margin-top: 12px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid rgba(var(--line), 0.1);
  background: none;
  color: rgba(var(--ink), 0.45);
  font-size: 10.5px;
  cursor: pointer;
}
.reset:hover { color: rgb(var(--ink)); }

/* Présentation : rien d'autre que le fluide */
body.presenting #panel,
body.presenting #gear-btn,
body.presenting #status,
body.presenting #hint { display: none; }
body.presenting { cursor: none; }
body.cursor-hidden, body.cursor-hidden * { cursor: none !important; }

@media (max-width: 600px) {
  #status, #hint { white-space: normal; text-align: center; width: calc(100vw - 100px); line-height: 1.4; }
  .keys-title { display: none; }
  #panel { width: auto; left: 10px; right: 10px; max-height: 70dvh; top: auto; bottom: 10px; }
  body.panel-closed #panel { transform: translateY(calc(100% + 20px)); }
  .keys { display: none; }
}
