:root {
  --ui-ink: #121212;
  --muted: #5f5f5f;
  --muted-2: #6a6a6a;
  --line: #e4e2dd;
  --line-soft: #eeece8;
  --field: #f7f6f3;
  --bubble: #f1f0ec;
  --ok: #1f8a5b;
  --gutter: clamp(16px, 4vw, 56px);
  --card-shadow: 0 1px 2px rgba(18, 18, 18, 0.06), 0 24px 64px rgba(18, 18, 18, 0.2);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --font: Geist, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ui-ink);
  background: #121212;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { display: inline-flex; flex: none; }
.icon svg { display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes drift { from { transform: scale(1); } to { transform: scale(1.03); } }
@keyframes sweep { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes reveal { from { opacity: 0; filter: blur(6px); transform: translateY(4px); } to { opacity: 1; filter: none; transform: none; } }
@keyframes bounce { 0%, 80%, 100% { transform: none; opacity: 0.35; } 40% { transform: translateY(-3px); opacity: 1; } }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- Stage: the full-screen colour field with the greeting ---------- */

.stage {
  position: relative;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ground, #121212);
  color: var(--stage-ink, #fff);
  transition: background-color 1.1s ease, color 1.1s ease;
}
.posters { position: absolute; inset: 0; pointer-events: none; }
.poster { position: absolute; inset: 0; background: var(--p-ground); opacity: 0; transition: opacity 1.1s ease; }
.poster.on { opacity: 1; }

/* The greeting sits whole in the free area, scaled to fit its width and height. */
.word-box { position: absolute; display: flex; align-items: center; justify-content: center; }
.word {
  --fw: var(--fit);
  --fh: var(--lh);
  font-size: min(var(--max), calc(var(--aw) / var(--fw)), calc(var(--ah) / var(--fh)));
  line-height: 1.1;
  white-space: nowrap;
  color: var(--p-ink);
  animation: drift 18s ease-in-out infinite alternate;
}

.split { --aw: calc(100vw - 2 * var(--gutter) - 448px); --ah: calc(100dvh - 176px); --max: 520px; }
.split .word-box { top: 96px; bottom: 80px; left: calc(var(--gutter) + 448px); right: var(--gutter); }

@media (min-width: 900px) {
  .word.vertical { writing-mode: vertical-rl; --fw: 1.15; --fh: var(--fit); }
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 20px var(--gutter) 0;
}
.mark { font-size: 26px; font-weight: 600; letter-spacing: -0.035em; line-height: 44px; color: inherit; text-decoration: none; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.navlink { height: 44px; padding: 0 12px; border: none; border-radius: 999px; background: none; font-size: 15px; font-weight: 500; }
.navlink:hover { text-decoration: underline; text-underline-offset: 4px; }
.pill {
  position: relative;
  height: 44px;
  margin-left: 4px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}
.pill:hover { background: color-mix(in srgb, currentColor 12%, transparent); }
.pill:focus-within { outline: 2px solid currentColor; outline-offset: 3px; }
/* Invisible itself, but its open list is drawn by the browser from these colours, not the pill's. */
.overlay-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; color: var(--ui-ink); background: #fff; color-scheme: light; }
.overlay-select option { color: var(--ui-ink); background: #fff; }

.center { position: relative; z-index: 2; flex: 1; display: flex; align-items: center; padding: 28px var(--gutter); }

.bottombar {
  position: relative;
  z-index: 2;
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 0 var(--gutter) 18px;
  font-size: 14px;
  font-weight: 500;
}
.dots { display: flex; margin-left: -19px; }
.dot { width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center; border: none; background: none; }
.dot span { display: block; width: 6px; height: 6px; border-radius: 999px; background: currentColor; opacity: 0.45; transition: width 0.4s ease, opacity 0.4s ease; }
.dot.on span { width: 22px; opacity: 1; }

/* ---------- Card ---------- */

.card {
  width: 100%;
  max-width: 384px;
  padding: 28px;
  background: #fff;
  color: var(--ui-ink);
  border-radius: 22px;
  box-shadow: var(--card-shadow);
  animation: rise 0.5s var(--ease) both;
}
.stack { display: flex; flex-direction: column; gap: 22px; }
.intro { display: flex; flex-direction: column; gap: 10px; }
.card h1 { margin: 0; font-size: 28px; line-height: 1.25; font-weight: 600; letter-spacing: -0.02em; white-space: pre-line; }
.lede { margin: 0; font-size: 15px; line-height: 1.6; color: var(--muted); }
.fields { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.control {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
  font-size: 16px;
  font-weight: 500;
  color: var(--ui-ink);
}
.control:focus { outline: 2px solid var(--ui-ink); outline-offset: 2px; }
.select-wrap { position: relative; display: block; }
.select-wrap select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer; }
.select-wrap .icon { position: absolute; right: 14px; top: 15px; pointer-events: none; color: var(--muted); }
.hint { font-size: 12px; font-weight: 400; color: var(--muted-2); }
.btn {
  height: 52px;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.16s ease;
}
.btn-primary { border: none; background: var(--ui-ink); color: #fff; }
.btn-primary:hover { background: #2b2b2b; color: #fff; }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-primary:focus-visible { outline-color: var(--ui-ink); }
.btn-outline { border: 1.5px solid var(--ui-ink); background: #fff; color: var(--ui-ink); }
.btn-outline:hover { background: var(--field); }
.btn-sm { height: 44px; width: auto; padding: 0 16px; font-size: 14px; }
.fine { margin: -8px 0 0; text-align: center; font-size: 12px; color: var(--muted-2); }
.form-error { margin: -8px 0 0; font-size: 13px; color: #b42318; }
.form-error:empty { display: none; }

.from { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; font-size: 14px; font-weight: 500; color: #3d3d3d; }
.avatar {
  width: 40px;
  height: 40px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--a-ground);
  color: var(--a-ink);
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
}
.avatar.sm { width: 36px; height: 36px; font-size: 15px; }
.pair {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--field);
  font-size: 13px;
  font-weight: 500;
  color: #3d3d3d;
}

/* ---------- Info sheet ---------- */

dialog.sheet {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 24px 28px 28px;
  border: none;
  border-radius: 22px;
  box-shadow: var(--card-shadow);
  color: var(--ui-ink);
  animation: rise 0.35s var(--ease) both;
}
dialog.sheet::backdrop { background: rgba(18, 18, 18, 0.5); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.sheet p, .sheet li { font-size: 15px; line-height: 1.6; color: #3d3d3d; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; }
.sheet h3 { margin: 22px 0 0; font-size: 16px; font-weight: 600; }
.sheet > p { margin: 0 0 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }
.nav .nav-compact { display: none; }
.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  text-decoration: none;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 8%, transparent); }

/* ---------- Chat ---------- */

.stage-chat {
  height: var(--app-h, 100dvh);
  min-height: 0;
  --aw: calc(100vw - 2 * var(--gutter) - 584px);
  --ah: calc(100dvh - 176px);
  --max: 420px;
}
.stage-chat .word-box { top: 96px; bottom: 80px; left: calc(var(--gutter) + 584px); right: var(--gutter); }
.chat-wrap { position: relative; z-index: 2; flex: 1; min-height: 0; display: flex; padding: 20px var(--gutter); }
.chat {
  position: relative;
  width: 100%;
  max-width: 520px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  color: var(--ui-ink);
  border-radius: 22px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
  animation: rise 0.5s var(--ease) both;
}
.chat-head { display: flex; align-items: center; gap: 12px; padding: 14px 10px 14px 20px; border-bottom: 1px solid var(--line-soft); }
.avatars { display: flex; }
.avatars .avatar + .avatar { margin-left: -12px; box-shadow: 0 0 0 2px #fff; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.who-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 600; }
.who-sub { display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; font-size: 13px; color: var(--muted); }
.presence { width: 7px; height: 7px; flex: none; border-radius: 999px; background: #b5b2ab; }
.presence.on { background: var(--ok); }
.chat-body { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; background: #fff; }

.list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 20px 12px; display: flex; flex-direction: column; }
.row { display: flex; flex-direction: column; margin-top: 18px; }
.row:first-child { margin-top: 0; }
.row.same { margin-top: 6px; }
.row.me { align-items: flex-end; }
.row.them { align-items: flex-start; }
.row.new { animation: pop 0.3s var(--ease) both; }
.bubble { max-width: 82%; margin: 0; padding: 11px 16px; border-radius: 20px; font-size: 15px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble p { margin: 0; }
.me .bubble { background: var(--ui-ink); color: #fff; border-bottom-right-radius: 6px; }
.me .bubble.sending { opacity: 0.6; }
.them .bubble { background: var(--bubble); border-bottom-left-radius: 6px; }
.bubble.pending {
  color: var(--muted);
  background: linear-gradient(100deg, var(--bubble) 35%, #fbfaf7 50%, var(--bubble) 65%);
  background-size: 300% 100%;
  animation: sweep 1.5s linear infinite;
}
.reveal { animation: reveal 0.7s var(--ease) both; }
.orig { margin-top: 10px; padding-top: 10px; border-top: 1px solid #dedcd6; animation: pop 0.3s var(--ease) both; }
.orig-label { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); }
.bubble .orig-text { margin-top: 4px; font-size: 14px; color: #3d3d3d; }
.meta { display: inline-flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.meta-btn { min-height: 32px; margin: 2px 0 0 -4px; padding: 0 4px; border: none; background: none; font-size: 12px; color: var(--muted); }
.meta-btn:hover { color: var(--ui-ink); }
.meta-link { margin: -8px -4px; padding: 8px 4px; border: none; background: none; font-size: 12px; font-weight: 600; color: var(--ui-ink); text-decoration: underline; text-underline-offset: 3px; }
.bell { position: relative; }
.bell.on::after { content: ''; position: absolute; top: 11px; right: 11px; width: 8px; height: 8px; border-radius: 999px; background: var(--ok); box-shadow: 0 0 0 2px #fff; }

.recent { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-soft); }
.recent h2 { margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.recent ul { margin: 0; padding: 0; list-style: none; }
.recent a { min-height: 48px; margin: 0 -10px; padding: 0 10px; display: flex; align-items: center; gap: 12px; border-radius: 12px; color: var(--ui-ink); text-decoration: none; }
.recent a:hover { background: var(--field); }
.recent-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 500; }
.recent-time { flex: none; font-size: 12px; color: var(--muted-2); }
.sender { margin: 0 0 4px 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.sys { align-self: center; margin: 0 0 6px; padding: 7px 14px; border-radius: 999px; background: var(--field); font-size: 12px; line-height: 1.5; color: var(--muted); text-align: center; }
.dots3 { display: inline-flex; gap: 3px; }
.dots3 i { width: 4px; height: 4px; border-radius: 999px; background: currentColor; animation: bounce 1.2s ease-in-out infinite; }
.dots3 i:nth-child(2) { animation-delay: 0.15s; }
.dots3 i:nth-child(3) { animation-delay: 0.3s; }

.share { margin: 16px 16px 0; padding: 20px; display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--field); animation: pop 0.3s var(--ease) both; }
.share h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.share p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--muted); }
.linkbox { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.linkbox > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 500; }
.waiting { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500; color: #3d3d3d; }
.pulse { width: 8px; height: 8px; border-radius: 999px; background: var(--ok); animation: pulse 1.6s ease-in-out infinite; }

.typing { padding: 0 26px 6px; font-size: 12px; color: var(--muted); }
.banner { margin: 0 16px 6px; padding: 10px 14px; border: 1px solid #efddb8; border-radius: 14px; background: #fbf3e4; font-size: 13px; line-height: 1.45; color: #4a3a1a; }
.composer { display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line-soft); }
.composer-row { display: flex; align-items: center; gap: 8px; }
.composer input { flex: 1; min-width: 0; height: 48px; padding: 0 18px; border: 1px solid var(--line); border-radius: 999px; background: var(--field); font-size: 16px; color: var(--ui-ink); }
.composer input:focus { outline: 2px solid var(--ui-ink); outline-offset: 2px; }
.composer .hint { display: flex; align-items: center; gap: 6px; padding-left: 18px; }
.send { width: 48px; height: 48px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 999px; background: var(--ui-ink); color: #fff; }
.send:hover { background: #2b2b2b; }
.send:focus-visible { outline-color: var(--ui-ink); }
.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 5;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ui-ink);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transform: translateX(-50%);
}
.mobile-only { display: none; }

/* ---------- Smaller screens ---------- */

@media (max-width: 1099px) {
  .stage-chat .word-box { display: none; }
  .chat-wrap { justify-content: center; }
}

@media (max-width: 899px) {
  .split { --aw: calc(100vw - 2 * var(--gutter)); --ah: 22dvh; --max: 240px; }
  .split .word-box { top: 76px; bottom: auto; height: 22dvh; left: var(--gutter); right: var(--gutter); }
  .split .center { align-items: flex-end; justify-content: center; padding-top: calc(22dvh + 24px); }
  .split .card { max-width: 440px; }
  .split .bottombar { display: none; }
  .nav .navlink { padding: 0 8px; }
}

@media (max-width: 560px) {
  .nav .navlink { display: none; }
  .nav .nav-compact { display: inline-flex; }
  .mark { font-size: 24px; }
}

@media (max-width: 720px) {
  .stage-chat .topbar, .stage-chat .bottombar, .stage-chat .posters { display: none; }
  .chat-wrap { padding: 0; }
  .chat { max-width: none; border-radius: 0; box-shadow: none; background: var(--ground); animation: none; }
  .chat-head { padding: max(14px, env(safe-area-inset-top)) 6px 18px 16px; border-bottom: none; color: var(--stage-ink); }
  .chat-head .avatar { background: var(--stage-ink); color: var(--ground); }
  .bell.on::after { box-shadow: 0 0 0 2px var(--ground); }
  .avatars .avatar + .avatar { box-shadow: 0 0 0 2px var(--ground); }
  .chat-head .who-sub { color: inherit; }
  .chat-body { border-radius: 22px 22px 0 0; }
  .list { padding: 18px 16px 12px; }
  .bubble { max-width: 86%; }
  .composer { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .mobile-only { display: inline-flex; }
  .card { padding: 24px; }
  .card h1 { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
