/* ===========================================================
   SIGNAL — design tokens
   Palette: deep-space navy + electric indigo, built around
   the idea of a live peer-to-peer mesh (nodes + pulses).
   =========================================================== */
:root {
  --bg: #0b0f19;
  --bg-elevated: #111726;
  --bg-elevated-2: #161d2f;
  --border: #232b40;
  --text: #e7e9f0;
  --text-dim: #8b93a7;
  --text-faint: #565f78;

  --indigo: #6366f1;
  --indigo-bright: #818cf8;
  --indigo-dim: #3730a3;
  --coral: #ff6b6b;
  --mint: #34d399;
  --amber: #fbbf24;

  --grad-primary: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  --grad-glow: radial-gradient(circle, rgba(99, 102, 241, 0.35) 0%, transparent 70%);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 999px;

  --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.25);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", monospace;
}

@media (prefers-color-scheme: light) {
  /* App is intentionally dark-first (video calls are watched in dim rooms) */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

p { color: var(--text-dim); line-height: 1.6; margin: 0; }

code, .mono { font-family: var(--font-mono); letter-spacing: 0.02em; }

::selection { background: var(--indigo-dim); color: #fff; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

:focus-visible {
  outline: 2px solid var(--indigo-bright);
  outline-offset: 3px;
  border-radius: 4px;
}

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

/* ---------- layout shells ---------- */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--grad-primary);
  box-shadow: 0 0 14px var(--indigo);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

/* ---------- node-network hero canvas (signature element) ---------- */
.node-field {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.55;
}

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--bg-elevated-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 13px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.25s var(--ease-spring), box-shadow 0.25s var(--ease-out),
              border-color 0.25s var(--ease-out), background 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
  user-select: none;
}

.btn:hover {
  transform: translateY(-2px);
  border-color: var(--indigo-bright);
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.18);
}
.btn:active { transform: translateY(0) scale(0.98); }

.btn.primary {
  background: var(--grad-primary);
  border: none;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.35);
}
.btn.primary:hover {
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.5);
  filter: brightness(1.08);
}

.btn.ghost { background: transparent; }
.btn.danger { background: var(--coral); border: none; color: #1a0505; }
.btn.danger:hover { box-shadow: 0 10px 24px rgba(255, 107, 107, 0.35); }
.btn.sm { padding: 9px 16px; font-size: 0.85rem; }
.btn.icon-only { padding: 13px; border-radius: var(--radius-full); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.btn.round {
  width: 52px; height: 52px; border-radius: 50%;
  padding: 0;
}

/* ripple */
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.25) 0%, transparent 60%);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.4s, transform 0.4s;
}
.btn:active::after { opacity: 1; transform: scale(1.4); transition: 0s; }

/* ---------- cards / inputs ---------- */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s var(--ease-out), border-color 0.35s;
}

.card.hoverable:hover {
  transform: translateY(-4px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: var(--shadow-card), var(--shadow-glow);
}

.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.field label { font-size: 0.82rem; color: var(--text-dim); font-weight: 500; }

.field input, .field select {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--indigo-bright);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
  background: #0f1524;
}
.field input::placeholder { color: var(--text-faint); }

/* ---------- badges / chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.12);
  color: var(--indigo-bright);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
.chip.live {
  background: rgba(52, 211, 153, 0.12);
  color: var(--mint);
  border-color: rgba(52, 211, 153, 0.3);
}
.chip.live .live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--mint);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

/* ---------- reveal-on-load animation ---------- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  animation: reveal-up 0.7s var(--ease-out) forwards;
}
@keyframes reveal-up {
  to { opacity: 1; transform: translateY(0); }
}
.reveal.d1 { animation-delay: 0.05s; }
.reveal.d2 { animation-delay: 0.15s; }
.reveal.d3 { animation-delay: 0.25s; }
.reveal.d4 { animation-delay: 0.35s; }

/* ---------- footer credit ---------- */
.dev-credit {
  position: fixed;
  bottom: 16px;
  right: 18px;
  z-index: 50;
  font-size: 0.78rem;
  color: var(--text-faint);
  background: rgba(17, 23, 38, 0.75);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.3s var(--ease-spring), border-color 0.3s, color 0.3s;
}
.dev-credit:hover {
  transform: translateY(-3px) scale(1.03);
  border-color: var(--indigo-bright);
  color: var(--text);
}
.dev-credit a {
  background: var(--grad-primary);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 700;
}
.dev-credit .heart {
  color: var(--coral);
  animation: heartbeat 1.6s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  25% { transform: scale(1.25); }
  40% { transform: scale(1); }
}

/* ---------- toast ---------- */
.toast-stack {
  position: fixed; top: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--indigo-bright);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: var(--shadow-card);
  animation: toast-in 0.35s var(--ease-spring) forwards;
  max-width: 320px;
}
.toast.error { border-left-color: var(--coral); }
.toast.success { border-left-color: var(--mint); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* =========================================================
   ROOM PAGE
   ========================================================= */
.room-shell {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: 56px 1fr 84px;
  grid-template-areas:
    "header header"
    "stage side"
    "controls controls";
  height: 100vh;
  background: var(--bg);
}

.room-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  z-index: 5;
}

.room-stage {
  grid-area: stage;
  position: relative;
  overflow: auto;
  padding: 18px;
  background:
    radial-gradient(circle at 20% 20%, rgba(99,102,241,0.06), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(168,85,247,0.06), transparent 40%);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  height: 100%;
}

.video-tile {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.3s var(--ease-out);
  animation: tile-in 0.45s var(--ease-spring);
}
@keyframes tile-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
.video-tile:hover { transform: translateY(-2px); }
.video-tile.speaking {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2), 0 0 30px rgba(52, 211, 153, 0.15);
}
.video-tile video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: #05070c;
}
.video-tile .avatar-fallback {
  width: 76px; height: 76px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  color: #fff;
}
.video-tile .tile-label {
  position: absolute;
  bottom: 10px; left: 10px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(11, 15, 25, 0.72);
  backdrop-filter: blur(6px);
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
}
.video-tile .tile-icons {
  position: absolute; top: 10px; right: 10px;
  display: flex; gap: 6px;
}
.video-tile .tile-icons span {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(11, 15, 25, 0.72);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem;
}
.hand-badge {
  animation: wave 1s ease-in-out infinite;
  transform-origin: 70% 70%;
}
@keyframes wave {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(14deg); }
  75% { transform: rotate(-10deg); }
}

.sidebar {
  grid-area: side;
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.side-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.side-tab {
  flex: 1;
  text-align: center;
  padding: 13px 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.side-tab:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.side-tab.active { color: var(--indigo-bright); border-color: var(--indigo-bright); }

.side-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.side-panel.active { display: flex; }

.chat-list { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { animation: reveal-up 0.3s var(--ease-out); }
.chat-msg .who { font-size: 0.75rem; color: var(--indigo-bright); font-weight: 700; margin-bottom: 2px; }
.chat-msg .bubble {
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.mine .bubble { background: var(--indigo-dim); border-color: var(--indigo); }
.chat-msg.system { text-align: center; color: var(--text-faint); font-size: 0.76rem; }
.chat-msg .file-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  transition: border-color 0.2s, transform 0.2s;
}
.chat-msg .file-card:hover { border-color: var(--indigo-bright); transform: translateX(2px); }

.typing-indicator { padding: 0 14px 8px; font-size: 0.76rem; color: var(--text-faint); min-height: 18px; }
.typing-dots span {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-faint); margin-right: 3px;
  animation: typing-bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-row {
  display: flex; gap: 8px; padding: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 10px 16px;
  color: var(--text);
  font-size: 0.86rem;
}
.chat-input-row input:focus { outline: none; border-color: var(--indigo-bright); }

.participants-list { flex: 1; overflow-y: auto; padding: 10px; }
.participant-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  transition: background 0.2s;
}
.participant-row:hover { background: rgba(255,255,255,0.03); }
.participant-row .p-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.participant-row .p-name { font-size: 0.87rem; font-weight: 600; flex: 1; }
.participant-row .p-icons { display: flex; gap: 6px; color: var(--text-faint); font-size: 0.85rem; }

/* whiteboard */
.whiteboard-wrap { flex: 1; position: relative; background: #f5f5f7; }
#whiteboard { width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.wb-toolbar {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
  background: rgba(17,23,38,0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 10px;
  box-shadow: var(--shadow-card);
}
.wb-color {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.2s var(--ease-spring), border-color 0.2s;
}
.wb-color:hover { transform: scale(1.2); }
.wb-color.selected { border-color: #fff; transform: scale(1.15); }

/* controls bar */
.controls-bar {
  grid-area: controls;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}
.controls-bar .btn.round.off { background: var(--coral); border-color: transparent; }
.controls-bar .btn.round.active-glow {
  background: var(--grad-primary);
  box-shadow: 0 0 20px rgba(99,102,241,0.5);
}

/* floating reactions */
.reaction-float {
  position: fixed;
  bottom: 100px;
  font-size: 2rem;
  animation: float-up 2.6s ease-out forwards;
  pointer-events: none;
  z-index: 100;
}
@keyframes float-up {
  0% { opacity: 0; transform: translateY(0) scale(0.5) rotate(0deg); }
  15% { opacity: 1; transform: translateY(-40px) scale(1.1) rotate(-8deg); }
  100% { opacity: 0; transform: translateY(-360px) scale(1) rotate(8deg); }
}

/* connection quality */
.net-quality { display: flex; align-items: center; gap: 3px; }
.net-quality .bar { width: 3px; background: var(--text-faint); border-radius: 2px; }
.net-quality .bar:nth-child(1) { height: 6px; }
.net-quality .bar:nth-child(2) { height: 9px; }
.net-quality .bar:nth-child(3) { height: 12px; }
.net-quality.good .bar { background: var(--mint); }
.net-quality.ok .bar:nth-child(1), .net-quality.ok .bar:nth-child(2) { background: var(--amber); }
.net-quality.poor .bar:nth-child(1) { background: var(--coral); }

/* responsive */
@media (max-width: 880px) {
  .room-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto 84px;
    grid-template-areas: "header" "stage" "side" "controls";
  }
  .sidebar { border-left: none; border-top: 1px solid var(--border); max-height: 40vh; }
}
