@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg: #000000;
  --panel: #121212;
  --panel2: #1a1a1a;
  --line: rgba(255, 255, 255, 0.08);
  --text: #ffffff;
  --muted: #9a9a9a;
  --grad: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
  --grad-soft: linear-gradient(135deg, rgba(168, 85, 247, 0.25), rgba(236, 72, 153, 0.18));
  --ok: #4ade80;
  --danger: #fb7185;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  color-scheme: dark;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: calc(14px + var(--safe-t));
}
#app.chat-open {
  display: block;
  height: auto;
  min-height: 100dvh;
  overflow: visible;
  padding: calc(14px + var(--safe-t)) 14px calc(16px + var(--safe-b));
}
#app.chat-open .topbar { padding: 0; }
#app.chat-open .pager { display: none; }
#app.chat-open .nav,
#app.keyboard-open .nav {
  display: none;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  margin-bottom: 14px;
  animation: fade .35s ease both;
}
.brand {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.brand span {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.pill {
  font-size: .72rem;
  font-weight: 600;
  color: #fff;
  background: var(--panel2);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 999px;
}

/* ---------- pager ---------- */
.pager {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
}
.pager-track {
  display: flex;
  height: 100%;
  will-change: transform;
}
.page {
  flex: 0 0 100%;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: none;
  padding: 4px 14px calc(100px + var(--safe-b));
  will-change: opacity;
}
.page::-webkit-scrollbar { display: none; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: calc(12px + var(--safe-b));
  width: min(452px, calc(100% - 28px));
  margin: 0 auto;
  padding: 5px;
  border-radius: 999px;
  z-index: 30;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  isolation: isolate;
  background: rgba(14, 14, 16, 0.78);
  border: 1px solid var(--line);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  animation: navIn .35s ease both;
}
.nav-blob {
  position: absolute;
  top: 5px;
  bottom: 5px;
  left: 5px;
  right: 5px;
  z-index: 1;
  pointer-events: none;
}
.nav-blob-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.nb-shadow { fill: rgba(0, 0, 0, 0.55); }
.nb-glow { fill: #e879f9; opacity: .28; }
.nb-rim { vector-effect: non-scaling-stroke; }
.nav-track {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.nav button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: .8rem;
  letter-spacing: .01em;
  padding: 13px 6px;
  border-radius: 16px;
  outline: none;
  transition: color .28s ease, transform .2s ease;
}
.nav button:active { transform: scale(.96); }
.nav button.active { color: #fff; }

.view { display: none; }
.view.active {
  display: block;
  animation: viewIn .38s cubic-bezier(.22, 1, .36, 1) both;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.card h2, .card h3 {
  margin: 0 0 6px;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.muted { color: var(--muted); font-size: .86rem; line-height: 1.45; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.list-item {
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
  font: inherit;
  transition: border-color .15s ease, transform .12s ease;
}
.list-item:active { transform: scale(.985); }
.list-item:hover, .list-item:focus-visible {
  border-color: rgba(236, 72, 153, 0.45);
  outline: none;
}
.list-item .name {
  font-weight: 650;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ec4899;
  box-shadow: 0 0 10px rgba(236, 72, 153, .8);
}
.list-item .preview {
  color: var(--muted);
  font-size: .84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tag {
  font-size: .7rem;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  background: #fff;
  color: #000;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.back {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: #fff;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  font: inherit;
  font-weight: 700;
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 48vh;
  max-height: calc(100dvh - 220px);
  overflow: auto;
  padding: 2px 0 10px;
}
.bubble {
  max-width: 86%;
  padding: 11px 13px;
  border-radius: 14px;
  line-height: 1.4;
  font-size: .92rem;
  white-space: pre-wrap;
  word-break: break-word;
  animation: fade .2s ease both;
}
.bubble.them {
  align-self: flex-start;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bubble.me {
  align-self: flex-end;
  background: #2a2a2a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom-right-radius: 5px;
}
.bubble .meta {
  display: block;
  margin-top: 5px;
  font-size: .66rem;
  opacity: .55;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}
.composer textarea {
  resize: none;
  min-height: 48px;
  max-height: 120px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  caret-color: #fff;
  padding: 12px 14px;
  font: inherit;
  outline: none;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
}
.composer textarea:focus,
.composer textarea:focus-visible {
  outline: none;
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: none;
}
.composer button, .primary {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  min-width: 52px;
  font: inherit;
  font-weight: 700;
  color: #000;
  background: #fff;
  outline: none;
  box-shadow: none;
}
.composer button:focus,
.composer button:focus-visible,
.primary:focus,
.primary:focus-visible {
  outline: none;
  box-shadow: none;
}
.composer button:disabled { opacity: .45; }

.stat {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.stat div {
  padding: 12px;
  border-radius: 12px;
  background: var(--panel2);
  border: 1px solid var(--line);
}
.stat b {
  display: block;
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: 1.15rem;
  margin-top: 4px;
}

.empty, .error, .loading {
  text-align: center;
  padding: 32px 12px;
  color: var(--muted);
}
.error { color: var(--danger); }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes navIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .nav, .topbar { animation: none; }
  .view.active { animation: fade .2s ease both; }
}
