* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
:root {
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #0a0c10;
  --surface: #11151d;
  --border: #232a36;
  --border2: #2a3242;
  --text: #d0d6e0;
  --muted: #9aa5b8;
  --dim: #8b95a8;
  --accent: #7aa2f7;
  --you: #163050;
  --you-text: #e8f0ff;
}
html,
body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: 100svh;
  display: flex;
  overflow: hidden;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.screen {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.hidden {
  display: none !important;
}
.brand {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  font-size: 0.78rem;
  padding: 7px 11px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border2);
  border-radius: 999px;
  background: var(--surface);
}
.brand-lg {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  font-size: 1.4rem;
  margin-bottom: 10px;
}
.top {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 6px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--bg);
}
.who-chip {
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 7px 11px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border2);
  border-radius: 999px;
  background: #16233c;
  text-decoration: none;
}
#adminBtn { color: #7aa2f7; }
.back,
#send,
#attachBtn,
.row-btn,
#joinBtn,
#createGroupBtn,
#lbClose,
#lbSave,
#attachSheet button {
  font-family: inherit;
  touch-action: manipulation;
}
#composeBtn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: #16233c;
  color: #cfe0ff;
  font-size: 1.4rem;
  line-height: 1;
}
.back {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
}
#inboxPane,
#threadPane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  flex: 1;
  background: var(--bg);
}
.jump-down {
  position: absolute;
  right: 16px;
  bottom: 88px;
  z-index: 8;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: #16233c;
  color: #cfe0ff;
  font-size: 1.2rem;
  font-family: inherit;
}
.info-media {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 12px;
  max-height: 240px;
  overflow: auto;
}
.info-media img,
.info-media video {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  background: #05070a;
}
.seen-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  color: var(--text);
}
#inboxList {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
#inboxEmpty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.conv {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  font-family: inherit;
  border-bottom: 1px solid #12161e;
}
.conv:active,
.conv.on {
  background: #11151d;
}
.conv .meta {
  flex: 1;
  min-width: 0;
}
.conv .name-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.conv .name {
  font-weight: 700;
  font-size: 1rem;
}
.conv .time {
  color: var(--dim);
  font-size: 0.72rem;
  flex: 0 0 auto;
}
.conv .preview {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #0a0c10;
  font-size: 0.7rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
}
.av {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: 0 0 auto;
  font-size: 0.95rem;
}
.av.sm {
  width: 32px;
  height: 32px;
  font-size: 0.78rem;
}
.av.h0 { background: #16233c; color: #7aa2f7; }
.av.h1 { background: #241830; color: #bb9af7; }
.av.h2 { background: #162016; color: #9ece6a; }
.av.h3 { background: #2a2214; color: #e0af68; }
.av.h4 { background: #3a1520; color: #f7768e; }
.av.h5 { background: #102028; color: #7dcfff; }
.av.group { background: #1a2230; color: #cfe0ff; }

.empty,
.join-copy {
  color: #5a6478;
  text-align: center;
  padding: 12px 0 18px;
  line-height: 1.7;
  font-size: 0.9rem;
}
#whoList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
#whoList button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #2a3242;
  background: #11151d;
  color: #9aa5b8;
  font-family: inherit;
  font-size: 0.95rem;
}
#whoList button.on {
  border-color: #7aa2f7;
  background: #16233c;
  color: #cfe0ff;
}
.thread-top .thread-who {
  min-width: 0;
}
#threadName {
  font-weight: 700;
}
#threadSub {
  color: var(--dim);
  font-size: 0.72rem;
  min-height: 1em;
  line-height: 1.2;
}
#thread {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 12px 18px;
  background: #05070a;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.day {
  align-self: center;
  color: var(--dim);
  font-size: 0.72rem;
  margin: 6px 0;
}
.msg-wrap {
  position: relative;
  max-width: 82%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.msg-wrap.you { align-self: flex-end; }
.msg-wrap.them { align-self: flex-start; }
.msg-wrap.has-reacts { margin-bottom: 12px; }
.msg {
  max-width: 100%;
  min-width: 0;
  padding: 10px 14px 12px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg.you {
  background: var(--you);
  color: var(--you-text);
  border-bottom-right-radius: 4px;
}
.msg.them {
  background: #141820;
  border: 1px solid var(--border);
  color: #d8dee8;
  border-bottom-left-radius: 4px;
}
.msg .who {
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: #8bb4e8;
}
.msg.them .who {
  color: #9aa5b8;
}
.msg .when {
  font-size: 0.65rem;
  color: #7a8496;
}
.msg-wrap.typing-wrap {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transition: max-height 0.22s ease, opacity 0.2s ease;
}
.msg-wrap.typing-wrap.on {
  max-height: 40px;
  opacity: 1;
}
.msg.typing {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 40px;
  padding: 8px 12px;
  background: #12161e;
  border-color: #1e2633;
}
.msg.typing .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7a8496;
  animation: typing-pulse 1.5s ease-in-out infinite;
}
.msg.typing .dot:nth-child(2) { animation-delay: 0.18s; }
.msg.typing .dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-pulse {
  0%, 80%, 100% { opacity: 0.22; transform: none; }
  40% { opacity: 0.55; }
}
.msg-meta {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 2px;
  line-height: 1;
}
.msg-meta .when {
  flex: 0 0 auto;
}
.msg-meta .receipts {
  flex: 0 0 auto;
}
.msg.media,
.msg.gif {
  width: min(240px, 100%);
  max-width: 240px;
  padding: 4px 4px 8px;
  overflow: hidden;
}
.msg.media img,
.msg.media video,
.msg.gif img,
.msg.gif video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: #0a0c10;
  vertical-align: middle;
}
.msg audio {
  width: 220px;
}
.msg .cap {
  padding: 6px 8px 4px;
}
.msg a.file {
  color: #7dcfff;
  display: block;
  padding: 8px;
}
footer {
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  flex: 0 0 auto;
}
#inputRow {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#text {
  flex: 1;
  min-width: 0;
  padding: 12px;
  min-height: 48px;
  max-height: 140px;
  border: 1px solid var(--border2);
  border-radius: 12px;
  background: #05070a;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  resize: none;
}
#send {
  flex: 0 0 auto;
  min-width: 68px;
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: #16233c;
  color: #cfe0ff;
  font-size: 1rem;
  font-weight: 700;
}
#attachBtn,
#emojiBtn {
  width: 44px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--accent);
  font-size: 1.15rem;
  font-family: inherit;
  font-weight: 800;
}
#emojiBtn { font-size: 1.2rem; }
.picker-shell {
  margin-bottom: 8px;
  border: 1px solid var(--border2);
  border-radius: 12px;
  background: #0c1018;
  overflow: hidden;
}
.picker-tabs {
  display: flex;
  border-bottom: 1px solid var(--border2);
}
.picker-tab {
  flex: 1;
  min-height: 40px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.picker-tab.on {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.picker-body {
  max-height: 240px;
  overflow: auto;
  padding: 8px;
}
#emojiPanel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
#emojiPanel button {
  min-height: 40px;
  border: none;
  background: transparent;
  font-size: 1.25rem;
  border-radius: 8px;
}
#gifQ {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  min-height: 40px;
  border: 1px solid var(--border2);
  border-radius: 10px;
  background: #05070a;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
#gifGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
#gifGrid img,
#gifGrid video {
  width: 100%;
  height: 88px;
  object-fit: cover;
  border-radius: 8px;
  background: #05070a;
}
.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 10px;
  border-left: 3px solid var(--accent);
  margin-bottom: 6px;
}
.reply-bar .q-thumb { width: 48px; height: 48px; flex-basis: 48px; }
.reply-lab { font-size: 0.7rem; color: var(--accent); font-weight: 700; }
.reply-prev { font-size: 0.82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
#replyCancel {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
}
.caption {
  white-space: normal;
  overflow-wrap: anywhere;
}
.card {
  display: block;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #0a0e14;
  text-decoration: none;
  color: inherit;
  width: 100%;
  max-width: 100%;
}
.msg.you .card { border-color: #1e3a5c; background: #102038; }
.card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  display: block;
  background: #0a0c10;
}
.card .c-body { padding: 8px 10px 10px; }
.card .c-site {
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .c-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin: 2px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .c-desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card.skeleton .c-title { color: #8b95a8; font-weight: 500; }
.msg a.short {
  color: #7dcfff;
  text-decoration: none;
  font-size: 0.85rem;
  display: inline-block;
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.msg a.short:hover { text-decoration: underline; }

.reacts {
  position: absolute;
  bottom: -11px;
  z-index: 2;
  display: flex;
  gap: 3px;
  pointer-events: auto;
}
.msg-wrap.them .reacts { right: 8px; left: auto; }
.msg-wrap.you .reacts { left: 8px; right: auto; }
.reacts button {
  border: 1px solid #3d4a62;
  background: #1a2230;
  color: var(--text);
  border-radius: 999px;
  min-height: 22px;
  padding: 0 7px;
  font-size: 0.78rem;
  font-family: inherit;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.reacts button.mine {
  border-color: var(--accent);
  background: #16233c;
}
#reactPop {
  position: fixed;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 999px;
  background: #141820;
  border: 1px solid #3d4a62;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
}
#reactPop button {
  min-width: 36px;
  min-height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1.15rem;
  border-radius: 50%;
  font-family: inherit;
}
#reactPop button.act {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  min-width: auto;
  padding: 0 8px;
  border-radius: 10px;
}
.quote {
  border-left: 2px solid var(--accent);
  padding: 4px 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 0 8px 8px 0;
}
.quote span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote.has-media {
  flex-direction: column;
  align-items: stretch;
  cursor: default;
  padding: 4px;
  gap: 4px;
}
.quote.has-media .vid-box,
.quote img.q-play,
.quote.has-media video {
  width: 100%;
  max-width: 240px;
}
.quote img.q-play {
  display: block;
  height: auto;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  background: #0a0c10;
}
.q-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  background: #05070a;
  flex: 0 0 44px;
}
.deleted {
  font-style: italic;
  color: #7a8496;
}
.receipts {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  line-height: 1;
  flex: 0 0 auto;
}
.tick {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: -0.12em;
  line-height: 1;
}
.tick.h0 { color: #7aa2f7; }
.tick.h1 { color: #bb9af7; }
.tick.h2 { color: #9ece6a; }
.tick.h3 { color: #e0af68; }
.tick.h4 { color: #f7768e; }
.tick.h5 { color: #7dcfff; }
.tick.dim { opacity: 0.35; color: #8b95a8; }
.tick.sent { opacity: 0.55; color: #8b95a8; }
.tick.delivered { opacity: 0.42; color: #c5d0e0; }
.tick.read { opacity: 1; }
.tick.plus {
  width: auto;
  min-width: 16px;
  padding: 0 4px;
  font-size: 0.62rem;
  font-weight: 800;
  color: #cfe0ff;
  background: #16233c;
  border: 1px solid #2a3242;
}
#attachSheet {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}
#attachSheet button {
  flex: 1 0 auto;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border2);
  border-radius: 11px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}
#attachSheet button.rec {
  border-color: #f7768e;
  color: #ff6b81;
  background: #3a1520;
}
.pending {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px 8px;
  color: var(--muted);
  font-size: 0.82rem;
}
.pending img {
  height: 48px;
  border-radius: 8px;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.sheet-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}
.sheet-panel {
  position: relative;
  z-index: 1;
  max-height: 82vh;
  overflow: auto;
  background: #141820;
  border: 1px solid #3d4a62;
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 12px 14px calc(env(safe-area-inset-bottom, 0px) + 18px);
}
.sheet-h {
  font-size: 1.05rem;
  font-weight: 700;
  color: #cfe0ff;
  margin-bottom: 10px;
}
.row-btn,
.person {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 12px;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--border2);
  background: #0c1018;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  margin-bottom: 8px;
}
.person input {
  accent-color: var(--accent);
}
#joinScreen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.join-card {
  width: min(420px, 100%);
}
.join-card label,
.sheet-panel label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin: 12px 0 6px;
}
.join-card input,
.sheet-panel input[type="text"],
#groupTitle,
#joinName,
#joinCode {
  width: 100%;
  padding: 12px;
  min-height: 48px;
  border: 1px solid var(--border2);
  border-radius: 12px;
  background: #05070a;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
#joinBtn,
#createGroupBtn {
  width: 100%;
  margin-top: 16px;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: #16233c;
  color: #cfe0ff;
  font-weight: 700;
  font-size: 1rem;
}
.err {
  color: #f7768e;
  margin-top: 10px;
  font-size: 0.86rem;
}
.split-drag {
  display: none;
  flex: 0 0 8px;
  cursor: col-resize;
  background: var(--border);
  z-index: 3;
}
.split-drag:hover,
.split-drag.dragging {
  background: var(--accent);
}
.vid-box { position: relative; }
.pip-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  z-index: 2;
  border: none;
  border-radius: 8px;
  background: rgba(10, 12, 16, 0.72);
  color: #cfe0ff;
  font-size: 0.78rem;
  padding: 4px 8px;
  cursor: pointer;
  font-family: inherit;
}
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #000c;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
#lbStage {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#lbStage img,
#lbStage video {
  max-width: 96%;
  max-height: 96%;
  object-fit: contain;
  cursor: default;
}
#lbBar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: #111;
}
#lbBar button,
#lbBar a {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  background: #1a2230;
  color: #cfe0ff;
  font-family: inherit;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
#lbName {
  flex: 1;
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (min-width: 900px) {
  #mainScreen {
    flex-direction: row;
  }
  .split-drag { display: block; }
  #inboxPane {
    flex: 0 0 var(--inbox-w, 320px);
    width: var(--inbox-w, 320px);
    min-width: 200px;
    max-width: 60vw;
    border-right: none;
    display: flex !important;
  }
  #threadPane {
    display: flex !important;
  }
  #threadPane.empty-desk {
    align-items: center;
    justify-content: center;
    color: #5a6478;
  }
  #threadPane.empty-desk footer,
  #threadPane.empty-desk #thread,
  #threadPane.empty-desk .thread-top {
    display: none;
  }
  .back {
    display: none;
  }
  #thread {
    padding: 18px 22px 24px;
  }
  .msg-wrap {
    max-width: 68%;
  }
}
