:root {
  --ink: #05070c;
  --deep: #0a1018;
  --signal: #4fd6c8;
  --ember: #ff8a4c;
  --mist: #8a97ab;
  --paper: #e8eef5;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, "Cascadia Mono", "Roboto Mono",
    "DejaVu Sans Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 90% at 50% 108%, rgba(79, 214, 200, 0.09), transparent 62%),
    linear-gradient(180deg, var(--ink) 0%, var(--deep) 72%, var(--ink) 100%);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

#field {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- centre plate ------------------------------------------------------ */

.plate {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: max(1.5rem, env(safe-area-inset-top)) 1.5rem max(1.5rem, env(safe-area-inset-bottom));
  text-align: center;
  pointer-events: none;
}

.owner {
  font-size: clamp(0.66rem, 1.5vw, 0.8rem);
  font-weight: 500;
  letter-spacing: 0.42em;
  text-indent: 0.42em; /* balance the trailing letter-space */
  text-transform: uppercase;
  color: var(--mist);
}

.owner:empty {
  display: none;
}

.owner:empty + .rule {
  display: none;
}

.rule {
  width: clamp(2.5rem, 7vw, 4.5rem);
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(138, 151, 171, 0.65), transparent);
  transform-origin: center;
}

.host {
  font-family: var(--mono);
  /* Long names step down rather than wrap: at a fixed advance width, the size
     that fits N characters across the plate is proportional to 1/N. The var is
     set from the DOM; the 1 fallback simply leaves the vw cap in charge. */
  font-size: clamp(1.4rem, min(11.5vw, calc(150vw / var(--host-chars, 1))), 8.5rem);
  font-weight: 500;
  line-height: 0.94;
  letter-spacing: -0.035em;
  max-width: 94vw;
  overflow-wrap: anywhere;
  color: var(--paper);
  text-shadow: 0 0 72px rgba(79, 214, 200, 0.15);
  transition: text-shadow 620ms ease-out;
}

/* Once the name has locked, drop the animation and its compositing layer. */
.host.locked {
  animation: none;
  opacity: 1;
  filter: none;
  clip-path: none;
}

.status {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin-top: 0.35rem;
  font-size: clamp(0.68rem, 1.6vw, 0.8rem);
  letter-spacing: 0.05em;
  color: var(--mist);
}

.dot {
  width: 6px;
  height: 6px;
  background: var(--signal);
  box-shadow: 0 0 0 0 rgba(79, 214, 200, 0.5);
  transition:
    background 200ms ease-out,
    box-shadow 700ms ease-out;
}

/* ---- the beat ---------------------------------------------------------- */
/* Fired from the shader's pulse so the plate and the field share one clock. */

body.ping .dot {
  background: var(--ember);
  box-shadow: 0 0 0 7px rgba(255, 138, 76, 0);
  transition:
    background 90ms ease-out,
    box-shadow 90ms ease-out;
}

body.ping .host {
  text-shadow: 0 0 82px rgba(79, 214, 200, 0.38);
  transition: text-shadow 140ms ease-out;
}

/* ---- entrance ---------------------------------------------------------- */

.owner,
.rule,
.host,
.status {
  opacity: 0;
}

html.ready .owner {
  animation: rise 900ms 80ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

html.ready .rule {
  animation: draw 800ms 320ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

html.ready .host {
  animation: lock 1100ms 420ms cubic-bezier(0.16, 0.8, 0.24, 1) both;
}

html.ready .status {
  animation: rise 900ms 1000ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes draw {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* signal lock: the name resolves out of noise */
@keyframes lock {
  from {
    opacity: 0;
    filter: blur(14px);
    letter-spacing: 0.06em;
    clip-path: inset(0 0 46% 0);
  }
  to {
    opacity: 1;
    filter: none; /* drop the filter layer entirely once it lands */
    letter-spacing: -0.035em;
    clip-path: inset(0 0 0 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .owner,
  .rule,
  .host,
  .status {
    opacity: 1;
  }

  html.ready .owner,
  html.ready .rule,
  html.ready .host,
  html.ready .status {
    animation: none;
  }

  .host,
  .dot {
    transition: none;
  }
}
