:root {
  --bg: #000810;
  --panel: rgba(0, 8, 22, 0.78);
  --panel-border: rgba(0, 229, 255, 0.18);
  --text: #e8f4ff;
  --muted: #7090b8;
  --accent: #00e5ff;
  --accent-2: #8b5cf6;
  --accent-3: #00ff88;
  --peer: rgba(139, 92, 246, 0.16);
  --self: rgba(0, 229, 255, 0.15);
  --shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 80px rgba(0, 229, 255, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 15% 40%, rgba(0, 20, 55, 0.9) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 65%, rgba(22, 0, 55, 0.85) 0%, transparent 50%),
    #000810;
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

.scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  isolation: isolate;
}

/* ── Futuristic cyberpunk scene ──────────────── */
.cyber-grid,
.glow-blob,
.ping,
.scan-h,
.stream,
.node,
.corner-tl,
.corner-br {
  position: absolute;
}

/* Perspective dot-grid floor */
.cyber-grid {
  inset: -30%;
  background-image: radial-gradient(circle, rgba(0, 229, 255, 0.38) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: perspective(500px) rotateX(72deg) translateY(-10%);
  transform-origin: center 40%;
  opacity: 0.17;
  animation: gridScroll 14s linear infinite;
}

/* Ambient colour glows */
.glow-blob {
  border-radius: 50%;
  filter: blur(90px);
  mix-blend-mode: screen;
}

.glow-cyan {
  width: 55vw;
  height: 55vw;
  top: -15%;
  left: -8%;
  background: radial-gradient(circle, rgba(0, 200, 255, 0.44) 0%, transparent 70%);
  animation: glowFloat 10s ease-in-out infinite alternate;
}

.glow-violet {
  width: 65vw;
  height: 65vw;
  bottom: -20%;
  right: -12%;
  background: radial-gradient(circle, rgba(120, 40, 255, 0.4) 0%, transparent 70%);
  animation: glowFloat 14s ease-in-out infinite alternate-reverse;
}

/* Radar ping rings */
.ping {
  top: 55%;
  left: 35%;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: pingExpand 6s ease-out infinite;
}

.ping-2 {
  animation-delay: 2s;
}

.ping-3 {
  animation-delay: 4s;
}

/* Horizontal scan beam */
.scan-h {
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(0, 229, 255, 0.1) 10%,
    rgba(0, 229, 255, 0.9) 50%,
    rgba(0, 229, 255, 0.1) 90%,
    transparent 100%
  );
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.55), 0 0 50px rgba(0, 229, 255, 0.18);
  animation: scanDown 9s linear infinite;
}

/* Vertical data-stream tracers */
.stream {
  top: 0;
  width: 1px;
  height: 38vh;
  opacity: 0;
  animation: streamFall linear infinite;
}

.stream::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(0, 255, 136, 0.65) 20%,
    rgba(0, 229, 255, 0.95) 50%,
    rgba(0, 255, 136, 0.65) 80%,
    transparent 100%
  );
  filter: blur(0.5px);
}

.stream-1 { left: 6%;  animation-duration: 4.2s; animation-delay: 0.5s; }
.stream-2 { left: 21%; animation-duration: 5.8s; animation-delay: 2.4s; }
.stream-3 { left: 47%; animation-duration: 4.9s; animation-delay: 1.2s; }
.stream-4 { left: 73%; animation-duration: 6.5s; animation-delay: 3.8s; }
.stream-5 { left: 89%; animation-duration: 3.8s; animation-delay: 1.0s; }

/* Glowing node beacons */
.node {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: nodePulse 3s ease-in-out infinite alternate;
}

.node-1 {
  top: 18%;
  left: 16%;
  background: #00e5ff;
  box-shadow: 0 0 8px 3px rgba(0, 229, 255, 0.75), 0 0 28px 8px rgba(0, 229, 255, 0.28);
}

.node-2 {
  top: 62%;
  right: 20%;
  width: 5px;
  height: 5px;
  background: #8b5cf6;
  box-shadow: 0 0 8px 3px rgba(139, 92, 246, 0.75), 0 0 28px 8px rgba(139, 92, 246, 0.28);
  animation-delay: 1.5s;
  animation-duration: 4.2s;
}

.node-3 {
  bottom: 25%;
  left: 65%;
  width: 4px;
  height: 4px;
  background: #00ff88;
  box-shadow: 0 0 6px 2px rgba(0, 255, 136, 0.75), 0 0 20px 6px rgba(0, 255, 136, 0.28);
  animation-delay: 2.8s;
  animation-duration: 3.7s;
}

/* HUD corner brackets */
.corner-tl {
  top: 1.5rem;
  left: 1.5rem;
  width: 4.5rem;
  height: 4.5rem;
  border-top: 1px solid rgba(0, 229, 255, 0.55);
  border-left: 1px solid rgba(0, 229, 255, 0.55);
  animation: hudBlink 4.5s ease-in-out infinite;
}

.corner-br {
  bottom: 1.5rem;
  right: 1.5rem;
  width: 4.5rem;
  height: 4.5rem;
  border-bottom: 1px solid rgba(139, 92, 246, 0.55);
  border-right: 1px solid rgba(139, 92, 246, 0.55);
  animation: hudBlink 4.5s ease-in-out infinite;
  animation-delay: 2.25s;
}

.app-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 2rem;
}

.chat-panel {
  position: relative;
  width: min(100%, 52rem);
  height: min(88vh, 52rem);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  padding: 1.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 1.75rem;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0) 35%, rgba(0, 229, 255, 0.06) 100%);
  pointer-events: none;
}

.chat-header,
.status-text,
.messages,
.composer {
  position: relative;
  z-index: 1;
}

.chat-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--accent-2);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

h1 {
  margin: 0;
  font-family: 'Syne', sans-serif;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.95;
}

.status-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding-right: 0.35rem;
}

.messages::-webkit-scrollbar {
  width: 0.6rem;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.message-card {
  max-width: 85%;
  padding: 0.95rem 1rem;
  border-radius: 1.15rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(12px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.message-card p {
  margin: 0.4rem 0 0;
  line-height: 1.5;
  white-space: pre-wrap;
}

.own-message {
  align-self: end;
  background: var(--self);
}

.peer-message {
  align-self: start;
  background: var(--peer);
}

.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.message-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.copy-button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.68rem;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.copy-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.22);
}

.toast-region {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: end;
  gap: 0.8rem;
  width: min(24rem, calc(100vw - 2rem));
}

.toast {
  width: 100%;
  padding: 0.95rem 1rem;
  border-radius: 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(7, 12, 22, 0.92);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
  animation: toastIn 220ms ease;
}

.toast-success {
  border-color: rgba(0, 229, 255, 0.45);
}

.toast-warning {
  border-color: rgba(255, 219, 110, 0.42);
}

.toast-error {
  border-color: rgba(255, 138, 91, 0.42);
}

.toast-body {
  color: var(--text);
  line-height: 1.45;
}

.toast-actions {
  display: flex;
  justify-content: end;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.toast-button,
.toast-close {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.toast-button:hover,
.toast-close:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
}

.toast-button-danger {
  border-color: rgba(255, 138, 91, 0.4);
  background: rgba(255, 138, 91, 0.18);
}

.toast-close {
  font-size: 0.82rem;
}

.toast-leaving {
  animation: toastOut 220ms ease forwards;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 1.25rem;
}

.composer {
  display: grid;
  gap: 0.45rem;
}

.composer-label {
  color: var(--muted);
  font-size: 0.85rem;
  padding-left: 0.2rem;
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.85rem;
}

textarea {
  width: 100%;
  resize: none;
  padding: 0.85rem 1.1rem;
  min-height: 4.4rem;
  border-radius: 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(3, 8, 18, 0.72);
  color: var(--text);
}

textarea:focus {
  outline: 2px solid rgba(0, 229, 255, 0.45);
  outline-offset: 2px;
}

.send-button,
.ghost-button {
  border: 0;
  border-radius: 999px;
  padding: 0.9rem 1.2rem;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease, background-color 160ms ease;
}

.send-button {
  align-self: end;
  min-width: 7rem;
  color: #fff;
  background: #ff7a2f;
  font-weight: 700;
  box-shadow: 0 4px 18px rgba(255, 122, 47, 0.35);
}

.ghost-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.send-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.send-button:disabled,
.ghost-button:disabled,
.copy-button:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@keyframes gridScroll {
  0% {
    background-position: 0 0;
  }

  100% {
    background-position: 0 44px;
  }
}

@keyframes glowFloat {
  0% {
    transform: scale(1) translate(0, 0);
    opacity: 0.75;
  }

  100% {
    transform: scale(1.14) translate(3%, -4%);
    opacity: 1;
  }
}

@keyframes pingExpand {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.65);
  }

  100% {
    box-shadow: 0 0 0 90vmax rgba(0, 229, 255, 0);
  }
}

@keyframes scanDown {
  0% {
    top: -2px;
    opacity: 0;
  }

  4% {
    opacity: 1;
  }

  96% {
    opacity: 1;
  }

  100% {
    top: 100vh;
    opacity: 0;
  }
}

@keyframes streamFall {
  0% {
    transform: translateY(-38vh);
    opacity: 0;
  }

  7% {
    opacity: 0.85;
  }

  88% {
    opacity: 0.85;
  }

  96% {
    opacity: 0;
  }

  100% {
    transform: translateY(100vh);
    opacity: 0;
  }
}

@keyframes nodePulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }

  100% {
    transform: scale(1.65);
    opacity: 1;
  }
}

@keyframes hudBlink {
  0%,
  100% {
    opacity: 0.32;
  }

  50% {
    opacity: 0.88;
  }
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translate3d(0, 0.8rem, 0) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }

  to {
    opacity: 0;
    transform: translate3d(0, 0.8rem, 0) scale(0.98);
  }
}

@media (max-width: 700px) {
  body {
    overflow: auto;
  }

  .app-shell {
    padding: 1rem;
  }

  .chat-panel {
    height: min(92vh, 58rem);
    padding: 1rem;
  }

  .chat-header {
    grid-template-columns: 1fr;
    display: grid;
  }

  .message-card {
    max-width: 100%;
  }

  .message-meta {
    align-items: start;
    flex-direction: column;
  }

  .message-actions {
    width: 100%;
    justify-content: space-between;
  }

  .ghost-button {
    width: 100%;
  }

  .toast-region {
    right: 1rem;
    bottom: 1rem;
    width: min(100%, calc(100vw - 2rem));
  }
}

@media (max-width: 560px) {
  .composer-row {
    grid-template-columns: 1fr;
  }

  .send-button {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cyber-grid,
  .glow-blob,
  .ping,
  .scan-h,
  .stream,
  .node,
  .corner-tl,
  .corner-br,
  .send-button,
  .ghost-button,
  .copy-button,
  .toast,
  .toast-leaving,
  .toast-button,
  .toast-close {
    animation: none;
    transition: none;
  }
}