:root {
  --bg: #0b1020;
  --bg-soft: #111933;
  --card: rgba(255, 255, 255, 0.04);
  --card-border: rgba(255, 255, 255, 0.09);
  --text: #e7ecf5;
  --text-dim: #9aa6c2;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --accent: #22d3ee;
  --ok: #34d399;
  --danger: #f87171;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f9;
    --bg-soft: #ffffff;
    --card: rgba(15, 23, 42, 0.03);
    --card-border: rgba(15, 23, 42, 0.10);
    --text: #0f172a;
    --text-dim: #5b6b8c;
    --shadow: 0 12px 40px rgba(31, 41, 75, 0.15);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(139, 92, 246, 0.25), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(34, 211, 238, 0.18), transparent 55%),
    var(--bg);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.brand-mark {
  font-size: 22px;
  filter: drop-shadow(0 2px 6px rgba(139, 92, 246, 0.6));
}
.brand-name {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 0.3px;
}

.me {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 14px;
  backdrop-filter: blur(8px);
}
.me-label { color: var(--text-dim); }
.me-avatar { font-size: 18px; }
.me-name { font-weight: 600; }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 18px 120px;
  text-align: center;
}

/* ---------- Peers ---------- */
.peers {
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  justify-content: center;
  align-items: flex-start;
  max-width: 900px;
}

.peer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 120px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  padding: 6px;
  border-radius: 16px;
  transition: transform 0.15s ease;
  position: relative;
}
.peer:hover { transform: translateY(-3px); }
.peer:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.peer-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 38px;
  background: linear-gradient(160deg, rgba(99, 102, 241, 0.35), rgba(34, 211, 238, 0.22));
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  position: relative;
}
.peer-avatar::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.2s ease;
}
.peer:hover .peer-avatar::after { border-color: rgba(34, 211, 238, 0.5); }

.peer.dragover .peer-avatar {
  background: linear-gradient(160deg, rgba(52, 211, 153, 0.5), rgba(34, 211, 238, 0.4));
  transform: scale(1.06);
}
.peer.busy .peer-avatar { animation: pulse 1.2s ease-in-out infinite; }

.peer-name { font-weight: 600; font-size: 14px; }
.peer-sub { font-size: 12px; color: var(--text-dim); min-height: 14px; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(34, 211, 238, 0); }
}

/* ---------- Empty / waiting state ---------- */
.empty { max-width: 460px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.empty[hidden] { display: none; }
.empty h1 { font-size: 22px; margin: 14px 0 2px; }
.empty-sub { color: var(--text-dim); margin: 0 0 18px; line-height: 1.5; }

.radar {
  width: 110px; height: 110px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle, rgba(99,102,241,0.18), transparent 70%);
  position: relative;
}
.radar::before, .radar::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(99, 102, 241, 0.4);
  animation: ripple 2.4s ease-out infinite;
}
.radar::after { animation-delay: 1.2s; }
.radar-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); }
@keyframes ripple {
  0% { width: 18px; height: 18px; opacity: 0.9; }
  100% { width: 110px; height: 110px; opacity: 0; }
}

.connect-card {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  text-align: left;
}
.qr { border-radius: 12px; background: #fff; padding: 6px; display: block; }
.connect-info { display: flex; flex-direction: column; gap: 6px; }
.connect-hint { font-size: 13px; color: var(--text-dim); }
.connect-url {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  word-break: break-all;
}

/* ---------- Connection status ---------- */
.conn-status {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.conn-status[data-state="online"] { color: var(--ok); }
.conn-status[data-state="online"]::before { content: "● "; }
.conn-status[data-state="offline"] { color: var(--danger); }
.conn-status[data-state="connecting"]::before { content: "◌ "; }

/* ---------- Transfers ---------- */
.transfers {
  position: fixed;
  right: 16px;
  bottom: 54px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(340px, calc(100vw - 32px));
  z-index: 6;
}
.transfer {
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  animation: slidein 0.2s ease;
}
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.transfer-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 8px; }
.transfer-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer-meta { color: var(--text-dim); white-space: nowrap; }
.bar { height: 8px; border-radius: 999px; background: rgba(255,255,255,0.10); overflow: hidden; }
.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.12s linear;
}
.transfer.done .bar-fill { background: linear-gradient(90deg, var(--ok), var(--accent)); }
.transfer.failed .bar-fill { background: var(--danger); }
.transfer-dir { font-size: 11px; color: var(--text-dim); }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 18, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  backdrop-filter: blur(4px);
  animation: fade 0.15s ease;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: min(420px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.modal-title span { color: var(--accent); }
.modal-body { color: var(--text-dim); font-size: 14px; line-height: 1.6; margin-bottom: 16px; }
.modal-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.action-buttons { display: flex; gap: 12px; }
.action-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 10px;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.action-btn:hover { transform: translateY(-2px); border-color: var(--accent); }
.action-icon { font-size: 26px; }
.modal-cancel {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
}
.modal-row .modal-cancel { width: auto; margin-top: 0; padding: 10px 16px; }
.btn-primary {
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary:hover { filter: brightness(1.08); }

textarea#text-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--card);
  color: var(--text);
  padding: 12px;
  font: inherit;
  resize: vertical;
}
textarea#text-input:focus { outline: 2px solid var(--primary); }

.text-view-content {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  margin: 0;
  font: 14px/1.5 ui-monospace, Menlo, Consolas, monospace;
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 40;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-left: 3px solid var(--primary);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: slidein 0.2s ease;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }

@media (max-width: 480px) {
  .connect-card { flex-direction: column; text-align: center; }
  .connect-info { align-items: center; }
  .transfers { left: 16px; right: 16px; width: auto; }
}
