/* qareeb — one chat, filtered to 50 metres.
   Tokens first, then gate, chat, people panel, profile sheet. */

:root {
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --bg: #0a0d0c;
  --bg-glow: radial-gradient(120% 80% at 70% -10%, rgba(110, 231, 183, 0.09), transparent 60%);
  --surface: #111716;
  --surface-2: #161d1b;
  --surface-3: #1c2523;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #eef4f2;
  --muted: #9aa8a3;
  --faint: #7d8a85;
  --accent: #6ee7b7;
  --accent-ink: #05231a;
  --accent-soft: rgba(110, 231, 183, 0.12);
  --accent-line: rgba(110, 231, 183, 0.28);
  --danger: #ff9b9b;
  --danger-soft: rgba(255, 155, 155, 0.12);
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.9);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    --bg: #f4f4f1;
    --bg-glow: radial-gradient(120% 80% at 70% -10%, rgba(11, 125, 95, 0.1), transparent 60%);
    --surface: #ffffff;
    --surface-2: #fbfbf8;
    --surface-3: #f1f2ee;
    --line: rgba(13, 26, 22, 0.09);
    --line-2: rgba(13, 26, 22, 0.16);
    --text: #101815;
    --muted: #5c6a65;
    --faint: #636f6a;
    --accent: #0b7d5f;
    --accent-ink: #ffffff;
    --accent-soft: rgba(11, 125, 95, 0.1);
    --accent-line: rgba(11, 125, 95, 0.26);
    --danger: #c2410c;
    --danger-soft: rgba(194, 65, 12, 0.1);
    --shadow: 0 22px 48px -30px rgba(13, 26, 22, 0.45);
    color-scheme: light;
  }
}

:root[data-theme='light'] {
  --bg: #f4f4f1;
  --bg-glow: radial-gradient(120% 80% at 70% -10%, rgba(11, 125, 95, 0.1), transparent 60%);
  --surface: #ffffff;
  --surface-2: #fbfbf8;
  --surface-3: #f1f2ee;
  --line: rgba(13, 26, 22, 0.09);
  --line-2: rgba(13, 26, 22, 0.16);
  --text: #101815;
  --muted: #5c6a65;
  --faint: #636f6a;
  --accent: #0b7d5f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(11, 125, 95, 0.1);
  --accent-line: rgba(11, 125, 95, 0.26);
  --danger: #c2410c;
  --danger-soft: rgba(194, 65, 12, 0.1);
  --shadow: 0 22px 48px -30px rgba(13, 26, 22, 0.45);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-glow);
  background-repeat: no-repeat;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- brand ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  position: relative;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
}

.brand__ring {
  position: absolute;
  inset: 0;
  border: 1px solid var(--line-2);
  border-radius: 50%;
}

.brand__ring::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid var(--line);
  border-radius: 50%;
}

.brand__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand__name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.brand__tag {
  font-size: 12px;
  color: var(--faint);
}

/* ---------- gate ---------- */

.gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 22px 22px calc(20px + env(safe-area-inset-bottom));
  gap: 18px;
}

@media (min-width: 900px) {
  .gate {
    align-items: center;
    justify-content: center;
    gap: 26px;
  }
  .brand--gate {
    position: absolute;
    top: 26px;
    left: 26px;
  }
}

.gate__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
}

.radar {
  position: relative;
  width: min(52vw, 210px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}

.radar__ring {
  position: absolute;
  border: 1px solid var(--line);
  border-radius: 50%;
}
.radar__ring--1 { inset: 0; border-style: dashed; opacity: 0.7; }
.radar__ring--2 { inset: 18%; }
.radar__ring--3 { inset: 34%; border-color: var(--line-2); }

.radar__sweep {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0 88%,
    color-mix(in oklab, var(--accent) 8%, transparent) 96%,
    color-mix(in oklab, var(--accent) 30%, transparent) 99.4%,
    transparent 100%
  );
  -webkit-mask: radial-gradient(circle, transparent 30%, #000 31%);
  mask: radial-gradient(circle, transparent 30%, #000 31%);
  animation: sweep 5.5s linear infinite;
}

.radar__core {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  position: relative;
}

.radar__core::after {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 1px solid var(--accent-line);
  animation: pulse 2.8s var(--ease) infinite;
}

@keyframes sweep { to { transform: rotate(360deg); } }
@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  70% { transform: scale(1.5); opacity: 0; }
  100% { opacity: 0; }
}

.gate__title {
  margin: 0;
  font-size: clamp(28px, 7vw, 38px);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 600;
}

.gate__copy {
  margin: 0;
  color: var(--muted);
  font-size: 14.5px;
  max-width: 34ch;
}

.gate__asks {
  list-style: none;
  margin: 6px 0 4px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
  width: 100%;
  max-width: 380px;
}

.gate__asks li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--muted);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: color-mix(in oklab, var(--surface) 60%, transparent);
}

.gate__asks .icon {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: var(--accent);
}

.gate__asks strong {
  color: var(--text);
  font-weight: 550;
}

.gate__hint {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
  max-width: 34ch;
}

.gate__note {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--faint);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 50px;
  padding: 0 22px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 550;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 160ms var(--ease), background 160ms var(--ease), border-color 160ms var(--ease), opacity 160ms var(--ease);
}

.btn:active { transform: scale(0.985); }
.btn--wide { width: 100%; max-width: 380px; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 30px -14px var(--accent-line); }
.btn--primary:hover { background: color-mix(in oklab, var(--accent) 88%, var(--text)); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn--ghost:hover { color: var(--text); border-color: var(--line-2); }
.btn[disabled] { opacity: 0.55; cursor: default; }

.chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease);
}

.chip:hover { color: var(--text); border-color: var(--line-2); background: var(--surface-2); }
.chip--ghost { border-style: dashed; cursor: default; color: var(--faint); }

.iconbtn {
  position: relative;
  width: 38px;
  height: 38px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.iconbtn:hover { color: var(--text); border-color: var(--line-2); }
.iconbtn--small { width: 30px; height: 30px; border: none; }

.badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

/* ---------- app shell ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

@media (min-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr) 320px; }
  .app--folded { grid-template-columns: minmax(0, 1fr) 0px; }
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  min-width: 0;
}

.chat__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 3;
}

.chat__id { flex: 1; min-width: 0; }
.chat__id h1 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.chat__id p {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-btn { border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%; }

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0;
  color: #06120f;
  background: var(--surface-3);
  overflow: hidden;
  flex: none;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar--you { box-shadow: 0 0 0 2px var(--accent-line); }
.avatar--big { width: 72px; height: 72px; font-size: 20px; }

.avatar--mint { background: #7ff0c4; }
.avatar--sand { background: #e8cfa4; }
.avatar--sky { background: #a8d4f5; }
.avatar--rose { background: #f3b6c8; }
.avatar--lilac { background: #cbbcf6; }

.chat__scroll {
  overflow-y: auto;
  padding: 18px 16px 8px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
  display: flex;
  flex-direction: column;
}

.msgs {
  list-style: none;
  margin: auto auto 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 720px;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  animation: rise 220ms var(--ease) both;
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.msg--mine { flex-direction: row-reverse; }

.msg .avatar { width: 28px; height: 28px; border: none; }

.msg__body { max-width: min(74%, 520px); display: flex; flex-direction: column; gap: 4px; }
.msg--mine .msg__body { align-items: flex-end; }

.msg__who { font-size: 11.5px; color: var(--faint); padding: 0 6px; }

.bubble {
  padding: 9px 13px;
  border-radius: 16px 16px 16px 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 14.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg--mine .bubble {
  border-radius: 16px 16px 6px 16px;
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.bubble--pending { opacity: 0.6; }

.bubble--blocked,
.bubble--held {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
}

.bubble--blocked {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 38%, transparent);
  color: var(--danger);
}

.msg--mine .bubble--blocked {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 38%, transparent);
  color: var(--danger);
}

.bubble--held {
  background: var(--surface-3);
  border-color: var(--line-2);
  color: var(--muted);
}

.bubble--blocked .icon,
.bubble--held .icon { width: 15px; height: 15px; margin-top: 2px; flex: none; }

.msg__menu { align-self: center; opacity: 0; transition: opacity 140ms var(--ease); }
.msg:hover .msg__menu,
.msg:focus-within .msg__menu { opacity: 1; }

.msg__menu button {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.msg__menu button:hover { color: var(--text); border-color: var(--line); }

@media (hover: none) { .msg__menu { opacity: 0.6; } }

.chat__empty {
  max-width: 40ch;
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
}

.chat__empty strong { display: block; color: var(--text); font-weight: 550; margin-bottom: 6px; font-size: 15px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px max(16px, calc((100% - 752px) / 2)) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.composer textarea {
  flex: 1;
  min-height: 46px;
  max-height: 128px;
  padding: 12px 15px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  resize: none;
  outline: none;
  font-size: 16px;
  line-height: 1.45;
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}

.composer textarea::placeholder { color: color-mix(in oklab, var(--muted) 85%, transparent); }
.composer textarea:focus { border-color: var(--accent-line); background: var(--surface); }

.send {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: transform 160ms var(--ease), background 160ms var(--ease);
}

.send:active { transform: scale(0.94); }
.send[disabled] { background: var(--surface-3); color: var(--faint); cursor: default; }
.send .icon { width: 19px; height: 19px; }

/* ---------- people panel ---------- */

.people {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: color-mix(in oklab, var(--surface) 55%, transparent);
  overflow: hidden;
}

.people__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 10px;
}

.eyebrow {
  margin: 0;
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.people__count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }

.people__list {
  list-style: none;
  margin: 0;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  scrollbar-width: thin;
}

.person {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 12px;
  animation: rise 200ms var(--ease) both;
}

.person:hover { background: var(--surface-2); }
.person__name { flex: 1; min-width: 0; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person__dist { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.person .avatar { width: 28px; height: 28px; }

.people__empty {
  margin: auto 16px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  color: var(--faint);
  font-size: 12.5px;
  text-align: center;
  line-height: 1.5;
}

.people__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.people__foot .chip--ghost { margin-left: auto; }

/* mobile: the panel becomes a drawer over the chat */
@media (max-width: 899px) {
  .people {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(86vw, 340px);
    z-index: 12;
    border-left: 1px solid var(--line-2);
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(102%);
    transition: transform 260ms var(--ease);
    padding-top: env(safe-area-inset-top);
  }

  .app--panel .people { transform: none; }

  .app--panel::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 7, 0.45);
    z-index: 11;
  }
}

/* ---------- profile sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  overflow-y: auto;
}

@media (min-width: 900px) { .sheet { place-items: center; } }

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 7, 0.62);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 220ms var(--ease);
}

.sheet__panel {
  position: relative;
  width: min(100%, 460px);
  max-height: min(92dvh, 640px);
  overflow-y: auto;
  padding: 24px 22px calc(22px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  transition: transform 260ms var(--ease), opacity 260ms var(--ease);
}

@media (min-width: 900px) {
  .sheet__panel { border-radius: 26px; border-bottom: 1px solid var(--line); padding: 26px; }
}

.sheet[data-open='true'] .sheet__backdrop { opacity: 1; }
.sheet[data-open='true'] .sheet__panel { transform: none; opacity: 1; }

.sheet__panel h2 { margin: 0 0 6px; font-size: 19px; letter-spacing: -0.025em; font-weight: 600; }
.sheet__copy { margin: 0 0 16px; color: var(--muted); font-size: 13.5px; }

.profile__avatar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.sheet__label {
  display: block;
  font-size: 12px;
  color: var(--faint);
  margin: 0 2px 6px;
}

.sheet__panel input[type='text'] {
  width: 100%;
  height: 50px;
  padding: 0 15px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  outline: none;
  font-size: 16px;
}

.sheet__panel input[type='text']:focus { border-color: var(--accent-line); }

.sheet__err { min-height: 18px; margin: 8px 2px 0; font-size: 12.5px; color: var(--danger); }

.sheet__actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet__actions .btn { flex: 1; height: 46px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--surface-3);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
  z-index: 30;
  max-width: min(92vw, 460px);
  text-align: center;
}

.toast[data-show='true'] { opacity: 1; transform: translate(-50%, 0); }

.menu {
  position: fixed;
  z-index: 25;
  min-width: 168px;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  gap: 2px;
}

.menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}

.menu button:hover { background: var(--surface-3); }
.menu button[data-danger='true'] { color: var(--danger); }

@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;
  }
}
