:root {
  --bg: #0f0c1d;
  --bg2: #17132b;
  --card: #1f1a38;
  --line: #2e2752;
  --text: #f2effc;
  --muted: #a39cc4;
  --accent: #8b5cf6;
  --accent2: #ec4899;
  --mine: linear-gradient(135deg, #8b5cf6, #d946ef);
  --theirs: #262046;
  --danger: #f43f5e;
  --ok: #34d399;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  /* Anti-copie : aucune sélection, pas de menu « enregistrer l’image » */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, .selectable { -webkit-user-select: text; user-select: text; }
img, canvas { -webkit-user-drag: none; pointer-events: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1em; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; height: 100dvh; }

/* ---------- Accueil ---------- */
#onboard { align-items: center; justify-content: center; padding: 24px; background: radial-gradient(circle at 30% 10%, #2a1d55, var(--bg) 60%); }
.onboard-card { width: 100%; max-width: 380px; text-align: center; }
.logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 10px 40px #8b5cf655; }
.onboard-card h1 { margin: 16px 0 6px; font-size: 28px; }
.onboard-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; text-align: left; }
.onboard-card label { font-size: 14px; color: var(--muted); }
.field { width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 17px; outline: none; }
.field:focus { border-color: var(--accent); }

.btn { padding: 12px 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px; }
.btn.primary { background: var(--mine); border: 0; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Verrou ---------- */
#lock { align-items: center; justify-content: center; background: var(--bg); z-index: 50; }
.lock-box { text-align: center; }
.lock-icon { font-size: 42px; }
.pin-dots { display: flex; gap: 16px; justify-content: center; margin: 18px 0 28px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--text); border-color: var(--text); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 16px; }
.keypad button { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--card); font-size: 26px; }
.keypad button:active { background: var(--line); }
.keypad .ghost { background: transparent; font-size: 18px; }

/* ---------- Conversation ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 12px 10px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--mine); display: grid; place-items: center; font-weight: 700; position: relative; flex: none; }
.avatar.online::after { content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg2); }
.who { flex: 1; min-width: 0; }
.who .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .status { font-size: 13px; color: var(--muted); }
.who .status.typing { color: var(--accent2); }
.icon-btn { background: transparent; border: 0; font-size: 20px; width: 40px; height: 40px; border-radius: 12px; flex: none; }
.icon-btn:active { background: var(--card); }

.banner { margin: 8px 12px 0; padding: 10px 14px; border-radius: 12px; background: #2b2150; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner span { flex: 1; }
.banner button { margin-left: auto; padding: 6px 12px; border-radius: 10px; border: 0; background: var(--accent); font-weight: 600; font-size: 13px; flex: none; }

.list { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 6px; -webkit-overflow-scrolling: touch; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; max-width: 260px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

.msg { max-width: 78%; display: flex; flex-direction: column; animation: pop .18s ease-out; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.bubble { padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.mine .bubble { background: var(--mine); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; }
.bubble.photo { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.theirs .bubble.photo.new { background: transparent; border: 2px solid var(--accent2); color: var(--accent2); cursor: pointer; }
.bubble.photo.done { opacity: .6; font-weight: 500; }
.meta { font-size: 11px; color: var(--muted); margin: 3px 6px 0; display: flex; gap: 6px; }
.meta .cd { color: var(--accent2); font-variant-numeric: tabular-nums; }
.msg.fading { animation: fade .5s forwards; }
@keyframes fade { to { opacity: 0; transform: scale(.9); filter: blur(6px); } }

.waiting { position: absolute; inset: 70px 0 80px; display: flex; align-items: center; justify-content: center; padding: 20px; pointer-events: none; }
.waiting-card { pointer-events: auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 22px; text-align: center; max-width: 360px; width: 100%; }
.waiting-card .big { font-size: 40px; }
.waiting-card h2 { margin: 8px 0 4px; font-size: 19px; }
.invite-box { margin: 14px 0; padding: 12px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); font-size: 13px; word-break: break-all; font-family: ui-monospace, Menlo, monospace; }
.waiting-card .row { justify-content: center; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--bg2); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 120px; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px; outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.timer-btn { height: 40px; padding: 0 10px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); font-size: 12px; white-space: nowrap; flex: none; }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--mine); font-size: 18px; flex: none; }
.send:disabled { opacity: .4; }
.composer.disabled { opacity: .4; pointer-events: none; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; background: #000; z-index: 40; display: flex; align-items: center; justify-content: center; }
.overlay canvas { max-width: 100%; max-height: 100%; }
#viewer { cursor: pointer; }
.ring { position: absolute; top: calc(16px + var(--safe-t)); right: 16px; width: 36px; height: 36px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.5; }
#ring-bg { stroke: #ffffff33; }
#ring-fg { stroke: #fff; stroke-dasharray: 100.53; stroke-linecap: round; }
.viewer-hint { position: absolute; bottom: calc(20px + var(--safe-b)); color: #fff9; font-size: 13px; }
.preview-bar { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 14px calc(14px + var(--safe-b)); display: flex; gap: 10px; align-items: center; justify-content: space-between; background: linear-gradient(transparent, #000d); }
.seg { display: flex; background: #ffffff1a; border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font-size: 14px; }
.seg button.on { background: #fff; color: #000; font-weight: 700; }

.sheet-wrap { position: fixed; inset: 0; background: #0009; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; background: var(--bg2); border-radius: 22px 22px 0 0; padding: 16px 18px calc(24px + var(--safe-b)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font-size: 20px; }
.group { padding: 14px 0; border-bottom: 1px solid var(--line); }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 6px; font-size: 16px; }
.group p { margin: 0 0 10px; }
.fingerprint { font-size: 26px; letter-spacing: 4px; text-align: center; padding: 10px; background: var(--bg); border-radius: 12px; }
body:not(.owner) .owner-only { display: none; }

/* Voile de confidentialité quand l'appli perd le focus (capture, multitâche…) */
.veil { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; font-size: 56px; }

.toast { position: fixed; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); background: #2b2150; border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 60; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 8px 30px #0008; }

@media print { body { display: none !important; } }

.banner button.ghost { background: transparent; padding: 6px 4px; margin-left: 0; }

/* Photo visible uniquement pendant l'appui */
#viewer { touch-action: none; }
#viewer canvas { visibility: hidden; }
#viewer.held canvas { visibility: visible; }
#viewer .viewer-hint { display: none; }
#viewer.held .viewer-hint { display: block; }
#viewer.held .viewer-hold, #viewer.held .viewer-close { display: none; }
.viewer-hold { position: absolute; color: #fffc; text-align: center; font-size: 16px; line-height: 1.5; pointer-events: none; }
.viewer-hold .big { font-size: 48px; margin-bottom: 10px; }
.viewer-close { position: absolute; top: calc(14px + var(--safe-t)); left: 14px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: #ffffff22; color: #fff; font-size: 18px; }

/* Accueil : étapes d'installation sur iPhone */
#ob-text { white-space: pre-line; text-align: left; display: inline-block; font-size: 16px; line-height: 1.7; }
.ob-field { display: flex; flex-direction: column; gap: 10px; }
.ob-copy { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* Installation obligatoire */
#install { align-items: center; justify-content: center; padding: 24px 20px 90px; background: radial-gradient(circle at 30% 10%, #2a1d55, var(--bg) 60%); overflow-y: auto; }
.install { width: 100%; max-width: 400px; text-align: center; }
.install h1 { margin: 14px 0 6px; font-size: 26px; }
.install .logo { width: 76px; height: 76px; }
.steps { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.steps li { display: flex; gap: 14px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; font-size: 16px; line-height: 1.45; }
.steps small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.steps .num { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--mine); display: grid; place-items: center; font-weight: 800; }
.ico { width: 22px; height: 22px; vertical-align: -5px; color: #60a5fa; margin: 0 2px; }
.btn.big { width: 100%; padding: 16px; font-size: 17px; margin-top: 22px; }
.warn { background: #3b1d2a; border: 1px solid var(--danger); border-radius: 14px; padding: 14px; margin: 22px 0 0; text-align: left; line-height: 1.5; }
.in-note { margin-top: 18px; padding: 12px 14px; border-radius: 14px; background: #2b2150; font-size: 14px; }
.arrow-down { position: fixed; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); font-size: 34px; color: #60a5fa; animation: bounce 1.2s infinite; }
@keyframes bounce { 50% { transform: translate(-50%, 10px); } }
.pulse { color: var(--text); animation: pulse .6s 3; }
@keyframes pulse { 50% { opacity: .3; } }
