/* ============================================================
   App shell: top bar, radar stage, footer, overlays.

   The stage keeps a 1:1 ratio using aspect-ratio where available
   and a padding-top fallback elsewhere, so it never collapses or
   distorts on older engines.
   ============================================================ */

body {
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 4vw, 28px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--gradient-accent);
  color: #fff;
  box-shadow: var(--glow);
}

.brand-mark svg {
  width: 16px;
  height: 16px;
}

.topbar-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Stage ---------- */

/*
  The wrap is a centered flex column: the square stage on top and the
  intro copy below it in normal flow. Keeping the copy in flow means
  hiding it never moves the stage.
*/
.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  padding: 32px 16px 64px;
}

.stage {
  position: relative;
  width: 92vw;
  max-width: 620px;
}

/* Modern engines: a clean square via aspect-ratio. */
@supports (aspect-ratio: 1 / 1) {
  .stage {
    aspect-ratio: 1 / 1;
  }
}

/* Fallback: the classic padding-top trick forces a 1:1 box everywhere. */
@supports not (aspect-ratio: 1 / 1) {
  .stage {
    height: 0;
    padding-top: 100%;
  }
}

.beams {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/*
  Nodes sit above both the radar and the beams. An explicit z-index keeps
  the stacking deterministic regardless of DOM order or engine quirks.
*/
.nodes {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
}

/* ---------- Intro copy ---------- */

/*
  No fixed min-height here on purpose: the element sizes to its real
  content, and hiding uses visibility, which preserves that height so
  the stage never shifts when devices appear or disappear.
*/
.stage-copy {
  width: 100%;
  max-width: 480px;
  text-align: center;
  transition: opacity var(--speed-med) ease;
}

.stage-copy h1 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stage-copy p {
  margin-top: 6px;
  font-size: 0.95rem;
  color: var(--text-2);
}

.stage-copy .stage-tip {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--text-3);
}

/* Hide the copy once devices are present, but keep its space reserved. */
.stage-wrap.has-peers .stage-copy {
  opacity: 0;
  visibility: hidden;
}

/* ---------- Footer ---------- */

.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 28px) 16px;
  font-size: 0.8rem;
  color: var(--text-3);
}

.foot-right {
  display: flex;
  align-items: center;
  gap: 10px;
  /* Prevent the right-hand cluster from forcing horizontal overflow. */
  min-width: 0;
}

/*
  The live transfer chip can hold long strings ("Sending · 42% · 12.3 MB/s").
  Clamp it so it truncates instead of overflowing on narrow screens.
*/
.transfer-chip {
  max-width: 60vw;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Drag & drop overlay ---------- */

.drop-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 20, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--speed-med) ease;
}

.drop-overlay.visible {
  opacity: 1;
}

.drop-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 48px 64px;
  text-align: center;
  border: 2px dashed var(--accent-b);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.drop-icon svg {
  width: 52px;
  height: 52px;
  color: var(--accent-a);
}

.drop-card strong {
  font-family: var(--font-display);
  font-size: 1.4rem;
}

.drop-card span:not(.drop-icon) {
  max-width: 320px;
  font-size: 0.9rem;
  color: var(--text-2);
}

/* ---------- Mount points ---------- */

.modal-root,
.toast-root {
  position: fixed;
  z-index: 90;
}

.modal-root {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
}

.toast-root {
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  :root {
    --node-size: 78px;
    --node-avatar: 50px;
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
  }

  .brand-name {
    display: none;
  }

  .stage-wrap {
    gap: 28px;
    padding-bottom: 48px;
  }

  .foot {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }

  /* Let the chip use more of the row now that the footer stacks. */
  .transfer-chip {
    max-width: 90vw;
  }

  .toast-root {
    left: 16px;
    right: 16px;
    bottom: 64px;
  }

  .drop-card {
    padding: 32px 28px;
    margin: 0 20px;
  }
}