:root {
  --bg: #101114;
  --surface: #1a1c21;
  --surface-2: #24272e;
  --line: #2e323a;
  --text: #eceef2;
  --muted: #9097a3;
  --accent: #5b8cff;
  --accent-ink: #ffffff;
  --me: #2f5bd3;
  --them: #262a32;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  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);
}

/* ---------- écrans ---------- */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  position: relative;
}
.screen.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}
h1 { font-size: 22px; font-weight: 600; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
.logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 4px; }
.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin-top: 16px; }
.back { position: absolute; top: 12px; left: 8px; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  font-weight: 600;
  background: var(--surface-2);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  font-size: 20px;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--surface-2); }

/* ---------- code ---------- */
.code-input {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  letter-spacing: .05em;
}
.code-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.scanner { position: relative; width: 100%; max-width: 320px; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; background: #000; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .8); border-radius: 16px; }

/* ---------- NIP ---------- */
.pin { gap: 16px; justify-content: flex-end; padding-bottom: 32px; }
.pin-title { min-height: 1em; }
.pin-sub { max-width: 300px; font-size: 14px; }
.dots { display: flex; gap: 14px; height: 18px; align-items: center; margin-top: 12px; }
.dots span { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s; }
.dots span.on { background: var(--text); border-color: var(--text); }
.busy .dots span { animation: pulse 1s infinite ease-in-out; }
.dots.shake { animation: shake .35s; }
.pin-err { color: var(--danger); min-height: 1.4em; font-size: 14px; }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 26px; margin-top: 8px; }
.keypad button {
  height: 76px;
  border-radius: 50%;
  border: 0;
  background: var(--surface);
  font-size: 28px;
  font-weight: 400;
  touch-action: manipulation;
}
.keypad button:active { background: var(--surface-2); }
.keypad [data-k=del] { background: transparent; font-size: 24px; color: var(--muted); }
.keypad .ok { background: transparent; color: var(--accent); font-size: 30px; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- avis ---------- */
.notice-ico {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--danger); color: #fff; font-size: 34px; font-weight: 700;
}
.notice-ico.ok { background: var(--ok); }
.screen.center > p.muted { max-width: 340px; }

/* ---------- jumelage ---------- */
.qr { width: min(260px, 70vw); aspect-ratio: 1; background: #fff; border-radius: 12px; padding: 8px; image-rendering: pixelated; }
.qr.expired { opacity: .15; }
.pair-code { font-size: 15px; word-break: break-all; max-width: 320px; }
.pair-done { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.fp { font-size: 22px; font-weight: 600; }

/* ---------- iOS ---------- */
.steps { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 14px; text-align: left; max-width: 340px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); padding: 12px 14px; border-radius: 12px; }
.step-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.share-ico { width: 20px; height: 20px; vertical-align: -4px; color: var(--accent); }
.arrow-down { font-size: 34px; color: var(--accent); margin-top: 18px; animation: bob 1.4s infinite ease-in-out; }
@keyframes bob { 50% { transform: translateY(8px); } }
.ios-other { display: flex; flex-direction: column; gap: 14px; align-items: center; }

/* ---------- conversation ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px 6px 16px;
  border-bottom: 1px solid var(--line);
}
.chat-title { flex: 1; font-weight: 600; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 8px; }
.status-dot.on { background: var(--ok); }
.chat-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: var(--surface); color: var(--muted); font-size: 14px;
}
.msgs {
  flex: 1; overflow-y: auto; padding: 12px 12px 4px;
  display: flex; flex-direction: column; gap: 6px;
  overscroll-behavior: contain;
}
.empty { margin: auto; }
.msg {
  max-width: 80%;
  padding: 8px 12px 6px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.me { align-self: flex-end; background: var(--me); border-bottom-right-radius: 6px; }
.msg.them { align-self: flex-start; background: var(--them); border-bottom-left-radius: 6px; }
.msg.err .text { font-style: italic; color: var(--muted); }
.msg .text { white-space: pre-wrap; }
.meta { display: flex; justify-content: flex-end; gap: 8px; font-size: 11px; opacity: .7; margin-top: 2px; }
.eph-label:empty { display: none; }
.seen { font-weight: 600; }

.composer {
  border-top: 1px solid var(--line);
  padding: 8px 10px 10px;
  display: flex; flex-direction: column; gap: 6px;
}
.composer.disabled { opacity: .45; pointer-events: none; }
.eph-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); padding: 0 4px; }
.eph-toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.eph-toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
.eph-sel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; font-size: 14px; }
.eph-sel:disabled { opacity: .4; }
.send-row { display: flex; align-items: flex-end; gap: 8px; }
.input {
  flex: 1; resize: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 9px 14px;
  max-height: 140px;
  line-height: 1.35;
  font-size: 16px;
}
.input:focus { outline: none; border-color: var(--accent); }
.send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; display: grid; place-items: center;
}
.send svg { width: 20px; height: 20px; }

/* ---------- feuille de paramètres ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 10;
}
.sheet {
  width: 100%; max-width: 480px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 8px 8px calc(12px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.set-fp { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 14px; }
.set-fp .fp { font-size: 17px; }
.row {
  text-align: left; border: 0; background: transparent;
  padding: 15px 14px; border-radius: 10px;
}
.row:active { background: var(--surface-2); }
.row.danger { color: var(--danger); }

/* ---------- divers ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--surface-2); color: var(--text);
  padding: 10px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); z-index: 30;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  font-size: 14px; text-align: center;
}
.install-banner {
  position: fixed; left: 8px; right: 8px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); padding: 10px 6px 10px 12px;
  border-radius: 14px; z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  font-size: 14px;
}
.install-banner img { width: 32px; height: 32px; border-radius: 8px; }
.install-banner span { flex: 1; }

.dlg {
  border: 0; border-radius: 16px; padding: 20px;
  background: var(--surface); color: var(--text);
  width: min(340px, calc(100% - 32px));
}
.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- pages /ecrire et /lire (hors app) ---------- */
.note-page {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.note-card {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.note-card.center { align-items: center; text-align: center; justify-content: center; }
.note-card .stack { max-width: none; }
.note-text {
  width: 100%;
  resize: vertical;
  min-height: 140px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.4;
}
.note-text:focus { outline: none; border-color: var(--accent); }
.note-opts { display: flex; align-items: center; gap: 10px; }
.note-count { margin-left: auto; }
.note-result { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 6px; }
.note-result .qr { width: min(300px, 80vw); }
.note-result .qr.dead { opacity: .12; }
.note-status { text-align: center; }
.note-status.ok { color: var(--ok); font-weight: 600; }
.note-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.danger-text { color: var(--danger); }
.link-btn { background: none; border: 0; padding: 8px; align-self: center; text-decoration: underline; }
.note-msg {
  width: 100%;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  font-size: 17px;
}
.reply-form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; text-align: left; }
.reply-text { min-height: 90px; }
.reply-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reply-done { color: var(--ok); font-weight: 600; }
