/* ---------- design tokens ---------- */
:root {
  --bg: #0b0f1a;
  --bg-2: #111726;
  --panel: #151c2c;
  --panel-2: #1b2438;
  --line: #243049;
  --txt: #e6ebf5;
  --txt-dim: #9aa7c2;
  --txt-faint: #8693b2;
  --accent: #6d8cff;
  --accent-2: #9b6dff;
  --accent-grad: linear-gradient(135deg, #6d8cff, #9b6dff);
  --me-bubble: linear-gradient(135deg, #4f6bff, #7d4fff);
  --ok: #3ddc97;
  --warn: #ffcf5c;
  --off: #57617a;
  --radius: 16px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--txt);
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(155, 109, 255, 0.18), transparent 60%),
    radial-gradient(1000px 600px at -10% 110%, rgba(109, 140, 255, 0.16), transparent 55%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ---------- nickname gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  background: rgba(6, 9, 16, 0.6);
  backdrop-filter: blur(6px);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 30px 26px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.4s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.gate-logo { font-size: 54px; line-height: 1; filter: drop-shadow(0 6px 18px rgba(109,140,255,0.5)); }
.gate-title {
  margin: 12px 0 6px;
  font-size: 30px;
  letter-spacing: -0.5px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gate-sub { margin: 0 auto 22px; color: var(--txt-dim); font-size: 14.5px; line-height: 1.55; max-width: 34ch; }
.gate-label { display: block; text-align: left; font-size: 12.5px; color: var(--txt-faint); margin: 0 0 7px 4px; text-transform: uppercase; letter-spacing: 0.6px; }
.gate-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--txt);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.gate-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,140,255,0.25); }
.gate-btn {
  width: 100%;
  margin-top: 14px;
  padding: 14px 16px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  border: none;
  border-radius: 12px;
  background: var(--accent-grad);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
.gate-btn:hover { filter: brightness(1.08); }
.gate-btn:active { transform: translateY(1px); }
.gate-foot { margin: 18px 0 0; color: var(--txt-faint); font-size: 12px; line-height: 1.5; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.app[hidden] { display: none; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(17, 23, 38, 0.7);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark { font-size: 20px; }
.brand-name { letter-spacing: -0.3px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt-dim);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  cursor: default;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; box-shadow: 0 0 0 0 rgba(0,0,0,0); }
.dot--off { background: var(--off); }
.dot--wait { background: var(--warn); animation: pulse 1.6s infinite; }
.dot--on { background: var(--ok); animation: pulse 2.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(61,220,151,0.5);} 70% { box-shadow: 0 0 0 7px rgba(61,220,151,0);} 100% { box-shadow: 0 0 0 0 rgba(61,220,151,0);} }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.pill:hover { background: var(--panel-2); border-color: var(--accent); }
.pill-ico { font-size: 13px; }
.pill--me { max-width: 160px; }
.pill--me #me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }

/* ---------- body: chat + people ---------- */
.body { flex: 1; display: flex; min-height: 0; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px clamp(12px, 4vw, 40px) 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; }

/* system line */
.sys { align-self: center; margin: 8px 0; color: var(--txt-faint); font-size: 12px; background: var(--panel); border: 1px solid var(--line); padding: 4px 12px; border-radius: 999px; }

/* message row */
.msg { display: flex; gap: 10px; max-width: min(78%, 720px); margin-top: 12px; animation: pop 0.18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.cont { margin-top: 2px; }
.msg .avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #0b0f1a;
}
.msg.cont .avatar { visibility: hidden; height: 0; }
.msg .stack { display: flex; flex-direction: column; min-width: 0; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; margin: 0 2px 3px; }
.msg.cont .meta { display: none; }
.msg .who { font-size: 13px; font-weight: 700; }
.msg .time { font-size: 11px; color: var(--txt-faint); }
.bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 9px 13px;
  border-radius: 4px 14px 14px 14px;
  font-size: 15px;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.cont .bubble { border-radius: 14px; }

/* my own messages */
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .stack { align-items: flex-end; }
.msg.me .bubble { background: var(--me-bubble); border: none; color: #fff; border-radius: 14px 4px 14px 14px; }
.msg.me.cont .bubble { border-radius: 14px; }
.msg.me .meta { flex-direction: row-reverse; }

/* typing indicator */
.typing { padding: 2px clamp(12px, 4vw, 40px) 8px; color: var(--txt-dim); font-size: 12.5px; min-height: 18px; display: flex; align-items: center; gap: 7px; }
.typing[hidden] { display: none; }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--txt-dim); animation: blink 1.2s infinite; }
.typing .dots i:nth-child(2) { animation-delay: 0.2s; }
.typing .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

/* people sidebar */
.people {
  width: 240px;
  flex: none;
  border-left: 1px solid var(--line);
  background: rgba(17, 23, 38, 0.5);
  overflow-y: auto;
  padding: 14px 12px;
}
.people-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--txt-faint); margin: 4px 6px 12px; }
.people-close { display: none; border: none; background: none; color: var(--txt-dim); font-size: 16px; line-height: 1; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.people-close:hover { background: var(--panel); color: var(--txt); }

/* mobile scrim behind the slide-in roster (only ever visible on small screens) */
.scrim { display: none; position: fixed; inset: 0; z-index: 35; background: rgba(6, 9, 16, 0.5); }
.people-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.person { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.person:hover { background: var(--panel); }
.person .avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #0b0f1a; flex: none; }
.person .pname { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .tag { margin-left: auto; font-size: 11px; color: var(--accent); }
.person.pending .pname { color: var(--txt-faint); font-style: italic; }

/* ---------- composer ---------- */
.composer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px clamp(12px, 4vw, 40px);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(17, 23, 38, 0.7);
  backdrop-filter: blur(10px);
}
.icon-btn {
  width: 42px; height: 42px; flex: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 19px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--accent); }
.input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  font-size: 15px;
  color: var(--txt);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,140,255,0.22); }
.send-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: none; border-radius: 12px;
  background: var(--accent-grad);
  color: #fff; cursor: pointer;
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
}
.send-btn:hover { filter: brightness(1.08); }
.send-btn:active { transform: translateY(1px); }
.send-btn:disabled { opacity: 0.45; cursor: default; filter: none; }

/* emoji panel */
.emoji-panel {
  position: absolute;
  left: clamp(12px, 4vw, 40px);
  bottom: calc(100% - 4px);
  width: min(320px, calc(100vw - 32px));
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 20;
}
.emoji-panel[hidden] { display: none; }
.emoji-panel button {
  border: none; background: none; font-size: 20px; line-height: 1;
  padding: 6px 0; border-radius: 8px; cursor: pointer;
}
.emoji-panel button:hover { background: var(--panel); }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .brand-name { display: none; }
  .status-text { display: none; }
  .status { padding: 6px 8px; }
  .people {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(280px, 82vw);
    z-index: 40;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    padding-top: max(16px, env(safe-area-inset-top));
  }
  .people.open { transform: none; }
  .people-close { display: inline-flex; align-items: center; justify-content: center; }
  .scrim:not([hidden]) { display: block; }
  .msg { max-width: 86%; }
}
