:root {
  --bg: #111318;
  --surface: #1b1e25;
  --surface-2: #252932;
  --pad: #16181e;
  --text: #e8eaef;
  --muted: #8b91a0;
  --accent: #4f8cff;
  --ok: #3ccf7a;
  --warn: #f2b84b;
  --err: #f0605d;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: var(--surface-2);
  border-radius: 10px;
  touch-action: manipulation;
}

header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.status { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--err); flex: none; }
.status.wait .dot { background: var(--warn); }
.status.ok .dot { background: var(--ok); }

.modes { display: flex; background: var(--surface); border-radius: 10px; padding: 3px; }
.mode { background: transparent; padding: 6px 8px; font-size: 14px; color: var(--muted); }
.mode.active { background: var(--surface-2); color: var(--text); }

.icon { width: 38px; height: 34px; font-size: 18px; background: var(--surface); }
.icon.active { background: var(--accent); }

/* Bandeau de diagnostic du mode souris (caméra) */
#cam {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 12px 8px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--surface);
}
#cam[hidden] { display: none; }
#cam-preview { width: 42px; height: 56px; border-radius: 8px; background: #000; object-fit: cover; flex: none; }
.cam-info { flex: 1; min-width: 0; font-size: 13px; }
#cam-quality { font-weight: 600; }
#cam-detail { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cam-good { color: var(--ok); }
.cam-ok { color: var(--warn); }
.cam-bad { color: var(--err); }
#cam-calib { padding: 8px 10px; font-size: 13px; flex: none; }
#cam-calib:disabled { opacity: .5; }

#pad {
  flex: 1;
  margin: 0 12px;
  border-radius: var(--radius);
  background: var(--pad);
  border: 1px solid #262a33;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  position: relative;
}
#pad.touching { border-color: #343a47; background: #191c23; }
#pad.gyro-active { border-color: var(--accent); }
#hint { color: var(--muted); text-align: center; font-size: 14px; padding: 0 24px; pointer-events: none; white-space: pre-line; }

#keys {
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
  overflow-x: auto;
}
#keys[hidden] { display: none; }
#keys button { flex: 1 0 auto; padding: 10px 12px; font-size: 14px; }

footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  height: 92px;
}
.mbtn { flex: 1; font-size: 15px; color: var(--muted); background: var(--surface); touch-action: none; }
.mbtn.small { flex: 0 0 52px; }
.mbtn.pressed { background: var(--accent); color: #fff; }

#kbd {
  position: fixed;
  left: -1000px;
  top: 0;
  width: 10px;
  opacity: 0;
  font-size: 16px; /* évite le zoom automatique d'iOS */
}

dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 18px;
  -webkit-user-select: text;
  user-select: text;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
dialog label output { color: var(--text); float: right; }
dialog label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
dialog input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
dialog input[type="range"] { width: 100%; accent-color: var(--accent); }

.pair { background: var(--surface-2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.pair label { color: var(--muted); }
.code { font: 600 26px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 2px; color: var(--text); }
.help { margin: 0; font-size: 13px; color: var(--muted); }
.link { background: none; color: var(--accent); padding: 0; text-align: left; font-size: 14px; text-decoration: none; }

/* Page d'accueil affichée sur ordinateur */
#desktop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 48px 16px;
  -webkit-user-select: text;
  user-select: text;
}
#desktop[hidden] { display: none; }
.landing { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 16px; }
.landing img { border-radius: 16px; }
.landing h1 { margin: 0; font-size: 32px; }
.tagline { margin: 0; color: var(--muted); font-size: 17px; }
.download { display: block; text-align: center; text-decoration: none; border-radius: 10px; font-size: 16px; }
.download:hover { filter: brightness(1.1); }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; line-height: 1.5; }
.steps code, .help code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 14px; }
.landing .link { font-size: 14px; align-self: flex-start; cursor: pointer; }
.primary { background: var(--accent); color: #fff; padding: 12px; font-weight: 600; }
