:root {
  color: #1c2733;
  background: #f2f5f8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(34, 144, 255, .12), transparent 34rem), #f2f5f8;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.shell { width: min(1080px, calc(100% - 32px)); margin: 0 auto; padding: 36px 0 64px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-mark { display: grid; width: 44px; height: 44px; place-items: center; color: #fff; background: #1684e8; border-radius: 12px; font-size: 22px; font-weight: 800; box-shadow: 0 8px 24px rgba(22,132,232,.25); }
h1, h2, p { margin: 0; }
.brand h1 { font-size: 19px; }
.brand p, .help { margin-top: 3px; color: #708090; font-size: 13px; }
.card { background: rgba(255,255,255,.97); border: 1px solid #dfe6ed; border-radius: 18px; box-shadow: 0 18px 55px rgba(45,66,86,.08); }
.compact { width: min(440px, 100%); margin: 8vh auto 0; padding: 32px; }
.compact h2 { margin-top: 5px; }
.eyebrow { color: #1684e8; font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
h2 { font-size: clamp(21px, 3vw, 28px); letter-spacing: -.02em; }
.form-stack { display: grid; gap: 18px; margin-top: 26px; }
label { display: grid; gap: 8px; color: #465564; font-size: 13px; font-weight: 650; }
input { width: 100%; padding: 11px 13px; color: #1c2733; background: #fff; border: 1px solid #cfd9e2; border-radius: 10px; outline: none; }
input:focus { border-color: #1684e8; box-shadow: 0 0 0 3px rgba(22,132,232,.13); }
button { padding: 10px 16px; border: 0; border-radius: 10px; font-weight: 720; }
button:disabled { cursor: not-allowed; opacity: .5; }
.primary { color: #fff; background: #1684e8; }
.primary:hover:not(:disabled) { background: #0874d3; }
.ghost { color: #405162; background: #eaf0f5; }
.danger { color: #b42318; background: #feeceb; }
.help { margin-top: 18px; line-height: 1.6; text-align: center; }
.pending-icon { margin-bottom: 12px; font-size: 38px; text-align: center; }
#pending-view > p { margin-top: 12px; color: #607080; line-height: 1.6; }
.device-summary { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 22px 0; padding: 16px; background: #f4f7f9; border-radius: 12px; }
.device-summary dt { color: #718191; }
.device-summary dd { margin: 0; font-weight: 700; }
.button-row, .account-actions, .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.workspace { width: min(920px, 100%); margin: 0 auto; }
.connection-console { overflow: hidden; }
.topbar { min-height: 66px; padding: 12px 20px; border-bottom: 1px solid #e6edf2; }
.current-summary { display: flex; align-items: center; gap: 10px; min-width: 0; }
.current-summary div { display: grid; gap: 2px; min-width: 0; }
.current-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-summary small { color: #7b8b99; font-size: 11px; }
.online-dot { width: 9px; height: 9px; flex: 0 0 auto; background: #19a463; border: 2px solid #d7f4e5; border-radius: 50%; box-shadow: 0 0 0 3px rgba(25,164,99,.1); }
.account-actions { justify-content: flex-end; color: #607080; font-size: 14px; }
.icon-button, .text-button { color: #607080; background: transparent; }
.icon-button { display: grid; width: 34px; height: 34px; padding: 0; place-items: center; border-radius: 50%; font-size: 20px; }
.icon-button:hover, .text-button:hover { color: #1684e8; background: #edf6fe; }
.text-button { padding: 8px 10px; }
.status { display: inline-flex; padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.status.online, .status.p2p { color: #067647; background: #e8f7ef; }
.status.offline { color: #607080; background: #edf1f4; }
.status.relay { color: #9a6700; background: #fff4ce; }
.status.connecting { color: #125f9f; background: #e5f2ff; }
.topology-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 22px 24px 0; }
.topology-heading h2 { font-size: 18px; }
.topology-heading p { margin-top: 4px; color: #7b8b99; font-size: 12px; }
.device-topology {
  position: relative;
  width: min(calc(100% - 32px), 760px);
  height: 480px;
  margin: 4px auto 0;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(22,132,232,.15) 0, rgba(22,132,232,.06) 24%, transparent 52%),
    radial-gradient(circle, rgba(129,151,170,.22) 1px, transparent 1.5px);
  background-size: auto, 24px 24px;
  border: 0;
}
#device-links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#device-links line { stroke: #aebfce; stroke-width: 2.5; opacity: .72; transition: stroke .2s ease, stroke-width .2s ease, opacity .2s ease; }
#device-links line.selected { stroke: #1684e8; stroke-width: 4; opacity: 1; }
.topology-nodes { position: absolute; inset: 0; }
.topology-node {
  position: absolute;
  display: grid;
  width: 150px;
  justify-items: center;
  gap: 3px;
  padding: 0 8px;
  color: #263746;
  background: transparent;
  border: 0;
  border-radius: 14px;
  text-align: center;
  transform: translate(-50%, -50%);
  z-index: 2;
}
.remote-device-node { cursor: pointer; }
.remote-device-node:hover, .remote-device-node.selected { background: transparent; box-shadow: none; }
.remote-device-node:focus-within { outline: 2px solid #1684e8; outline-offset: 5px; }
.topology-node strong { display: block; max-width: 138px; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.topology-node small { color: #6f8190; font-size: 11px; font-weight: 550; }
.device-node-visual { position: relative; display: grid; width: 80px; height: 80px; place-items: center; }
.device-node-icon {
  position: relative;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  background: #e9f4fd;
  border: 2px solid #b9daf6;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(22,132,232,.12);
  transition: transform .18s ease, box-shadow .18s ease;
  z-index: 2;
}
.device-node-icon svg { width: 32px; height: 32px; fill: #1684e8; }
.remote-device-node:hover .device-node-icon { transform: scale(1.07); box-shadow: 0 9px 24px rgba(22,132,232,.2); }
.current-device-node { width: 170px; }
.device-broadcast {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  --signal-color: rgba(22,132,232,.32);
}
/* PP直连's homepage waveform: 80px, four waves, 5s, ease-in,
   scale .5 -> 1 -> 5.5 and opacity 0 -> 1 -> 0. Keep the element
   mounted across presence polls so the fading tail never resets. */
.device-signal-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80px;
  height: 80px;
  margin: -40px 0 0 -40px;
  border: 1px solid var(--signal-color);
  border-radius: 50%;
  opacity: 0;
  will-change: transform, opacity;
  animation: topology-broadcast 5s ease-in infinite;
  animation-delay: -4.9s;
}
.device-signal-ring:nth-child(2) { animation-delay: -3.65s; }
.device-signal-ring:nth-child(3) { animation-delay: -2.4s; }
.device-signal-ring:nth-child(4) { animation-delay: -1.15s; }
.current-device-node .device-node-icon { width: 72px; height: 72px; color: #fff; background: #1684e8; border-color: #1684e8; box-shadow: 0 10px 28px rgba(22,132,232,.34); }
.current-device-node .device-node-icon svg { width: 40px; height: 40px; fill: #fff; }
.current-device-node small { color: #1684e8; font-weight: 700; }
.remote-device-node.selected .device-node-icon { background: #dcf6e9; border-color: #74cea0; }
.remote-device-node.selected .device-node-icon svg { fill: #07864b; }
.topology-empty { position: absolute; right: 0; bottom: 54px; left: 0; color: #718191; font-size: 13px; text-align: center; }
.topology-instruction { position: absolute; right: 0; bottom: 15px; left: 0; color: #7b8b99; font-size: 12px; text-align: center; pointer-events: none; }
.device-file-picker { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; opacity: 0; cursor: pointer; z-index: 3; touch-action: manipulation; }
.device-file-picker::file-selector-button { cursor: pointer; }
.device-topology.dragging::after { position: absolute; inset: 10px; display: grid; content: "松开以发送文件"; color: #1684e8; background: rgba(237,247,255,.94); border: 2px dashed #1684e8; border-radius: 14px; place-items: center; font-weight: 700; z-index: 5; }
@keyframes topology-broadcast {
  0% { opacity: 0; transform: scale(.5); }
  10% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(5.5); }
}
.activity-section { margin-top: 18px; padding: 16px 22px 20px; border-top: 1px solid #e6edf2; }
.incoming-section { background: #fffaf0; }
.activity-title { display: flex; align-items: baseline; gap: 9px; }
.activity-title strong { font-size: 14px; }
.activity-title span { color: #8493a0; font-size: 11px; }
.transfer-list { display: grid; gap: 8px; margin-top: 10px; }
.transfer-item { padding: 12px 14px; background: #f8fafb; border: 1px solid #e5ebf0; border-radius: 10px; }
.transfer-head, .transfer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.transfer-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfer-meta { margin-top: 5px; color: #718191; font-size: 12px; }
.progress { height: 7px; margin: 12px 0 8px; overflow: hidden; background: #e8edf2; border-radius: 99px; }
.progress span { display: block; width: 0; height: 100%; background: #1684e8; transition: width .2s ease; }
.transfer-foot { color: #607080; font-size: 12px; }
.incoming-actions { display: flex; gap: 8px; margin-top: 12px; }
.empty { padding: 16px 0 2px; color: #8a98a4; font-size: 12px; text-align: center; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100% - 40px)); padding: 13px 16px; color: #fff; background: #213244; border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.toast.error { background: #b42318; }
@media (max-width: 650px) {
  .shell { width: min(100% - 16px, 1080px); padding: 16px 0 36px; }
  .brand { margin: 0 6px 16px; }
  .compact { padding: 24px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .account-actions { gap: 5px; }
  .account-actions > #current-user { display: none; }
  .topology-heading { padding: 18px 16px 0; }
  .topology-heading p { max-width: 270px; }
  .device-topology { width: 100%; height: 400px; }
  .topology-node { width: 112px; padding: 7px 4px; }
  .topology-node strong { max-width: 106px; font-size: 12px; }
  .device-node-visual { width: 68px; height: 68px; }
  .device-node-icon { width: 52px; height: 52px; }
  .device-node-icon svg { width: 28px; height: 28px; }
  .current-device-node { width: 130px; }
  .current-device-node .device-node-icon { width: 64px; height: 64px; }
  .current-device-node .device-node-icon svg { width: 36px; height: 36px; }
  .activity-section { padding-right: 14px; padding-left: 14px; }
  .transfer-head, .transfer-foot { align-items: flex-start; }
}
@media (prefers-color-scheme: dark) {
  :root { color: #eef4fa; background: #11161c; }
  body { background: radial-gradient(circle at top left, rgba(22,132,232,.16), transparent 34rem), #11161c; }
  .card { background: #171d24; border-color: #2a3540; }
  .brand p, .help, #pending-view > p, .account-actions, .transfer-meta, .transfer-foot { color: #9baaba; }
  input { color: #eef4fa; background: #11171d; border-color: #3a4652; }
  label { color: #bec9d3; }
  .ghost, .status.offline { color: #cfdae4; background: #2a3540; }
  .topbar, .activity-section { border-color: #2a3540; }
  .current-summary small, .topology-heading p, .activity-title span { color: #9baaba; }
  .icon-button, .text-button { color: #b5c2ce; }
  .icon-button:hover, .text-button:hover { color: #67b9ff; background: #202d38; }
  .device-topology { background: radial-gradient(circle at center, rgba(22,132,232,.17) 0, rgba(22,132,232,.06) 26%, transparent 54%), radial-gradient(circle, rgba(126,149,169,.2) 1px, transparent 1.5px); background-size: auto, 24px 24px; }
  .topology-node, .remote-device-node:hover, .remote-device-node.selected { color: #eaf1f7; }
  .remote-device-node:hover, .remote-device-node.selected { background: transparent; }
  .topology-node small, .topology-empty, .topology-instruction { color: #9baaba; }
  #device-links line { stroke: #485968; }
  #device-links line.selected { stroke: #43a6ff; }
  .device-topology.dragging::after { color: #67b9ff; background: rgba(24,35,44,.95); border-color: #43a6ff; }
  .device-summary { background: #202a33; }
  .incoming-section { background: #211f18; }
  .transfer-item { background: #1b232b; border-color: #34414d; }
  .progress { background: #34414d; }
}
@media (prefers-reduced-motion: reduce) {
  .device-signal-ring { animation: none; opacity: .5; }
  .device-signal-ring:nth-child(1) { transform: scale(1.5); }
  .device-signal-ring:nth-child(2) { transform: scale(2.5); opacity: .35; }
  .device-signal-ring:nth-child(3) { transform: scale(3.5); opacity: .2; }
  .device-signal-ring:nth-child(4) { transform: scale(4.5); opacity: .05; }
}

[hidden] { display: none !important; }
#management { max-width: 900px; margin: 24px auto; padding: 24px; }
#editor { display: grid; gap: 12px; max-width: 420px; }
#permissions { display: flex; gap: 16px; }
#applications { margin: 16px 0; }
#editor label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: 8px; }
#editor input[type="checkbox"] { width: auto; margin: 0; }
#management h2, #management h3 { margin: 20px 0 12px; }
