:root {
  --bg: #0c0e14;
  --bg-2: #12141d;
  --panel: #161925;
  --panel-2: #1b1f2e;
  --line: #242838;
  --text: #e6e8f0;
  --muted: #8b90a6;
  --faint: #5b6076;
  --accent: #7c6cf0;
  --accent-2: #3fb98a;
  --danger: #e6685a;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over .gate/.app `display` rules below,
   otherwise a hidden panel stays painted and intercepts clicks. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Login / signup gate ---------------- */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1000px 600px at 70% -10%, rgba(124, 108, 240, 0.18), transparent 60%),
    radial-gradient(800px 500px at 10% 110%, rgba(63, 185, 138, 0.12), transparent 55%),
    var(--bg);
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #5a4bd0);
  font-size: 18px; color: #fff;
}
.brand-name { font-weight: 700; letter-spacing: -0.2px; }
.brand-sub { color: var(--faint); font-size: 12px; }

/* Log in / Create account switch */
.gate-tabs {
  display: flex; gap: 6px; margin-bottom: 20px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px;
}
.gate-tab {
  flex: 1; background: none; border: none; cursor: pointer;
  color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 8px; border-radius: 7px; transition: background 0.15s, color 0.15s;
}
.gate-tab:hover { color: var(--text); }
.gate-tab.sel { background: var(--panel-2); color: var(--text); }

.gate-card h1 { font-size: 24px; margin: 0 0 8px; letter-spacing: -0.4px; }
.gate-hint { color: var(--muted); line-height: 1.5; margin: 0 0 22px; font-size: 14px; }
.gate-hint strong { color: var(--accent-2); }

.field {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  transition: border-color 0.15s;
}
.field + .field { margin-top: 10px; }
.field:focus-within { border-color: var(--accent); }
.field .at { color: var(--faint); font-weight: 600; }
.field input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 16px; padding: 14px 0;
  font-family: "JetBrains Mono", monospace;
}

/* ---------------- Profile editor ---------------- */
.profile-edit { display: flex; gap: 14px; align-items: center; margin-top: 18px; }
.avatar-preview {
  width: 56px; height: 56px; border-radius: 14px; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  font-size: 20px; text-transform: uppercase; overflow: hidden;
  border: 1px solid var(--line);
}
.profile-controls { flex: 1; min-width: 0; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; padding: 0;
  border: 2px solid transparent; cursor: pointer;
}
.swatch.sel { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #fff; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; cursor: pointer;
  font-family: inherit; line-height: 1;
}
.mini-btn:hover { border-color: var(--accent); }
.mini-btn.ghost { color: var(--muted); }
.mini-btn.warn { color: #e6938a; }
.mini-btn.warn:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.color-pick { position: relative; overflow: hidden; }
.color-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.profile-hint { color: var(--faint); font-size: 11px; margin: 8px 0 0; }

/* profile chip in the top bar */
.profile-btn {
  background: none; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; border-radius: 8px;
}
.profile-btn:hover .avatar { outline: 2px solid var(--accent); outline-offset: 1px; }

/* profile modal */
.modal {
  position: fixed; inset: 0; z-index: 60; padding: 20px;
  display: grid; place-items: center; background: rgba(0, 0, 0, 0.55);
}
.modal-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: 16px; padding: 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
}
.modal-card {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal-card h2 { margin: 0 0 16px; font-size: 18px; letter-spacing: -0.3px; }
.modal-sep { border: none; border-top: 1px solid var(--line); margin: 24px 0 18px; }
.modal-sub { margin: 0 0 6px; font-size: 14px; letter-spacing: -0.2px; }
.modal-sub .opt {
  color: var(--faint); font-size: 11px; font-weight: 500;
  letter-spacing: 0; margin-left: 6px; text-transform: uppercase;
}

/* Account (name / password) fields */
.account-fields { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.acct-row { display: flex; flex-direction: column; gap: 5px; }
.acct-row span { color: var(--muted); font-size: 12px; font-weight: 600; }
.acct-row input {
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); outline: none; padding: 10px 12px; font-size: 14px;
  font-family: "JetBrains Mono", monospace;
}
.acct-row input:focus { border-color: var(--accent); }
.acct-row input::placeholder { color: var(--faint); font-family: "Inter", sans-serif; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.modal-actions button {
  flex: 1; border-radius: 10px; padding: 11px; font-weight: 600;
  cursor: pointer; font-size: 14px; border: none; font-family: inherit;
}
#profile-save { background: linear-gradient(135deg, var(--accent), #6a58e0); color: #fff; }
#profile-save:hover { filter: brightness(1.08); }
#profile-cancel { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
#acct-save { background: linear-gradient(135deg, var(--accent), #6a58e0); color: #fff; }
#acct-save:hover { filter: brightness(1.08); }
#acct-save:disabled { opacity: 0.55; cursor: wait; }
.ghost-btn { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line) !important; }
.ghost-btn:hover { color: var(--danger); border-color: var(--danger) !important; }

/* People & access panel */
.vis-options { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.vis-row {
  display: flex; gap: 10px; align-items: flex-start; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; color: var(--muted); line-height: 1.4;
}
.vis-row:hover { border-color: var(--accent); }
.vis-row input { margin-top: 2px; accent-color: var(--accent); }
.vis-row strong { color: var(--text); font-weight: 600; }

.people-add { display: flex; gap: 8px; margin-top: 12px; }
.people-add input {
  flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); outline: none; padding: 10px 12px; font-size: 14px;
  font-family: "JetBrains Mono", monospace;
}
.people-add input:focus { border-color: var(--accent); }
.people-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.people-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px;
}
.people-who { display: flex; flex-direction: column; gap: 3px; font-size: 14px; min-width: 0; }
.people-tag {
  color: var(--accent-2); font-size: 11px;
  font-family: "JetBrains Mono", monospace; letter-spacing: 0.5px;
}
.people-empty { color: var(--faint); font-size: 13px; padding: 6px 0; }
.people-controls { display: flex; align-items: center; gap: 8px; flex: none; }
.people-can-invite {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
  color: var(--muted); font-size: 12px; white-space: nowrap;
}
.people-can-invite input { accent-color: var(--accent); cursor: pointer; }

/* code entry + the code you get back when you make a chat */
.code-input {
  width: 100%; margin-top: 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); outline: none; padding: 14px;
  font-family: "JetBrains Mono", monospace; font-size: 22px;
  letter-spacing: 4px; text-align: center; text-transform: uppercase;
}
.code-input.name {
  font-family: inherit; font-size: 16px; letter-spacing: 0;
  text-align: left; text-transform: none;
}
.code-input:focus { border-color: var(--accent); }
.code-input:disabled { opacity: 0.6; }
.code-input::placeholder { color: var(--faint); letter-spacing: 2px; }
.code-out {
  margin: 8px 0 12px; padding: 14px;
  background: var(--bg); border: 1px dashed rgba(124, 108, 240, 0.5);
  border-radius: 10px; color: var(--accent);
  font-family: "JetBrains Mono", monospace; font-size: 26px;
  letter-spacing: 6px; text-align: center;
}
#code-join, #new-create { background: linear-gradient(135deg, var(--accent), #6a58e0); color: #fff; }
#code-join:hover, #new-create:hover { filter: brightness(1.08); }
#code-join:disabled, #new-create:disabled { opacity: 0.55; cursor: wait; }
#code-cancel, #new-cancel { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }

.gate-error {
  margin-top: 12px; color: var(--danger); font-size: 13px;
  background: rgba(230, 104, 90, 0.1);
  border: 1px solid rgba(230, 104, 90, 0.3);
  padding: 10px 12px; border-radius: 8px;
}
.gate-error.ok {
  color: var(--accent-2);
  background: rgba(63, 185, 138, 0.1);
  border-color: rgba(63, 185, 138, 0.3);
}

#gate-submit {
  margin-top: 18px; width: 100%;
  background: linear-gradient(135deg, var(--accent), #6a58e0);
  color: #fff; border: none; border-radius: var(--radius);
  padding: 14px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}
#gate-submit:hover { filter: brightness(1.08); }
#gate-submit:active { transform: translateY(1px); }
#gate-submit:disabled { opacity: 0.55; cursor: wait; }

.gate-foot { margin-top: 20px; color: var(--faint); font-size: 12px; }

/* ---------------- App shell ---------------- */
.app { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

.avatar {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 600;
  font-size: 12px; text-transform: uppercase; overflow: hidden;
}
.avatar img, .avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

.brand-mark.sm { width: 26px; height: 26px; border-radius: 7px; font-size: 14px; }

.topbar {
  height: 56px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.topbar-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* chat switcher + shareable code */
.room-select {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 10px; font-family: inherit; font-size: 14px; font-weight: 600;
  max-width: 220px; cursor: pointer; outline: none;
}
.room-select:hover { border-color: var(--accent); }
.room-code {
  background: rgba(124, 108, 240, 0.12); color: var(--accent);
  border: 1px dashed rgba(124, 108, 240, 0.5); border-radius: 8px;
  padding: 6px 9px; cursor: pointer;
  font-family: "JetBrains Mono", monospace; font-size: 12px; letter-spacing: 1px;
}
.room-code:hover { background: rgba(124, 108, 240, 0.22); }
.topbar-title .hash { color: var(--faint); }
.online { color: var(--accent-2); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.online .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); }

.messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 2px;
}

.msg { display: flex; gap: 12px; padding: 8px 8px; border-radius: 10px; position: relative; }
.msg:hover { background: var(--bg-2); }
.msg.grouped { padding-top: 1px; padding-bottom: 1px; }
.msg.grouped .avatar { visibility: hidden; height: 0; }
.msg.grouped .msg-head { display: none; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-name { font-weight: 600; font-size: 14px; }
.msg-time { color: var(--faint); font-size: 11px; }
.msg-text { color: var(--text); line-height: 1.5; word-wrap: break-word; white-space: pre-wrap; }

/* Delete button: only on messages you're allowed to remove, only on hover. */
.msg-del {
  position: absolute; top: 4px; right: 6px;
  width: 24px; height: 24px; padding: 0; line-height: 1;
  display: none; place-items: center;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 7px;
  font-size: 16px; cursor: pointer; font-family: inherit;
}
.msg.can-del:hover .msg-del { display: grid; }
.msg-del:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.msg-del:disabled { opacity: 0.5; cursor: wait; }

.msg-system {
  text-align: center; color: var(--faint); font-size: 12px;
  padding: 6px 0; font-style: italic;
}

.composer { flex: none; padding: 14px 20px 18px; border-top: 1px solid var(--line); background: var(--bg-2); }
.composer form { display: flex; gap: 10px; align-items: center; }

/* photo / GIF in a message */
.attach-btn {
  flex: none; width: 44px; height: 44px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.attach-btn:hover { border-color: var(--accent); color: var(--text); }
.attach-preview {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px;
}
.attach-preview img {
  width: 44px; height: 44px; object-fit: cover; border-radius: 8px; display: block;
}
.attach-note { color: var(--faint); font-size: 12px; flex: 1; }

.msg-image {
  margin-top: 6px; color: var(--faint); font-size: 12px;
  max-width: 320px;
}
.msg-image img {
  display: block; max-width: 100%; max-height: 320px;
  width: auto; height: auto; border-radius: 10px; border: 1px solid var(--line);
}
.composer input {
  flex: 1; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 16px; color: var(--text);
  outline: none; font-size: 15px; font-family: inherit;
}
.composer input:focus { border-color: var(--accent); }
#send-btn {
  background: linear-gradient(135deg, var(--accent), #6a58e0);
  color: #fff; border: none; border-radius: var(--radius);
  padding: 0 20px; font-weight: 600; cursor: pointer; font-size: 14px;
}
#send-btn:hover { filter: brightness(1.08); }
.composer-foot {
  margin-top: 8px; color: var(--faint); font-size: 12px;
  display: flex; justify-content: space-between;
}
.handle { color: var(--accent); font-family: "JetBrains Mono", monospace; }
.topbar-title .brand-mark { display: inline-grid; }

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .topbar-title .brand-mark.sm { display: none; }
  .room-select { max-width: 150px; }
  .online { font-size: 12px; }
}

.banner {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 10px 18px;
  border-radius: 10px; font-size: 13px; z-index: 50; max-width: 90vw;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
