:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #14161a;
  --muted: #646b78;
  --border: #dde1e8;
  --accent: #2f6fed;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --ok: #17924f;
  --warn: #b26b00;
  --danger: #d23b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 20px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --text: #e8eaee;
    --muted: #9198a5;
    --border: #2b3039;
    --accent: #5b8cff;
    --accent-soft: rgba(91, 140, 255, 0.16);
    --ok: #3ccf7f;
    --warn: #f0a838;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; padding-top: max(14px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }

main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px; }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 550; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; padding: 12px; }
.btn:focus-visible, .peer:focus-visible, .me-name:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Stage */
.stage {
  position: relative; min-height: 340px; display: grid; place-items: center;
  border-radius: 20px; overflow: hidden; margin-top: 4px;
}
.radar { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.radar span {
  position: absolute; width: 140px; height: 140px; border-radius: 50%;
  border: 1px solid var(--accent); opacity: 0; animation: ping 4.5s cubic-bezier(.2,.6,.3,1) infinite;
}
.radar span:nth-child(2) { animation-delay: 1.5s; }
.radar span:nth-child(3) { animation-delay: 3s; }
@keyframes ping { 0% { transform: scale(.4); opacity: .5; } 100% { transform: scale(3.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .radar span { animation: none; opacity: .15; } }

.empty { position: relative; text-align: center; color: var(--muted); padding: 24px; }
.empty .big { color: var(--text); font-size: 18px; font-weight: 600; margin: 0 0 6px; }
.empty p { margin: 0; }

.peers {
  position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 18px;
  padding: 28px 8px; width: 100%;
}
.peer {
  position: relative; width: 148px; padding: 16px 12px 12px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .15s, border-color .15s;
  animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.peer:hover { transform: translateY(-2px); border-color: var(--accent); }
.peer.drag { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.04); }
.peer .icon {
  width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
}
.peer .icon svg { width: 28px; height: 28px; }
.peer .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer .meta { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.tag {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag.p2p { color: var(--ok); }
.tag.relay { color: var(--warn); }
.peer .text-btn {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center;
}
.peer .text-btn:hover { background: var(--surface-2); color: var(--text); }
.peer .ring { position: absolute; inset: -1px; border-radius: 18px; pointer-events: none; }

/* Me */
.me {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin: 8px 0 20px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.me-card { display: flex; gap: 12px; align-items: center; min-width: 0; }
.me-icon { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); flex: none; }
.me-icon svg { width: 20px; height: 20px; }
.label { font-size: 12px; color: var(--muted); }
.me-name { border: 0; background: none; padding: 0; font-weight: 600; cursor: pointer; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.rooms { display: flex; gap: 6px; flex-wrap: wrap; }
.room-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); }

/* Transfers */
.transfers h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.transfers ul { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 8px; }
.tx {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
}
.tx .t-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .t-sub { font-size: 13px; color: var(--muted); grid-column: 1; }
.tx .t-actions { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.tx .bar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.tx .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.tx.done .bar i { background: var(--ok); }
.tx.failed .bar i { background: var(--danger); }
.tx .files { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.rfile { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rfile img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; }
.rfile .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rfile .fs { color: var(--muted); font-size: 13px; }
.rfile a.btn { text-decoration: none; padding: 4px 10px; font-size: 13px; }

/* Dialogs */
.dlg {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text);
  width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg-body { padding: 20px; margin: 0; }
.dlg h3 { margin: 0 0 12px; font-size: 18px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.muted { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.pair-grid { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px; align-items: center; }
.pair-grid > div { min-width: 0; }
@media (max-width: 440px) { .pair-grid { grid-template-columns: 1fr; justify-items: center; } .pair-grid > div:last-child { width: 100%; } }
.qr { background: #fff; padding: 8px; border-radius: 10px; line-height: 0; }
.qr svg { width: 140px; height: 140px; display: block; }
.code { font: 700 30px/1.1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .14em; margin-bottom: 10px; }
.link-row { display: flex; gap: 8px; margin-bottom: 10px; }
.link-row .btn { flex: none; }
.link-row input, .dlg textarea {
  flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 8px 10px;
}
.dlg textarea { width: 100%; resize: vertical; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.file-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; display: grid; gap: 4px; }
.file-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.file-list li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list li span:last-child { color: var(--muted); flex: none; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); }
