/* ---------- Fonts ---------- */
@font-face { font-family: "Helvetica Now Display"; src: url("fonts/HelveticaNowDisplay-Medium.otf") format("opentype"); font-weight: 500 600; font-display: swap; }
@font-face { font-family: "Helvetica Now Display"; src: url("fonts/HelveticaNowDisplay-Bold.otf") format("opentype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Helvetica Now Text"; src: url("fonts/HelveticaNowText-Regular.otf") format("opentype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Helvetica Now Text"; src: url("fonts/HelveticaNowText-Medium.otf") format("opentype"); font-weight: 500 600; font-display: swap; }
@font-face { font-family: "Helvetica Now Text"; src: url("fonts/HelveticaNowText-Bold.otf") format("opentype"); font-weight: 700; font-display: swap; }

/* ---------- Tokens ---------- */
:root {
  /* Black and white only. In dark mode the two simply trade places. */
  --accent: #000000;
  --accent-text: #000000;
  --accent-ink: #ffffff;       /* text on accent fills */

  --bg: #ffffff;
  --surface: #ffffff;
  --fill: rgba(0, 0, 0, 0.05);
  --text: #000000;
  --text-2: rgba(0, 0, 0, 0.5);
  --separator: rgba(0, 0, 0, 0.12);
  --material: rgba(255, 255, 255, 0.78);
  --material-edge: rgba(0, 0, 0, 0.08);
  --scrim: rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.14);
  --danger: rgba(0, 0, 0, 0.5);
  --ring: rgba(0, 0, 0, 0.09);
  --trail: rgba(0, 0, 0, 0.1);

  /* Helvetica Now served from /fonts; Helvetica Neue / Arial only while loading. */
  --font-display: "Helvetica Now Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-text: "Helvetica Now Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #ffffff;
    --accent-text: #ffffff;
    --accent-ink: #000000;
    --bg: #000000;
    --surface: #000000;
    --fill: rgba(255, 255, 255, 0.08);
    --text: #ffffff;
    --text-2: rgba(255, 255, 255, 0.5);
    --separator: rgba(255, 255, 255, 0.16);
    --material: rgba(16, 16, 16, 0.78);
    --material-edge: rgba(255, 255, 255, 0.12);
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 0 0 1px rgba(255, 255, 255, 0.16);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.7);
    --danger: rgba(255, 255, 255, 0.5);
    --ring: rgba(255, 255, 255, 0.12);
    --trail: rgba(255, 255, 255, 0.14);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.47 var(--font-text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; letter-spacing: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* Press feedback lands on pointer-down and is instant. */
.press { transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2), opacity 0.2s; }
.press:active { transform: scale(0.94); transition-duration: 0.08s; }

/* ---------- Chrome ---------- */
/* Large title flush left with its action on the same line, like Music and the App Store. */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(20px, env(safe-area-inset-top)) 20px 0;
}
.nav { display: flex; order: 2; }
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 999px;
  background: var(--fill); color: var(--accent-text);
  font-size: 15px; font-weight: 600; letter-spacing: 0;
}
.pill svg { width: 16px; height: 16px; }

/* ---------- Radar ---------- */
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 0 16px; min-height: 0; }
.radar { position: relative; width: min(90vw, 60vh, 560px); aspect-ratio: 1; }
.ring { position: absolute; inset: 0; margin: auto; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--ring); }
.r1 { width: 34%; height: 34%; }
.r2 { width: 67%; height: 67%; }
.r3 { width: 100%; height: 100%; }
.sweep {
  position: absolute; inset: 0; border-radius: 50%;
  /* Bright leading edge at 0deg, fading trail behind it. */
  background: conic-gradient(from 0deg,
    transparent 0deg 250deg,
    transparent 250deg,
    var(--trail) 359.5deg,
    transparent 360deg);
  -webkit-mask: radial-gradient(circle closest-side, #000 calc(100% - 1px), transparent 100%);
  mask: radial-gradient(circle closest-side, #000 calc(100% - 1px), transparent 100%);
  animation: spin 4s linear infinite;
  will-change: transform;
}
@keyframes spin { to { transform: rotate(360deg); } }

.me { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.me::before, .me::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: var(--accent); opacity: 0;
  animation: pulse 3s cubic-bezier(0.2, 0.6, 0.3, 1) infinite;
}
.me::after { animation-delay: 1.5s; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.12; } 100% { transform: scale(2.8); opacity: 0; } }

.avatar {
  position: relative;
  width: 68px; height: 68px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
}
.avatar > svg:first-child { width: 30px; height: 30px; }
.me-avatar {
  z-index: 1;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: none;
}

.peer {
  position: absolute; width: 112px; margin-left: -56px; margin-top: -34px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 2;
  transition: left 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.peer .avatar { transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2), box-shadow 0.2s; }
.peer .avatar:active { transform: scale(0.9); transition-duration: 0.08s; }
.peer.drop .avatar { transform: scale(1.12); box-shadow: 0 0 0 3px var(--accent), var(--shadow-sm); }
.blip { position: absolute; inset: 0; border-radius: 50%; pointer-events: none; opacity: 0; border: 2px solid var(--accent); }
.peer .labels { display: flex; flex-direction: column; align-items: center; }
.peer .name {
  font-size: 13px; line-height: 1.25; font-weight: 600; letter-spacing: -0.005em;
  max-width: 112px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.peer .status { font-size: 12px; line-height: 1.3; letter-spacing: 0; color: var(--text-2); min-height: 16px; font-variant-numeric: tabular-nums; }
.peer .status.ok { color: var(--accent-text); font-weight: 600; }
.peer .status.bad { color: var(--danger); }
.progress { position: absolute; inset: -5px; width: 78px; height: 78px; transform: rotate(-90deg); pointer-events: none; }
.progress circle { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; transition: stroke-dashoffset 0.25s linear; }
.badge {
  position: absolute; right: -2px; bottom: -2px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 0 0 3px var(--bg); transform: scale(0); transition: transform 0.4s cubic-bezier(0.3, 1.6, 0.4, 1);
}
.badge svg { width: 14px; height: 14px; }
.peer.sent .badge { transform: scale(1); }
.peer.waiting .avatar { animation: wait 1.4s ease-in-out infinite; }
@keyframes wait { 50% { box-shadow: 0 0 0 7px var(--ring), var(--shadow-sm); } }

.hint { margin: 0; color: var(--text-2); text-align: center; font-size: 15px; letter-spacing: 0; min-height: 22px; transition: opacity 0.3s; }

.bottom { display: flex; justify-content: center; padding: 8px 16px max(20px, env(safe-area-inset-bottom)); }
.identity {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px 0 12px; border-radius: 999px;
  background: var(--material);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: inset 0 0 0 0.5px var(--material-edge), var(--shadow-sm);
  font-size: 15px; letter-spacing: 0;
}
.identity .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.identity .label { color: var(--text-2); }
.identity .value { font-weight: 600; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Sheets ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.scrim[hidden] { display: none; }
.scrim-bg { position: absolute; inset: 0; background: var(--scrim); opacity: 0; }
.sheet {
  position: relative;
  width: min(400px, 100%); max-height: 88vh; overflow: auto;
  background: var(--material);
  -webkit-backdrop-filter: blur(40px) saturate(180%); backdrop-filter: blur(40px) saturate(180%);
  box-shadow: inset 0 0 0 0.5px var(--material-edge), var(--shadow-lg);
  border-radius: 28px;
  padding: 28px 20px 20px; text-align: center;
  display: flex; flex-direction: column; align-items: center;
  touch-action: none;
  will-change: transform;
}
.grabber { display: none; width: 36px; height: 5px; border-radius: 3px; background: var(--separator); margin: -16px 0 14px; flex: none; }
@media (max-width: 600px) {
  .scrim { align-items: flex-end; padding: 0; }
  .sheet { width: 100%; border-radius: 28px 28px 0 0; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .grabber { display: block; }
}
.sheet h2 {
  font-family: var(--font-display);
  margin: 14px 0 2px; font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -0.026em;
}
.sheet p { margin: 0 0 16px; color: var(--text-2); font-size: 15px; letter-spacing: 0; }
.sheet-avatar { width: 72px; height: 72px; box-shadow: none; background: var(--ring); color: var(--accent-text); }

.files {
  list-style: none; padding: 0 14px; margin: 0 0 18px; width: 100%; text-align: left;
  background: var(--fill); border-radius: 14px;
}
.files:empty { display: none; }
.files li { display: flex; align-items: center; gap: 12px; padding: 10px 0; box-shadow: inset 0 -0.5px 0 var(--separator); }
.files li:last-child { box-shadow: none; }
.files .thumb {
  width: 40px; height: 40px; border-radius: 9px; object-fit: cover; flex: none;
  background: var(--surface); display: grid; place-items: center;
  color: var(--text-2); font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
}
.files .meta { flex: 1; min-width: 0; }
.files .fname { font-size: 15px; font-weight: 600; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files .fsize { color: var(--text-2); font-size: 13px; letter-spacing: 0; }
.files a.save {
  color: var(--accent-text); font-size: 15px; font-weight: 600; text-decoration: none;
  height: 30px; line-height: 30px; padding: 0 12px; border-radius: 999px; background: var(--surface);
}

.bar { width: 100%; height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; margin-bottom: 18px; }
.bar > div { height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width 0.25s linear; }

.actions { display: flex; gap: 10px; width: 100%; }
.actions:empty { display: none; }
.actions button {
  flex: 1; height: 50px; border-radius: 14px; font-size: 17px; font-weight: 600; letter-spacing: 0;
}
.field {
  width: 100%; height: 50px; margin: 0 0 18px; padding: 0 16px; border: 0; border-radius: 14px;
  background: var(--fill); color: var(--text); font: 17px var(--font-text); outline: none;
  user-select: text; -webkit-user-select: text;
}
.field:focus { box-shadow: inset 0 0 0 1.5px var(--text); }
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: var(--fill); color: var(--text); }

.qr { padding: 14px; background: #fff; border-radius: 18px; margin: 0 0 14px; box-shadow: var(--shadow-sm); }
.qr img, .qr canvas { display: block; width: 184px; height: 184px; }
.links { display: flex; flex-direction: column; gap: 2px; margin-bottom: 18px; font: 600 15px/1.4 ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: 0; color: var(--accent-text); user-select: all; -webkit-user-select: all; }

.toast {
  position: fixed; left: 50%; top: max(16px, env(safe-area-inset-top)); z-index: 20;
  transform: translate(-50%, -140%);
  height: 44px; padding: 0 20px; border-radius: 999px; display: flex; align-items: center;
  background: var(--material);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: inset 0 0 0 0.5px var(--material-edge), var(--shadow-lg);
  font-size: 15px; font-weight: 600; letter-spacing: 0;
  opacity: 0; visibility: hidden;
  transition: transform 0.45s cubic-bezier(0.3, 1.3, 0.4, 1), opacity 0.3s, visibility 0s 0.45s;
  max-width: calc(100% - 32px); white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }

/* ---------- Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
  .sweep, .me::before, .me::after, .peer.waiting .avatar { animation: none; }
  .sweep { opacity: 0; }
  .toast { transition: opacity 0.2s; }
}
@media (prefers-reduced-transparency: reduce) {
  .identity, .sheet, .toast { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  .ring { box-shadow: inset 0 0 0 1px var(--text-2); }
  .sheet, .identity, .toast { background: var(--surface); box-shadow: inset 0 0 0 1px var(--text), var(--shadow-lg); }
}
