:root {
  --background: #0a0a10;
  --foreground: #f5f4f2;
  --card: #18181d;
  --card-2: #1b1b21;
  --muted: #222229;
  --muted-fg: rgba(245, 244, 242, 0.5);
  --primary: #ffffff;
  --primary-fg: #101014;
  --border: rgba(255, 255, 255, 0.10);
  --text-dim: rgba(255, 255, 255, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--background);
  background-image:
    radial-gradient(ellipse 800px 600px at 20% 30%, rgba(72, 49, 157, 0.18), transparent 60%),
    radial-gradient(ellipse 700px 500px at 80% 70%, rgba(20, 90, 130, 0.18), transparent 60%),
    radial-gradient(ellipse 600px 500px at 50% 50%, rgba(40, 30, 80, 0.15), transparent 60%);
  background-attachment: fixed;
  color: var(--foreground);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

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

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(circle 600px at 30% 20%, rgba(94, 60, 180, 0.25), transparent 70%),
    radial-gradient(circle 500px at 75% 60%, rgba(30, 110, 160, 0.22), transparent 70%),
    radial-gradient(circle 700px at 50% 90%, rgba(50, 30, 90, 0.18), transparent 70%);
  filter: blur(40px);
  pointer-events: none;
  z-index: 0;
}
body > * { position: relative; z-index: 1; }

/* === TOP BAR === */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.tb-icon {
  background: transparent;
  border: 0;
  color: var(--foreground);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}
.tb-icon:hover { background: var(--muted); }
.tb-icon .material-symbols-outlined { font-size: 24px; }

.tb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
}
.tb-logo, .modal-logo { width: 32px; height: 32px; display: block; flex-shrink: 0; color: white; }
.tb-logo img, .modal-logo img { width: 100%; height: 100%; display: block; }
.tb-name {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--foreground);
}

.tb-spacer { flex: 1; }

/* === MAIN SHELL === */
.shell {
  display: grid;
  grid-template-columns: 88px 1fr;
  padding-top: 56px;
  height: 100vh;
  transition: grid-template-columns .2s ease;
}

.shell.nav-collapsed { grid-template-columns: 0 1fr; }
.shell.nav-collapsed .nav { border-right: none; }
.shell.nav-collapsed .nav-item { opacity: 0; pointer-events: none; }

/* === LEFT NAV (icon rail) === */
.nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  background: var(--background);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 64px;
  width: 100%;
  border-radius: 32px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  font-size: 18px;
  font-weight: 600;
  padding: 0 24px;
  margin: 4px 0;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.12);
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { background: rgba(0, 0, 0, 0.45); border-color: rgba(255, 255, 255, 0.4); }
.nav-item:active { transform: scale(0.98); }
.nav-item.active { background: rgba(0, 0, 0, 0.5); border-color: rgba(255, 255, 255, 0.45); box-shadow: 0 0 0 2px var(--primary), 0 4px 16px rgba(0,0,0,0.3); }
.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: transparent;
  color: var(--foreground);
}
.nav-icon .material-symbols-outlined {
  font-size: 24px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 40;
}
.nav-label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === CHAT LIST (capsules) === */
.chat-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 32px;
  background: var(--background);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.chat-capsule {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  height: 72px;
  padding: 0 24px;
  border-radius: 36px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  color: var(--foreground);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.12);
  white-space: nowrap;
  flex-shrink: 0;
}
.chat-capsule:hover { background: rgba(0, 0, 0, 0.45); border-color: rgba(255, 255, 255, 0.4); }
.chat-capsule:active { transform: scale(0.99); }
.chat-capsule.active { background: rgba(0, 0, 0, 0.5); border-color: rgba(255, 255, 255, 0.45); box-shadow: 0 0 0 2px var(--primary), 0 4px 16px rgba(0,0,0,0.3); }

.chat-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: transparent;
  color: var(--foreground);
}
.chat-avatar .material-symbols-outlined {
  font-size: 32px;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 40;
}

.chat-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  font-weight: 600;
  font-size: 18px;
  color: var(--foreground);
}

.shell {
  display: grid;
  grid-template-columns: 88px 1fr;
  padding-top: 56px;
  height: 100vh;
  transition: grid-template-columns 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.shell > .nav { transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.shell.nav-collapsed { grid-template-columns: 0 1fr; }
.shell.nav-collapsed > .nav { width: 0; border-right: none; }

@media (min-width: 1024px) {
  .shell { grid-template-columns: 320px 1fr; }
  .shell.nav-collapsed { grid-template-columns: 0 1fr; }
}

/* === CONTENT === */
.content {
  background: var(--background);
  overflow: hidden;
}

.content-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.content-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.search:focus-within {
  border-color: var(--primary);
  background: var(--card-2);
}
.search-icon {
  color: var(--muted-fg);
  font-size: 20px;
}
.search input {
  background: transparent;
  border: 0;
  outline: none;
  color: var(--foreground);
  font-size: 14px;
  flex: 1;
}
.search input::placeholder { color: var(--text-dim); }

/* === CHAT STAGE === */
.chat-stage {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted-fg);
  gap: 12px;
  padding: 32px;
  text-align: center;
}
.empty-icon {
  font-size: 64px;
  opacity: 0.4;
}
.empty-title {
  font-size: 17px;
  font-weight: 500;
  color: var(--foreground);
}
.empty-sub { font-size: 13px; }

/* === ACTIVE CHAT (will be styled when active) === */
.chat-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.chat-peer-bar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 14px;
}
.chat-peer-bar .online {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}
.chat-peer-bar .offline {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
}
.msg.me {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
  align-self: flex-end;
}
.msg.peer { align-self: flex-start; }
.msg.time {
  font-size: 11px;
  color: var(--text-dim);
  align-self: center;
  padding: 4px 8px;
  background: transparent;
  border: 0;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  background: var(--background);
  border-top: 1px solid var(--border);
}
.composer input {
  flex: 1;
  padding: 11px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--foreground);
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}
.composer input:focus { border-color: var(--primary); }
.composer input::placeholder { color: var(--text-dim); }
.composer button {
  padding: 11px 22px;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.composer button:disabled { opacity: 0.4; cursor: not-allowed; }

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  padding: 20px 24px;
  border-radius: 16px;
  width: min(480px, 92vw);
  border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}
.modal-logo { width: 22px; height: 22px; display: block; flex-shrink: 0; color: white; }
.muted { color: var(--muted-fg); font-size: 13px; }
.muted-title { font-weight: 500; margin-bottom: 2px; font-size: 14px; }
.ts-wrapper { margin: 0; min-height: 0; }
.ts-wrapper:not(:empty) { margin: 12px 0; min-height: 65px; }
.hidden { display: none !important; }

.seed {
  background: var(--background);
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 12px;
}
.seed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}
.seed-grid div {
  background: var(--card-2);
  padding: 6px 10px;
  border-radius: 8px;
}
.pubid-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 12px 0;
  flex-wrap: wrap;
}
.pubid-box b { font-family: ui-monospace, monospace; color: var(--foreground); }
.copy {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted-fg);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 10px;
  text-transform: uppercase;
}
.btn-primary {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--primary);
  color: var(--primary-fg);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  background: var(--card-2);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.btn-secondary:hover { border-color: rgba(255,255,255,0.25); }

.restore-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--muted);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  resize: vertical;
  min-height: 60px;
}
.restore-input:focus { outline: none; border-color: var(--primary); }

.modal-actions { display: flex; flex-direction: column; gap: 0; margin-top: 12px; }

/* === SCROLLBARS === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.14);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }
::-webkit-scrollbar-track { background: transparent; }

/* === AVATAR (topbar) + POPOVER === */
.tb-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--g-bg, var(--muted));
  color: var(--g-color, var(--primary));
  border: 3px solid var(--g-color, var(--border));
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.01em;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  user-select: none;
  overflow: hidden;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}
.tb-avatar:hover { background: var(--card-2); border-color: rgba(255,255,255,0.35); }
.tb-avatar:active { transform: scale(0.96); }
.tb-avatar[hidden] { display: none; }

.avatar-menu {
  position: fixed;
  top: 60px;
  right: 12px;
  z-index: 60;
  width: min(360px, calc(100vw - 24px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.avatar-menu.hidden { display: none; }

.am-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 12px;
  border-bottom: 1px solid var(--border);
}
.am-avatar {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--g-bg, var(--muted));
  color: var(--g-color, var(--primary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 20px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  border: 3px solid var(--g-color, var(--border));
}
.am-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.am-name {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--g-color, var(--foreground));
  word-break: break-all;
  line-height: 1.3;
}
.am-key {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--muted-fg);
  word-break: break-all;
  line-height: 1.3;
}
.am-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted-fg);
}
.am-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 6px var(--primary);
}
.am-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.am-btn {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  transition: background 0.15s ease;
}
.am-btn:hover { background: var(--muted); }
.am-btn-danger { color: #ff8a8a; border-color: rgba(255,138,138,0.25); }
.am-btn-danger:hover { background: rgba(255,138,138,0.10); border-color: rgba(255,138,138,0.4); }

.am-gender {
  display: flex;
  gap: 6px;
}
.g-btn {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--muted);
  color: var(--foreground);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.g-btn:hover { border-color: rgba(255,255,255,0.25); }
.g-btn.active {
  border-color: var(--g-color, var(--primary));
  background: var(--g-bg, rgba(132,228,186,0.12));
  color: var(--g-color, var(--primary));
}
.g-btn[data-g="N"].active {
  --g-color: #ffffff;
  --g-bg: rgba(255,255,255,0.10);
}
.g-btn[data-g="W"].active {
  --g-color: #ff8aad;
  --g-bg: rgba(255,138,173,0.14);
}
.g-btn[data-g="M"].active {
  --g-color: #6ea8ff;
  --g-bg: rgba(110,168,255,0.14);
}

.gender-N { --g-color: #ffffff; --g-bg: rgba(255,255,255,0.10); }
.gender-W { --g-color: #ff8aad; --g-bg: rgba(255,138,173,0.14); }
.gender-M { --g-color: #6ea8ff; --g-bg: rgba(110,168,255,0.14); }
