/* ---------- Tokens (from the Figma file) ---------- */
:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --hover: #eceef2;
  --border: #e3e4e8;
  --border-strong: #cfd1d7;
  --text: #16171a;
  --text-2: #45474d;
  --muted: #6b6e76;
  --accent: #3d5df0;
  --accent-soft: rgba(61, 93, 240, 0.12);
  --accent-ring: rgba(61, 93, 240, 0.28);
  --on-accent: #ffffff;
  --line: rgba(61, 93, 240, 0.16);
  --danger: #d33a3a;
  --shadow: 0 12px 32px rgba(22, 23, 26, 0.12), 0 2px 6px rgba(22, 23, 26, 0.06);

  --font: "Host Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --emoji: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  --bubble: 112px;
  --emoji-size: 72px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0f11;
  --surface: #151619;
  --surface-2: #1b1c20;
  --hover: #1d1e22;
  --border: #26272c;
  --border-strong: #35373d;
  --text: #ececee;
  --text-2: #b6b8bd;
  --muted: #8a8d94;
  --accent: #6b8cff;
  --accent-soft: rgba(107, 140, 255, 0.16);
  --accent-ring: rgba(107, 140, 255, 0.35);
  --on-accent: #0e0f11;
  --line: rgba(107, 140, 255, 0.12);
  --danger: #ff6b6b;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0f11;
    --surface: #151619;
    --surface-2: #1b1c20;
    --hover: #1d1e22;
    --border: #26272c;
    --border-strong: #35373d;
    --text: #ececee;
    --text-2: #b6b8bd;
    --muted: #8a8d94;
    --accent: #6b8cff;
    --accent-soft: rgba(107, 140, 255, 0.16);
    --accent-ring: rgba(107, 140, 255, 0.35);
    --on-accent: #0e0f11;
    --line: rgba(107, 140, 255, 0.12);
    --danger: #ff6b6b;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

@media (max-width: 640px) {
  :root { --bubble: 88px; --emoji-size: 54px; }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.emoji { font-family: var(--emoji); line-height: 1; font-style: normal; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon {
  display: inline-block;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}
.icon-chevron { --icon: url("/assets/chevron-down.svg"); width: 14px; height: 14px; color: var(--muted); }

/* Background glow: Figma "Ellipse 1" (accent at 12% fading out over 640px),
   painted with dithering in app.js so it doesn't band. */
:root { --glow-opacity: 0.7; }
.glow {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 1280px;
  height: 1280px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
:root[data-theme="dark"] { --glow-opacity: 1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --glow-opacity: 1; } }

/* ---------- Profile (top left) ---------- */
.profile {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  width: 250px;
  max-width: calc(100vw - 16px);
  padding: 10px 10px 6px;
}

.profile-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}
.profile-button:hover, .profile-button[aria-expanded="true"] { background: var(--accent-soft); }

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  line-height: 13px;
}

.profile-text { display: flex; flex: 1; flex-direction: column; gap: 1px; min-width: 0; }
.profile-name, .profile-sub { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.profile-name { color: var(--text); font-size: 15px; font-weight: 600; line-height: 19.5px; letter-spacing: -0.15px; }
.profile-sub { color: var(--text-2); font-size: 11.7px; line-height: 14px; }

.menu {
  position: absolute;
  top: calc(100% - 2px);
  left: 10px;
  width: 230px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  text-align: left;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-emoji { font-size: 16px; width: 16px; text-align: center; }

.menu-section { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 6px; }
.menu-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.menu-divider { height: 1px; margin: 6px 10px; background: var(--border); }

.segmented {
  display: flex;
  gap: 1px;
  padding: 2px;
  border-radius: 9px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.segmented button {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"], .segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border-strong), 0 1px 2px rgba(0, 0, 0, 0.06);
}

/* ---------- Device map ---------- */
.stage { position: fixed; inset: 0; }

.links { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.links line { stroke: var(--line); stroke-width: 1; }
.links line.active { stroke: var(--accent); stroke-opacity: 0.5; stroke-dasharray: 4 6; animation: dash 0.8s linear infinite; }

.devices { position: absolute; inset: 0; }

.device {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 180px;
  margin-left: -90px;
  margin-top: calc(var(--bubble) / -2);
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  will-change: transform;
  animation: appear 0.5s ease-out both;
}
.device.leaving { animation: vanish 0.3s ease-in forwards; pointer-events: none; }

.bubble {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--bubble);
  height: var(--bubble);
  border: 1px solid var(--border);
  border-radius: 98px;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.bubble .emoji { font-size: var(--emoji-size); }

.device.peer:hover .bubble, .device.peer:focus-visible .bubble {
  border-color: var(--accent-ring);
  box-shadow: 0 0 0 6px var(--accent-soft);
}
.device.peer:focus-visible { outline: none; }
.device.dragover .bubble {
  border-color: var(--accent);
  box-shadow: 0 0 0 10px var(--accent-soft);
  transform: scale(1.06);
}
.device.me { cursor: default; }

.progress {
  position: absolute;
  inset: -5px;
  width: calc(100% + 10px);
  height: calc(100% + 10px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.progress circle { fill: none; stroke-width: 2.5; }
.progress .track { stroke: var(--accent-soft); }
.progress .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 0.2s; }
.device.waiting .progress { animation: spin 1.6s linear infinite; }

.device-label { display: flex; flex-direction: column; align-items: center; max-width: 100%; }
.device-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.device-sub { color: var(--text-2); font-size: 11.7px; white-space: nowrap; }
.device-sub.accent { color: var(--accent); }

.empty {
  position: absolute;
  left: 50%;
  bottom: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: min(420px, calc(100% - 32px));
  margin: 0;
  transform: translateX(-50%);
  text-align: center;
}
.empty-title { color: var(--text); font-size: 15px; font-weight: 500; }
.empty-hint { color: var(--muted); font-size: 13px; }

.status-pill {
  position: absolute;
  top: 18px;
  right: 16px;
  margin: 0;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11.7px;
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(340px, calc(100vw - 32px));
}

.incoming-stack {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: rgba(8, 9, 11, 0.45);
  backdrop-filter: blur(4px);
  animation: fade 0.2s ease-out;
}
.incoming-stack:empty { display: none; }
.incoming-stack .toast { width: min(380px, 100%); padding: 16px; animation: pop 0.2s ease-out; }
@keyframes fade { from { opacity: 0; } }

.toast {
  display: flex;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: rise 0.25s ease-out;
}
.toast.incoming { border-color: var(--accent-ring); }
.toast-emoji {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--surface-2);
  font-size: 24px;
}
.toast-body { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.toast-title { color: var(--text-2); font-size: 13px; }
.toast-title b { color: var(--text); font-weight: 600; }
.toast-file {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.toast-meta { color: var(--muted); font-size: 12px; }
.toast-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn-primary { background: var(--accent); box-shadow: none; color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Dialogs ---------- */
.dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog[open] { animation: pop 0.16s ease-out; }
.dialog-sm { width: min(380px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(8, 9, 11, 0.45); backdrop-filter: blur(4px); }

.dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px 20px; }
.dialog-head { display: flex; align-items: center; gap: 16px; }
.dialog-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.3px; }
.dialog-head p { margin: 2px 0 0; font-size: 13px; }
.bubble-lg { --bubble: 64px; flex: none; }
.bubble-lg .emoji { font-size: 40px; }
.logo { width: 52px; height: 52px; flex: none; border-radius: 12px; object-fit: contain; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--text-2); font-size: 13px; font-weight: 500; }
.field input {
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  font-size: 14px;
}
.field input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-soft); }

.emoji-tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.emoji-tabs button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.emoji-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 4px;
  max-height: 188px;
  padding: 6px;
  overflow-y: auto;
  border-radius: 10px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.emoji-grid button {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 24px;
}
.emoji-grid button:hover { background: var(--hover); }
.emoji-grid button[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-ring); }

.emoji-custom { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.emoji-custom input { width: 72px; height: 32px; text-align: center; font-family: var(--emoji); font-size: 18px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.dialog-actions .btn-start { margin-right: auto; }
.dialog-note { margin: -4px 0 0; font-size: 13px; }
.form-error { margin: -4px 0 0; color: var(--danger); font-size: 13px; }

/* ---------- Motion ---------- */
@keyframes appear { from { opacity: 0; scale: 0.8; } to { opacity: 1; scale: 1; } }
@keyframes vanish { to { opacity: 0; scale: 0.8; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes spin { to { transform: rotate(270deg); } }
@keyframes dash { to { stroke-dashoffset: -10; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
