/* EmoMask — l'interface reste sombre et calme ; la seule couleur vive est celle de l'émotion
   de l'autre (--emo), qui teinte l'aura, les accents et les contrôles en temps réel. */
@property --emo { syntax: '<color>'; inherits: true; initial-value: #FFC83D; }

:root {
  --night: #0E1022;
  --deep: #151933;
  --panel: #1B2042;
  --line: #2C3260;
  --text: #EEF0FF;
  --muted: #9AA0C8;
  --hang: #F0464B;
  --emo: #FFC83D;
  --font: 'Bricolage Grotesque', 'Segoe UI Variable Display', 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --emoji: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
  transition: --emo 600ms ease;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-variation-settings: 'opsz' 16;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
a { color: var(--text); text-underline-offset: 3px; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--emo); outline-offset: 2px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ----------------------------------------------------------- boutons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  padding: 12px 20px; border-radius: 999px; cursor: pointer; font-weight: 600;
  transition: background 150ms, border-color 150ms, transform 80ms;
}
.btn:hover { border-color: color-mix(in oklab, var(--emo) 55%, var(--line)); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--emo); color: #1a1205; border-color: transparent; }
.btn.primary:hover { background: color-mix(in oklab, var(--emo) 85%, white); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--deep); border-radius: 12px;
  width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:hover { border-color: var(--muted); }

/* ------------------------------------------------------------ accueil */
#lobby {
  height: 100%; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 560px);
}
.stage { position: relative; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage-caption {
  position: absolute; left: 0; right: 0; bottom: 6%; margin: 0; text-align: center;
  font-size: 22px; font-weight: 600; font-variation-settings: 'opsz' 36;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.stage-caption span:first-child { font-family: var(--emoji); }
.setup {
  padding: clamp(28px, 6vh, 64px) clamp(24px, 4vw, 52px); overflow: auto;
  background: var(--deep); border-left: 1px solid var(--line);
}
.setup h1 {
  margin: 0; font-size: clamp(48px, 6vw, 76px); line-height: 0.95; letter-spacing: -0.03em;
  font-weight: 800; font-variation-settings: 'opsz' 96, 'wdth' 80;
}
.lede { margin: 14px 0 30px; font-size: 19px; line-height: 1.45; color: var(--muted); max-width: 32ch; }
form { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; color: var(--muted); }
.field input:not([type=range]), .custom input {
  width: 100%; background: var(--night); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; outline: none;
}
.field input:focus, .custom input:focus { border-color: var(--emo); }
.input-row { display: flex; gap: 8px; }
.skins { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.skins legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.skin-opt { position: relative; cursor: pointer; display: grid; gap: 4px; text-align: center; font-size: 14px; font-weight: 600; }
.skin-opt input { position: absolute; opacity: 0; pointer-events: none; }
.skin-opt canvas {
  width: 100%; aspect-ratio: 1; border-radius: 18px; border: 2px solid var(--line); display: block; background: var(--night);
}
.skin-opt input:checked + canvas { border-color: var(--emo); }
.skin-opt input:focus-visible + canvas { outline: 2px solid var(--emo); outline-offset: 2px; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-size: 15px; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background 150ms; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform 150ms; }
.switch input:checked + .track { background: var(--emo); }
.switch input:checked + .track .knob { transform: translateX(18px); background: #1a1205; }
.switch input:focus-visible + .track { outline: 2px solid var(--emo); outline-offset: 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.actions .btn { flex: 1 1 180px; }
.fine { margin-top: 28px; font-size: 13.5px; color: var(--muted); max-width: 46ch; }

/* --------------------------------------------------------------- appel */
#call { position: fixed; inset: 0; }
#remoteCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(18px, env(safe-area-inset-top)) 22px 40px;
  background: linear-gradient(rgba(8, 10, 22, 0.75), transparent);
}
.who { min-width: 0; flex: 1; }
.who b { display: block; font-size: 24px; line-height: 1.1; font-weight: 700; font-variation-settings: 'opsz' 48; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net { display: flex; gap: 10px; align-items: center; font-size: 14px; font-variant-numeric: tabular-nums; flex: none; margin-left: 12px; }
.badge { white-space: nowrap; }
.badge { padding: 4px 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); }
.badge::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #45d483; margin-right: 7px; vertical-align: 1px; }
.badge.relay::before { background: #ffb340; }
.timer { color: var(--muted); }

.remote-emo {
  position: absolute; left: 50%; transform: translateX(-50%); top: 22px;
  display: flex; align-items: center; gap: 14px; padding: 10px 20px 10px 12px;
  background: rgba(14, 16, 34, 0.72); backdrop-filter: blur(12px); border-radius: 22px;
  border: 1px solid color-mix(in oklab, var(--emo) 40%, transparent);
  min-width: 240px;
}
.remote-emo .em { font-family: var(--emoji); font-size: 40px; line-height: 1; }
.remote-emo b { font-size: 20px; font-weight: 700; display: block; line-height: 1.15; }
.remote-emo small { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.meter { height: 4px; background: rgba(255, 255, 255, 0.1); border-radius: 4px; margin: 6px 0 4px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--emo); border-radius: 4px; transition: width 120ms linear; }

.waiting {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(460px, 92vw);
  text-align: center; display: grid; gap: 12px; justify-items: center;
  background: rgba(14, 16, 34, 0.8); backdrop-filter: blur(14px); padding: 26px; border-radius: 26px; border: 1px solid var(--line);
}
.w-title { margin: 0; font-size: 24px; font-weight: 700; }
.w-sub { margin: 0; color: var(--muted); }
.invite { display: flex; gap: 8px; width: 100%; }
.invite input { flex: 1; min-width: 0; background: var(--night); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; }

.pip {
  position: absolute; right: 20px; bottom: 112px; width: clamp(150px, 19vw, 250px); aspect-ratio: 3 / 4;
  border-radius: 22px; overflow: hidden; background: var(--night); border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.pip canvas, .pip video { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pip video, #selfOverlay { object-fit: cover; transform: scaleX(-1); }
.pip video { opacity: 1; }
.pip-label {
  position: absolute; left: 10px; right: 10px; bottom: 10px; font-size: 13.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 12px; background: rgba(8, 10, 22, 0.65); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pip-label span:first-child { font-family: var(--emoji); }
.calib, .nocam {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center;
  background: rgba(8, 10, 22, 0.55); font-weight: 600; padding: 12px;
}
.calib .ring { width: 54px; height: 54px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, 0.15); border-top-color: var(--emo); animation: spin 0.9s linear infinite; }

.controls {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 6px; padding: 8px; border-radius: 26px;
  background: rgba(14, 16, 34, 0.78); backdrop-filter: blur(14px); border: 1px solid var(--line);
}
.ctl {
  appearance: none; border: 0; background: transparent; cursor: pointer; width: 74px; padding: 8px 0 6px; border-radius: 18px;
  display: grid; justify-items: center; gap: 3px; font-size: 11.5px; color: var(--muted);
}
.ctl svg { width: 24px; height: 24px; color: var(--text); }
.ctl:hover { background: rgba(255, 255, 255, 0.06); }
.ctl[aria-pressed='true'] { color: var(--text); }
#btnCam[aria-pressed='true'], #btnMask.open, #btnLearn.open, #btnDebug.open { background: color-mix(in oklab, var(--emo) 22%, transparent); }
#btnMic .off { display: none; }
#btnMic[aria-pressed='false'] .on { display: none; }
#btnMic[aria-pressed='false'] .off { display: block; color: var(--hang); }
.ctl.hang svg { color: #fff; background: var(--hang); border-radius: 50%; padding: 6px; width: 36px; height: 36px; margin-top: -6px; }

.sheet, .drawer {
  position: absolute; background: rgba(21, 25, 51, 0.96); backdrop-filter: blur(16px); border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.sheet { left: 50%; bottom: 112px; transform: translateX(-50%); width: min(460px, 94vw); border-radius: 24px; padding: 18px 20px 20px; display: grid; gap: 16px; }
.drawer { top: 14px; right: 14px; bottom: 14px; width: min(400px, 94vw); border-radius: 24px; padding: 18px 20px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.drawer.wide { width: min(460px, 94vw); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; font-size: 18px; }
.sheet-head .icon-btn { width: 36px; height: 36px; border-radius: 10px; }
.seg { display: flex; gap: 6px; background: var(--night); padding: 4px; border-radius: 14px; border: 1px solid var(--line); }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; padding: 9px 4px; line-height: 1.15; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--emo) 60%, transparent); }
.slider span { display: flex; justify-content: space-between; color: var(--text) !important; font-weight: 600; }
.slider output { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 400; }
.slider small { color: var(--muted); font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--emo); }
.hint { margin: 0; color: var(--muted); font-size: 14.5px; }
.learn-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.learn-item {
  appearance: none; display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 14px; cursor: pointer; text-align: left;
  background: var(--night); border: 1px solid var(--line); font-weight: 600; font-size: 14px;
}
.learn-item:hover { border-color: var(--emo); }
.learn-item .e { font-family: var(--emoji); font-size: 22px; }
.learn-item .n { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.learn-item.has .n { color: #45d483; }
.custom { display: grid; grid-template-columns: 64px 1fr; gap: 8px; }
.custom #customEmoji { text-align: center; font-family: var(--emoji); font-size: 20px; padding: 6px; }
.custom button { grid-column: 1 / -1; }
.learn-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: auto; padding-top: 6px; }
.rec { position: absolute; inset: 0; border-radius: 24px; background: rgba(14, 16, 34, 0.94); display: grid; place-content: center; justify-items: center; text-align: center; gap: 6px; }
.rec-count { font-size: 96px; font-weight: 800; line-height: 1; font-variation-settings: 'opsz' 96; color: var(--emo); font-variant-numeric: tabular-nums; }
.rec p { margin: 0; font-size: 18px; max-width: 24ch; }
.stats { margin: 0; font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: pre-line; }
.dbg-canvas { width: 100%; display: block; }

.toast {
  position: absolute; left: 50%; top: 120px; transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; font-size: 14.5px;
  transition: opacity 200ms, transform 200ms; max-width: min(560px, 92vw); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { position: fixed; inset: 0; background: rgba(8, 10, 22, 0.86); display: grid; place-content: center; justify-items: center; gap: 16px; z-index: 50; }
.loading p { margin: 0; color: var(--muted); max-width: 40ch; text-align: center; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--emo); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }


/* ------------------------------------------------- effets v0.3 */
.gaze-target {
  position: absolute; z-index: 6; transform: translate(-50%, -50%); pointer-events: none;
  display: grid; justify-items: center; gap: 14px; text-align: center;
}
.gaze-target i {
  width: 22px; height: 22px; border-radius: 50%; background: #fff; display: block;
  box-shadow: 0 0 0 6px color-mix(in oklab, var(--emo) 55%, transparent), 0 0 34px 10px color-mix(in oklab, var(--emo) 45%, transparent);
  animation: gazePulse 1.1s ease-in-out infinite;
}
.gaze-target span { font-weight: 600; font-size: 15px; padding: 6px 12px; border-radius: 12px; background: rgba(8, 10, 22, 0.7); white-space: nowrap; }
@keyframes gazePulse { 50% { transform: scale(0.72); } }
#call.calibrating .waiting, #call.calibrating .remote-emo { opacity: 0; pointer-events: none; transition: opacity 200ms; }
.fx-opts { border-top: 1px solid var(--line); padding-top: 12px; }
.fx-opts summary { cursor: pointer; font-weight: 600; color: var(--muted); list-style: none; display: flex; justify-content: space-between; }
.fx-opts summary::after { content: '+'; font-weight: 400; }
.fx-opts[open] summary::after { content: '–'; }
.fx-opts[open] { display: grid; gap: 14px; }
.fx-opts .switch small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 2px; }
.sheet { max-height: calc(100dvh - 140px); overflow: auto; }

/* ------------------------------------------------------------ mobile */
@media (max-width: 860px) {
  body { overflow: auto; }
  #lobby { grid-template-columns: 1fr; grid-template-rows: 46vh auto; height: auto; min-height: 100%; }
  .setup { border-left: 0; border-top: 1px solid var(--line); }
  .pip { width: 120px; bottom: 104px; right: 12px; }
  .remote-emo { top: 78px; left: 16px; transform: none; min-width: 0; padding-right: 14px; }
  .remote-emo .em { font-size: 32px; }
  .remote-emo small { display: none; }
  .ctl { width: 50px; font-size: 0; gap: 0; padding: 10px 0; }
  .controls { gap: 2px; }
  .seg button { font-size: 12.5px; }
  .skin-opt { font-size: 12.5px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
