:root {
  --bg: #080808;
  --panel: #0e0e0e;
  --panel2: #141414;
  --panel3: #1b1b1b;
  --line: #222;
  --line2: #333;
  --line3: #4a4a4a;
  --text: #e8e8e8;
  --soft: #bdbdbd;
  --mute: #8c8c8c;
  --dim: #5e5e5e;
  --white: #f4f4f4;
  --danger: #c9c9c9;
  --font: 'Schibsted Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
::selection { background: #e8e8e8; color: #080808; }
:focus-visible { outline: 1px solid var(--white); outline-offset: 2px; }

* { scrollbar-width: thin; scrollbar-color: #333 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2c2c2c; }
::-webkit-scrollbar-thumb:hover { background: #444; }

svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; flex: none; }

/* ---------- shared controls ---------- */

.btn {
  background: var(--white); color: #080808; font-weight: 600; padding: 10px 18px;
  border: 1px solid var(--white); transition: background .12s, color .12s;
}
.btn:hover { background: #fff; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line3); }
.btn.ghost:hover { border-color: var(--soft); background: var(--panel3); }
.btn.small { padding: 6px 12px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { color: var(--mute); font-size: 13px; }
.input, .field input, .field textarea {
  width: 100%; background: #0a0a0a; border: 1px solid var(--line2); padding: 10px 12px; color: var(--text);
  transition: border-color .12s;
}
.field textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.input:focus, .field input:focus, .field textarea:focus { border-color: var(--soft); outline: none; }
.hint { color: var(--dim); font-size: 12px; }
.form-err { color: var(--soft); font-size: 13px; min-height: 18px; margin: -4px 0 12px; }
.form-err:not(:empty)::before { content: ''; display: inline-block; width: 6px; height: 6px; background: var(--white); margin-right: 8px; }

.check { display: flex; align-items: center; gap: 10px; color: var(--soft); cursor: pointer; user-select: none; margin-bottom: 18px; }
.check input { appearance: none; width: 16px; height: 16px; border: 1px solid var(--line3); background: #0a0a0a; display: grid; place-items: center; margin: 0; cursor: pointer; flex: none; }
.check input:checked { background: var(--white); border-color: var(--white); }
.check input:checked::after { content: ''; width: 8px; height: 8px; background: #080808; }

.avatar {
  width: 36px; height: 36px; flex: none; position: relative; background: var(--panel3); color: var(--soft);
  display: grid; place-items: center; font-weight: 600; font-size: 14px; overflow: hidden; border: 1px solid var(--line);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sz-28 { width: 28px; height: 28px; font-size: 12px; }
.avatar.sz-44 { width: 44px; height: 44px; font-size: 16px; }
.avatar.sz-96 { width: 96px; height: 96px; font-size: 34px; }
.avatar.sz-128 { width: 128px; height: 128px; font-size: 44px; }
.dot { position: absolute; right: 0; bottom: 0; width: 9px; height: 9px; background: var(--white); border: 2px solid var(--bg); display: none; }
.has-dot.on .dot { display: block; }

/* ---------- auth ---------- */

.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background:
    linear-gradient(var(--bg), transparent 30%, transparent 70%, var(--bg)),
    repeating-linear-gradient(0deg, transparent 0 47px, #121212 47px 48px),
    repeating-linear-gradient(90deg, transparent 0 47px, #121212 47px 48px),
    var(--bg);
  overflow: auto;
}
.auth-box { width: min(400px, 100%); }
.wordmark { font-size: 64px; font-weight: 700; letter-spacing: -0.045em; line-height: 1; margin: 0 0 10px; color: var(--white); display: flex; align-items: flex-end; }
.wordmark::after { content: ''; width: 0.3em; height: 0.12em; background: var(--white); margin: 0 0 0.1em 0.12em; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .wordmark::after { animation: none; } }
.tagline { color: var(--mute); margin: 0 0 28px; max-width: 30ch; }
.auth-card { border: 1px solid var(--line2); background: rgba(10, 10, 10, .92); padding: 22px; }
.tabs { display: flex; border-bottom: 1px solid var(--line2); margin: -22px -22px 22px; }
.tabs button { flex: 1; padding: 14px; color: var(--mute); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs button.on { color: var(--white); border-bottom-color: var(--white); }
.auth-card .btn { width: 100%; padding: 12px; }

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

.shell { display: grid; grid-template-columns: 64px minmax(0, 1fr); height: 100dvh; }
.rail { border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 2px; background: var(--bg); }
.rail .logo { width: 28px; height: 28px; margin: 6px 0 16px; background: var(--white); flex: none; }
.rail .tab {
  width: 64px; height: 52px; display: grid; place-items: center; color: var(--dim); position: relative; transition: color .12s;
}
.rail .tab:hover { color: var(--soft); }
.rail .tab.on { color: var(--white); background: var(--panel2); }
.rail .tab.on::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--white); }
.rail .spacer { flex: 1; }
.rail .tab .badge { position: absolute; top: 9px; right: 14px; }
.badge { min-width: 17px; height: 17px; padding: 0 5px; background: var(--white); color: #080808; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.panel { flex: 1; min-height: 0; display: none; }
.panel.on { display: flex; }
.scroll { overflow-y: auto; min-height: 0; }

/* ---------- chat ---------- */

.chat { display: grid; grid-template-columns: 300px minmax(0, 1fr); width: 100%; }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.side-top { padding: 18px 18px 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.side-top .wm { font-size: 22px; font-weight: 700; letter-spacing: -0.04em; }
.side-sec { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 6px; color: var(--dim); font-size: 12.5px; font-weight: 500; }
.icon-btn { width: 28px; height: 28px; display: grid; place-items: center; color: var(--mute); }
.icon-btn:hover { color: var(--white); background: var(--panel3); }
.conv { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 18px; text-align: left; position: relative; color: var(--soft); }
.conv:hover { background: var(--panel); }
.conv.on { background: var(--panel2); color: var(--white); }
.conv.on::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px; background: var(--white); }
.conv .ctitle { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.conv.unread .ctitle { color: var(--white); font-weight: 600; }
.conv .glyph { width: 36px; height: 36px; display: grid; place-items: center; background: var(--panel3); border: 1px solid var(--line); color: var(--soft); flex: none; }
.empty-note { color: var(--dim); padding: 6px 18px; font-size: 13px; }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 0 20px; height: 64px; border-bottom: 1px solid var(--line); flex: none; }
.thread-head .back { display: none; }
.thread-head .ttl { flex: 1; min-width: 0; }
.thread-head .ttl b { display: block; font-size: 16px; font-weight: 600; color: var(--white); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-head .ttl span { color: var(--mute); font-size: 12.5px; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0 18px; min-height: 0; }
.notice { display: flex; align-items: center; gap: 10px; margin: 14px 20px 6px; padding: 10px 12px; border: 1px solid var(--line); color: var(--mute); font-size: 12.5px; }
.notice svg { width: 15px; height: 15px; }
.msg { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; padding: 1px 20px; transition: opacity .6s; }
.msg.first { margin-top: 16px; }
.msg .gutter { width: 36px; }
.msg .who { display: flex; align-items: baseline; gap: 10px; }
.msg .who button { font-weight: 600; color: var(--soft); }
.msg .who button:hover { color: var(--white); text-decoration: underline; }
.msg.me .who button { color: var(--white); }
.msg .when { color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.msg .body { color: #d4d4d4; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg .body a { color: var(--white); text-decoration: underline; text-underline-offset: 2px; }
.empty-thread { margin: auto; text-align: center; color: var(--dim); padding: 40px 20px; }

.composer { padding: 14px 20px 18px; flex: none; position: relative; }
.composer-box { display: flex; align-items: flex-end; border: 1px solid var(--line2); background: #0a0a0a; transition: border-color .12s; }
.composer-box:focus-within { border-color: var(--line3); }
.composer textarea { flex: 1; resize: none; background: none; border: 0; outline: 0; padding: 13px 14px; max-height: 160px; line-height: 1.45; min-height: 46px; }
.composer textarea::placeholder { color: var(--dim); }
.composer .cbtn { width: 46px; height: 46px; display: grid; place-items: center; color: var(--mute); flex: none; }
.composer .cbtn:hover { color: var(--white); }
.composer .send { background: var(--white); color: #080808; }
.composer .send:hover { background: #fff; color: #000; }
.composer .send:disabled { background: var(--panel3); color: var(--dim); cursor: default; }

.emoji-pop {
  position: absolute; right: 20px; bottom: calc(100% - 8px); width: 330px; max-width: calc(100% - 40px);
  background: var(--panel); border: 1px solid var(--line3); z-index: 20; display: none; box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.emoji-pop.on { display: block; }
.emoji-cats { display: flex; border-bottom: 1px solid var(--line2); overflow-x: auto; }
.emoji-cats button { padding: 10px 12px; color: var(--mute); font-size: 13px; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.emoji-cats button.on { color: var(--white); border-bottom-color: var(--white); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); padding: 6px; max-height: 220px; overflow-y: auto; }
.emoji-grid button { height: 38px; font-size: 22px; line-height: 1; font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }
.emoji-grid button:hover { background: var(--panel3); }

/* ---------- page ---------- */

.page { width: 100%; padding: 28px 32px 40px; overflow-y: auto; }
.page h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; margin: 0 0 4px; color: var(--white); }
.page .sub { color: var(--mute); margin: 0 0 24px; }

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

.profile-form { max-width: 460px; }
.pfp-row { display: flex; align-items: center; gap: 20px; margin-bottom: 26px; }
.pfp-row .btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.profile-actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.counter { text-align: right; color: var(--dim); font-size: 12px; }

/* ---------- modal / toast ---------- */

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .72); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(440px, 100%); max-height: min(640px, 90dvh); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line3); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--line2); }
.modal-head b { font-size: 16px; font-weight: 600; color: var(--white); }
.modal-body { padding: 18px 20px; overflow-y: auto; min-height: 0; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line2); display: flex; justify-content: flex-end; gap: 10px; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 8px 10px; }
.pick:hover { background: var(--panel3); }
.pick .nm { flex: 1; min-width: 0; }
.pick .nm b { display: block; font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .nm span { color: var(--mute); font-size: 12.5px; }
.pick .box { width: 16px; height: 16px; border: 1px solid var(--line3); flex: none; display: grid; place-items: center; }
.pick.sel .box { background: var(--white); border-color: var(--white); }
.pick.sel .box::after { content: ''; width: 8px; height: 8px; background: #080808; }
.pick-list { margin: 10px -10px 0; }
.card-profile { text-align: center; padding: 6px 0 4px; }
.card-profile .avatar { margin: 0 auto 14px; }
.card-profile h3 { margin: 0; font-size: 20px; font-weight: 700; color: var(--white); }
.card-profile .un { color: var(--mute); margin-bottom: 14px; }
.card-profile p { color: var(--soft); margin: 0 0 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--white); color: #080808; padding: 10px 16px; font-weight: 500; z-index: 80; max-width: calc(100% - 32px); }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .rail { order: 2; flex-direction: row; border-right: 0; border-top: 1px solid var(--line); padding: 0 0 env(safe-area-inset-bottom); justify-content: space-around; }
  .rail .logo, .rail .spacer { display: none; }
  .rail .tab { flex: 1; width: auto; height: 54px; }
  .rail .tab.on::before { left: 0; right: 0; top: 0; bottom: auto; width: auto; height: 2px; }
  .stage { order: 1; }
  .chat { grid-template-columns: 1fr; }
  .shell[data-mview="list"] .thread { display: none; }
  .shell[data-mview="chat"] .sidebar { display: none; }
  .thread-head .back { display: grid; margin-left: -8px; }
  .thread-head { padding: 0 12px 0 16px; }
  .msg { padding: 1px 14px; }
  .composer { padding: 10px 12px 12px; }
  .page { padding: 22px 16px 32px; }
  .wordmark { font-size: 52px; }
}
