:root {
  --bg: #020303;
  --fg: #f4f4ee;
  --muted: rgba(244, 244, 238, 0.68);
  --faint: rgba(244, 244, 238, 0.16);
  --hair: rgba(244, 244, 238, 0.34);
  --cyan: #a8f7ff;
  --hot: #ff426f;
  --vault: #9dffd7;
  --panel: rgba(3, 4, 5, 0.72);
  --font: "Courier New", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
}

body,
button {
  letter-spacing: 0;
}

button {
  font: inherit;
}

button:disabled {
  cursor: default;
}

#field-canvas,
.static-noise,
.scan-grid,
.blast-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#field-canvas {
  z-index: 1;
  width: 100vw;
  height: 100vh;
}

.static-noise {
  z-index: 3;
  opacity: 0.22;
  background-image:
    radial-gradient(circle at 25% 18%, rgba(168, 247, 255, 0.08), transparent 24%),
    radial-gradient(circle at 72% 70%, rgba(255, 66, 111, 0.08), transparent 28%),
    repeating-radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}

.scan-grid {
  z-index: 2;
  background:
    linear-gradient(rgba(244, 244, 238, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 244, 238, 0.035) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(circle at 50% 48%, black 0 44%, transparent 75%);
}

.blast-flash {
  z-index: 50;
  opacity: 0;
  background: radial-gradient(circle at 50% 55%, rgba(255, 255, 255, 0.92), rgba(168, 247, 255, 0.34) 24%, transparent 58%);
}

.terminal-shell {
  position: relative;
  z-index: 10;
  min-height: 100svh;
  padding: 24px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  isolation: isolate;
}

.terminal-shell::before,
.terminal-shell::after {
  content: "";
  position: fixed;
  inset: 14px;
  z-index: -1;
  border: 1px solid rgba(244, 244, 238, 0.12);
  pointer-events: none;
}

.terminal-shell::after {
  inset: 42px 46px;
  border-color: rgba(244, 244, 238, 0.07);
}

.hud-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  color: var(--fg);
  font-size: clamp(0.64rem, 1.1vw, 0.8rem);
  font-weight: 700;
  text-transform: uppercase;
}

.hud-row div:nth-child(2) {
  justify-self: center;
}

.hud-row div:last-child {
  justify-self: end;
}

.hud-actions {
  display: inline-flex;
  justify-self: center;
  align-items: center;
  gap: 8px;
}

.hud-button,
.article-close {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--fg);
  color: var(--fg);
  background: rgba(244, 244, 238, 0.04);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hud-button:hover,
.article-close:hover {
  color: var(--bg);
  background: var(--fg);
}

.experience {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 60px 0;
}

.center-copy {
  position: absolute;
  left: 50%;
  top: 17%;
  width: min(780px, calc(100vw - 48px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.micro-label,
.system-line,
.button-status {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.62rem, 1.15vw, 0.82rem);
  font-weight: 700;
  text-transform: uppercase;
}

.button-status {
  text-transform: none;
}

h1 {
  max-width: 100%;
  margin: 12px 0;
  color: var(--fg);
  font-size: clamp(3.7rem, 11vw, 11rem);
  font-weight: 900;
  line-height: 0.78;
  text-transform: uppercase;
  overflow-wrap: anywhere;
  text-shadow:
    0 0 16px rgba(244, 244, 238, 0.22),
    0 0 78px rgba(168, 247, 255, 0.16);
}

.reactor {
  position: absolute;
  left: 50%;
  top: 53%;
  width: min(560px, 44vw);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.reactor-ring {
  position: absolute;
  inset: 0;
  border: 1px solid var(--hair);
  border-radius: 50%;
  opacity: 0.52;
}

.ring-one {
  animation: ring-turn 14s linear infinite;
}

.ring-two {
  inset: 16%;
  border-color: rgba(168, 247, 255, 0.44);
  animation: ring-turn 9s linear infinite reverse;
}

.ring-three {
  inset: 30%;
  border-color: rgba(255, 66, 111, 0.48);
  box-shadow: 0 0 46px rgba(168, 247, 255, 0.14);
}

.reactor-ring::before,
.reactor-ring::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -50%);
  background: var(--fg);
  box-shadow: 0 0 16px currentColor;
}

.reactor-ring::before {
  top: 0;
  color: var(--cyan);
}

.reactor-ring::after {
  top: 100%;
  color: var(--hot);
}

.butterfly-core {
  position: absolute;
  inset: 35%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  filter: drop-shadow(0 0 28px rgba(157, 255, 215, 0.34));
  animation: core-breathe 2.6s ease-in-out infinite;
}

.butterfly-core i {
  display: block;
  border: 1px solid rgba(244, 244, 238, 0.65);
  background:
    linear-gradient(135deg, rgba(168, 247, 255, 0.28), transparent),
    rgba(157, 255, 215, 0.06);
}

.butterfly-core i:nth-child(1) {
  border-radius: 70% 18% 46% 18%;
}

.butterfly-core i:nth-child(2) {
  border-radius: 18% 70% 18% 46%;
}

.butterfly-core i:nth-child(3) {
  border-radius: 42% 18% 68% 18%;
}

.butterfly-core i:nth-child(4) {
  border-radius: 18% 42% 18% 68%;
}

.signal-label {
  position: absolute;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.25;
  text-transform: uppercase;
}

.signal-a {
  left: -6%;
  top: 24%;
}

.signal-b {
  right: -4%;
  top: 48%;
  text-align: right;
}

.signal-c {
  left: 13%;
  bottom: 5%;
}

.hold-button {
  position: relative;
  z-index: 5;
  min-width: 192px;
  min-height: 42px;
  padding: 0 22px;
  display: inline-grid;
  place-items: center;
  border: 0;
  color: var(--bg);
  background: var(--fg);
  box-shadow:
    0 0 0 1px var(--fg),
    0 0 34px rgba(244, 244, 238, 0.12);
  cursor: pointer;
  text-transform: uppercase;
  user-select: none;
  touch-action: none;
}

.hold-button::before,
.hold-button::after,
.hold-frame::before,
.hold-frame::after {
  content: "";
  position: absolute;
  width: 42px;
  height: 42px;
  border-color: var(--fg);
  pointer-events: none;
}

.hold-button::before {
  right: calc(100% + 46px);
  top: 50%;
  border-top: 1px solid;
  border-left: 1px solid;
  transform: translateY(-50%) rotate(-45deg);
}

.hold-button::after {
  left: calc(100% + 46px);
  top: 50%;
  border-top: 1px solid;
  border-right: 1px solid;
  transform: translateY(-50%) rotate(45deg);
}

.hold-frame::before {
  right: calc(100% + 20px);
  top: 50%;
  height: 1px;
  width: 28px;
  background: var(--fg);
  transform: translateY(-50%);
}

.hold-frame::after {
  left: calc(100% + 20px);
  top: 50%;
  height: 1px;
  width: 28px;
  background: var(--fg);
  transform: translateY(-50%);
}

.hold-progress {
  position: absolute;
  inset: 0;
  transform: scaleX(0);
  transform-origin: left;
  background: linear-gradient(90deg, var(--cyan), var(--vault), var(--fg));
  mix-blend-mode: multiply;
}

.hold-copy {
  position: relative;
  z-index: 1;
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

.hold-button:hover:not(:disabled) {
  filter: invert(1);
}

.hold-button:disabled {
  cursor: wait;
  opacity: 0.48;
}

.button-status {
  position: absolute;
  left: 50%;
  bottom: 24%;
  width: min(620px, calc(100vw - 48px));
  transform: translateX(-50%);
  text-align: center;
  line-height: 1.6;
}

.telemetry {
  position: fixed;
  right: 24px;
  bottom: 74px;
  z-index: 12;
  width: min(340px, calc(100vw - 48px));
  border: 1px solid var(--fg);
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.telemetry::before {
  content: "BUTTERFLY VAULT";
  position: absolute;
  left: 13px;
  top: -23px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.telemetry div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--faint);
}

.telemetry div:last-child {
  border-bottom: 0;
}

.telemetry span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
}

.telemetry strong {
  color: var(--fg);
  font-size: 0.86rem;
  white-space: nowrap;
}

.copy-address {
  min-width: 92px;
  padding: 0;
  border: 0;
  color: var(--fg);
  background: transparent;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 900;
  text-align: right;
  white-space: nowrap;
  cursor: pointer;
}

.copy-address::after {
  content: "COPY";
  display: inline-block;
  margin-left: 8px;
  padding: 2px 5px;
  border: 1px solid var(--hair);
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
  vertical-align: 1px;
}

.copy-address:hover:not(:disabled) {
  color: var(--cyan);
}

.copy-address:hover:not(:disabled)::after {
  border-color: var(--cyan);
  color: var(--cyan);
}

.copy-address:disabled {
  color: var(--fg);
  opacity: 0.62;
}

.copy-address:disabled::after {
  content: "SET";
}

.article-page {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 30%, rgba(168, 247, 255, 0.12), transparent 34%),
    rgba(2, 3, 3, 0.9);
  backdrop-filter: blur(14px);
  overflow: auto;
}

.article-page[hidden] {
  display: none;
}

.article-shell {
  position: relative;
  width: min(860px, 100%);
  max-height: min(760px, calc(100svh - 56px));
  overflow: auto;
  padding: 34px;
  border: 1px solid var(--fg);
  background:
    linear-gradient(rgba(244, 244, 238, 0.04) 1px, transparent 1px),
    rgba(3, 4, 5, 0.92);
  background-size: 100% 38px, auto;
  box-shadow: 0 0 70px rgba(168, 247, 255, 0.12);
}

.article-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 1;
}

.article-kicker {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.article-shell h2 {
  margin: 0 0 22px;
  font-size: clamp(2.4rem, 7vw, 5.8rem);
  line-height: 0.88;
}

.article-shell h3 {
  margin: 30px 0 10px;
  color: var(--cyan);
  font-size: 1rem;
  text-transform: uppercase;
}

.article-shell p {
  max-width: 720px;
  margin: 0 0 14px;
  color: rgba(244, 244, 238, 0.76);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 1rem;
  line-height: 1.82;
}

.article-shell code {
  padding: 2px 5px;
  color: var(--fg);
  background: rgba(244, 244, 238, 0.1);
  font-family: var(--font);
  font-size: 0.88em;
}

.blast-shard {
  position: fixed;
  z-index: 60;
  display: block;
  background: var(--fg);
  pointer-events: none;
  clip-path: polygon(50% 0, 100% 30%, 82% 100%, 11% 76%, 0 26%);
  animation: shard-out 940ms cubic-bezier(0.14, 0.74, 0.15, 1) forwards;
}

.blast-shard.hot {
  background: var(--cyan);
  box-shadow: 0 0 18px var(--cyan);
}

.is-firing .terminal-shell {
  animation: shake 680ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.is-firing .blast-flash {
  animation: flash 720ms ease-out both;
}

.is-firing .reactor {
  animation: reactor-pop 920ms ease-out both;
}

@keyframes ring-turn {
  to {
    transform: rotate(360deg);
  }
}

@keyframes core-breathe {
  0%,
  100% {
    transform: scale(0.96);
    opacity: 0.74;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

@keyframes shard-out {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.7) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.28) rotate(var(--turn));
  }
}

@keyframes flash {
  0% {
    opacity: 0;
  }
  18% {
    opacity: 0.92;
  }
  100% {
    opacity: 0;
  }
}

@keyframes shake {
  10%,
  90% { transform: translate3d(-1px, 0, 0); }
  20%,
  80% { transform: translate3d(2px, 1px, 0); }
  30%,
  50%,
  70% { transform: translate3d(-4px, -2px, 0); }
  40%,
  60% { transform: translate3d(4px, 2px, 0); }
}

@keyframes reactor-pop {
  0% {
    filter: brightness(1);
    transform: translate(-50%, -50%) scale(1);
  }
  30% {
    filter: brightness(2.4);
    transform: translate(-50%, -50%) scale(1.18);
  }
  100% {
    filter: brightness(1);
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (max-width: 900px) {
  html,
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .terminal-shell {
    min-height: 100svh;
    padding: 18px;
    grid-template-rows: auto minmax(650px, 1fr) auto;
  }

  .hud-row {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }

  .hud-row div,
  .hud-row div:last-child {
    justify-self: center;
  }

  .hud-row div:first-child,
  .hud-row div:last-child {
    display: none;
  }

  .hud-actions {
    display: flex;
  }

  .center-copy {
    top: 10%;
    width: calc(100vw - 52px);
  }

  h1 {
    font-size: clamp(2.9rem, 12.4vw, 4rem);
    line-height: 0.88;
  }

  .reactor {
    width: min(430px, 86vw);
    top: 48%;
  }

  .button-status {
    bottom: 18%;
  }

  .telemetry {
    position: relative;
    right: auto;
    bottom: auto;
    width: min(420px, calc(100vw - 80px));
    margin: 8px auto 18px;
  }

  .telemetry div {
    display: grid;
    align-items: start;
    justify-content: stretch;
    gap: 5px;
  }

  .telemetry strong {
    white-space: normal;
  }

  .copy-address {
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .bottom-row {
    gap: 8px;
    padding-bottom: 8px;
  }

  .article-page {
    padding: 18px;
  }

  .article-shell {
    max-height: calc(100svh - 36px);
    padding: 24px;
  }
}

@media (max-width: 520px) {
  .terminal-shell::after {
    display: none;
  }

  .experience {
    padding: 44px 0;
  }

  .center-copy {
    top: 8%;
  }

  .system-line {
    display: none;
  }

  .hold-button::before,
  .hold-button::after {
    display: none;
  }

  .signal-label {
    display: none;
  }

  .button-status {
    bottom: 16%;
    max-width: 280px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
