:root {
  --bg: #EEF1F5;
  --panel: #FFFFFF;
  --ink: #16233A;
  --ink-soft: #5B6B84;
  --line: #C9D2DE;
  --signal: #FF6B35;
  --signal-soft: #FFE3D4;
  --connected: #2FB673;
  --connected-soft: #DCF3E8;
  --danger: #D8455B;
  --danger-soft: #FBE3E7;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px;
  background-position: -1px -1px;
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.stage { width: 100%; max-width: 600px; }

h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(40px, 6vw, 60px);
  font-weight: 700;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.tagline { color: var(--ink-soft); font-size: clamp(16px, 2vw, 19px); margin: 0 0 32px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 1px 2px rgba(22, 35, 58, 0.04), 0 8px 24px rgba(22, 35, 58, 0.05);
}

.foot {
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 16px;
}

/* ---- link signature: two nodes with a connecting wire ---- */
.link { margin-bottom: 26px; }
.link-row {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.node {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--line);
  border: 2px solid var(--panel);
  outline: 2px solid var(--line);
  flex-shrink: 0;
  transition: outline-color .3s, background .3s;
}
.node.on { background: var(--connected); outline-color: var(--connected); }
.node.pending { background: var(--signal); outline-color: var(--signal); }

.wire {
  flex: 1;
  height: 2px;
  max-width: 180px;
  background-image: linear-gradient(90deg, var(--line) 50%, transparent 50%);
  background-size: 10px 2px;
  position: relative;
  margin: 0 8px;
}
.wire.live { background-image: linear-gradient(90deg, var(--connected) 50%, transparent 50%); }
.wire.active { background-image: linear-gradient(90deg, var(--signal) 50%, transparent 50%); }
.wire .pulse {
  position: absolute; top: -3px; left: 0;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--signal);
  opacity: 0;
}
.wire.active .pulse { opacity: 1; animation: travel 1.1s linear infinite; }
.wire.active.rev .pulse { animation-name: travel-rev; }

@keyframes travel {
  0% { left: 0; }
  100% { left: calc(100% - 8px); }
}
@keyframes travel-rev {
  0% { left: calc(100% - 8px); }
  100% { left: 0; }
}

.link-labels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.link-labels span:last-child { text-align: right; }
#linkStatusLabel { color: var(--ink-soft); transition: color .3s; }
#linkStatusLabel.ok { color: var(--connected); }
#linkStatusLabel.busy { color: var(--signal); }

/* ---- role picker ---- */
.role-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 22px 16px;
  text-align: left;
  cursor: pointer;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--ink);
  transition: border-color .15s, background .15s, transform .1s;
}
.role-btn span {
  display: block;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 4px;
}
.role-btn:hover { border-color: var(--signal); background: #fff; }
.role-btn:active { transform: scale(0.98); }

/* ---- forms & buttons ---- */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
input[type=text] {
  width: 100%;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 22px;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
input[type=text]:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
input[type=text]::placeholder { color: var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  margin-top: 14px;
  transition: background .15s;
}
.btn:hover { background: #0d1728; }
.btn:disabled { background: var(--line); cursor: default; }
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: var(--bg); color: var(--ink); }
.btn-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-pair .btn { margin-top: 0; }

/* ---- sender waiting ---- */
.code-display {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 34px;
  font-weight: 500;
  letter-spacing: .15em;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 14px;
  cursor: pointer;
  user-select: all;
  transition: border-color .15s;
}
.code-display:hover { border-color: var(--signal); }

.hint { font-size: 13px; color: var(--ink-soft); text-align: center; margin: 0 0 12px; }
.hint.mono {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px;
  margin: 12px 0 0;
  word-break: break-all;
}
.status {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  margin-top: 14px;
  min-height: 16px;
}
.status.err { color: var(--danger); }

/* ---- file transfer ---- */
.drop {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 30px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop.drag { border-color: var(--signal); background: var(--signal-soft); }
.drop p { margin: 0; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.drop strong { color: var(--ink); }

.file-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px; font-size: 13px;
}
.file-row .name { font-weight: 600; word-break: break-all; padding-right: 10px; }
.file-row .size { color: var(--ink-soft); font-family: 'IBM Plex Mono', monospace; white-space: nowrap; }
.file-row .ok { color: var(--connected); font-family: 'IBM Plex Mono', monospace; font-size: 12px; white-space: nowrap; }

.progress-track {
  height: 8px; border-radius: 4px; background: var(--bg);
  border: 1px solid var(--line); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: var(--signal); border-radius: 4px;
  transition: width .12s linear;
}
.progress-fill.done { background: var(--connected); }
.progress-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11.5px; color: var(--ink-soft);
  margin-top: 6px;
}

.done-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--connected-soft); color: #1B7C50;
  border-radius: 6px; padding: 6px 10px;
  font-size: 12.5px; font-weight: 600;
  margin-bottom: 14px;
}

.received-files { margin-top: 4px; }
.received-files .file-row { margin-top: 10px; margin-bottom: 0; }
.received-files a {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600; font-size: 13px;
  color: var(--signal);
  text-decoration: none;
  white-space: nowrap;
  margin-left: 12px;
}
.received-files a:hover { text-decoration: underline; }

.banner {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  text-align: center;
  margin: 16px 0 0;
}

.back {
  display: block;
  margin: 18px auto 0;
  background: none; border: none; padding: 0;
  font-family: 'Inter', sans-serif;
  font-size: 12.5px; color: var(--ink-soft);
  cursor: pointer; text-decoration: underline;
}
.back:hover { color: var(--ink); }

.hidden { display: none !important; }

@media (max-width: 420px) {
  .card { padding: 20px; }
  .role-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .wire .pulse { animation: none !important; }
  .progress-fill { transition: none; }
}
