:root {
  --bg: #0b0e13;
  --panel: rgba(22, 26, 34, 0.94);
  --line: rgba(255, 255, 255, 0.09);
  --text: #e9edf3;
  --muted: #8f99a8;
  --accent: #4f8cff;
  --ok: #3ddc84;
  --warn: #ffb547;
  --bad: #ff5d5d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- connexion ---------- */
#login { display: grid; place-items: center; padding: 24px; background: radial-gradient(120% 80% at 50% 0%, #17223a 0%, var(--bg) 60%); }
.card { width: 100%; max-width: 360px; text-align: center; }
.logo { width: 76px; height: 76px; border-radius: 20px; box-shadow: 0 10px 40px rgba(79, 140, 255, .25); }
h1 { font-size: 24px; margin: 18px 0 6px; letter-spacing: -.01em; }
.sub { color: var(--muted); margin: 0 0 22px; }
#code {
  width: 100%; font-size: 30px; letter-spacing: .38em; text-align: center; padding: 14px 10px 14px 22px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text); outline: none;
  user-select: text; -webkit-user-select: text;
}
#code:focus { border-color: var(--accent); }
.primary {
  width: 100%; margin-top: 14px; padding: 14px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 16px;
}
.primary:active { filter: brightness(.9); }
.err { color: var(--bad); min-height: 1.4em; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 26px; }

/* ---------- vue ---------- */
#viewer { background: #000; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
#screen { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: auto; background: #000; will-change: transform; }
#cursor { position: absolute; left: 0; top: 0; pointer-events: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,.5)); will-change: transform; }

#mouseBtns { position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); pointer-events: none; }
.mbtn {
  position: absolute; bottom: 0; width: 62px; height: 62px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.22); background: rgba(20, 24, 32, .38); color: rgba(255,255,255,.85);
  font-weight: 700; font-size: 17px; pointer-events: auto; touch-action: none; backdrop-filter: blur(4px);
}
#btnL { left: max(14px, env(safe-area-inset-left)); }
#btnR { right: max(14px, env(safe-area-inset-right)); }
.mbtn.on { background: rgba(79, 140, 255, .75); border-color: var(--accent); color: #fff; }

.chip {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: max(18px, env(safe-area-inset-bottom));
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px;
}

#handle {
  position: absolute; top: max(6px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14); background: rgba(16, 19, 26, .55); color: #fff; opacity: .75;
  backdrop-filter: blur(6px); z-index: 20;
}
#handle.open svg { transform: rotate(180deg); }
#dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
#dot.ok { background: var(--ok); }
#dot.bad { background: var(--bad); }

#toolbar {
  position: absolute; top: calc(max(6px, env(safe-area-inset-top)) + 36px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 6px; max-width: calc(100vw - 16px); overflow-x: auto;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line); z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.45); scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }
.tb {
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px; padding: 6px 6px 4px;
  border: 0; border-radius: 11px; background: transparent; font-size: 11px; color: var(--muted); flex: none;
}
.tb svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tb.active, .tb:active { background: rgba(255,255,255,.08); color: var(--text); }
.seg { display: flex; background: rgba(255,255,255,.06); border-radius: 11px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--accent); color: #fff; }
.seg.wide { width: 100%; }
.seg.wide button { flex: 1; }

.panel {
  position: absolute; top: calc(max(6px, env(safe-area-inset-top)) + 110px); left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 16px)); max-height: calc(100% - 130px); overflow-y: auto; padding: 12px;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line); z-index: 19;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.grid button, #keybar button {
  padding: 11px 6px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.05); font-size: 13px;
}
.grid button:active, #keybar button:active { background: rgba(79,140,255,.35); }
.list button { display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 6px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.04); }
.list button.on { border-color: var(--accent); background: rgba(79,140,255,.18); }
.row { margin-bottom: 14px; }
.row > label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.row.check label { color: var(--text); display: flex; gap: 10px; align-items: center; font-size: 14px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.stat { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
#pHelp h3 { font-size: 15px; margin: 2px 0 8px; }
#pHelp ul { margin: 0; padding-left: 18px; color: #c9d1dc; }
#pHelp li { margin: 5px 0; }

#keybar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 5px; padding: 6px; overflow-x: auto;
  background: var(--panel); border-top: 1px solid var(--line); z-index: 21; scrollbar-width: none;
}
#keybar::-webkit-scrollbar { display: none; }
#keybar button { flex: none; min-width: 50px; padding: 10px 8px; }
#keybar button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#keybar .close { margin-left: auto; color: var(--muted); }
#kbd { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; font-size: 16px; }

#toast {
  position: absolute; left: 50%; bottom: 90px; transform: translate(-50%, 10px); max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  font-size: 13px; text-align: center; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.6); z-index: 40; }
.ov-box { text-align: center; padding: 24px; max-width: 340px; }
.ov-box p { margin: 14px 0 0; }
.spinner { width: 34px; height: 34px; margin: 0 auto; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.help-foot { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
#helpOk { margin-top: 12px; padding: 11px; }
#pHelp { top: calc(max(6px, env(safe-area-inset-top)) + 40px); max-height: calc(100% - 52px); }

.steps { color: #c9d1dc; text-align: left; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 0; }
.ghost { margin-top: 12px; padding: 9px 18px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
#guard {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(max(6px, env(safe-area-inset-top)) + 40px);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 16px); padding: 9px 10px 9px 14px;
  border-radius: 14px; background: rgba(60, 42, 8, .94); border: 1px solid rgba(255, 181, 71, .5); color: #ffe2b0;
  font-size: 13px; z-index: 18; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
#guardBtn { flex: none; padding: 8px 12px; border-radius: 10px; border: 0; background: var(--warn); color: #201400; font-weight: 600; font-size: 13px; }
#pubBtn { margin-top: 0; padding: 11px; font-size: 14px; }
