:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1f232c;
  --line: #2a2f3a;
  --text: #e9ebf0;
  --dim: #9aa3b2;
  --accent: #7b8cde;
  --danger: #e5484d;
  --radius: 16px;
}
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel2: #eceef2;
  --line: #dde1e8;
  --text: #16181d;
  --dim: #667085;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
.ic { width: 22px; height: 22px; flex: none; }

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- shell ---------- */
.shell { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.main { flex: 1; min-height: 0; display: flex; }
.pane { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page { flex: 1; overflow-y: auto; padding-bottom: 24px; }
.page-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  position: sticky; top: 0; z-index: 2;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.page-head h1 { font-size: 22px; flex: 1; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:hover { background: var(--panel2); }

.nav {
  display: flex; background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand { display: none; }
.nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 7px; color: var(--dim); font-size: 11px;
}
.nav button.on { color: var(--accent); }

.shell.has-view .pane-list, .shell.has-view .nav { display: none; }
.shell:not(.has-view) .pane-detail { display: none; }
.empty { flex: 1; display: grid; place-items: center; color: var(--dim); padding: 24px; text-align: center; }

@media (min-width: 900px) {
  .shell { flex-direction: row; }
  .nav {
    order: -1; flex-direction: column; width: 210px; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 18px 10px;
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; padding: 4px 12px 16px; }
  .nav .brand img { width: 30px; height: 30px; }
  .nav button {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    padding: 10px 12px; border-radius: 10px; font-size: 15px;
  }
  .nav button.on { background: var(--panel2); }
  .shell.has-view .pane-list, .shell.has-view .nav { display: flex; }
  .shell:not(.has-view) .pane-detail { display: flex; }
  .pane-list { flex: 0 0 400px; border-right: 1px solid var(--line); }
}

/* ---------- shared pieces ---------- */
.av {
  --s: 40px;
  width: var(--s); height: var(--s); border-radius: 50%; flex: none;
  display: inline-grid; place-items: center;
  background: var(--c, var(--accent)); color: #fff;
  font-weight: 600; font-size: calc(var(--s) * 0.42);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600;
}
.btn.quiet { background: var(--panel2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.wide { width: 100%; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.section-title { padding: 18px 16px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px;
  background: var(--panel2); border: 1px solid var(--line); font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.field { display: block; padding: 0 16px 14px; }
.field > span { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
.field .with-assist { display: flex; gap: 8px; align-items: flex-start; }
.input {
  width: 100%; padding: 11px 12px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); outline: none; resize: vertical;
}
.input:focus { border-color: var(--accent); }
.assist {
  flex: none; width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; background: var(--panel2); color: var(--accent);
}
.switch { position: relative; width: 46px; height: 28px; border-radius: 999px; background: var(--line); flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }
.rowline {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.rowline .grow { flex: 1; min-width: 0; }
.rowline .grow b { display: block; font-weight: 600; }
.rowline .grow span { display: block; color: var(--dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--panel2); color: var(--dim); }

/* ---------- login and pin ---------- */
.center { flex: 1; display: grid; place-items: center; padding: 24px; }
.login { width: min(360px, 100%); display: grid; gap: 12px; }
.login-logo { width: 76px; height: 76px; justify-self: center; }
.login h1 { font-size: 34px; text-align: center; margin-bottom: 4px; letter-spacing: -0.03em; }
.login p { text-align: center; color: var(--dim); margin-bottom: 12px; }
.pin { display: grid; gap: 22px; justify-items: center; }
.pin-dots { display: flex; gap: 14px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--dim); }
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-dots.bad { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; }
.keys button { height: 72px; border-radius: 50%; background: var(--panel2); font-size: 24px; }
.keys button:active { background: var(--line); }

/* ---------- feed ---------- */
.post { margin: 0 12px 12px; padding: 14px; }
.post header { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.post header b { display: block; }
.post p { margin: 10px 0; white-space: pre-wrap; }
.post-img { height: 200px; border-radius: 12px; background-size: cover; background-position: center; margin-bottom: 10px; }
.post footer { display: flex; gap: 18px; color: var(--dim); }
.post footer button { display: flex; align-items: center; gap: 6px; color: inherit; }
.post footer button.on { color: #e5484d; }
.post footer button.on .ic { fill: currentColor; }
.comments { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; display: grid; gap: 8px; }
.comment { display: flex; gap: 8px; font-size: 14px; }
.comment b { margin-right: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form .input { padding: 8px 12px; border-radius: 999px; }

/* ---------- profile, world ---------- */
.cover { height: 150px; background-size: cover; background-position: center; position: relative; }
.cover .icon-btn { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 10px; background: rgba(0, 0, 0, .45); color: #fff; }
.profile-top { padding: 0 16px 14px; margin-top: -34px; position: relative; }
.profile-top .av { border: 4px solid var(--bg); }
.profile-top h2 { margin-top: 8px; }
.profile-actions { display: flex; gap: 10px; margin-top: 12px; }
.place {
  position: relative; display: block; width: calc(100% - 24px); margin: 0 12px 12px; height: 130px;
  border-radius: var(--radius); overflow: hidden; text-align: left; color: #fff;
  background-size: cover; background-position: center;
}
.place::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top, rgba(0, 0, 0, .8), transparent 65%); }
.place > div { position: absolute; left: 14px; right: 14px; bottom: 12px; z-index: 1; }
.place b { font-size: 17px; display: block; }
.place > div > span { font-size: 13px; opacity: .85; }
.faces { display: flex; margin-top: 6px; }
.faces .av { margin-right: -6px; border: 2px solid rgba(0, 0, 0, .5); }

/* ---------- chat ---------- */
.chat { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.bg, .bg-fade { position: absolute; inset: 0; }
.bg { background-repeat: no-repeat; background-color: #000; }
.bg-fade {
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, .5) 0, rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, .1) 38%, rgba(0, 0, 0, .78) 66%, #000 96%);
}
.mode-off .bg, .mode-off .bg-fade { display: none; }
.mode-clear .bg-fade { display: none; }
.mode-clear .bg { position: fixed; z-index: 40; }
.mode-clear > :not(.bg):not(.bg-toggle) { visibility: hidden; }

/* The toggle keeps the same place in all three modes. */
.bg-toggle {
  position: absolute; z-index: 41; top: calc(10px + env(safe-area-inset-top)); right: 10px;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; gap: 0;
  background: rgba(20, 22, 28, .6); color: #fff; backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, .18);
}
.bg-toggle .ic { width: 20px; height: 20px; grid-area: 1 / 1; margin-top: -6px; }
.bg-toggle .dots { grid-area: 1 / 1; display: flex; gap: 3px; margin-top: 24px; }
.bg-toggle .dots i { width: 4px; height: 4px; border-radius: 50%; background: rgba(255, 255, 255, .35); }
.bg-toggle .dots i.on { background: #fff; }

.chat-head, .cast, .msgs, .composer, .chat .chips, .hint { position: relative; z-index: 1; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 62px 10px 8px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title b, .chat-head .title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title span { font-size: 13px; color: var(--dim); }

.cast { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.cast .people { display: flex; gap: 10px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.cast .people button { display: grid; justify-items: center; gap: 2px; font-size: 11px; color: var(--dim); }
.cast .people button:active .av { transform: scale(.92); }
.cast .auto { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }

.msgs { flex: 1; overflow-y: auto; padding: 14px 12px 6px; display: flex; flex-direction: column; gap: 6px; }
.msgs::before { content: ""; flex: 1; }
.row { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.row.mine { justify-content: flex-end; }
.wrap { max-width: min(78%, 520px); display: grid; justify-items: start; }
.row.mine .wrap { justify-items: end; }
.who { font-size: 12px; color: var(--dim); margin: 0 0 2px 10px; }
.bubble {
  text-align: left; padding: 9px 13px; border-radius: 18px; border-bottom-left-radius: 6px;
  background: var(--panel2); white-space: pre-wrap; overflow-wrap: anywhere;
}
.row.mine .bubble { background: var(--accent); color: #fff; border-radius: 18px; border-bottom-right-radius: 6px; }
.bubble.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; }
.msg-actions button {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 13px;
}
.msg-actions .ic { width: 16px; height: 16px; }
.sys { align-self: center; text-align: center; font-size: 13px; color: var(--dim); padding: 6px 12px; max-width: 86%; }
.typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.hint { text-align: center; font-size: 13px; color: var(--dim); padding: 0 12px 6px; }
.composer {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.composer .input { border-radius: 999px; padding: 10px 14px; }
.composer .send { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.composer .assist { border-radius: 50%; }

/* Over a picture: light text, see-through surfaces. */
.mode-fade { --text: #fff; --dim: #cfd3dc; --line: rgba(255, 255, 255, .16); color: #fff; }
.mode-fade .chat-head, .mode-fade .cast { background: transparent; border-color: transparent; }
.mode-fade .bubble { background: rgba(22, 24, 30, .72); backdrop-filter: blur(6px); }
.mode-fade .row.mine .bubble { background: color-mix(in srgb, var(--accent) 88%, transparent); }
.mode-fade .composer { background: transparent; border-color: transparent; }
.mode-fade .composer .input, .mode-fade .chip, .mode-fade .assist, .mode-fade .msg-actions button {
  background: rgba(22, 24, 30, .72); border-color: rgba(255, 255, 255, .16); backdrop-filter: blur(6px);
}
.mode-fade .icon-btn { color: #fff; }

/* Adjusting the picture: everything steps aside except the picture and its panel. */
.adjusting .msgs, .adjusting .composer, .adjusting .cast, .adjusting .chips, .adjusting .hint { visibility: hidden; }
.adjusting .bg-fade { display: none; }
.adjusting .bg { z-index: 2; cursor: grab; touch-action: none; }
.adjusting .bg:active { cursor: grabbing; }
.adjust {
  position: absolute; z-index: 3; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  padding: 12px; display: grid; gap: 12px; color: var(--text);
  background: rgba(20, 22, 28, .9); border-color: rgba(255, 255, 255, .16); backdrop-filter: blur(10px); color: #fff;
}
.adjust .thumbs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.adjust .thumbs button {
  flex: none; width: 64px; height: 64px; border-radius: 10px; background-size: cover; background-position: center;
  border: 2px solid transparent; display: grid; place-items: center; background-color: rgba(255, 255, 255, .1); color: #fff;
}
.adjust .thumbs button.on { border-color: #fff; }
.adjust label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.adjust input[type="range"] { flex: 1; accent-color: var(--accent); }
.adjust .foot { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.adjust .foot span { flex: 1; opacity: .8; }

/* ---------- misc pages ---------- */
.persona-card { margin: 0 12px; padding: 16px; display: flex; gap: 14px; align-items: center; }
.policy { padding: 0 18px 30px; user-select: none; -webkit-user-select: none; color: var(--dim); }
.policy h3 { color: var(--text); margin: 18px 0 6px; font-size: 16px; }
.policy p { margin-bottom: 10px; }
.pad { padding: 0 16px 16px; }
.setup-top { height: 180px; background-size: cover; background-position: center; position: relative; }
.setup-top .icon-btn { position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 10px; background: rgba(0, 0, 0, .45); color: #fff; }
