:root {
  --bg: #121317;
  --panel: rgba(20, 21, 26, 0.94);
  --line: #2a2d35;
  --text: #e9ebef;
  --muted: #9aa0ab;
  --accent: #ff4d6d;
  --accent-2: #3fa7ff;
  /* écart commun entre les contrôles du panneau (boutons, vignettes) et entre pastilles */
  --gap: 10px;
  --gap-s: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  overflow-y: auto;
  padding: 16px 16px 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(8px);
  z-index: 2;
  touch-action: pan-y;   /* le panneau défile, mais pincer ne zoome pas la page */
  overscroll-behavior: contain;
}

#panel header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
#panel h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
#panel h1 + span { color: var(--muted); font-size: 12px; }
#panel section { padding: 14px 0; border-top: 1px solid var(--line); }
#panel h2 { margin: 10px 0 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

#panel .current {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 6px; margin: 0; text-align: left; cursor: pointer;
  background: none; border: 1px solid transparent; border-radius: 10px; color: var(--text); font: inherit;
}
#panel .current:hover { border-color: var(--line); background: #1d1f25; }
.current .dot { width: 44px; height: 44px; border-radius: 50%; flex: none; border: 2px solid #fff3; }
.current strong { display: block; font-size: 15px; }
.current small { color: var(--muted); }
.current .pen { margin-left: auto; color: var(--muted); font-size: 16px; }

.editor { margin: 8px 0 4px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #17181d; }
.editor .row { margin-top: 0; }
.finishes { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
#panel .finishes button { padding: 6px 4px; font-size: 12px; }
#panel .finishes button.on { border-color: #fff; background: #303541; }
#panel button.primary-soft { width: 100%; border-color: var(--accent); color: #ffb3c1; }
#panel h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; }

#panel button.wide { grid-column: 1 / -1; width: 100%; }

/* Tout bloc de boutons posé sous un autre élément prend l'écart commun (:where garde
   la spécificité basse : les enfants des grilles .actions / .xr gardent le seul gap). */
#panel :where(.actions, .projects, .refs, .finishes, .wide, .primary-soft):not(:first-child, section) { margin-top: var(--gap); }
input[type=text] {
  flex: 1; min-width: 0; background: #1d1f25; color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font: inherit;
}
.projects { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap); }
.projects li { display: flex; gap: var(--gap); }
.projects li.on .open { border-color: #fff; }
#panel .projects .open { flex: 1; display: flex; align-items: center; gap: 8px; padding: 4px; text-align: left; min-width: 0; }
.projects img, .projects .nothumb { width: 72px; height: 36px; object-fit: cover; border-radius: 4px; background: #2a2d35; flex: none; }
.projects strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projects small { color: var(--muted); font-size: 11px; }
#panel .projects .del { padding: 4px 8px; color: #ff8f9f; }

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: var(--gap-s); }
.sw {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  outline-offset: 2px;
}
.sw:hover { transform: scale(1.12); }
.swatches > p { grid-column: 1 / -1; margin: 0; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px #000; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.row input[type=color] { width: 48px; height: 28px; border: 1px solid var(--line); background: none; padding: 0; }
select {
  background: #1d1f25; color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px; font: inherit;
}

.caps { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.cap {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px 5px; background: #1d1f25; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font: inherit; font-size: 12px;
}
.cap canvas { width: 64px; height: 40px; }
.cap.on { border-color: #fff; background: #303541; }

.slider { display: block; margin-top: 12px; }
.slider output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { width: 100%; margin-top: 4px; accent-color: var(--accent); }
.slider.dim { opacity: 0.4; }

.check { display: flex; align-items: center; gap: 8px; margin-top: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
#panel button:not(.sw):not(.cap) {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #1d1f25; color: var(--text); font: inherit; cursor: pointer;
}
#panel button:not(.sw):not(.cap):hover { background: #262932; }
#panel button.danger { color: #ff8f9f; }
.xr { display: grid; gap: var(--gap); }
#panel :is(.actions, .xr) > * { margin: 0; }
#xr-status:empty { display: none; }
#panel button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 11px; }
#panel button.primary:disabled { background: #2a2d35; border-color: var(--line); color: var(--muted); cursor: not-allowed; }
#xr-status { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.lan { margin: 6px 0 0; padding: 8px; border-radius: 8px; background: #1d1f25; font-size: 12px; color: var(--muted); line-height: 1.6; }
.lan b { color: var(--text); font-size: 14px; user-select: all; }

details { border-top: 1px solid var(--line); padding-top: 12px; }
summary { cursor: pointer; color: var(--muted); }
.help { color: var(--muted); font-size: 12px; padding-left: 16px; }
p.help { padding-left: 0; }
.help b { color: var(--text); font-weight: 600; }

#hud {
  position: fixed;
  bottom: 16px;
  left: calc(50% + 150px);
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(10, 10, 12, 0.7);
  font-size: 13px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1;
}
#hud .dot { width: 14px; height: 14px; border-radius: 50%; }

#toast {
  position: fixed;
  top: 16px;
  left: calc(50% + 150px);
  transform: translate(-50%, -12px);
  padding: 9px 16px;
  border-radius: 8px;
  background: rgba(10, 10, 12, 0.85);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 3;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#panel-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 4;
  width: 40px; height: 40px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 18px;
  touch-action: manipulation;
}

@media (max-width: 760px) {
  #panel { transform: translateX(-100%); transition: transform .2s; width: min(300px, 85vw); }
  body.panel-open #panel { transform: none; }
  #panel-toggle { display: block; }
  #hud, #toast { left: 50%; }
  #hud { max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; }
}

/* Session VR rendue par le PC : la vue spectateur prend toute la fenêtre */
#specbar {
  display: none;
  position: fixed; top: 12px; right: 12px; z-index: 4;
  align-items: center; gap: 6px; padding: 6px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel);
  transition: opacity .3s;
}
#specbar button {
  padding: 7px 10px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: #1d1f25; color: var(--text); font: inherit; font-size: 13px;
}
#specbar button:hover { background: #262932; }
#specbar button.on { border-color: var(--accent); color: #ffb3c1; }
#specbar .msg { display: none; color: var(--muted); font-size: 12px; padding: 0 6px; }
:root:fullscreen #specbar:not(:hover) { opacity: 0.15; }
body.xr-live #specbar { display: flex; }
body.xr-live.spec-off #specbar .msg { display: inline; }
body.xr-live.spec-off #scene { visibility: hidden; }
body.xr-live #scene { cursor: default; }
body.xr-live #panel { transform: translateX(-100%); transition: transform .2s; }
body.xr-live.panel-open #panel { transform: none; }
body.xr-live #panel-toggle { display: block; }
body.xr-live #hud, body.xr-live #toast { left: 50%; }
@media (max-width: 760px) {
  #specbar { left: 60px; flex-wrap: wrap; }
}

/* Écran tactile : croix de déplacement, nacelle, bulle du pincement */
.touch-only { display: none; }
body.touch .touch-only { display: block; }
#touch-pad {
  display: none;
  position: fixed; z-index: 1;
  left: calc(316px + env(safe-area-inset-left));
  bottom: calc(60px + env(safe-area-inset-bottom));
  align-items: flex-end; gap: 10px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
body.touch:not(.pad-off) #touch-pad { display: flex; }
@media (max-width: 760px) {
  #touch-pad { left: calc(16px + env(safe-area-inset-left)); }
}
#touch-pad .cross {
  position: relative; width: 132px; height: 132px; border-radius: 50%;
  background: rgba(10, 10, 12, 0.45); border: 1px solid #fff2;
}
#touch-pad .cross span {
  position: absolute; width: 44px; height: 44px; display: grid; place-items: center;
  color: #fffa; font-size: 18px; pointer-events: none;
}
#touch-pad .cross span.on { color: var(--accent); }
#touch-pad [data-dir=fwd] { left: 44px; top: 0; }
#touch-pad [data-dir=back] { left: 44px; bottom: 0; }
#touch-pad [data-dir=left] { left: 0; top: 44px; }
#touch-pad [data-dir=right] { right: 0; top: 44px; }
#touch-pad .cross i {
  position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; background: #fff3; border: 1px solid #fff5; pointer-events: none;
}
#touch-pad .lift { display: grid; gap: 8px; }
#touch-pad .lift button {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid #fff2;
  background: rgba(10, 10, 12, 0.45); color: #fffa; font-size: 20px; touch-action: none;
}
#touch-pad .lift button.on { color: var(--accent); border-color: var(--accent); }
#touch-bubble {
  position: fixed; z-index: 3; transform: translate(-50%, -50%);
  padding: 6px 12px; border-radius: 999px; background: rgba(10, 10, 12, 0.8);
  font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .4s;
}
#touch-bubble.show { opacity: 1; transition: none; }

/* Modèle photo */
.file-btn {
  display: block; text-align: center; padding: 8px; border-radius: 8px; cursor: pointer;
  border: 1px dashed var(--line); color: var(--text); background: #1d1f25;
}
.file-btn:hover { background: #262932; }
.file-btn input { display: none; }
.refs { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap-s); }
.refs .ref { position: relative; }
.refs img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; display: block; }
.refs .ref.on img { border-color: #fff; }
#panel .refs button { position: absolute; top: 2px; right: 2px; padding: 0 5px; font-size: 11px; background: rgba(0,0,0,0.6); border: none; }
#refview {
  position: fixed; right: 16px; bottom: 60px; z-index: 2;
  padding: 4px; border-radius: 8px; background: rgba(10, 10, 12, 0.7);
  pointer-events: none;
}
#refview img { display: block; height: var(--ref-h, 180px); max-width: 40vw; object-fit: contain; border-radius: 4px; }
