:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #121a2e;
  --muted: #64708f;
  --line: #e3e8f2;
  --accent: #4f6bff;
  --accent-2: #8b5cf6;
  --ok: #16a34a;
  --bad: #dc2626;
  --soft: #eef1ff;
  --shadow: 0 10px 40px rgba(20, 30, 70, .18);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #141a2e;
    --text: #e8ecf8;
    --muted: #9aa4c4;
    --line: #232b45;
    --soft: #1c2440;
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { font-size: 12px; background: var(--soft); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 18px; margin: 8px 0 4px; }

/* ---------- en-tête */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: .01em; flex: none; }
.brand b { color: var(--accent-2); font-weight: 800; }
.me {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; cursor: pointer;
  font-size: 13px;
}
.me-label { color: var(--muted); }
#me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.me svg { color: var(--muted); flex: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; }
.me.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }

main { max-width: 760px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px; }

/* ---------- radar */
.radar-card { position: relative; overflow: hidden; }
.radar { position: absolute; left: 50%; top: 58%; width: 0; height: 0; pointer-events: none; }
.radar i {
  position: absolute; left: -260px; top: -260px; width: 520px; height: 520px; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent) 35%, transparent);
  animation: ping 4.5s ease-out infinite; opacity: 0;
}
.radar i:nth-child(2) { animation-delay: 1.5s; }
.radar i:nth-child(3) { animation-delay: 3s; }
@keyframes ping { 0% { transform: scale(.15); opacity: .9; } 100% { transform: scale(1); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .radar i { animation: none; } }

.peers { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 10px; padding: 26px 0 10px; min-height: 150px; align-content: center; }
.peer {
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: 104px;
  border: 0; background: none; cursor: pointer; padding: 6px 4px; border-radius: 16px;
  transition: transform .15s;
}
.peer:hover .avatar { transform: translateY(-2px); }
.peer:active { transform: scale(.95); }
.peer.target .avatar { box-shadow: 0 0 0 4px var(--accent), var(--shadow); transform: scale(1.06); }
.peer-name { font-weight: 600; font-size: 14px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-sub { font-size: 12px; color: var(--muted); margin-top: -4px; }
.peers-empty { position: relative; text-align: center; padding: 16px 8px 4px; }
.peers-empty p { margin: 6px 0; }
.hint { position: relative; text-align: center; margin: 4px 0 0; }

.avatar {
  width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; box-shadow: 0 6px 20px rgba(40, 50, 120, .25); transition: transform .15s, box-shadow .15s;
}
.avatar svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar.sm { width: 40px; height: 40px; box-shadow: none; }
.avatar.md { width: 48px; height: 48px; box-shadow: none; }
.avatar.lg { width: 84px; height: 84px; }

.qr { width: 200px; height: 200px; background: #fff; border-radius: 14px; padding: 8px; display: block; margin: 0 auto 8px; }

/* ---------- listes */
.list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.list:empty { display: none; }
.list.nested { margin: 8px 0 0; padding-left: 12px; border-left: 2px solid var(--line); }
.empty { color: var(--muted); margin: 8px 0 0; font-size: 14px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: var(--soft); min-width: 0; }
.transfer > .item { background: transparent; padding: 4px 0; }
.transfer { padding: 10px 12px; border-radius: 14px; background: var(--soft); }
.transfer.done > .item .sub { color: var(--ok); }
.transfer.declined > .item .sub, .transfer.failed > .item .sub, .transfer.expired > .item .sub { color: var(--bad); }
.transfer .nested .item { background: var(--card); }
.thumb {
  width: 48px; height: 48px; border-radius: 10px; flex: none; overflow: hidden;
  display: grid; place-items: center; background: var(--card); color: var(--muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase; text-decoration: none; border: 1px solid var(--line);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grow { flex: 1; min-width: 0; }
.name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 6px; flex: none; align-items: center; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }
.text-box { margin-top: 8px; padding: 10px 12px; border-radius: 12px; background: var(--card); display: grid; gap: 8px; }
.text-body { white-space: pre-wrap; word-break: break-word; margin: 0; }
.text-body a { color: var(--accent); }

details summary { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
.summary-title { font-weight: 700; font-size: 17px; }
.summary-title::before { content: '▸'; display: inline-block; width: 18px; color: var(--muted); transition: transform .15s; }
details[open] .summary-title::before { transform: rotate(90deg); }
.dir-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- boutons */
.btn {
  border: 0; border-radius: 12px; padding: 0 16px; min-height: 42px; font-weight: 600;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn.ghost { background: var(--soft); color: var(--text); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- fenêtres */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 12, 28, .5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
.overlay.center { align-items: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(520px, 100%); background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; box-shadow: var(--shadow); animation: up .22s cubic-bezier(.2, .9, .3, 1);
}
@media (min-width: 640px) { .overlay:not(.center) { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-title { font-weight: 700; font-size: 18px; }
.choice {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 16px; border-radius: 16px; border: 1px solid var(--line); cursor: pointer; color: var(--accent);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 9%, transparent), color-mix(in srgb, var(--accent-2) 9%, transparent));
}
.choice > span { display: grid; color: var(--text); }
.choice svg { flex: none; }
.choices { display: grid; gap: 10px; }
@media (min-width: 480px) { .choices:has(> .choice + .choice:not([hidden])) { grid-template-columns: 1fr 1fr; } }
.tip { margin: -2px 2px 0; line-height: 1.4; }
.folder-thumb { color: #f5b301; background: color-mix(in srgb, #f5b301 12%, var(--card)); }
.more { padding: 2px 10px; }
.text-form { display: flex; gap: 8px; }
.text-form textarea {
  flex: 1; min-width: 0; resize: vertical; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
.dialog {
  width: min(380px, 100%); background: var(--card); border-radius: 22px; padding: 22px 18px 18px;
  text-align: center; box-shadow: var(--shadow); animation: pop .2s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.in-avatar { display: flex; justify-content: center; margin-bottom: 6px; }
.in-files { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.in-files li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.manual { margin: 12px 0; padding: 12px; border-radius: 14px; background: var(--soft); display: grid; gap: 6px; justify-items: center; }
.manual p { margin: 0; }
.addr code { font-size: 15px; font-weight: 600; padding: 6px 10px; background: var(--card); user-select: all; }
.pair-code { font: 700 32px/1.1 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .3em; padding-left: .3em; color: var(--accent); }
.link.inline { padding: 0; font-size: inherit; }
.ip-row { display: block; text-align: left; margin-bottom: 12px; }
.ip-row select { display: block; width: 100%; margin-top: 4px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); z-index: 30; text-align: center;
}

@media (max-width: 420px) {
  .me-label { display: none; }
  .peer { width: 92px; }
}

/* ---------- galerie plein écran */
body.viewer-open { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .96); color: #fff;
  display: block; user-select: none; -webkit-user-select: none; animation: fade .18s ease;
}
.viewer svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viewer svg .fill { fill: currentColor; stroke: none; }
.v-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 24px;
  background: linear-gradient(rgba(0, 0, 0, .65), transparent); transition: opacity .2s;
}
.v-title { flex: 1; min-width: 0; text-align: center; }
.v-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-count { font-size: 12px; opacity: .7; }
.v-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; flex: none;
  background: rgba(255, 255, 255, .14); color: #fff; cursor: pointer; text-decoration: none;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.v-btn:active { transform: scale(.94); }
.v-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; }
.v-slide { position: absolute; inset: 0; display: grid; place-items: center; will-change: transform; }
.v-slide.from-right { animation: vin-r .24s cubic-bezier(.2, .9, .3, 1); }
.v-slide.from-left { animation: vin-l .24s cubic-bezier(.2, .9, .3, 1); }
.v-slide.bump-left { animation: bump-l .3s ease; }
.v-slide.bump-right { animation: bump-r .3s ease; }
@keyframes vin-r { from { transform: translateX(28%); opacity: 0; } }
@keyframes vin-l { from { transform: translateX(-28%); opacity: 0; } }
@keyframes bump-l { 40% { transform: translateX(-24px); } }
@keyframes bump-r { 40% { transform: translateX(24px); } }
.v-img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; transform-origin: center; -webkit-user-drag: none; }
.v-nav {
  position: absolute; top: 50%; z-index: 3; transform: translateY(-50%);
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .14); color: #fff; transition: opacity .2s, background .2s;
}
.v-nav:hover { background: rgba(255, 255, 255, .26); }
.v-prev { left: 16px; }
.v-next { right: 16px; }
@media (hover: none) { .v-nav { display: none; } }
.v-hint {
  position: absolute; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 3; margin: 0;
  font-size: 13px; padding: 7px 12px; border-radius: 999px; background: rgba(255, 255, 255, .14); white-space: nowrap; transition: opacity .2s;
}
.viewer.ui-off .v-top, .viewer.ui-off .v-nav, .viewer.ui-off .v-hint { opacity: 0; pointer-events: none; }
.v-spinner {
  position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px; z-index: 2;
  border: 3px solid rgba(255, 255, 255, .25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.v-error { text-align: center; max-width: 320px; padding: 20px; }
.v-error p { opacity: .85; line-height: 1.5; }
.v-error-btn { display: inline-block; margin-top: 8px; padding: 10px 16px; border-radius: 12px; color: #fff; text-decoration: none; font-weight: 600; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* ---------- lecteur vidéo */
.vp { position: relative; width: 100%; height: 100%; display: grid; place-items: center; background: #000; }
.vp video { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; display: block; }
.vp:fullscreen { width: 100vw; height: 100vh; }
.vp-big {
  position: absolute; left: 50%; top: 50%; width: 76px; height: 76px; margin: -38px 0 0 -38px; z-index: 2;
  border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 40px rgba(79, 107, 255, .45);
  transition: opacity .2s, transform .2s;
}
.vp-big svg { width: 34px; height: 34px; margin-left: 4px; }
.vp.playing .vp-big { opacity: 0; transform: scale(.8); pointer-events: none; }
.vp-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; align-items: center; gap: 8px;
  padding: 28px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .75)); transition: opacity .25s;
}
.vp.playing:not(.show) .vp-bar { opacity: 0; pointer-events: none; }
.vp.playing:not(.show) { cursor: none; }
.vp-btn {
  width: 38px; height: 38px; border: 0; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: transparent; color: #fff; cursor: pointer; font: 700 13px system-ui, sans-serif;
}
.vp-btn:hover { background: rgba(255, 255, 255, .14); }
.vp-speed { width: auto; min-width: 38px; padding: 0 6px; border-radius: 10px; }
.vp-time { font: 600 12px ui-monospace, Menlo, Consolas, monospace; opacity: .9; flex: none; min-width: 36px; text-align: center; }
.vp-range {
  --p: 0%; flex: 1; min-width: 60px; height: 22px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
.vp-range::-webkit-slider-runnable-track {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent) 0, var(--accent-2) var(--p), rgba(255, 255, 255, .3) var(--p));
}
.vp-range::-moz-range-track { height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .3); }
.vp-range::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--accent); }
.vp-range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5.5px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 107, 255, .35);
}
.vp-range::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: #fff; }
.vp-flash {
  position: absolute; top: 50%; z-index: 2; transform: translateY(-50%); display: flex; align-items: center; gap: 4px;
  padding: 12px 16px; border-radius: 999px; background: rgba(255, 255, 255, .16); font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none;
}
.vp-flash.left { left: 12%; }
.vp-flash.right { right: 12%; }
.vp-flash.on { animation: flash-seek .6s ease; }
@keyframes flash-seek { 15%, 60% { opacity: 1; } 100% { opacity: 0; } }
@media (max-width: 420px) { .vp-mute { display: none; } .vp-bar { gap: 4px; } }

/* ---------- vignettes cliquables */
button.thumb { padding: 0; cursor: pointer; font: inherit; color: var(--muted); position: relative; }
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.play-badge {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 14px;
  background: rgba(0, 0, 0, .25); text-shadow: 0 1px 4px rgba(0, 0, 0, .6);
}
.name.clickable { cursor: pointer; }
.name.clickable:hover { color: var(--accent); }

/* ---------- icônes Phosphor (public/icons, licence MIT) : <i class="pi" style="--i:url(/icons/nom.svg)"> */
.pi {
  display: inline-block; width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.22em;
  background: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat;
}
.avatar .pi { width: 34px; height: 34px; }
.avatar.sm .pi { width: 20px; height: 20px; }
.avatar.md .pi { width: 24px; height: 24px; }
.avatar.lg .pi { width: 42px; height: 42px; }
.viewer .pi { width: 24px; height: 24px; }
.vp-big .pi { width: 34px; height: 34px; margin-left: 4px; }

/* ---------- l'historique reste dans son cadre (noms, liens et textes très longs) */
.list { grid-template-columns: minmax(0, 1fr); }
.list > li, .transfer, .item, .grow, .text-box { min-width: 0; }
.transfer { overflow: hidden; }
.name { max-width: 100%; }
.sub, .text-body, .in-files li { overflow-wrap: anywhere; word-break: break-word; }
.text-box { grid-template-columns: minmax(0, 1fr); }
.text-body a { overflow-wrap: anywhere; }
.item > .actions { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 420px) {
  .transfer > .item { flex-wrap: wrap; }
  .transfer > .item > .actions { margin-left: auto; }
  .list.nested .item .actions .btn { padding: 0 10px; }
}
.speed { font-weight: 700; color: var(--accent); white-space: nowrap; }
