:root {
  color-scheme: light;
  --bg: #f4f4f5;
  --surface: #ffffff;
  --ink: #111111;
  --muted: #6b6b6b;
  --line: #e4e4e7;
  --tile: #ececec;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  accent-color: #111111;
  --ok: #111111;
  --danger: #111111;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f0f10;
    --surface: #1a1a1c;
    --ink: #f5f5f5;
    --muted: #a1a1aa;
    --line: #2e2e32;
    --tile: #2a2a2e;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    accent-color: #f5f5f5;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; overflow-x: clip; }
body {
  margin: 0;
  overflow-wrap: anywhere;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
img, svg { max-width: 100%; }
a:link, a:visited { color: inherit; }
label { color: var(--muted); }
p a, .status a, .meta a, .lead a, .callout a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
button, input, textarea, select { font: inherit; font-size: 16px; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
::selection { background: var(--ink); color: var(--bg); }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 10px;
  z-index: 40;
}
.skip:focus { top: calc(8px + env(safe-area-inset-top)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  text-decoration: none;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-size: 18px;
}
.mark { width: 28px; height: 28px; display: block; flex: none; }
.tabs { display: none; gap: 4px; }
.tabs a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
}
.tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); }
.spacer { margin-left: auto; }

button:not(.backdrop), .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
  cursor: pointer;
}
.btn:active, button:not(.backdrop):active { transform: scale(0.98); }
.btn.secondary, button.secondary, button.ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
a.btn:link, a.btn:visited { color: var(--bg); }
a.btn.secondary:link, a.btn.secondary:visited { color: var(--ink); }
.login { min-width: 84px; }
button.ghost { width: auto; padding: 0 14px; }

.account { position: relative; }
.account summary {
  list-style: none;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 14px;
}
.account summary::-webkit-details-marker { display: none; }
.sheet {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: min(280px, calc(100vw - 24px));
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 32;
  display: grid;
  max-height: min(70dvh, 420px);
  overflow: auto;
}
.sheet a, .sheet button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}
.sheet a:hover, .sheet button:hover, .sheet a:focus-visible, .sheet button:focus-visible {
  background: var(--tile);
}
.sheet-name { margin: 4px 12px 8px; font-weight: 650; }
.backdrop { display: none; }

.wrap {
  width: min(880px, 100%);
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}
.foot {
  display: none;
}

h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.04em; margin: 8px 0; }
h2 { font-size: 18px; letter-spacing: -0.02em; margin: 0 0 8px; }
.lead, .meta { color: var(--muted); }
.lead { margin-top: 0; }
.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.callout {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--tile);
  color: var(--ink);
}
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 14px 0;
}
.stack { display: grid; gap: 10px; }
.field { display: grid; gap: 6px; }
label { color: var(--muted); font-size: 14px; }
input:-webkit-autofill, textarea:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--bg) inset;
}
input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  caret-color: var(--ink);
}
textarea { min-height: 120px; resize: vertical; }
.secret { display: flex; gap: 8px; align-items: center; }
.secret input { flex: 1; min-width: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.count {
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.count b { display: block; font-size: 24px; letter-spacing: -0.04em; }
.narrow { width: min(440px, 100%); margin: 12px auto; min-width: 0; }
.codebox { display: grid; gap: 8px; max-width: 100%; min-width: 0; }
.codebox .secondary { justify-self: start; }
pre.card {
  max-width: 100%;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
a.cta-primary {
  width: 100%;
  min-height: 56px;
  margin: 4px 0 16px;
  font-size: 18px;
  font-weight: 700;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--tile);
  flex: none;
  filter: grayscale(1);
}
.avatar.lg { width: 88px; height: 88px; border-radius: 24px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.people, .threads, .sessions { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.person, .thread-link, .session {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  text-decoration: none;
}
.person p, .thread-link p, .session p { margin: 0; overflow-wrap: anywhere; }
.person[aria-current="page"], .thread-link[aria-current="page"] { outline: 2px solid var(--ink); }

.profile { display: grid; justify-items: start; gap: 8px; }
.profile .avatar.lg { margin-bottom: 4px; }

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin: 0 0 14px;
  animation: arrive 0.35s ease;
}
.msg-main { min-width: 0; max-width: min(100%, 520px); }
.msg-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }
.msg-top .name { font-weight: 650; }
.msg-top time { color: var(--muted); font-size: 13px; }
.bubble {
  margin: 0;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}
.msg.creator .bubble { background: var(--ink); color: var(--bg); border-color: transparent; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-top { justify-content: flex-end; }
.empty { color: var(--muted); text-align: center; padding: 32px 12px; }

.sk {
  height: 72px;
  margin: 0 0 12px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--line), var(--surface), var(--line));
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
}

.page-chat { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.page-chat .topbar { position: relative; }
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; width: min(760px, 100%); margin: 0 auto; }
.thread { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { padding: 12px 16px 0; }
.hero h1 { font-size: 26px; letter-spacing: -0.04em; margin: 0 0 6px; }
.subline { margin: 0 0 8px; font-size: 17px; }
.hero .btn { margin: 8px 0 4px; }
.mention { font-weight: 700; }
.quote { margin: 0 0 6px; padding-left: 8px; border-left: 2px solid var(--line); color: var(--muted); font-size: 14px; }
.reacts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.reacts button { min-height: 36px; padding: 0 8px; background: transparent; color: var(--ink); border: 1px solid var(--line); }
.status { margin: 4px 0 0; color: var(--muted); }
.log {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 16px;
}
.dock {
  flex: none;
  padding: 8px 12px calc(76px + env(safe-area-inset-bottom) + var(--kb, 0px));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(16px);
}
.composer { display: flex; gap: 8px; align-items: center; }
.composer input { flex: 1; min-width: 0; background: var(--surface); }
.watch {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.inbox { display: grid; gap: 12px; }
.conversation .thread-log { display: grid; gap: 8px; margin: 12px 0; }
.back { display: inline-flex; align-items: center; min-height: 44px; }

.qr svg { width: min(220px, 100%); height: auto; background: #fff; border-radius: 12px; }
.codes { padding-left: 1.2rem; }
.codes code { letter-spacing: 0.04em; }
.row-actions { display: flex; gap: 8px; align-items: center; }
.toast {
  position: fixed;
  z-index: 40;
  top: calc(72px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow);
}
.toast-err { background: var(--surface); color: var(--ink); border: 1px solid var(--ink); }
.form-error {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--ink);
  border-radius: 12px;
  color: var(--ink);
}
.picture { min-height: 88px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 18;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11px;
  border-radius: 12px;
}
.tabbar a[aria-current="page"] { color: var(--ink); font-weight: 650; }
.tabbar svg { width: 22px; height: 22px; }

@media (max-width: 799px) {
  .account[open] .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
    min-height: 100%;
    width: 100%;
  }
  .account[open] .sheet {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    z-index: 31;
  }
  .inbox.has-thread .inbox-list { display: none; }
  .inbox:not(.has-thread) .conversation { display: none; }
  html.keyboard .tabbar { transform: translateY(110%); }
  html.keyboard .dock { padding-bottom: calc(8px + var(--kb, 0px)); }
}

@media (min-width: 800px) {
  .tabs { display: flex; }
  .tabbar { display: none; }
  .wrap { padding: 28px 24px 64px; }
  .foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: min(880px, calc(100% - 48px));
    margin: 0 auto 28px;
    color: var(--muted);
    font-size: 14px;
  }
  .foot a { color: var(--muted); display: inline-flex; align-items: center; min-height: 44px; }
  .page-chat .dock { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .inbox { grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
  .inbox.has-thread .inbox-list, .inbox .conversation { display: block; }
}

@keyframes arrive {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .sk, .btn, button { animation: none; transition: none; }
  .log { scroll-behavior: auto; }
}
